Revision 1234

View differences:

org.gvsig.seismic/tags/org.gvsig.seismic-1.0.238/org.gvsig.seismic/org.gvsig.seismic.app/org.gvsig.seismic.app.geoprocess/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.seismic.geoprocess.convexhull.NewConvexHullLibrary
2
org.gvsig.seismic.geoprocess.pointtoline.PointToLineLibrary
org.gvsig.seismic/tags/org.gvsig.seismic-1.0.238/org.gvsig.seismic/org.gvsig.seismic.app/org.gvsig.seismic.app.geoprocess/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
  <id>gvsig-plugin-package</id>
3
  <formats>
4
    <format>zip</format>
5
  </formats>
6
  <baseDirectory>${project.artifactId}</baseDirectory>
7
  <includeBaseDirectory>true</includeBaseDirectory>
8
  <files>
9
    <file>
10
      <source>target/${project.artifactId}-${project.version}.jar</source>
11
      <outputDirectory>lib</outputDirectory>
12
    </file>
13
    <file>
14
      <source>target/package.info</source>
15
    </file>
16
  </files>
17

  
18
  <fileSets>
19
    <fileSet>
20
      <directory>src/main/resources-plugin</directory>
21
      <outputDirectory>.</outputDirectory>
22
    </fileSet>
23
  </fileSets>
24

  
25
  <dependencySets>
26
    <dependencySet>
27
      <useProjectArtifact>false</useProjectArtifact>
28
      <useTransitiveDependencies>false</useTransitiveDependencies>
29
      <outputDirectory>lib</outputDirectory>
30
      <includes>
31
      	<include>org.gvsig:org.gvsig.seismic.geoprocess.convexhull</include>
32
        <include>org.gvsig:org.gvsig.seismic.geoprocess.pointtoline</include>
33
        <include>org.gvsig:org.gvsig.seismic.lib.api</include>
34
        <include>org.gvsig:org.gvsig.seismic.swing.api</include>
35
        <include>org.gvsig:org.gvsig.seismic.lib.impl</include>
36
        <include>org.gvsig:org.gvsig.seismic.swing.impl</include>
37
        <include>org.gvsig:org.gvsig.seismic.provider</include>
38
      </includes>
39
    </dependencySet>
40
  </dependencySets>
41

  
42
</assembly>
0 43

  
org.gvsig.seismic/tags/org.gvsig.seismic-1.0.238/org.gvsig.seismic/org.gvsig.seismic.app/org.gvsig.seismic.app.geoprocess/src/main/java/org/gvsig/seismic/geoprocess/convexhull/NewConvexHullParametersPanel.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.seismic.geoprocess.convexhull;
25

  
26
import java.awt.BorderLayout;
27
import java.awt.Color;
28
import java.awt.Dimension;
29
import java.awt.GridBagConstraints;
30
import java.awt.GridBagLayout;
31
import java.awt.Insets;
32
import java.awt.ScrollPane;
33
import java.awt.event.ActionEvent;
34
import java.awt.event.ActionListener;
35
import java.awt.event.ItemEvent;
36
import java.awt.event.ItemListener;
37
import java.awt.event.MouseEvent;
38
import java.awt.event.MouseListener;
39
import java.util.ArrayList;
40
import java.util.List;
41

  
42
import javax.swing.AbstractButton;
43
import javax.swing.BorderFactory;
44
import javax.swing.BoxLayout;
45
import javax.swing.ButtonGroup;
46
import javax.swing.ComboBoxModel;
47
import javax.swing.DefaultComboBoxModel;
48
import javax.swing.JButton;
49
import javax.swing.JComboBox;
50
import javax.swing.JLabel;
51
import javax.swing.JPanel;
52
import javax.swing.JRadioButton;
53
import javax.swing.border.EmptyBorder;
54
import javax.swing.border.TitledBorder;
55

  
56
import org.gvsig.fmap.dal.exception.DataException;
57
import org.gvsig.fmap.dal.feature.FeatureStore;
58
import org.gvsig.fmap.dal.feature.FeatureType;
59
import org.gvsig.geoprocess.lib.api.GeoProcessLocator;
60
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer;
61
import org.gvsig.geoprocess.sextante.gui.algorithm.AlgorithmOutputPanel;
62
import org.gvsig.tools.dataTypes.DataTypes;
63

  
64
import es.unex.sextante.core.GeoAlgorithm;
65
import es.unex.sextante.core.ObjectAndDescription;
66
import es.unex.sextante.core.OutputObjectsSet;
67
import es.unex.sextante.core.ParametersSet;
68
import es.unex.sextante.core.Sextante;
69
import es.unex.sextante.dataObjects.IVectorLayer;
70
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel;
71
import es.unex.sextante.gui.algorithm.OutputChannelSelectionPanel;
72
import es.unex.sextante.gui.core.SextanteGUI;
73
import es.unex.sextante.outputs.Output;
74

  
75
public class NewConvexHullParametersPanel extends GeoAlgorithmParametersPanel implements ActionListener, MouseListener {
76
	
77
	/**
78
	 * 
79
	 */
80
	private static final long serialVersionUID = 7681551721513083013L;
81
	
82
	private GeoAlgorithm                     m_Algorithm        = null;
83
	private List<JComboBox>                  groupingFields     = null;
84
	private JComboBox                        layersCombo        = null;
85
	private AlgorithmOutputPanel             output             = null;
86

  
87
	private OutputChannelSelectionPanel      outputChannelSelectionPanel;
88
	private JPanel                           outputPanel;
89

  
90
	private JRadioButton joinByField = null;
91

  
92
	private JPanel fieldContainer;
93

  
94
	private JButton addButton;
95
	private JButton removebutton;
96
	
97
	private JLabel groupLabel = null;
98
	private JRadioButton selectedFeatures;
99

  
100
	private JRadioButton allFeatures;
101
	private ButtonGroup bg;
102
	
103
	public NewConvexHullParametersPanel() {
104
		super();
105
	}
106

  
107
    public void init(GeoAlgorithm algorithm) {
108
    	m_Algorithm         = algorithm;
109
    	groupingFields     = new ArrayList<JComboBox>();
110

  
111
    	initGUI();
112
    	reloadFields();
113
    	updateComponents();
114
    }
115
    
116
	private void initGUI() {
117
		this.setLayout(new BorderLayout());
118
		groupLabel = new JLabel();
119
		
120
		JPanel pan = new JPanel();
121
		GridBagLayout gbl = new GridBagLayout();
122
		pan.setLayout(gbl);
123
		pan.setBorder(BorderFactory.createLineBorder(Color.gray));
124
		
125
		GridBagConstraints gbc = new GridBagConstraints();
126
		gbc.fill = GridBagConstraints.HORIZONTAL;
127
		gbc.weightx = 1.0;
128
		gbc.gridx = 0;
129
		gbc.insets = new Insets(0, 4, 4, 4);
130
		
131
		gbc.gridy = 0;		
132
		JPanel fileContainer0 = new JPanel();
133
		fileContainer0.setPreferredSize(new Dimension(fileContainer0.getWidth(),65));
134
		fileContainer0.setLayout(new BoxLayout(fileContainer0,BoxLayout.Y_AXIS));
135
		fileContainer0.setBorder(new TitledBorder("Entrada"));
136
		fileContainer0.add(getComboPanel(GeoProcessLocator.getGeoProcessManager().getTranslation("grouping_layer"), getLayers1Combo()));
137
		pan.add(fileContainer0, gbc);
138
		
139
		
140
		gbc.gridy = 1;		
141
		JPanel p = new JPanel();
142
		p.setLayout(new BorderLayout());
143
		p.setBorder(new TitledBorder("Opciones"));
144
		
145
		p.add(getChecks(),BorderLayout.WEST);
146
		p.add(getButtons(),BorderLayout.EAST);
147
		
148
		fieldContainer = new JPanel();
149
		GridBagLayout gbl2 = new GridBagLayout();
150
		fieldContainer.setLayout(gbl2);
151
		//fieldContainer.setPreferredSize(new Dimension(fileContainer0.getWidth(),65));
152
		fieldContainer.setLayout(new BoxLayout(fieldContainer,BoxLayout.Y_AXIS));
153
		fieldContainer.add(getFieldComboPanel());
154
		
155
		p.add(fieldContainer, BorderLayout.SOUTH);
156
		
157
		pan.add(p, gbc);
158
		
159
		getFieldList(true);
160

  
161
		gbc.gridy = 5;
162
		JPanel fileContainer2 = new JPanel();
163
		fileContainer2.setPreferredSize(new Dimension(fileContainer0.getWidth(),65));
164
		fileContainer2.setLayout(new BoxLayout(fileContainer2,BoxLayout.Y_AXIS));
165
		fileContainer2.setBorder(new TitledBorder("Salida"));
166
		fileContainer2.add(getOutputChannelSelectionPanel());
167
		pan.add(fileContainer2, gbc);
168
		
169
		ScrollPane scroll = new ScrollPane();
170
		scroll.setPreferredSize(new Dimension(scroll.getWidth(), 250));
171
		scroll.add(pan);
172
		this.add(scroll, BorderLayout.CENTER);
173
	}
174
	
175
	private JPanel getChecks() {
176
		JPanel p = new JPanel(new BorderLayout());
177
		p.setPreferredSize(new Dimension(300,50));
178
		p.add(getAllCheckBox(), BorderLayout.NORTH);
179
		p.add(getSelectedCheckBox(), BorderLayout.CENTER);
180
		p.add(getCheckBox(), BorderLayout.SOUTH);
181
		
182
		bg = new ButtonGroup();
183
		bg.add(getAllCheckBox());
184
		bg.add(getSelectedCheckBox());
185
		bg.add(getCheckBox());
186
		
187
		return p;
188
	}
189

  
190
	private JPanel getButtons() {
191
		JPanel p = new JPanel();
192
		p.setBorder(new EmptyBorder(25, 0, 0, 0));
193
		p.add(getAddButton(),BorderLayout.WEST);
194
		p.add(getRemoveButton(),BorderLayout.EAST);
195
		return p;
196
	}
197

  
198
	private JRadioButton getCheckBox() {
199
		if(this.joinByField == null){
200
			this.joinByField = new JRadioButton(GeoProcessLocator.getGeoProcessManager().getTranslation("Option"));
201
			this.joinByField.setSelected(false);
202
			this.joinByField.addItemListener(new ItemListener() {
203
				public void itemStateChanged(ItemEvent arg0) {
204
					updateComponents();
205
				}
206
			});
207
		}
208
		return joinByField;
209
	}
210
	
211
	private void updateComponents() {
212
		for(int i=0; i<groupingFields.size();i++){
213
			groupingFields.get(i).setEnabled(joinByField.isSelected());
214
		}
215
		getAddButton().setEnabled(joinByField.isSelected());
216
		getRemoveButton().setEnabled(joinByField.isSelected());
217
		groupLabel.setEnabled(joinByField.isSelected());
218
	}
219
	
220
	private JRadioButton getAllCheckBox() {
221
		if(this.allFeatures == null){
222
			this.allFeatures = new JRadioButton(GeoProcessLocator.getGeoProcessManager().getTranslation("All_geometries_convex_hull"));
223
			this.allFeatures.setSelected(true);
224
			this.allFeatures.addItemListener(new ItemListener() {
225
				public void itemStateChanged(ItemEvent arg0) {
226
					updateComponents();
227
				}
228
			});
229
		}
230
		return allFeatures;
231
	}
232
	
233
	private JRadioButton getSelectedCheckBox() {
234
		if(this.selectedFeatures == null){
235
			this.selectedFeatures = new JRadioButton(GeoProcessLocator.getGeoProcessManager().getTranslation("Selected_geometries_convex_hull"));
236
			this.selectedFeatures.setSelected(false);
237
			this.selectedFeatures.addItemListener(new ItemListener() {
238
				public void itemStateChanged(ItemEvent arg0) {
239
					updateComponents();
240
				}
241
			});
242
		}
243
		return selectedFeatures;
244
	}
245
	
246
	private JButton getRemoveButton() {
247
		if(removebutton == null){
248
			removebutton = new JButton("-");
249
			removebutton.setPreferredSize(new Dimension(25,25));
250
			removebutton.addActionListener(new ActionListener() {
251
				public void actionPerformed(ActionEvent arg0) {
252
					if(fieldContainer.getComponentCount()>1){
253
						fieldContainer.remove(fieldContainer.getComponentCount()-1);
254
						groupingFields.remove(groupingFields.size()-1);
255
						refreshPanel();
256
					}
257
				}
258
			});
259
		}
260
		return removebutton;
261
	}
262

  
263
	private AbstractButton getAddButton() {
264
		if(addButton == null){
265
			addButton = new JButton("+");
266
			addButton.setPreferredSize(new Dimension(25,25));
267
			addButton.addActionListener(new ActionListener() {
268
				public void actionPerformed(ActionEvent arg0) {
269
					fieldContainer.add(getFieldComboPanel());
270
					refreshPanel();
271
				}
272
			});
273
		}
274
		return addButton;
275
	}
276
	
277
	private void refreshPanel() {
278
		fieldContainer.repaint();
279
		fieldContainer.revalidate();
280
	}
281
	/**
282
	 * Gets the output panel (SEXTANTE)
283
	 * @return
284
	 */
285
	private JPanel getOutputChannelSelectionPanel() {
286
		if(outputPanel == null) {
287
			try {
288
				outputPanel = new JPanel();
289
				outputPanel.setLayout(new BorderLayout());
290
				final OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
291
				final Output out = ooSet.getOutput(ConvexHullAlgorithm.RESULT);
292
				outputChannelSelectionPanel = new OutputChannelSelectionPanel(out, m_Algorithm.getParameters());
293
				outputPanel.add(new JLabel("Capa de salida [Vectorial]    "), BorderLayout.WEST);
294
				outputPanel.add(outputChannelSelectionPanel, BorderLayout.CENTER);
295
			} catch (final Exception e) {
296
				Sextante.addErrorToLog(e);
297
			}
298
		}
299
		return outputPanel;
300
	}
301
	
302
	/**
303
	 * Gets the output panel (DAL)
304
	 * @return
305
	 */
306
	@SuppressWarnings("unused")
307
	private AlgorithmOutputPanel getAlgorithmOutputPanel() {
308
		if(output == null) {
309
			output = new AlgorithmOutputPanel();
310
		}
311
		return output;
312
	}
313
	
314
	public JPanel getComboPanel(String text, JComboBox combo) {
315
		JPanel panel = new JPanel();
316
		GridBagLayout gbl = new GridBagLayout();
317
		panel.setLayout(gbl);
318

  
319
		GridBagConstraints gbc = new GridBagConstraints();
320
		gbc.fill = GridBagConstraints.NONE;
321
		gbc.weightx = 0;
322
		gbc.gridx = 0;
323
		gbc.insets = new Insets(0, 2, 0, 5);
324
		JLabel label = new JLabel(text);
325
		label.setPreferredSize(new Dimension(180, 18));
326
		panel.add(label, gbc);
327

  
328
		gbc.fill = GridBagConstraints.HORIZONTAL;
329
		gbc.weightx = 1.0;
330
		gbc.gridx = 1;
331
		gbc.anchor = GridBagConstraints.EAST;
332
		gbc.insets = new Insets(0, 2, 0, 0);
333
		panel.add(combo, gbc);
334
		return panel;
335
	}
336
	
337
	/**
338
	 * Gets a new JPanel with the text and JComboBox 
339
	 * @param text
340
	 * @param combo
341
	 * @return
342
	 */
343
	public JPanel getFieldComboPanel() {
344
		JPanel panel = new JPanel();
345
		GridBagLayout gbl = new GridBagLayout();
346
		panel.setLayout(gbl);
347

  
348
		GridBagConstraints gbc = new GridBagConstraints();
349
		gbc.fill = GridBagConstraints.NONE;
350
		gbc.weightx = 0;
351
		gbc.gridx = 0;
352
		gbc.insets = new Insets(0, 2, 0, 5);
353
		JLabel label = new JLabel();
354
		if(groupingFields.size()==0){
355
			label = groupLabel;
356
			label.setText(GeoProcessLocator.getGeoProcessManager().getTranslation("grouping_field"));
357
		}
358
		
359
		label.setPreferredSize(new Dimension(180,25));
360
		panel.add(label, gbc);
361

  
362
		gbc.fill = GridBagConstraints.HORIZONTAL;
363
		gbc.weightx = 1.0;
364
		gbc.gridx = 1;
365
		gbc.anchor = GridBagConstraints.EAST;
366
		gbc.insets = new Insets(0, 2, 0, 0);
367
		panel.add(createFieldCombo(), gbc);
368
		return panel;
369
	}
370
	
371
	/**
372
	 * Gets a ComboBox
373
	 * @return
374
	 */
375
	private JComboBox createFieldCombo() {
376
		JComboBox groupingField = new JComboBox();
377
		groupingField.setPreferredSize(new Dimension(0, 18));
378
		ComboBoxModel comboModel = new DefaultComboBoxModel(getFieldList(false).toArray());
379
		groupingField.setModel(comboModel);
380
		groupingField.addActionListener(this);
381
		groupingFields.add(groupingField);
382
		
383
		return groupingField;
384
	}
385
	
386
	
387
	
388
	/**
389
	 * Gets a ComboBox
390
	 * @return
391
	 */
392
	public JComboBox getLayers1Combo() {
393
		if(layersCombo == null) {
394
			layersCombo = new JComboBox();
395
			layersCombo.setPreferredSize(new Dimension(0, 18));
396
			ComboBoxModel comboModel = new DefaultComboBoxModel(getLayerList());
397
			layersCombo.setModel(comboModel);
398
			layersCombo.addActionListener(this);
399
		}
400
		return layersCombo;
401
	}
402
	
403
	
404
	
405
	
406
	//------------------------------------------------------------
407
	
408
	private void reloadFields() {
409
		List<String> list = getFieldList(false);
410
		for(int j=0; j<groupingFields.size(); j++){
411
			groupingFields.get(j).removeAllItems();
412
			for (int i = 0; i < list.size(); i++) {
413
				groupingFields.get(j).addItem(list.get(i));
414
			}
415
		}
416
	}
417
	
418
	/**
419
	 * Gets the selected vector layer in the JComboBox
420
	 * @return
421
	 */
422
	private IVectorLayer getSelectedVectorLayer() {
423
		if(layersCombo.getSelectedItem() != null)
424
			return (IVectorLayer)((ObjectAndDescription)layersCombo.getSelectedItem()).getObject();
425
		return null;
426
	}
427
	
428
	public void actionPerformed(ActionEvent e) {
429
		if(e.getSource() == getLayers1Combo()) {
430
			reloadFields();
431
		}
432
		
433
		if(e.getSource() instanceof JComboBox) {
434
			
435
			((JComboBox)e.getSource()).setEnabled(false);
436
			((JComboBox)e.getSource()).setEnabled(true);
437
		}
438
	}
439

  
440
	
441
	@Override
442
	public void assignParameters() {
443
		try {
444
			ParametersSet params = m_Algorithm.getParameters();
445
			params.getParameter(ConvexHullAlgorithm.LAYER).setParameterValue(getSelectedVectorLayer());
446
			params.getParameter(ConvexHullAlgorithm.FIELD).setParameterValue(getFieldsFilter());
447
			params.getParameter(ConvexHullAlgorithm.OPTION).setParameterValue((boolean)getCheckBox().isSelected());
448
			
449
			params.getParameter(ConvexHullAlgorithm.CHECK).setParameterValue((boolean)getSelectedCheckBox().isSelected());
450
			params.getParameter(ConvexHullAlgorithm.ALLCHECK).setParameterValue((boolean)getAllCheckBox().isSelected());
451
			
452
			OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
453
			Output out = ooSet.getOutput(ConvexHullAlgorithm.RESULT);
454
	        out.setOutputChannel(outputChannelSelectionPanel.getOutputChannel());
455
		} catch (Exception e) {
456
			Sextante.addErrorToLog(e);
457
        }
458
	}
459

  
460

  
461
	private List<String> getFieldsFilter() {
462
		List<String> fields = new ArrayList<String>();
463
		for(int i=0; i < groupingFields.size(); i++){
464
			fields.add((String)groupingFields.get(i).getSelectedItem());
465
		}
466
		return fields;
467
	}
468

  
469
	@Override
470
	public void setOutputValue(String arg0, String arg1) {
471
		
472
	}
473

  
474
	@Override
475
	public void setParameterValue(String arg0, String arg1) {
476
		
477
	}
478
	
479
	/**
480
	 * Gets the input layer list
481
	 * @return
482
	 */
483
	private ObjectAndDescription[] getLayerList() {
484
		IVectorLayer[] layers = SextanteGUI.getInputFactory()
485
					.getVectorLayers(IVectorLayer.SHAPE_TYPE_WRONG);
486
		ObjectAndDescription[] oad = new ObjectAndDescription[layers.length];
487
		for (int i = 0; i < layers.length; i++)
488
			oad[i] = new ObjectAndDescription(layers[i].getName(), layers[i]);
489
		return oad;
490
	}
491
	
492
	/**
493
	 * Gets the field list of the selected layer
494
	 * @return
495
	 */
496
	public List<String> getFieldList(boolean withGroupingField) {
497
		IVectorLayer layer = getSelectedVectorLayer();
498
		List<String> data = new ArrayList<String>();
499
		
500
		int indexGeom = -1;
501
		FeatureStore fs = ((FlyrVectIVectorLayer)layer).getFeatureStore();
502
		FeatureType ftype = null;
503
		try {
504
			ftype = fs.getDefaultFeatureType();
505
			if(ftype != null)
506
				indexGeom = ftype.getDefaultGeometryAttributeIndex();
507
		} catch (DataException e) {
508
			return data;
509
		}
510
		
511
		String groupingField = null;
512
		for(int k=0;k<groupingFields.size();k++){
513
			if(withGroupingField) {
514
				groupingField = (String)groupingFields.get(k).getSelectedItem();
515
			}
516
			
517
			for (int i = 0; i < layer.getFieldCount(); i++) {
518
				if(i != indexGeom && ftype.getAttributeDescriptor(i).getDataType().getType() != DataTypes.TIME) {
519
					if(groupingField == null || !groupingField.equals(layer.getFieldName(i)))
520
						data.add(layer.getFieldName(i));
521
				}
522
			}
523
		}
524
		return data;
525
	}
526
	
527

  
528
	
529
	public void mouseClicked(MouseEvent e) {
530
 	}
531

  
532
	public void mouseEntered(MouseEvent e) {
533
	}
534

  
535
	public void mouseExited(MouseEvent e) {
536
	}
537

  
538
	public void mousePressed(MouseEvent e) {
539
	}
540

  
541
	public void mouseReleased(MouseEvent e) {
542
	}
543

  
544
}
0 545

  
org.gvsig.seismic/tags/org.gvsig.seismic-1.0.238/org.gvsig.seismic/org.gvsig.seismic.app/org.gvsig.seismic.app.geoprocess/src/main/java/org/gvsig/seismic/geoprocess/convexhull/NewConvexHullLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.seismic.geoprocess.convexhull;
25

  
26
import org.gvsig.geoprocess.algorithm.base.core.AlgorithmAbstractLibrary;
27
import org.gvsig.geoprocess.algorithm.convexhull.ConvexHullLibrary;
28
import org.gvsig.i18n.Messages;
29
import org.gvsig.tools.library.LibraryException;
30

  
31
/**
32
 * Initialization of ConvexHullLibrary library.
33
 * 
34
 * @author <a href="mailto:jbadia@scolab.es">Jose Badia</a>
35
 */
36
public class NewConvexHullLibrary extends AlgorithmAbstractLibrary {
37

  
38
	@Override
39
	public void doRegistration() {
40
		require(ConvexHullLibrary.class);
41
	}
42
	
43
    @Override
44
    protected void doInitialize() throws LibraryException {
45

  
46
    }
47

  
48
    @Override
49
    protected void doPostInitialize() throws LibraryException {
50
        Messages.addResourceFamily(
51
            "org.gvsig.seismic.geoprocess.convexhull.convexhull",
52
            NewConvexHullLibrary.class.getClassLoader(), NewConvexHullLibrary.class
53
                .getClass().getName());
54
        registerGeoProcess(new ConvexHullAlgorithm());
55
    }
56

  
57
}
0 58

  
org.gvsig.seismic/tags/org.gvsig.seismic-1.0.238/org.gvsig.seismic/org.gvsig.seismic.app/org.gvsig.seismic.app.geoprocess/src/main/java/org/gvsig/seismic/geoprocess/convexhull/ConvexHullOperation.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/* CVS MESSAGES:
25
*
26
* $Id: ScalableConvexHullVisitor.java 10626 2007-03-06 16:55:54Z caballero $
27
* $Log$
28
* Revision 1.2  2007-03-06 16:47:58  caballero
29
* Exceptions
30
*
31
* Revision 1.1  2006/06/20 18:20:45  azabala
32
* first version in cvs
33
*
34
* Revision 1.2  2006/06/02 18:21:28  azabala
35
* *** empty log message ***
36
*
37
* Revision 1.1  2006/05/24 21:13:31  azabala
38
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
39
*
40
* Revision 1.3  2006/03/15 18:31:06  azabala
41
* *** empty log message ***
42
*
43
* Revision 1.2  2006/03/07 21:01:33  azabala
44
* *** empty log message ***
45
*
46
* Revision 1.1  2006/03/06 19:48:39  azabala
47
* *** empty log message ***
48
*
49
* Revision 1.2  2006/03/05 19:57:48  azabala
50
* *** empty log message ***
51
*
52
* Revision 1.1  2006/02/17 16:32:50  azabala
53
* *** empty log message ***
54
*
55
*
56
*/
57
package org.gvsig.seismic.geoprocess.convexhull;
58

  
59
import com.vividsolutions.jts.geom.Geometry;
60
import com.vividsolutions.jts.geom.GeometryCollection;
61
import com.vividsolutions.jts.geom.GeometryFactory;
62

  
63
import es.unex.sextante.core.Sextante;
64

  
65
import org.gvsig.fmap.dal.exception.DataException;
66
import org.gvsig.fmap.dal.feature.FeatureStore;
67
import org.gvsig.fmap.geom.GeometryLocator;
68
import org.gvsig.fmap.geom.GeometryManager;
69
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
70
import org.gvsig.fmap.geom.operation.GeometryOperationException;
71
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
72
import org.gvsig.fmap.geom.operation.fromjts.FromJTS;
73
import org.gvsig.geoprocess.algorithm.base.util.GeometryUtil;
74

  
75
/**
76
 * Convex Hull operation
77
 * @author Nacho Brodin (nachobrodin@gmail.com)
78
 */
79
public class ConvexHullOperation {
80
	public static final String  NAME             = "ConvexHull";
81
	public static final int     CODE             = GeometryLocator.getGeometryManager().getGeometryOperationCode(NAME);
82
	Geometry                    geometry         = null;
83
	GeometryFactory             geomFact         = null;
84
	private GeometryManager     geometryManager  = null;
85
	
86
	public ConvexHullOperation() {
87
		geometry = null;
88
		geometryManager = GeometryLocator.getGeometryManager();
89
	}
90
	
91
	public void setFeatureStore(FeatureStore out, String[] attrNames) throws DataException {
92
	}
93
	
94
	/**
95
	 * Returns FMap convex hull geometry.
96
	 * @return
97
	 */
98
	public org.gvsig.fmap.geom.Geometry getGeometry() {
99
		if(geometry == null)
100
			return null;
101
		GeometryOperationContext ctx = new GeometryOperationContext();
102
		ctx.setAttribute(FromJTS.PARAM, geometry);
103
		try {
104
			return (org.gvsig.fmap.geom.Geometry)geometryManager.invokeOperation(FromJTS.NAME, ctx);
105
		} catch (GeometryOperationNotSupportedException e) {
106
			Sextante.addErrorToLog(e);
107
			return null;
108
		} catch (GeometryOperationException e) {
109
			Sextante.addErrorToLog(e);
110
			return null;
111
		}
112
	}
113

  
114
	
115
	public org.gvsig.fmap.geom.Geometry invoke(Geometry actualGeometry) {
116
		if(actualGeometry == null)
117
			return null;
118
		
119
		//com.vividsolutions.jts.geom.Geometry actualGeometry = GeometryUtil.geomToJTS(g);
120
		
121
		if(geometry == null)
122
			geometry = actualGeometry;
123
		else {
124
			com.vividsolutions.jts.geom.Geometry[] geoms = new com.vividsolutions.jts.geom.Geometry[2];
125
			geoms[0] = geometry;
126
			geoms[1] = actualGeometry;
127
			if(geomFact == null)
128
				geomFact = new GeometryFactory();
129
			GeometryCollection gc = geomFact.createGeometryCollection(geoms);
130
			geometry = gc.convexHull();	
131
		}
132
		return getGeometry();
133
	}
134

  
135
	/*
136
	 * (non-Javadoc)
137
	 * @see org.gvsig.fmap.geom.operation.GeometryOperation#getOperationIndex()
138
	 */
139
	public int getOperationIndex() {
140
		return CODE;
141
	}
142

  
143
}
144

  
0 145

  
org.gvsig.seismic/tags/org.gvsig.seismic-1.0.238/org.gvsig.seismic/org.gvsig.seismic.app/org.gvsig.seismic.app.geoprocess/src/main/java/org/gvsig/seismic/geoprocess/convexhull/ConvexHullAlgorithm.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.seismic.geoprocess.convexhull;
25

  
26
import java.util.ArrayList;
27
import java.util.HashMap;
28
import java.util.Iterator;
29
import java.util.List;
30
import java.util.Map;
31

  
32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.fmap.dal.feature.Feature;
34
import org.gvsig.fmap.dal.feature.FeatureQuery;
35
import org.gvsig.fmap.dal.feature.FeatureSelection;
36
import org.gvsig.fmap.dal.feature.FeatureSet;
37
import org.gvsig.fmap.dal.feature.FeatureStore;
38
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
39
import org.gvsig.geoprocess.algorithm.base.util.GeometryUtil;
40
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess;
41
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer;
42
import org.gvsig.tools.dataTypes.DataTypes;
43
import org.gvsig.tools.dispose.DisposableIterator;
44
import org.slf4j.Logger;
45
import org.slf4j.LoggerFactory;
46

  
47
import com.vividsolutions.jts.geom.Geometry;
48
import com.vividsolutions.jts.geom.GeometryFactory;
49

  
50
import es.unex.sextante.core.Sextante;
51
import es.unex.sextante.dataObjects.IFeature;
52
import es.unex.sextante.dataObjects.IFeatureIterator;
53
import es.unex.sextante.dataObjects.IVectorLayer;
54
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
55
import es.unex.sextante.exceptions.RepeatedParameterNameException;
56
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel;
57
import es.unex.sextante.outputs.OutputVectorLayer;
58

  
59
/**
60
 * Convex Hull Algorithm
61
 * 
62
 * @author Nacho Brodin (nachobrodin@gmail.com)
63
 * @author Jose Badia (jbadia@scolab.es)
64
 */
65
public class ConvexHullAlgorithm extends AbstractSextanteGeoProcess {
66
	private static final Logger log = LoggerFactory.getLogger(ConvexHullAlgorithm.class);
67
    public static final String LAYER = "LAYER";
68
    public static final String RESULT = "RESULT";
69
    public static final String CHECK = "CHECK";
70
    public static final String ALLCHECK = "ALLCHECK";
71
	public static final String FIELD = "FIELD";
72
	public static final String OPTION = "OPTION";
73

  
74
    public void defineCharacteristics() {
75
        setName(getTranslation("Convex Hull"));
76
        setGroup(getTranslation("basic_vect_algorithms"));
77
        // setGeneratesUserDefinedRasterOutput(false);
78
        try {
79
            m_Parameters.addInputVectorLayer(LAYER,
80
                getTranslation("Input_layer"), IVectorLayer.SHAPE_TYPE_WRONG,
81
                true);
82
            addOutputVectorLayer(RESULT, getTranslation("ConvexHull"),
83
                OutputVectorLayer.SHAPE_TYPE_POLYGON);
84
            m_Parameters.addBoolean(ALLCHECK,
85
                getTranslation("All_geometries_convex_hull"), true);
86
            m_Parameters.addBoolean(CHECK,
87
                    getTranslation("Selected_geometries_convex_hull"), false);
88
            m_Parameters.addMultipleInput(FIELD, getTranslation("Field"), DataTypes.STRING, true);
89
			m_Parameters.addBoolean(OPTION, getTranslation("Option"), false);
90
        } catch (RepeatedParameterNameException e) {
91
            Sextante.addErrorToLog(e);
92
        }
93
    }
94

  
95
    /*
96
     * (non-Javadoc)
97
     * 
98
     * @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm()
99
     */
100
    @SuppressWarnings("unchecked")
101
    public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
102
		if(existsOutPutFile(ConvexHullAlgorithm.RESULT, 0)) {
103
    		throw new GeoAlgorithmExecutionException(getTranslation("file_exists"));
104
    	}
105
		
106
        IVectorLayer input = m_Parameters.getParameterValueAsVectorLayer(LAYER);
107
        boolean allGeom = m_Parameters.getParameter(ALLCHECK).getParameterValueAsBoolean();
108
        boolean selectedGeom = m_Parameters.getParameter(CHECK).getParameterValueAsBoolean();
109
        boolean m_Option = m_Parameters.getParameterValueAsBoolean(OPTION);
110
	    List<String> m_Field = m_Parameters.getParameterValueAsArrayList(FIELD);
111
	    IVectorLayer output = null;
112
	    
113
	    if(allGeom || selectedGeom){
114
	    	// Caso de toda la feature o s?lo seleccionados
115
	    	 FeatureStore store = null;
116

  
117
	         if (input instanceof FlyrVectIVectorLayer){
118
	             store = ((FlyrVectIVectorLayer) input).getFeatureStore();
119
	    	}
120
	         else
121
	             return false;
122

  
123
	         ConvexHullOperation convexHullOperation = new ConvexHullOperation();
124

  
125
	         FeatureSet features = null;
126
	         try {
127
	             DisposableIterator it = null;
128
	             if (selectedGeom) {
129
	             	features = store.getFeatureSet();
130
	                 FeatureSelection ds = store.getFeatureSelection();
131
	                 it = ds.iterator();
132
	             } else {
133
	             	FeatureQuery query = getQueryFromAnalysisExtent(m_AnalysisExtent, store);
134
	                features = store.getFeatureSet(query);
135
	                it = features.iterator();
136
	             }
137

  
138
	             int numberOfFeatures = (int) features.getSize();
139
	             int iCount = 0;
140

  
141
	             while (it.hasNext()) {
142
	                 Feature feature = (Feature) it.next();
143
	                 List geomList = feature.getGeometries();
144
	                 setProgress(iCount, numberOfFeatures);
145
	                 iCount++;
146
	                 if (geomList == null) {
147
	                     org.gvsig.fmap.geom.Geometry geom = feature.getDefaultGeometry();
148
	                     if (geom != null)
149
	                         convexHullOperation.invoke(GeometryUtil.geomToJTS(geom));
150
	                     continue;
151
	                 }
152
	                 Iterator<Geometry> itGeom = geomList.iterator();
153
	                 while (itGeom.hasNext()) {
154
	                     Geometry g = itGeom.next();
155
	                     convexHullOperation.invoke(g);
156
	                 }
157
	             }
158
	             org.gvsig.fmap.geom.Geometry g = convexHullOperation.getGeometry();
159
	             if (g == null)
160
	                 return false;
161
	             String[] sNames = { "ID" };
162
	             Class[] types = { Integer.class };
163
	             output = getNewVectorLayer(RESULT, getTranslation("ConvexHull"),
164
	                     OutputVectorLayer.SHAPE_TYPE_POLYGON, types, sNames);
165

  
166
	             com.vividsolutions.jts.geom.Geometry jtsGeom =
167
	                 GeometryUtil.geomToJTS(g);
168

  
169
	             output.addFeature(jtsGeom, new Object[] { new Integer(0) });
170
	             it.dispose();
171
	         } catch (DataException e) {
172
	             log.error("", e);
173
	         } catch (CreateEnvelopeException e) {
174
	 			log.error("Error creating envelope", e);
175
	 		}
176
	         
177
	    }else{
178
	    	// Caso de elecci?n agrupando por campos
179
	    	String key = "";
180
	    	Map<String, ConvexHullOperation> convex = new HashMap<String, ConvexHullOperation>();
181
	    	Map<Object, Object[]> values = new HashMap<Object, Object[]>();
182

  
183
	    	List<Integer> fieldIndex = new ArrayList<Integer>(); 
184
	    	Iterator<String> itIndex = m_Field.iterator();
185
	    	while(itIndex.hasNext()){
186
	    		String f = (String) itIndex.next();
187
	    		fieldIndex.add(input.getFieldIndexByName(f));
188
	    	}
189

  
190
	    	if(m_Option){
191
	    		Class[] clss = new Class[fieldIndex.size()];
192
	    		String[] names = new String[fieldIndex.size()];
193
	    		for(int i=0; i<fieldIndex.size();i++){
194
	    			clss[i] = input.getFieldType(fieldIndex.get(i));
195
	    			names[i] = input.getFieldName(fieldIndex.get(i));
196
	    		}
197
	    		output = getNewVectorLayer(RESULT, getTranslation("ConvexHull"),
198
	    				OutputVectorLayer.SHAPE_TYPE_POLYGON, clss, names);
199
	    	}else{
200
	    		Class[] clss = {String.class};
201
	    		String[] names = {"gvSeismic_polygon"};
202
	    		output = getNewVectorLayer(RESULT, getTranslation("ConvexHull"),
203
	    				OutputVectorLayer.SHAPE_TYPE_POLYGON, clss, names);
204
	    	}
205

  
206
	    	final GeometryFactory gf = new GeometryFactory();
207
	    	int GEOMIndex = input.getFieldIndexByName("GEOM");
208

  
209
	    	if(m_Option){
210
	    		// HACK:
211
	    		// El campo GEOM es considerado entre los campos, pero no aparece como seleccionable
212
	    		// por lo que si el campo por el que agrupar est? por detr?s de ?l, hay que tenerlo
213
	    		// en cuenta
214
	    		for(int i=0; i<fieldIndex.size(); i++){
215
	    			System.out.print("\n             "+ fieldIndex.get(i) + " : "+ input.getFieldName(fieldIndex.get(i)));
216
	    			if(GEOMIndex != -1 && GEOMIndex < fieldIndex.get(i)){
217
	    				fieldIndex.set(i, fieldIndex.get(i)-1);
218
	    			}
219
	    		}
220
	    	}
221

  
222
	    	final IFeatureIterator iter = input.iterator();
223
	    	while(iter.hasNext()){
224
	    		IFeature feature = iter.next();
225
	    		key = "";  
226

  
227
	    		if(m_Option){
228
	    			for(int i=0; i<fieldIndex.size(); i++){
229
	    				if(!m_Field.isEmpty()){
230
	    					System.out.println("  "+ feature.getRecord().getValue(fieldIndex.get(i)));
231
	    					key += feature.getRecord().getValue(fieldIndex.get(i));
232
	    				}
233
	    			}
234
	    			if(m_Field.size()==0){
235
	    				key="(default)";
236
	    			}
237
	    		}else{
238
	    			key="(default)";
239
	    		}
240

  
241
	    		if(!convex.containsKey(key)){
242
	    			convex.put(key, new ConvexHullOperation());
243
	    			values.put(key, feature.getRecord().getValues());
244
	    		}
245

  
246
	    		Geometry geom = feature.getGeometry();
247
	    		if (geom != null){
248
	    			convex.get(key).invoke(geom);
249
	    		}
250
	    	}
251

  
252
	    	Iterator<String> itkeys = convex.keySet().iterator();
253
	    	while(itkeys.hasNext()){
254
	    		String k = (String) itkeys.next();
255
	    		org.gvsig.fmap.geom.Geometry g = convex.get(k).getGeometry();
256
	    		if (g != null){
257
	    			Object[] objs = new Object[fieldIndex.size()];
258
	    			for(int i=0; i<fieldIndex.size(); i++){
259
	    				objs[i] = values.get(k)[fieldIndex.get(i)];
260
	    			}
261
	    			com.vividsolutions.jts.geom.Geometry jtsGeom =
262
	    					GeometryUtil.geomToJTS(g);
263
	    			output.addFeature(jtsGeom, objs);
264
	    		}
265
	    	}
266

  
267
	    	output.setName("gvSeismic_convex");
268
	    }
269
	    
270
	    
271
        return !m_Task.isCanceled();
272
        
273
    }
274
    
275
	@Override
276
    public Class<? extends GeoAlgorithmParametersPanel> getCustomParametersPanelClass() {
277
        return NewConvexHullParametersPanel.class;
278
    }
279
    
280
}
0 281

  
org.gvsig.seismic/tags/org.gvsig.seismic-1.0.238/org.gvsig.seismic/org.gvsig.seismic.app/org.gvsig.seismic.app.geoprocess/src/main/java/org/gvsig/seismic/geoprocess/pointtoline/PointToLineLibrary.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.seismic.geoprocess.pointtoline;
25

  
26
import org.gvsig.geoprocess.algorithm.base.core.AlgorithmAbstractLibrary;
27
import org.gvsig.geoprocess.algorithm.convexhull.ConvexHullLibrary;
28
import org.gvsig.i18n.Messages;
29
import org.gvsig.tools.library.LibraryException;
30

  
31
/**
32
 * Initialization of PointToLineLibrary library.
33
 * 
34
 * @author <a href="mailto:jbadia@scolab.es">Jose Badia</a>
35
 */
36
public class PointToLineLibrary extends AlgorithmAbstractLibrary {
37

  
38
	@Override
39
	public void doRegistration() {
40
		require(ConvexHullLibrary.class);
41
//		require(DefaultSeismicSwingLibrary.class);
42
//		require(SeismicSwingLibrary.class);
43
//		require(DefaultSeismicLibrary.class);
44
//		require(SeismicLibrary.class);
45
	}
46
	
47
    @Override
48
    protected void doInitialize() throws LibraryException {
49

  
50
    }
51

  
52
    @Override
53
    protected void doPostInitialize() throws LibraryException {
54
        Messages.addResourceFamily(
55
            "org.gvsig.seismic.geoprocess.pointtoline.pointtoline",
56
            PointToLineLibrary.class.getClassLoader(), 
57
            PointToLineLibrary.class.getClass().getName());
58

  
59
        registerGeoProcess(new PointToLineAlgorithm());
60
    }
61

  
62
}
0 63

  
org.gvsig.seismic/tags/org.gvsig.seismic-1.0.238/org.gvsig.seismic/org.gvsig.seismic.app/org.gvsig.seismic.app.geoprocess/src/main/java/org/gvsig/seismic/geoprocess/pointtoline/PointToLineAlgorithm.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.seismic.geoprocess.pointtoline;
25

  
26
import java.util.ArrayList;
27
import java.util.HashMap;
28
import java.util.Iterator;
29
import java.util.List;
30
import java.util.Map;
31

  
32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.fmap.dal.feature.FeatureStore;
34
import org.gvsig.geoprocess.lib.sextante.AbstractSextanteGeoProcess;
35
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer;
36
import org.gvsig.tools.dataTypes.DataTypes;
37

  
38
import com.vividsolutions.jts.geom.Coordinate;
39
import com.vividsolutions.jts.geom.Geometry;
40
import com.vividsolutions.jts.geom.GeometryFactory;
41
import com.vividsolutions.jts.geom.LineString;
42
import com.vividsolutions.jts.geom.Point;
43

  
44
import es.unex.sextante.core.Sextante;
45
import es.unex.sextante.dataObjects.IFeature;
46
import es.unex.sextante.dataObjects.IFeatureIterator;
47
import es.unex.sextante.dataObjects.IVectorLayer;
48
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException;
49
import es.unex.sextante.exceptions.RepeatedParameterNameException;
50
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel;
51
import es.unex.sextante.outputs.OutputVectorLayer;
52

  
53
/**
54
 * @author <a href="mailto:jbadia@scolab.es>Jose Badia</a>
55
 */
56
public class PointToLineAlgorithm extends AbstractSextanteGeoProcess {
57

  
58
	public static final String         RESULT            = "RESULT";
59
	public static final String         LAYER             = "LAYER";
60
	public static final String         FIELD             = "FIELD";
61
	public static final String         OPTION             = "OPTION";
62

  
63
    private IVectorLayer       m_Layer;
64
    private IVectorLayer       m_Output;
65
    private List<String>       m_Field;
66
    private boolean            m_Option;
67
	 
68
	/*
69
	 * (non-Javadoc)
70
	 * @see es.unex.sextante.core.GeoAlgorithm#defineCharacteristics()
71
	 */
72
	public void defineCharacteristics(){
73
        setName(getTranslation("Puntos a l?neas"));
74
        setGroup(getTranslation("basic_vect_algorithms"));
75

  
76
        try {
77
			m_Parameters.addInputVectorLayer(LAYER, getTranslation("Input_layer"), IVectorLayer.SHAPE_TYPE_WRONG, true);
78
			m_Parameters.addMultipleInput(FIELD, getTranslation("Field"), DataTypes.STRING, true);
79
			m_Parameters.addBoolean(OPTION, getTranslation("Option"), false);
80
			addOutputVectorLayer(RESULT, getTranslation("Output_layer"), OutputVectorLayer.SHAPE_TYPE_UNDEFINED);
81
		} catch (RepeatedParameterNameException e) {
82
			Sextante.addErrorToLog(e);
83
		} 
84
	}
85
	
86
	 public boolean processAlgorithm() throws GeoAlgorithmExecutionException {
87
		  m_Layer = m_Parameters.getParameterValueAsVectorLayer(LAYER);
88
		  m_Option = m_Parameters.getParameterValueAsBoolean(OPTION);
89
	      m_Field = m_Parameters.getParameterValueAsArrayList(FIELD);
90
	      
91
	      List<Integer> fieldIndex = new ArrayList<Integer>(); 
92
	      Iterator<String> itIndex = m_Field.iterator();
93
	      while(itIndex.hasNext()){
94
	    	  String f = (String) itIndex.next();
95
	    	  fieldIndex.add(m_Layer.getFieldIndexByName(f));
96
	      }
97
	      
98
	      if(m_Option){
99
//		      Class[] clss = {m_Layer.getFieldType(fieldIndex)};
100
//		      String[] names = {m_Layer.getFieldName(fieldIndex)};
101
		      
102
	    	  Class[] clss = new Class[fieldIndex.size()+1];
103
	    	  String[] names = new String[fieldIndex.size()+1];
104
	    	  int i=0;
105
	    	  for(i=0; i<fieldIndex.size();i++){
106
	    		  clss[i] = m_Layer.getFieldType(fieldIndex.get(i));
107
	    		  names[i] = m_Layer.getFieldName(fieldIndex.get(i));
108
	    	  }
109
	    	  clss[i] = Double.class;
110
	    	  names[i] = "Length";
111
	    	  
112
		      m_Output = getNewVectorLayer(
113
		    		  RESULT, 
114
		    		  m_Layer.getName(), 
115
		    		  IVectorLayer.SHAPE_TYPE_LINE, 
116
		    		  clss,
117
		              names);
118
	      }else{
119
	    	  Class[] clss = {String.class};
120
		      String[] names = {"gvSeismic_lines"};
121
		      
122
		      m_Output = getNewVectorLayer(
123
		    		  RESULT, 
124
		    		  m_Layer.getName(), 
125
		    		  IVectorLayer.SHAPE_TYPE_LINE, 
126
		    		  clss,
127
		              names);
128
	      }
129
	      
130
	      Map<Object, List<Coordinate>> lines = new HashMap<Object, List<Coordinate>>();
131
	      Map<Object, Object[]> values = new HashMap<Object, Object[]>();
132
	      
133
	      final GeometryFactory gf = new GeometryFactory();
134
	      int GEOMIndex = m_Layer.getFieldIndexByName("GEOM");
135
	      
136
	      if(m_Option){
137
		      // HACK:
138
		      // El campo GEOM es considerado entre los campos, pero no aparece como seleccionable
139
		      // por lo que si el campo por el que agrupar est? por detr?s de ?l, hay que tenerlo
140
		      // en cuenta
141
	    	  for(int i=0; i<fieldIndex.size(); i++){
142
			      if(GEOMIndex < fieldIndex.get(i)){
143
			    	  fieldIndex.set(i, fieldIndex.get(i)-1);
144
			      }
145
	    	  }
146
	      }
147
	      
148
	      int numberOfFeatures = 0;
149
	      FeatureStore store;
150
		if (m_Layer instanceof FlyrVectIVectorLayer){
151
	            store = ((FlyrVectIVectorLayer) m_Layer).getFeatureStore();
152
	      		try {
153
					numberOfFeatures = (int) store.getFeatureCount();
154
				} catch (DataException e) {
155
					// TODO Auto-generated catch block
156
					e.printStackTrace();
157
				}
158
		}
159
          int iCount = 0;
160
	      
161
	      final IFeatureIterator iter = m_Layer.iterator();
162
	      while(iter.hasNext()){
163
		      IFeature feature = iter.next();
164
		   
165
		      setProgress(iCount, numberOfFeatures);
166
		      iCount++;
167
		      String currentField = "";
168
		      for(int i =0; i<fieldIndex.size(); i++){
169
		    	  currentField += feature.getRecord().getValue(fieldIndex.get(i));
170
		      }
171
		      if(!m_Option){
172
		    	  currentField = "(default)";
173
		      }
174
		      
175
		      if(!lines.containsKey(currentField)){
176
		    	  lines.put(currentField, new ArrayList<Coordinate>());
177
		    	  if(!m_Option){
178
		    		  Object[] vs = {"(default)"};
179
		    		  values.put(currentField, vs);
180
		    	  }else{
181
		    		  values.put(currentField, feature.getRecord().getValues());
182
		    	  }
183
		      }
184
		      
185
		      Geometry geom = feature.getGeometry();
186
		      for (int j = 0; j < geom.getNumGeometries(); j++) {
187
		         final Geometry subgeom = geom.getGeometryN(j);
188
		         final Coordinate coord = subgeom.getCoordinate();
189
		         lines.get(currentField).add(coord);
190
		      }
191
	      }
192
	      
193
	      Iterator<Object> it = lines.keySet().iterator();
194
	      while(it.hasNext()){
195
	    	  Object key = (Object) it.next();
196
	    	  Coordinate[] coords =  lines.get(key).toArray(new Coordinate[0]);
197
	    	  if(coords.length == 1){
198
	    		  m_Output.addFeature(gf.createPoint(lines.get(key).toArray(new Coordinate[0])[0]), 
199
						  values.get(key));
200
	    	  }else{
201
	    		  Object[] objs = new Object[fieldIndex.size()+1];
202
	    		  int i=0;
203
	    		  for(i=0; i<fieldIndex.size(); i++){
204
	    			  objs[i] = values.get(key)[fieldIndex.get(i)];
205
	    		  }
206
	    		  LineString line = gf.createLineString(
207
						  lines.get(key).toArray(new Coordinate[0]));
208
	    		  Point point1 = line.getStartPoint();
209
	    		  Point point2 = line.getEndPoint();
210
	    		  objs[i] = point2.distance(point1);
211
	    		  m_Output.addFeature(line, 
212
					  objs);
213
	    	  }
214
		  }
215
	      m_Output.setName("gvSeismic_line");
216
	      return !m_Task.isCanceled();
217
	   }
218
	
219
		@Override
220
	    public Class<? extends GeoAlgorithmParametersPanel> getCustomParametersPanelClass() {
221
	        return PointToLineParametersPanel.class;
222
	    }
223
}
0 224

  
org.gvsig.seismic/tags/org.gvsig.seismic-1.0.238/org.gvsig.seismic/org.gvsig.seismic.app/org.gvsig.seismic.app.geoprocess/src/main/java/org/gvsig/seismic/geoprocess/pointtoline/PointToLineParametersPanel.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.seismic.geoprocess.pointtoline;
25

  
26
import java.awt.BorderLayout;
27
import java.awt.Color;
28
import java.awt.Dimension;
29
import java.awt.GridBagConstraints;
30
import java.awt.GridBagLayout;
31
import java.awt.Insets;
32
import java.awt.ScrollPane;
33
import java.awt.event.ActionEvent;
34
import java.awt.event.ActionListener;
35
import java.awt.event.MouseEvent;
36
import java.awt.event.MouseListener;
37
import java.util.ArrayList;
38
import java.util.List;
39

  
40
import javax.swing.AbstractButton;
41
import javax.swing.BorderFactory;
42
import javax.swing.BoxLayout;
43
import javax.swing.ComboBoxModel;
44
import javax.swing.DefaultComboBoxModel;
45
import javax.swing.JButton;
46
import javax.swing.JCheckBox;
47
import javax.swing.JComboBox;
48
import javax.swing.JLabel;
49
import javax.swing.JPanel;
50
import javax.swing.border.TitledBorder;
51

  
52
import org.gvsig.fmap.dal.exception.DataException;
53
import org.gvsig.fmap.dal.feature.FeatureStore;
54
import org.gvsig.fmap.dal.feature.FeatureType;
55
import org.gvsig.geoprocess.lib.api.GeoProcessLocator;
56
import org.gvsig.geoprocess.lib.sextante.dataObjects.FlyrVectIVectorLayer;
57
import org.gvsig.geoprocess.sextante.gui.algorithm.AlgorithmOutputPanel;
58
import org.gvsig.tools.dataTypes.DataTypes;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff