root / trunk / extensions / extGeoProcessing / src / com / iver / gvsig / geoprocessing / gui / GeoProcessingPanel.java @ 3015
History | View | Annotate | Download (84 KB)
1 | 2370 | jmorell | /*
|
---|---|---|---|
2 | * Created on 01-jul-2005
|
||
3 | *
|
||
4 | * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
5 | *
|
||
6 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
7 | *
|
||
8 | * This program is free software; you can redistribute it and/or
|
||
9 | * modify it under the terms of the GNU General Public License
|
||
10 | * as published by the Free Software Foundation; either version 2
|
||
11 | * of the License, or (at your option) any later version.
|
||
12 | *
|
||
13 | * This program is distributed in the hope that it will be useful,
|
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
16 | * GNU General Public License for more details.
|
||
17 | *
|
||
18 | * You should have received a copy of the GNU General Public License
|
||
19 | * along with this program; if not, write to the Free Software
|
||
20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
21 | *
|
||
22 | * For more information, contact:
|
||
23 | *
|
||
24 | * Generalitat Valenciana
|
||
25 | * Conselleria d'Infraestructures i Transport
|
||
26 | * Av. Blasco Ib??ez, 50
|
||
27 | * 46010 VALENCIA
|
||
28 | * SPAIN
|
||
29 | *
|
||
30 | * +34 963862235
|
||
31 | * gvsig@gva.es
|
||
32 | * www.gvsig.gva.es
|
||
33 | *
|
||
34 | * or
|
||
35 | *
|
||
36 | * IVER T.I. S.A
|
||
37 | * Salamanca 50
|
||
38 | * 46005 Valencia
|
||
39 | * Spain
|
||
40 | *
|
||
41 | * +34 963163400
|
||
42 | * dac@iver.es
|
||
43 | */
|
||
44 | package com.iver.gvsig.geoprocessing.gui; |
||
45 | |||
46 | import javax.swing.JCheckBox; |
||
47 | import javax.swing.JComboBox; |
||
48 | import javax.swing.JDialog; |
||
49 | 2670 | jmorell | import javax.swing.JList; |
50 | 2370 | jmorell | import javax.swing.JPanel; |
51 | import javax.swing.JRadioButton; |
||
52 | import javax.swing.JTextField; |
||
53 | 2670 | jmorell | import javax.swing.JScrollPane; |
54 | 2370 | jmorell | |
55 | 2864 | jmorell | import com.hardcode.driverManager.DriverLoadException; |
56 | 2387 | jmorell | import com.hardcode.gdbms.engine.data.DataSource; |
57 | 2864 | jmorell | import com.hardcode.gdbms.engine.data.DataSourceFactory; |
58 | import com.hardcode.gdbms.engine.data.NoSuchTableException; |
||
59 | import com.hardcode.gdbms.engine.data.edition.DataWare; |
||
60 | 2670 | jmorell | import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException; |
61 | import com.hardcode.gdbms.engine.values.BooleanValue; |
||
62 | 2387 | jmorell | import com.hardcode.gdbms.engine.values.Value; |
63 | 2864 | jmorell | import com.hardcode.gdbms.engine.values.ValueFactory; |
64 | 2370 | jmorell | import com.iver.andami.PluginServices; |
65 | import com.iver.andami.ui.mdiManager.View; |
||
66 | import com.iver.andami.ui.mdiManager.ViewInfo; |
||
67 | import com.iver.cit.gvsig.fmap.DriverException; |
||
68 | import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
||
69 | 2402 | jmorell | import com.iver.cit.gvsig.fmap.core.FShape; |
70 | 2370 | jmorell | import com.iver.cit.gvsig.fmap.core.IGeometry; |
71 | import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
||
72 | import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
||
73 | 2387 | jmorell | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
74 | 2370 | jmorell | import com.iver.cit.gvsig.fmap.layers.FBitSet; |
75 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
76 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
77 | 2387 | jmorell | import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
78 | import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
||
79 | import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
||
80 | 2370 | jmorell | import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
81 | 2387 | jmorell | import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
82 | 2370 | jmorell | import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
83 | import com.iver.cit.gvsig.fmap.operations.strategies.SelectedShapeVisitor; |
||
84 | import com.iver.cit.gvsig.fmap.operations.strategies.SelectedZoomVisitor; |
||
85 | import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
||
86 | import com.iver.gvsig.geoprocessing.gui.operationpanels.GeoProcessingBufferPanel; |
||
87 | import com.iver.gvsig.geoprocessing.gui.operationpanels.GeoProcessingClipPanel; |
||
88 | 2402 | jmorell | import com.iver.gvsig.geoprocessing.gui.operationpanels.GeoProcessingDissolvePanel; |
89 | import com.iver.gvsig.geoprocessing.gui.operationpanels.GeoProcessingIntersectPanel; |
||
90 | import com.iver.gvsig.geoprocessing.gui.operationpanels.GeoProcessingMergePanel; |
||
91 | import com.iver.gvsig.geoprocessing.gui.operationpanels.GeoProcessingSpatialjoinPanel; |
||
92 | import com.iver.gvsig.geoprocessing.gui.operationpanels.GeoProcessingUnionPanel; |
||
93 | 2370 | jmorell | import com.iver.gvsig.geoprocessing.operations.GeoProcessingPersistenceOperations; |
94 | 2864 | jmorell | import com.iver.gvsig.geoprocessing.operations.GeoProcessingTableOperations; |
95 | 2370 | jmorell | import com.iver.gvsig.geoprocessing.operations.GeoProcessingTopologyOperations; |
96 | import com.iver.gvsig.geoprocessing.operations.strategies.SelectedShapeToJTSVisitor; |
||
97 | 2989 | jmorell | import com.vividsolutions.jts.geom.Coordinate; |
98 | 2370 | jmorell | import com.vividsolutions.jts.geom.Geometry; |
99 | 2989 | jmorell | import com.vividsolutions.jts.geom.GeometryCollection; |
100 | import com.vividsolutions.jts.geom.GeometryFactory; |
||
101 | import com.vividsolutions.jts.geom.LineString; |
||
102 | import com.vividsolutions.jts.geom.MultiPoint; |
||
103 | import com.vividsolutions.jts.geom.Point; |
||
104 | import com.vividsolutions.jts.geom.Polygon; |
||
105 | import com.vividsolutions.jts.operation.distance.DistanceOp; |
||
106 | 2370 | jmorell | |
107 | 2402 | jmorell | import java.awt.Component; |
108 | 2370 | jmorell | import java.awt.GridLayout; |
109 | import java.awt.GridBagLayout; |
||
110 | import java.awt.GridBagConstraints; |
||
111 | import java.awt.FlowLayout; |
||
112 | import java.awt.CardLayout; |
||
113 | import javax.swing.BoxLayout; |
||
114 | import java.awt.BorderLayout; |
||
115 | 2989 | jmorell | import java.io.File; |
116 | 2864 | jmorell | import java.sql.Types; |
117 | import java.util.BitSet; |
||
118 | 2670 | jmorell | import java.util.Vector; |
119 | |||
120 | 2370 | jmorell | import javax.swing.JButton; |
121 | |||
122 | public class GeoProcessingPanel extends JPanel implements View { |
||
123 | |||
124 | /**
|
||
125 | *
|
||
126 | */
|
||
127 | private static final long serialVersionUID = 1L; |
||
128 | private GeoProcessingOperationSelectorPanel geoProcessingOperationSelectorPanel = null; |
||
129 | private GeoProcessingBufferPanel geoProcessingBufferPanel = null; |
||
130 | private GeoProcessingClipPanel geoProcessingClipPanel = null; |
||
131 | 2402 | jmorell | private GeoProcessingDissolvePanel geoProcessingDissolvePanel = null; |
132 | private GeoProcessingMergePanel geoProcessingMergePanel = null; |
||
133 | private GeoProcessingIntersectPanel geoProcessingIntersectPanel = null; |
||
134 | private GeoProcessingUnionPanel geoProcessingUnionPanel = null; |
||
135 | private GeoProcessingSpatialjoinPanel geoProcessingSpatialjoinPanel = null; |
||
136 | 2370 | jmorell | private JPanel buttonsPanel = null; |
137 | |||
138 | private JButton jButton = null; |
||
139 | private JButton jButton1 = null; |
||
140 | private JButton jButton2 = null; |
||
141 | private ViewInfo viewInfo = null; |
||
142 | private FLayers layers = null; |
||
143 | /**
|
||
144 | * This constructor initializes the set of layers
|
||
145 | */
|
||
146 | public GeoProcessingPanel(FLayers layers) {
|
||
147 | super();
|
||
148 | this.layers = layers;
|
||
149 | initialize(); |
||
150 | } |
||
151 | |||
152 | /**
|
||
153 | * This method initializes this
|
||
154 | *
|
||
155 | * @return void
|
||
156 | */
|
||
157 | private void initialize() { |
||
158 | this.setLayout(new BorderLayout()); |
||
159 | this.setSize(416, 271); |
||
160 | this.add(getButtonsPanel(), java.awt.BorderLayout.SOUTH);
|
||
161 | this.add(getGeoProcessingOperationSelectorPanel(), java.awt.BorderLayout.NORTH);
|
||
162 | this.add(getGeoProcessingBufferPanel(), java.awt.BorderLayout.NORTH);
|
||
163 | this.add(getGeoProcessingClipPanel(), java.awt.BorderLayout.NORTH);
|
||
164 | 2402 | jmorell | this.add(getGeoProcessingDissolvePanel(), java.awt.BorderLayout.NORTH);
|
165 | this.add(getGeoProcessingMergePanel(), java.awt.BorderLayout.NORTH);
|
||
166 | this.add(getGeoProcessingIntersectPanel(), java.awt.BorderLayout.NORTH);
|
||
167 | this.add(getGeoProcessingUnionPanel(), java.awt.BorderLayout.NORTH);
|
||
168 | this.add(getGeoProcessingSpatialjoinPanel(), java.awt.BorderLayout.NORTH);
|
||
169 | 2370 | jmorell | geoProcessingOperationSelectorPanel.setVisible(true);
|
170 | geoProcessingBufferPanel.setVisible(false);
|
||
171 | geoProcessingClipPanel.setVisible(false);
|
||
172 | 2402 | jmorell | geoProcessingDissolvePanel.setVisible(false);
|
173 | geoProcessingMergePanel.setVisible(false);
|
||
174 | geoProcessingIntersectPanel.setVisible(false);
|
||
175 | geoProcessingUnionPanel.setVisible(false);
|
||
176 | geoProcessingSpatialjoinPanel.setVisible(false);
|
||
177 | 2370 | jmorell | jButton1.setEnabled(false);
|
178 | } |
||
179 | |||
180 | public ViewInfo getViewInfo() {
|
||
181 | // TODO Auto-generated method stub
|
||
182 | if (viewInfo == null) { |
||
183 | viewInfo=new ViewInfo(ViewInfo.MODALDIALOG);
|
||
184 | 2670 | jmorell | viewInfo.setTitle(PluginServices.getText(this,"Herramientas_de_analisis")); |
185 | 2370 | jmorell | } |
186 | return viewInfo;
|
||
187 | } |
||
188 | |||
189 | /**
|
||
190 | * This method initializes geoProcessingOperationSelectorPanel
|
||
191 | *
|
||
192 | * @return javax.swing.JPanel
|
||
193 | */
|
||
194 | private JPanel getGeoProcessingOperationSelectorPanel() { |
||
195 | if (geoProcessingOperationSelectorPanel == null) { |
||
196 | geoProcessingOperationSelectorPanel = new GeoProcessingOperationSelectorPanel();
|
||
197 | geoProcessingOperationSelectorPanel.setName("geoProcessingOperationSelectorPanel");
|
||
198 | } |
||
199 | return geoProcessingOperationSelectorPanel;
|
||
200 | } |
||
201 | |||
202 | /**
|
||
203 | * This method initializes geoProcessingBufferPanel
|
||
204 | *
|
||
205 | * @return javax.swing.JPanel
|
||
206 | */
|
||
207 | private JPanel getGeoProcessingBufferPanel() { |
||
208 | if (geoProcessingBufferPanel == null) { |
||
209 | geoProcessingBufferPanel = new GeoProcessingBufferPanel(layers);
|
||
210 | geoProcessingBufferPanel.setName("geoProcessingBufferPanel");
|
||
211 | } |
||
212 | return geoProcessingBufferPanel;
|
||
213 | } |
||
214 | |||
215 | /**
|
||
216 | * This method initializes geoProcessingClipPanel
|
||
217 | *
|
||
218 | * @return javax.swing.JPanel
|
||
219 | */
|
||
220 | private JPanel getGeoProcessingClipPanel() { |
||
221 | if (geoProcessingClipPanel == null) { |
||
222 | geoProcessingClipPanel = new GeoProcessingClipPanel(layers);
|
||
223 | geoProcessingClipPanel.setName("geoProcessingClipPanel");
|
||
224 | 2402 | jmorell | // Si no le meto esta l?nea, no se visualiza el men?. Ver que puede
|
225 | 2370 | jmorell | // estar pasando ...
|
226 | geoProcessingClipPanel.setPreferredSize(new java.awt.Dimension(300,300)); |
||
227 | } |
||
228 | return geoProcessingClipPanel;
|
||
229 | } |
||
230 | |||
231 | /**
|
||
232 | 2402 | jmorell | * This method initializes geoProcessingDissolvePanel
|
233 | *
|
||
234 | * @return javax.swing.JPanel
|
||
235 | */
|
||
236 | private JPanel getGeoProcessingDissolvePanel() { |
||
237 | if (geoProcessingDissolvePanel == null) { |
||
238 | geoProcessingDissolvePanel = new GeoProcessingDissolvePanel(layers);
|
||
239 | geoProcessingDissolvePanel.setName("geoProcessingDissolvePanel");
|
||
240 | } |
||
241 | return geoProcessingDissolvePanel;
|
||
242 | } |
||
243 | |||
244 | /**
|
||
245 | * This method initializes geoProcessingMergePanel
|
||
246 | *
|
||
247 | * @return javax.swing.JPanel
|
||
248 | */
|
||
249 | private JPanel getGeoProcessingMergePanel() { |
||
250 | if (geoProcessingMergePanel == null) { |
||
251 | geoProcessingMergePanel = new GeoProcessingMergePanel(layers);
|
||
252 | geoProcessingMergePanel.setName("geoProcessingMergePanel");
|
||
253 | } |
||
254 | return geoProcessingMergePanel;
|
||
255 | } |
||
256 | |||
257 | /**
|
||
258 | * This method initializes geoProcessingIntersectPanel
|
||
259 | *
|
||
260 | * @return javax.swing.JPanel
|
||
261 | */
|
||
262 | private JPanel getGeoProcessingIntersectPanel() { |
||
263 | if (geoProcessingIntersectPanel == null) { |
||
264 | geoProcessingIntersectPanel = new GeoProcessingIntersectPanel(layers);
|
||
265 | geoProcessingIntersectPanel.setName("geoProcessingIntersectPanel");
|
||
266 | } |
||
267 | return geoProcessingIntersectPanel;
|
||
268 | } |
||
269 | |||
270 | /**
|
||
271 | * This method initializes geoProcessingUnionPanel
|
||
272 | *
|
||
273 | * @return javax.swing.JPanel
|
||
274 | */
|
||
275 | private JPanel getGeoProcessingUnionPanel() { |
||
276 | if (geoProcessingUnionPanel == null) { |
||
277 | geoProcessingUnionPanel = new GeoProcessingUnionPanel(layers);
|
||
278 | geoProcessingUnionPanel.setName("geoProcessingUnionPanel");
|
||
279 | } |
||
280 | return geoProcessingUnionPanel;
|
||
281 | } |
||
282 | |||
283 | /**
|
||
284 | * This method initializes geoProcessingSpatialjoinPanel
|
||
285 | *
|
||
286 | * @return javax.swing.JPanel
|
||
287 | */
|
||
288 | private JPanel getGeoProcessingSpatialjoinPanel() { |
||
289 | if (geoProcessingSpatialjoinPanel == null) { |
||
290 | geoProcessingSpatialjoinPanel = new GeoProcessingSpatialjoinPanel(layers);
|
||
291 | geoProcessingSpatialjoinPanel.setName("geoProcessingSpatialjoinPanel");
|
||
292 | // Si no le meto esta l?nea, no se visualiza el men?. Ver que puede
|
||
293 | // estar pasando ...
|
||
294 | geoProcessingSpatialjoinPanel.setPreferredSize(new java.awt.Dimension(300,300)); |
||
295 | } |
||
296 | return geoProcessingSpatialjoinPanel;
|
||
297 | } |
||
298 | |||
299 | /**
|
||
300 | 2370 | jmorell | * This method initializes buttonsPanel
|
301 | *
|
||
302 | * @return javax.swing.JPanel
|
||
303 | */
|
||
304 | private JPanel getButtonsPanel() { |
||
305 | if (buttonsPanel == null) { |
||
306 | buttonsPanel = new JPanel(); |
||
307 | buttonsPanel.setName("buttonsPanel");
|
||
308 | 2402 | jmorell | buttonsPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.LOWERED)); |
309 | 2370 | jmorell | buttonsPanel.add(getJButton(), null);
|
310 | buttonsPanel.add(getJButton1(), null);
|
||
311 | buttonsPanel.add(getJButton2(), null);
|
||
312 | } |
||
313 | return buttonsPanel;
|
||
314 | } |
||
315 | |||
316 | /**
|
||
317 | * This method initializes jButton
|
||
318 | *
|
||
319 | * @return javax.swing.JButton
|
||
320 | */
|
||
321 | private JButton getJButton() { |
||
322 | if (jButton == null) { |
||
323 | jButton = new JButton(); |
||
324 | 2670 | jmorell | jButton.setText(PluginServices.getText(this,"Cerrar")); |
325 | 2370 | jmorell | jButton.addActionListener(new java.awt.event.ActionListener() {
|
326 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
327 | System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() |
||
328 | closeMethod(); |
||
329 | } |
||
330 | }); |
||
331 | } |
||
332 | return jButton;
|
||
333 | } |
||
334 | /**
|
||
335 | * This method initializes jButton1
|
||
336 | *
|
||
337 | * @return javax.swing.JButton
|
||
338 | */
|
||
339 | private JButton getJButton1() { |
||
340 | if (jButton1 == null) { |
||
341 | jButton1 = new JButton(); |
||
342 | 2670 | jmorell | jButton1.setText(PluginServices.getText(this,"Anterior")); |
343 | 2370 | jmorell | jButton1.addActionListener(new java.awt.event.ActionListener() {
|
344 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
345 | System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() |
||
346 | 2402 | jmorell | getGeoProcessingOperationSelectorPanel().setVisible(true);
|
347 | getGeoProcessingBufferPanel().setVisible(false);
|
||
348 | getGeoProcessingClipPanel().setVisible(false);
|
||
349 | getGeoProcessingDissolvePanel().setVisible(false);
|
||
350 | getGeoProcessingMergePanel().setVisible(false);
|
||
351 | getGeoProcessingIntersectPanel().setVisible(false);
|
||
352 | getGeoProcessingUnionPanel().setVisible(false);
|
||
353 | getGeoProcessingSpatialjoinPanel().setVisible(false);
|
||
354 | 2370 | jmorell | jButton1.setEnabled(false);
|
355 | 2670 | jmorell | jButton2.setText(PluginServices.getText(this,"Siguiente")); |
356 | 2370 | jmorell | } |
357 | }); |
||
358 | } |
||
359 | return jButton1;
|
||
360 | } |
||
361 | /**
|
||
362 | * This method initializes jButton2
|
||
363 | *
|
||
364 | * @return javax.swing.JButton
|
||
365 | */
|
||
366 | private JButton getJButton2() { |
||
367 | if (jButton2 == null) { |
||
368 | jButton2 = new JButton(); |
||
369 | 2670 | jmorell | jButton2.setText(PluginServices.getText(this,"Siguiente")); |
370 | 2370 | jmorell | jButton2.addActionListener(new java.awt.event.ActionListener() {
|
371 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
372 | System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() |
||
373 | 2670 | jmorell | if (jButton2.getText().equals(PluginServices.getText(this,"Siguiente"))) { |
374 | 2370 | jmorell | if (((JRadioButton)geoProcessingOperationSelectorPanel.getComponent(1)).isSelected()) { |
375 | getGeoProcessingOperationSelectorPanel().setVisible(false);
|
||
376 | 2402 | jmorell | getGeoProcessingBufferPanel().setVisible(true);
|
377 | 2370 | jmorell | getGeoProcessingClipPanel().setVisible(false);
|
378 | 2402 | jmorell | getGeoProcessingDissolvePanel().setVisible(false);
|
379 | getGeoProcessingMergePanel().setVisible(false);
|
||
380 | getGeoProcessingIntersectPanel().setVisible(false);
|
||
381 | getGeoProcessingUnionPanel().setVisible(false);
|
||
382 | getGeoProcessingSpatialjoinPanel().setVisible(false);
|
||
383 | 2370 | jmorell | } else if (((JRadioButton)geoProcessingOperationSelectorPanel.getComponent(2)).isSelected()) { |
384 | getGeoProcessingOperationSelectorPanel().setVisible(false);
|
||
385 | getGeoProcessingBufferPanel().setVisible(false);
|
||
386 | getGeoProcessingClipPanel().setVisible(true);
|
||
387 | 2402 | jmorell | getGeoProcessingDissolvePanel().setVisible(false);
|
388 | getGeoProcessingMergePanel().setVisible(false);
|
||
389 | getGeoProcessingIntersectPanel().setVisible(false);
|
||
390 | getGeoProcessingUnionPanel().setVisible(false);
|
||
391 | getGeoProcessingSpatialjoinPanel().setVisible(false);
|
||
392 | } else if (((JRadioButton)geoProcessingOperationSelectorPanel.getComponent(3)).isSelected()) { |
||
393 | getGeoProcessingOperationSelectorPanel().setVisible(false);
|
||
394 | getGeoProcessingBufferPanel().setVisible(false);
|
||
395 | getGeoProcessingClipPanel().setVisible(false);
|
||
396 | getGeoProcessingDissolvePanel().setVisible(true);
|
||
397 | getGeoProcessingMergePanel().setVisible(false);
|
||
398 | getGeoProcessingIntersectPanel().setVisible(false);
|
||
399 | getGeoProcessingUnionPanel().setVisible(false);
|
||
400 | getGeoProcessingSpatialjoinPanel().setVisible(false);
|
||
401 | } else if (((JRadioButton)geoProcessingOperationSelectorPanel.getComponent(4)).isSelected()) { |
||
402 | getGeoProcessingOperationSelectorPanel().setVisible(false);
|
||
403 | getGeoProcessingBufferPanel().setVisible(false);
|
||
404 | getGeoProcessingClipPanel().setVisible(false);
|
||
405 | getGeoProcessingDissolvePanel().setVisible(false);
|
||
406 | getGeoProcessingMergePanel().setVisible(true);
|
||
407 | getGeoProcessingIntersectPanel().setVisible(false);
|
||
408 | getGeoProcessingUnionPanel().setVisible(false);
|
||
409 | getGeoProcessingSpatialjoinPanel().setVisible(false);
|
||
410 | } else if (((JRadioButton)geoProcessingOperationSelectorPanel.getComponent(5)).isSelected()) { |
||
411 | getGeoProcessingOperationSelectorPanel().setVisible(false);
|
||
412 | getGeoProcessingBufferPanel().setVisible(false);
|
||
413 | getGeoProcessingClipPanel().setVisible(false);
|
||
414 | getGeoProcessingDissolvePanel().setVisible(false);
|
||
415 | getGeoProcessingMergePanel().setVisible(false);
|
||
416 | getGeoProcessingIntersectPanel().setVisible(true);
|
||
417 | getGeoProcessingUnionPanel().setVisible(false);
|
||
418 | getGeoProcessingSpatialjoinPanel().setVisible(false);
|
||
419 | } else if (((JRadioButton)geoProcessingOperationSelectorPanel.getComponent(6)).isSelected()) { |
||
420 | getGeoProcessingOperationSelectorPanel().setVisible(false);
|
||
421 | getGeoProcessingBufferPanel().setVisible(false);
|
||
422 | getGeoProcessingClipPanel().setVisible(false);
|
||
423 | getGeoProcessingDissolvePanel().setVisible(false);
|
||
424 | getGeoProcessingMergePanel().setVisible(false);
|
||
425 | getGeoProcessingIntersectPanel().setVisible(false);
|
||
426 | getGeoProcessingUnionPanel().setVisible(true);
|
||
427 | getGeoProcessingSpatialjoinPanel().setVisible(false);
|
||
428 | } else if (((JRadioButton)geoProcessingOperationSelectorPanel.getComponent(7)).isSelected()) { |
||
429 | getGeoProcessingOperationSelectorPanel().setVisible(false);
|
||
430 | getGeoProcessingBufferPanel().setVisible(false);
|
||
431 | getGeoProcessingClipPanel().setVisible(false);
|
||
432 | getGeoProcessingDissolvePanel().setVisible(false);
|
||
433 | getGeoProcessingMergePanel().setVisible(false);
|
||
434 | getGeoProcessingIntersectPanel().setVisible(false);
|
||
435 | getGeoProcessingUnionPanel().setVisible(false);
|
||
436 | getGeoProcessingSpatialjoinPanel().setVisible(true);
|
||
437 | 2370 | jmorell | } else {
|
438 | // Si no hay ninguna operaci?n de geoprocesamiento seleccionada no se cambia el di?logo de opciones.
|
||
439 | 2402 | jmorell | getGeoProcessingOperationSelectorPanel().setVisible(true);
|
440 | 2370 | jmorell | getGeoProcessingBufferPanel().setVisible(false);
|
441 | getGeoProcessingClipPanel().setVisible(false);
|
||
442 | 2402 | jmorell | getGeoProcessingDissolvePanel().setVisible(false);
|
443 | getGeoProcessingMergePanel().setVisible(false);
|
||
444 | getGeoProcessingIntersectPanel().setVisible(false);
|
||
445 | getGeoProcessingUnionPanel().setVisible(false);
|
||
446 | getGeoProcessingSpatialjoinPanel().setVisible(false);
|
||
447 | 2370 | jmorell | } |
448 | jButton1.setEnabled(true);
|
||
449 | 2670 | jmorell | jButton2.setText(PluginServices.getText(this,"Terminar")); |
450 | } else if (jButton2.getText().equals(PluginServices.getText(this,"Terminar"))) { |
||
451 | 2370 | jmorell | if (((JRadioButton)geoProcessingOperationSelectorPanel.getComponent(1)).isSelected()) { |
452 | bufferMethod(); |
||
453 | } else if (((JRadioButton)geoProcessingOperationSelectorPanel.getComponent(2)).isSelected()) { |
||
454 | 2402 | jmorell | clipMethod(); |
455 | } else if (((JRadioButton)geoProcessingOperationSelectorPanel.getComponent(3)).isSelected()) { |
||
456 | dissolveMethod(); |
||
457 | } else if (((JRadioButton)geoProcessingOperationSelectorPanel.getComponent(4)).isSelected()) { |
||
458 | mergeMethod(); |
||
459 | } else if (((JRadioButton)geoProcessingOperationSelectorPanel.getComponent(5)).isSelected()) { |
||
460 | intersectMethod(); |
||
461 | } else if (((JRadioButton)geoProcessingOperationSelectorPanel.getComponent(6)).isSelected()) { |
||
462 | unionMethod(); |
||
463 | } else if (((JRadioButton)geoProcessingOperationSelectorPanel.getComponent(7)).isSelected()) { |
||
464 | spatialjoinMethod(); |
||
465 | } else {
|
||
466 | 2370 | jmorell | //
|
467 | } |
||
468 | closeMethod(); |
||
469 | } |
||
470 | } |
||
471 | }); |
||
472 | } |
||
473 | return jButton2;
|
||
474 | } |
||
475 | 2670 | jmorell | private Geometry[] getJtsGeometries(FLayer bufferingLayer, boolean selected) { |
476 | 2402 | jmorell | FBitSet fBitSet = ((Selectable)bufferingLayer).getSelection(); |
477 | 2370 | jmorell | // Extraigo todos los elementos de la capa o solo los seleccionados
|
478 | 2670 | jmorell | //if (!((JCheckBox)component).isSelected()) {
|
479 | if (!selected) {
|
||
480 | 2387 | jmorell | VectorialAdapter va = (VectorialAdapter)((SingleLayer)bufferingLayer).getSource(); |
481 | fBitSet = new FBitSet();
|
||
482 | 2370 | jmorell | try {
|
483 | 2387 | jmorell | for (int i=0;i<va.getShapeCount();i++) { |
484 | fBitSet.set(i); |
||
485 | } |
||
486 | } catch (DriverIOException e) {
|
||
487 | 2370 | jmorell | // TODO Auto-generated catch block
|
488 | 2387 | jmorell | e.printStackTrace(); |
489 | 2370 | jmorell | } |
490 | 2402 | jmorell | ((Selectable)bufferingLayer).setSelection(fBitSet); |
491 | 2387 | jmorell | } |
492 | SelectedShapeToJTSVisitor visitor = new SelectedShapeToJTSVisitor();
|
||
493 | try {
|
||
494 | ((VectorialData)bufferingLayer).process(visitor); |
||
495 | } catch (DriverException e1) {
|
||
496 | // TODO Auto-generated catch block
|
||
497 | e1.printStackTrace(); |
||
498 | } catch (VisitException e1) {
|
||
499 | // TODO Auto-generated catch block
|
||
500 | e1.printStackTrace(); |
||
501 | } |
||
502 | 2670 | jmorell | // Si no hab?an elementos seleccionados, cambio la selecci?n temporal
|
503 | // completa actual por la original selecci?n nula
|
||
504 | if (!selected) ((Selectable)bufferingLayer).clearSelection();
|
||
505 | 2387 | jmorell | // Almaceno en un vector los elementos para el buffer
|
506 | 2402 | jmorell | return visitor.getJtsGeometries();
|
507 | } |
||
508 | private IGeometry[] getFmapGeometries(Geometry[] jtsGeometries) { |
||
509 | FShape[] shapes = new FShape[jtsGeometries.length]; |
||
510 | IGeometry[] geoms = new IGeometry[jtsGeometries.length]; |
||
511 | for (int i=0;i<jtsGeometries.length;i++) { |
||
512 | 2989 | jmorell | if (jtsGeometries[i] instanceof MultiPoint) { |
513 | double[] xcoords = new double[jtsGeometries[i].getNumGeometries()]; |
||
514 | double[] ycoords = new double[jtsGeometries[i].getNumGeometries()]; |
||
515 | for (int j=0;j<jtsGeometries[i].getNumGeometries();j++) { |
||
516 | xcoords[j] = ((Point)jtsGeometries[i].getGeometryN(j)).getX();
|
||
517 | ycoords[j] = ((Point)jtsGeometries[i].getGeometryN(j)).getY();
|
||
518 | } |
||
519 | geoms[i] = ShapeFactory.createMultipoint2D(xcoords, ycoords); |
||
520 | } else {
|
||
521 | shapes[i] = FConverter.jts_to_java2d(jtsGeometries[i]); |
||
522 | geoms[i] = ShapeFactory.createGeometry(shapes[i]); |
||
523 | } |
||
524 | 2402 | jmorell | } |
525 | return geoms;
|
||
526 | } |
||
527 | private void bufferMethod() { |
||
528 | String bufferingLayerName = (String)((JComboBox)geoProcessingBufferPanel.getComponent(2)).getSelectedItem(); |
||
529 | 2989 | jmorell | // TODO: Provisional. Hasta que Fernando le meta PKs al resto de ficheros.
|
530 | //System.out.println("bufferingLayerName = " + bufferingLayerName);
|
||
531 | boolean isDbfFile = false; |
||
532 | if (bufferingLayerName.endsWith(".shp") || bufferingLayerName.endsWith(".SHP")) isDbfFile = true; |
||
533 | 2402 | jmorell | FLayer bufferingLayer = layers.getLayer(bufferingLayerName); |
534 | 2670 | jmorell | boolean selected = false; |
535 | if (((JCheckBox)geoProcessingBufferPanel.getComponent(3)).isSelected()) selected = true; |
||
536 | Geometry[] geometries = getJtsGeometries(bufferingLayer, selected);
|
||
537 | 2402 | jmorell | IGeometry[] shapes = null; |
538 | 2864 | jmorell | boolean dissolveBuffer = false; |
539 | 2387 | jmorell | // Realizo el buffer llamando al metodo makeBuffer de GeoProcessingTopologyOperations
|
540 | if (((JRadioButton)geoProcessingBufferPanel.getComponent(4)).isSelected()) { |
||
541 | 2989 | jmorell | //dissolveBuffer = true;
|
542 | 2387 | jmorell | double bufferDistance = Double.parseDouble(((JTextField)geoProcessingBufferPanel.getComponent(7)).getText()); |
543 | if (((JCheckBox)geoProcessingBufferPanel.getComponent(13)).isSelected()) { |
||
544 | 2989 | jmorell | dissolveBuffer = true;
|
545 | 2387 | jmorell | Geometry jtsBuffer = GeoProcessingTopologyOperations.makeDissolveBuffer(geometries, bufferDistance, getQuadrantSegments()); |
546 | 2370 | jmorell | // Realizo las operaciones relacionadas con tablas que el buffer requiere llamando a los m?todos convenientes de GeoProcessingTableOperations
|
547 | // (A lo mejor este paso no es necesario) Convierto las tablas modificadas y las nuevas entidades JTS al modelo de gvSIG
|
||
548 | 2387 | jmorell | System.out.println("jtsBuffer = " + jtsBuffer); |
549 | 2370 | jmorell | FPolygon2D shapeBuffer = (FPolygon2D)FConverter.jts_to_java2d(jtsBuffer); |
550 | 2387 | jmorell | System.out.println("shapeBuffer = " + shapeBuffer); |
551 | 2402 | jmorell | shapes = new IGeometry[]{ShapeFactory.createGeometry(shapeBuffer)}; |
552 | 2370 | jmorell | // Guardo la tabla mediante gdbms. Guardo tambi?n las entidades JTS mediante gvSIG o usando solo gdbms (probablemente bastar? con usar gdbms)
|
553 | 2864 | jmorell | // Con dissolve. Habr? que hacer una tabla para un ?nico pol?gono o
|
554 | // multipol?gono. En la tabla solo meteremos los campos para los
|
||
555 | // que todos los elementos tengan atributos comunes. Si no hay
|
||
556 | // ning?n campo con estas caracter?sticas crearemos la tabla en
|
||
557 | // blanco.
|
||
558 | 2387 | jmorell | } else {
|
559 | double[] bufferDistances = new double[geometries.length]; |
||
560 | for (int i=0;i<bufferDistances.length;i++) { |
||
561 | bufferDistances[i] = bufferDistance; |
||
562 | } |
||
563 | Geometry[] jtsBuffers = GeoProcessingTopologyOperations.makeBuffers(geometries, bufferDistances, getQuadrantSegments());
|
||
564 | // Realizo las operaciones relacionadas con tablas que el buffer requiere llamando a los m?todos convenientes de GeoProcessingTableOperations
|
||
565 | // (A lo mejor este paso no es necesario) Convierto las tablas modificadas y las nuevas entidades JTS al modelo de gvSIG
|
||
566 | 2402 | jmorell | shapes = getFmapGeometries(jtsBuffers); |
567 | 2387 | jmorell | // Guardo la tabla mediante gdbms. Guardo tambi?n las entidades JTS mediante gvSIG o usando solo gdbms (probablemente bastar? con usar gdbms)
|
568 | 2864 | jmorell | // En este caso se guarda una tabla semejante a la del tema de entrada
|
569 | // solo que ahora los atributos se corresponden con los buffers
|
||
570 | // producidos por las entidades a las que correspond?an estos
|
||
571 | // atributos.
|
||
572 | 2370 | jmorell | } |
573 | 2387 | jmorell | } else if (((JRadioButton)geoProcessingBufferPanel.getComponent(5)).isSelected()) { |
574 | 2989 | jmorell | //dissolveBuffer = false;
|
575 | 2387 | jmorell | double[] bufferDistances = getBufferDistancesFromTable(bufferingLayer); |
576 | if (((JCheckBox)geoProcessingBufferPanel.getComponent(13)).isSelected()) { |
||
577 | 2989 | jmorell | dissolveBuffer = true;
|
578 | 2387 | jmorell | // Aqu? hay problemas ... Con distintas distancias y haciendo dissolve ...
|
579 | Geometry jtsBuffer = GeoProcessingTopologyOperations.makeDissolveBuffer(geometries, bufferDistances, getQuadrantSegments()); |
||
580 | // Realizo las operaciones relacionadas con tablas que el buffer requiere llamando a los m?todos convenientes de GeoProcessingTableOperations
|
||
581 | // (A lo mejor este paso no es necesario) Convierto las tablas modificadas y las nuevas entidades JTS al modelo de gvSIG
|
||
582 | System.out.println("jtsBuffer = " + jtsBuffer); |
||
583 | FPolygon2D shapeBuffer = (FPolygon2D)FConverter.jts_to_java2d(jtsBuffer); |
||
584 | System.out.println("shapeBuffer = " + shapeBuffer); |
||
585 | 2402 | jmorell | shapes = new IGeometry[]{ShapeFactory.createGeometry(shapeBuffer)}; |
586 | 2387 | jmorell | // Guardo la tabla mediante gdbms. Guardo tambi?n las entidades JTS mediante gvSIG o usando solo gdbms (probablemente bastar? con usar gdbms)
|
587 | } else {
|
||
588 | Geometry[] jtsBuffers = GeoProcessingTopologyOperations.makeBuffers(geometries, bufferDistances, getQuadrantSegments());
|
||
589 | // Realizo las operaciones relacionadas con tablas que el buffer requiere llamando a los m?todos convenientes de GeoProcessingTableOperations
|
||
590 | // (A lo mejor este paso no es necesario) Convierto las tablas modificadas y las nuevas entidades JTS al modelo de gvSIG
|
||
591 | 2402 | jmorell | shapes = getFmapGeometries(jtsBuffers); |
592 | 2387 | jmorell | // Guardo la tabla mediante gdbms. Guardo tambi?n las entidades JTS mediante gvSIG o usando solo gdbms (probablemente bastar? con usar gdbms)
|
593 | } |
||
594 | 2370 | jmorell | } |
595 | 2864 | jmorell | AlphanumericData lyr = (AlphanumericData)(layers.getLayer(geoProcessingBufferPanel.getSelectedLayerName())); |
596 | 2989 | jmorell | GeoProcessingPersistenceOperations.saveResultsToShapeFile(shapes, geoProcessingBufferPanel.getOutputFile()); |
597 | 2864 | jmorell | try {
|
598 | 2989 | jmorell | // TODO: Provisional. Hasta que Fernando le meta PKs al resto de ficheros.
|
599 | GeoProcessingTableOperations.saveBufferResultsToDbaseFile(geoProcessingBufferPanel.getOutputFile(), lyr, dissolveBuffer, isDbfFile); |
||
600 | 2864 | jmorell | } catch (IncompatibleTypesException e) {
|
601 | // TODO Auto-generated catch block
|
||
602 | e.printStackTrace(); |
||
603 | } catch (DriverException e) {
|
||
604 | // TODO Auto-generated catch block
|
||
605 | e.printStackTrace(); |
||
606 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
607 | // TODO Auto-generated catch block
|
||
608 | e.printStackTrace(); |
||
609 | } catch (DriverLoadException e) {
|
||
610 | // TODO Auto-generated catch block
|
||
611 | e.printStackTrace(); |
||
612 | } catch (NoSuchTableException e) {
|
||
613 | // TODO Auto-generated catch block
|
||
614 | e.printStackTrace(); |
||
615 | } |
||
616 | 2402 | jmorell | if (!((JCheckBox)geoProcessingBufferPanel.getComponent(3)).isSelected()) ((Selectable)bufferingLayer).clearSelection(); |
617 | 2370 | jmorell | } |
618 | 2670 | jmorell | private void mergeMethod() { |
619 | Object[] layerNamesToMerge = geoProcessingMergePanel.getLayerSelectedNames(); |
||
620 | 2864 | jmorell | String fieldsFromLayerName = geoProcessingMergePanel.getFieldsFromLayerName();
|
621 | 2989 | jmorell | // TODO: Provisional. Hasta que Fernando le meta PKs al resto de ficheros.
|
622 | boolean isDbfFile = false; |
||
623 | if (fieldsFromLayerName.endsWith(".shp") || fieldsFromLayerName.endsWith(".SHP")) isDbfFile = true; |
||
624 | 2864 | jmorell | AlphanumericData lyr = (AlphanumericData)layers.getLayer(fieldsFromLayerName); |
625 | 2670 | jmorell | FLayer[] layersToMerge = new FLayer[layerNamesToMerge.length]; |
626 | 2989 | jmorell | boolean[] selecteds = new boolean[layersToMerge.length]; |
627 | 2670 | jmorell | Vector allGeometriesToMerge = new Vector(); |
628 | for (int i=0;i<layerNamesToMerge.length;i++) { |
||
629 | layersToMerge[i] = layers.getLayer((String)layerNamesToMerge[i]);
|
||
630 | 2989 | jmorell | if (!((Selectable)layersToMerge[i]).getSelection().isEmpty()) selecteds[i] = true; |
631 | Geometry[] geometriesToMerge = getJtsGeometries(layersToMerge[i], selecteds[i]);
|
||
632 | 2670 | jmorell | for (int j=0;j<geometriesToMerge.length;j++) { |
633 | allGeometriesToMerge.add(geometriesToMerge[j]); |
||
634 | } |
||
635 | } |
||
636 | Geometry[] mergedGeometries = new Geometry[allGeometriesToMerge.size()]; |
||
637 | for (int i=0;i<allGeometriesToMerge.size();i++) { |
||
638 | mergedGeometries[i] = (Geometry)allGeometriesToMerge.get(i); |
||
639 | } |
||
640 | IGeometry[] shapes = getFmapGeometries(mergedGeometries);
|
||
641 | 2864 | jmorell | AlphanumericData[] lyrs = new AlphanumericData[layersToMerge.length]; |
642 | for (int i=0;i<layersToMerge.length;i++) { |
||
643 | lyrs[i] = (AlphanumericData)layersToMerge[i]; |
||
644 | } |
||
645 | // Pasarle tb la capa con los campos.
|
||
646 | 2989 | jmorell | GeoProcessingPersistenceOperations.saveResultsToShapeFile(shapes, geoProcessingMergePanel.getOutputFile()); |
647 | 2864 | jmorell | try {
|
648 | 2989 | jmorell | GeoProcessingTableOperations.saveMergeResultsToDbaseFile(geoProcessingMergePanel.getOutputFile(), lyrs, lyr, isDbfFile); |
649 | for (int i=0;i<lyrs.length;i++) { |
||
650 | lyrs[i].getRecordset().getSelection().clear(); |
||
651 | } |
||
652 | 2864 | jmorell | } catch (IncompatibleTypesException e) {
|
653 | // TODO Auto-generated catch block
|
||
654 | e.printStackTrace(); |
||
655 | } catch (DriverException e) {
|
||
656 | // TODO Auto-generated catch block
|
||
657 | e.printStackTrace(); |
||
658 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
659 | // TODO Auto-generated catch block
|
||
660 | e.printStackTrace(); |
||
661 | } catch (DriverLoadException e) {
|
||
662 | // TODO Auto-generated catch block
|
||
663 | e.printStackTrace(); |
||
664 | } catch (NoSuchTableException e) {
|
||
665 | // TODO Auto-generated catch block
|
||
666 | e.printStackTrace(); |
||
667 | } |
||
668 | 2670 | jmorell | } |
669 | 2402 | jmorell | private void dissolveMethod() { |
670 | 2670 | jmorell | String layerToDissolveName = (String)((JComboBox)geoProcessingDissolvePanel.getComponent(2)).getSelectedItem(); |
671 | FLayer layerToDissolve = layers.getLayer(layerToDissolveName); |
||
672 | boolean selected = false; |
||
673 | 2989 | jmorell | if (((JCheckBox)geoProcessingDissolvePanel.getComponent(3)).isSelected()) selected = true; |
674 | 2670 | jmorell | Geometry[] geometriesToDissolve = getJtsGeometries(layerToDissolve, selected);
|
675 | String dissolveAttributeName = (String)((JComboBox)geoProcessingDissolvePanel.getComponent(5)).getSelectedItem(); |
||
676 | 2864 | jmorell | AlphanumericData lyr = (AlphanumericData)layerToDissolve; |
677 | // No lo puedo llevar a GeoProcessingTopologyOperations porque no es solo
|
||
678 | // un problema JTS. Tampoco lo puedo llevar a GeoProcessingTableOperations
|
||
679 | // porque tampoco es un problema solo de GDBMS. Es mixto y por el momento
|
||
680 | // se queda aqu?.
|
||
681 | 2670 | jmorell | Vector resultGeometries = new Vector(); |
682 | DataSource ds;
|
||
683 | 2989 | jmorell | SelectableDataSource sds; |
684 | 2670 | jmorell | try {
|
685 | ds = lyr.getRecordset(); |
||
686 | 2989 | jmorell | sds = lyr.getRecordset(); |
687 | 2670 | jmorell | int fieldId = ds.getFieldIndexByName(dissolveAttributeName);
|
688 | 2989 | jmorell | FBitSet fBitSet = sds.getSelection(); |
689 | if (fBitSet.cardinality()==0) fBitSet.set(0, (int)lyr.getRecordset().getRowCount()); |
||
690 | Value[] fieldValues = new Value[sds.getSelection().cardinality()]; |
||
691 | int k=0; |
||
692 | 2670 | jmorell | for (int i=0;i<ds.getRowCount();i++) { |
693 | 2989 | jmorell | if (fBitSet.get(i)) {
|
694 | fieldValues[k] = ds.getFieldValue(i, fieldId); |
||
695 | k++; |
||
696 | } |
||
697 | 2670 | jmorell | } |
698 | for (int i=0;i<fieldValues.length;i++) { |
||
699 | Value valuei = fieldValues[i]; |
||
700 | Geometry geometryi = geometriesToDissolve[i]; |
||
701 | 2989 | jmorell | for (int j=0;j<fieldValues.length;j++) { |
702 | 2670 | jmorell | if (j!=i) {
|
703 | 2989 | jmorell | Value valuej = fieldValues[j]; |
704 | 2670 | jmorell | if (((BooleanValue)(valuej.equals(valuei))).getValue()) {
|
705 | Geometry geometryj = geometriesToDissolve[j]; |
||
706 | geometryi = geometryj.union(geometryi); |
||
707 | } |
||
708 | } |
||
709 | } |
||
710 | resultGeometries.add(geometryi); |
||
711 | } |
||
712 | 2864 | jmorell | for (int i=0;i<resultGeometries.size();i++) { |
713 | for (int j=0;j<resultGeometries.size();j++) { |
||
714 | 2989 | jmorell | if (j>i) {
|
715 | if (((Geometry)resultGeometries.get(i)).equals((Geometry)resultGeometries.get(j))) {
|
||
716 | resultGeometries.remove(j); |
||
717 | j--; |
||
718 | } |
||
719 | 2864 | jmorell | } |
720 | } |
||
721 | } |
||
722 | 2670 | jmorell | } catch (DriverException e) {
|
723 | // TODO Auto-generated catch block
|
||
724 | e.printStackTrace(); |
||
725 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
726 | // TODO Auto-generated catch block
|
||
727 | e.printStackTrace(); |
||
728 | } catch (IncompatibleTypesException e) {
|
||
729 | // TODO Auto-generated catch block
|
||
730 | e.printStackTrace(); |
||
731 | } |
||
732 | 2864 | jmorell | Geometry[] dissolvedGeometries = new Geometry[resultGeometries.size()]; |
733 | 2670 | jmorell | for (int i=0;i<resultGeometries.size();i++) { |
734 | 2864 | jmorell | dissolvedGeometries[i] = (Geometry)resultGeometries.get(i); |
735 | 2670 | jmorell | } |
736 | //
|
||
737 | 2864 | jmorell | //Geometry[] dissolvedGeometries = GeoProcessingTopologyOperations.makeDissolve(geometriesToDissolve, lyr, dissolveAttributeName);
|
738 | IGeometry[] shapes = getFmapGeometries(dissolvedGeometries);
|
||
739 | 2670 | jmorell | // Guardo la tabla mediante gdbms. Guardo tambi?n las entidades JTS mediante gvSIG o usando solo gdbms (probablemente bastar? con usar gdbms)
|
740 | 2989 | jmorell | GeoProcessingPersistenceOperations.saveResultsToShapeFile(shapes, geoProcessingDissolvePanel.getOutputFile()); |
741 | try {
|
||
742 | GeoProcessingTableOperations.saveDissolveResultsToDbaseFile(geoProcessingDissolvePanel.getOutputFile(), lyr, dissolveAttributeName); |
||
743 | lyr.getRecordset().getSelection().clear(); |
||
744 | 2864 | jmorell | } catch (IncompatibleTypesException e) {
|
745 | // TODO Auto-generated catch block
|
||
746 | e.printStackTrace(); |
||
747 | } catch (DriverException e) {
|
||
748 | // TODO Auto-generated catch block
|
||
749 | e.printStackTrace(); |
||
750 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
751 | // TODO Auto-generated catch block
|
||
752 | e.printStackTrace(); |
||
753 | } catch (DriverLoadException e) {
|
||
754 | // TODO Auto-generated catch block
|
||
755 | e.printStackTrace(); |
||
756 | } catch (NoSuchTableException e) {
|
||
757 | // TODO Auto-generated catch block
|
||
758 | e.printStackTrace(); |
||
759 | 2989 | jmorell | } |
760 | 2402 | jmorell | } |
761 | 2989 | jmorell | private void spatialjoinMethod() { |
762 | String layerToJoinName = (String)((JComboBox)geoProcessingSpatialjoinPanel.getComponent(0)).getSelectedItem(); |
||
763 | FLayer layerToJoin = layers.getLayer(layerToJoinName); |
||
764 | String joiningLayerName = (String)((JComboBox)geoProcessingSpatialjoinPanel.getComponent(3)).getSelectedItem(); |
||
765 | FLayer joiningLayer = layers.getLayer(joiningLayerName); |
||
766 | boolean selected = false; |
||
767 | try {
|
||
768 | if (((JCheckBox)geoProcessingSpatialjoinPanel.getComponent(1)).isSelected()) selected = true; |
||
769 | Geometry[] geometriesToJoin = getJtsGeometries(layerToJoin, selected);
|
||
770 | AlphanumericData lyrToJoin = (AlphanumericData)layerToJoin; |
||
771 | SelectableDataSource lyrToJoinSDS = lyrToJoin.getRecordset(); |
||
772 | FBitSet bitsetToJoin = lyrToJoinSDS.getSelection(); |
||
773 | if (bitsetToJoin.cardinality()==0) bitsetToJoin.set(0, (int)lyrToJoin.getRecordset().getRowCount()); |
||
774 | if (((JCheckBox)geoProcessingSpatialjoinPanel.getComponent(5)).isSelected()) selected = true; |
||
775 | Geometry[] joiningGeometries = getJtsGeometries(joiningLayer, selected);
|
||
776 | AlphanumericData joiningLyr = (AlphanumericData)joiningLayer; |
||
777 | SelectableDataSource joiningLyrSDS = joiningLyr.getRecordset(); |
||
778 | FBitSet joiningBitset = joiningLyrSDS.getSelection(); |
||
779 | if (joiningBitset.cardinality()==0) joiningBitset.set(0, (int)joiningLyr.getRecordset().getRowCount()); |
||
780 | DataSource lyrToJoinDS;
|
||
781 | DataSource joiningLyrDS;
|
||
782 | lyrToJoinDS = lyrToJoin.getRecordset(); |
||
783 | joiningLyrDS = joiningLyr.getRecordset(); |
||
784 | // Los campos se a?aden siempre. Los valores solo cuando toca ...
|
||
785 | String[] lyrToJoinFieldNames = new String[lyrToJoinDS.getFieldCount()]; |
||
786 | int[] lyrToJoinFieldTypes = new int[lyrToJoinDS.getFieldCount()]; |
||
787 | for (int i = 0; i < lyrToJoinDS.getFieldCount(); i++) { |
||
788 | lyrToJoinFieldNames[i] = lyrToJoinDS.getFieldName(i); |
||
789 | lyrToJoinFieldTypes[i] = lyrToJoinDS.getFieldType(i); |
||
790 | } |
||
791 | String[] joiningLyrFieldNames = new String[joiningLyrDS.getFieldCount()]; |
||
792 | int[] joiningLyrFieldTypes = new int[joiningLyrDS.getFieldCount()]; |
||
793 | for (int i = 0; i < joiningLyrDS.getFieldCount(); i++) { |
||
794 | joiningLyrFieldNames[i] = joiningLyrDS.getFieldName(i); |
||
795 | joiningLyrFieldTypes[i] = joiningLyrDS.getFieldType(i); |
||
796 | } |
||
797 | String[] joinedLyrFieldNames = new String[lyrToJoinDS.getFieldCount()+joiningLyrDS.getFieldCount()-2]; // Le quito los dos PKs |
||
798 | int[] joinedLyrFieldTypes = new int[lyrToJoinDS.getFieldCount()+joiningLyrDS.getFieldCount()-2]; |
||
799 | int l=0; |
||
800 | for (int i=0;i<lyrToJoinFieldNames.length-1;i++) { |
||
801 | joinedLyrFieldNames[i] = lyrToJoinFieldNames[i]; |
||
802 | joinedLyrFieldTypes[i] = lyrToJoinFieldTypes[i]; |
||
803 | l++; |
||
804 | } |
||
805 | for (int i=0;i<joiningLyrFieldNames.length-1;i++) { |
||
806 | joinedLyrFieldNames[i+l] = joiningLyrFieldNames[i]; |
||
807 | joinedLyrFieldTypes[i+l] = joiningLyrFieldTypes[i]; |
||
808 | } |
||
809 | DataSourceFactory dsf = lyrToJoinSDS.getDataSourceFactory(); |
||
810 | File file = geoProcessingSpatialjoinPanel.getOutputFile();
|
||
811 | dsf.createFileDataSource("gdbms dbf driver", "new_table", file.getAbsolutePath().replaceAll(".shp", ".dbf"), joinedLyrFieldNames, joinedLyrFieldTypes); |
||
812 | DataSource ds = dsf.createRandomDataSource("new_table"); |
||
813 | ds.start(); |
||
814 | DataWare dw = ds.getDataWare(DataSourceFactory.MANUAL_OPENING); |
||
815 | dw.beginTrans(); |
||
816 | ds.stop(); |
||
817 | lyrToJoinDS.stop(); |
||
818 | joiningLyrDS.stop(); |
||
819 | lyrToJoinSDS.stop(); |
||
820 | joiningLyrSDS.stop(); |
||
821 | |||
822 | // Recorrer las geometr?as buscando las que intersectan. No porque
|
||
823 | // por ejemplo los puntos no intersectan ...
|
||
824 | // Ver de que combinaci?n se trata y calcular nearest, part of o inside
|
||
825 | // seg?n corresponda.
|
||
826 | // Si intersecta copiarle los atributos. O sea rellenar Values como
|
||
827 | // toque ...
|
||
828 | Value[][] values = new Value[geometriesToJoin.length][joinedLyrFieldNames.length+1]; // +1 porque faltaba el PK |
||
829 | // Movida para el nearest entre puntos
|
||
830 | //Point[] joiningPoints = new Point[joiningGeometries.length];
|
||
831 | Geometry[] joiningGeometrySet = new Geometry[joiningGeometries.length]; |
||
832 | /*for (int i=0;i<joiningGeometries.length;i++) {
|
||
833 | joiningPoints[i] = (Point)joiningGeometries[i];
|
||
834 | }*/
|
||
835 | for (int i=0;i<joiningGeometries.length;i++) { |
||
836 | joiningGeometrySet[i] = (Geometry)joiningGeometries[i]; |
||
837 | } |
||
838 | //MultiPoint joiningMultiPoint = new MultiPoint(joiningPoints, new GeometryFactory());
|
||
839 | GeometryCollection joiningGeometryCollection = new GeometryCollection(joiningGeometrySet, new GeometryFactory()); |
||
840 | for (int i=0;i<geometriesToJoin.length;i++) { |
||
841 | Geometry geometryToJoin = geometriesToJoin[i]; |
||
842 | // Movida para el nearest entre puntos
|
||
843 | //Coordinate[] coords = DistanceOp.closestPoints(geometryToJoin, joiningMultiPoint);
|
||
844 | Coordinate[] coords = DistanceOp.closestPoints(geometryToJoin, joiningGeometryCollection);
|
||
845 | for (int j=0;j<joiningGeometries.length;j++) { |
||
846 | Geometry joiningGeometry = joiningGeometries[j]; |
||
847 | if (geometryToJoin instanceof Point && joiningGeometry instanceof Point) { |
||
848 | // Rellenar el PK. Lo tengo que hacer antes del break
|
||
849 | values[i][joinedLyrFieldNames.length] = ValueFactory.createValue(i); |
||
850 | for (int k=0;k<lyrToJoinFieldNames.length-1;k++) { |
||
851 | values[i][k] = lyrToJoinDS.getFieldValue(i, k); |
||
852 | } |
||
853 | if (coords[1].equals2D(joiningGeometry.getCoordinate())) { |
||
854 | for (int k=0;k<joiningLyrFieldNames.length-1;k++) { |
||
855 | values[i][k+l] = joiningLyrDS.getFieldValue(j, k); |
||
856 | } |
||
857 | break; // En el momento encontremos un pol?gono que contiene a otro le metemos los valores y nos vamos |
||
858 | } else {
|
||
859 | for (int k=0;k<joiningLyrFieldNames.length-1;k++) { |
||
860 | values[i][k+l] = ValueFactory.createNullValue(); |
||
861 | } |
||
862 | } |
||
863 | } else if (geometryToJoin instanceof Point && joiningGeometry instanceof LineString) { |
||
864 | // part of not supported yet
|
||
865 | } else if (geometryToJoin instanceof Point && joiningGeometry instanceof Polygon) { |
||
866 | // Rellenar el PK. Lo tengo que hacer antes del break
|
||
867 | values[i][joinedLyrFieldNames.length] = ValueFactory.createValue(i); |
||
868 | for (int k=0;k<lyrToJoinFieldNames.length-1;k++) { |
||
869 | values[i][k] = lyrToJoinDS.getFieldValue(i, k); |
||
870 | } |
||
871 | if (joiningGeometry.contains(geometryToJoin)) {
|
||
872 | for (int k=0;k<joiningLyrFieldNames.length-1;k++) { |
||
873 | System.out.println(i);
|
||
874 | values[i][k+l] = joiningLyrDS.getFieldValue(j, k); |
||
875 | } |
||
876 | break; // En el momento encontremos un pol?gono que contiene a otro le metemos los valores y nos vamos |
||
877 | } else {
|
||
878 | for (int k=0;k<joiningLyrFieldNames.length-1;k++) { |
||
879 | values[i][k+l] = ValueFactory.createNullValue(); |
||
880 | } |
||
881 | } |
||
882 | } else if (geometryToJoin instanceof LineString && joiningGeometry instanceof Point) { |
||
883 | // Rellenar el PK. Lo tengo que hacer antes del break
|
||
884 | values[i][joinedLyrFieldNames.length] = ValueFactory.createValue(i); |
||
885 | for (int k=0;k<lyrToJoinFieldNames.length-1;k++) { |
||
886 | values[i][k] = lyrToJoinDS.getFieldValue(i, k); |
||
887 | } |
||
888 | if (coords[1].equals2D(joiningGeometry.getCoordinate())) { |
||
889 | for (int k=0;k<joiningLyrFieldNames.length-1;k++) { |
||
890 | values[i][k+l] = joiningLyrDS.getFieldValue(j, k); |
||
891 | } |
||
892 | break; // En el momento encontremos un pol?gono que contiene a otro le metemos los valores y nos vamos |
||
893 | } else {
|
||
894 | for (int k=0;k<joiningLyrFieldNames.length-1;k++) { |
||
895 | values[i][k+l] = ValueFactory.createNullValue(); |
||
896 | } |
||
897 | } |
||
898 | } else if (geometryToJoin instanceof LineString && joiningGeometry instanceof LineString) { |
||
899 | // Rellenar el PK. Lo tengo que hacer antes del break
|
||
900 | values[i][joinedLyrFieldNames.length] = ValueFactory.createValue(i); |
||
901 | for (int k=0;k<lyrToJoinFieldNames.length-1;k++) { |
||
902 | values[i][k] = lyrToJoinDS.getFieldValue(i, k); |
||
903 | } |
||
904 | //if (coords[1].equals2D(joiningGeometry.getCoordinate())) {
|
||
905 | if (joiningGeometry.contains(geometryToJoin) || geometryToJoin.contains(joiningGeometry)) {
|
||
906 | for (int k=0;k<joiningLyrFieldNames.length-1;k++) { |
||
907 | values[i][k+l] = joiningLyrDS.getFieldValue(j, k); |
||
908 | } |
||
909 | break; // En el momento encontremos un pol?gono que contiene a otro le metemos los valores y nos vamos |
||
910 | } else {
|
||
911 | for (int k=0;k<joiningLyrFieldNames.length-1;k++) { |
||
912 | values[i][k+l] = ValueFactory.createNullValue(); |
||
913 | } |
||
914 | } |
||
915 | } else if (geometryToJoin instanceof LineString && joiningGeometry instanceof Polygon) { |
||
916 | // Rellenar el PK. Lo tengo que hacer antes del break
|
||
917 | values[i][joinedLyrFieldNames.length] = ValueFactory.createValue(i); |
||
918 | for (int k=0;k<lyrToJoinFieldNames.length-1;k++) { |
||
919 | values[i][k] = lyrToJoinDS.getFieldValue(i, k); |
||
920 | } |
||
921 | if (joiningGeometry.contains(geometryToJoin)) {
|
||
922 | for (int k=0;k<joiningLyrFieldNames.length-1;k++) { |
||
923 | values[i][k+l] = joiningLyrDS.getFieldValue(j, k); |
||
924 | } |
||
925 | break; // En el momento encontremos un pol?gono que contiene a otro le metemos los valores y nos vamos |
||
926 | } else {
|
||
927 | for (int k=0;k<joiningLyrFieldNames.length-1;k++) { |
||
928 | values[i][k+l] = ValueFactory.createNullValue(); |
||
929 | } |
||
930 | } |
||
931 | } else if (geometryToJoin instanceof Polygon && joiningGeometry instanceof Point) { |
||
932 | // nearest not supported yet
|
||
933 | } else if (geometryToJoin instanceof Polygon && joiningGeometry instanceof LineString) { |
||
934 | // nearest not supported yet
|
||
935 | } else if (geometryToJoin instanceof Polygon && joiningGeometry instanceof Polygon) { |
||
936 | // Rellenar el PK. Lo tengo que hacer antes del break
|
||
937 | values[i][joinedLyrFieldNames.length] = ValueFactory.createValue(i); |
||
938 | for (int k=0;k<lyrToJoinFieldNames.length-1;k++) { |
||
939 | values[i][k] = lyrToJoinDS.getFieldValue(i, k); |
||
940 | } |
||
941 | if (joiningGeometry.contains(geometryToJoin)) {
|
||
942 | for (int k=0;k<joiningLyrFieldNames.length-1;k++) { |
||
943 | values[i][k+l] = joiningLyrDS.getFieldValue(j, k); |
||
944 | } |
||
945 | break; // En el momento encontremos un pol?gono que contiene a otro le metemos los valores y nos vamos |
||
946 | } else {
|
||
947 | for (int k=0;k<joiningLyrFieldNames.length-1;k++) { |
||
948 | values[i][k+l] = ValueFactory.createNullValue(); |
||
949 | } |
||
950 | } |
||
951 | } else {
|
||
952 | // MultiPoint, LineSegment, LinearRing, MultiLineString, MultiPolygon faltan
|
||
953 | // por implementar ...
|
||
954 | } |
||
955 | } |
||
956 | } |
||
957 | for (int i=0;i<lyrToJoinSDS.getSelection().cardinality();i++) { |
||
958 | dw.insertFilledRow(values[i]); |
||
959 | } |
||
960 | /*for (int i=0;i<lyrToJoinDS.getRowCount();i++) {
|
||
961 | dw.insertFilledRow(values[i]);
|
||
962 | }*/
|
||
963 | dw.commitTrans(); |
||
964 | IGeometry[] shapes = getFmapGeometries(geometriesToJoin);
|
||
965 | // Guardo la tabla mediante gdbms. Guardo tambi?n las entidades JTS mediante gvSIG o usando solo gdbms (probablemente bastar? con usar gdbms)
|
||
966 | // Guardar las viejas geometr?as.
|
||
967 | GeoProcessingPersistenceOperations.saveResultsToShapeFile(shapes, geoProcessingSpatialjoinPanel.getOutputFile()); |
||
968 | //lyrToJoinSDS.getSelection().clear();
|
||
969 | //joiningLyrSDS.getSelection().clear();
|
||
970 | lyrToJoinSDS.setSelection(new FBitSet());
|
||
971 | joiningLyrSDS.setSelection(new FBitSet());
|
||
972 | } catch (DriverException e) {
|
||
973 | // TODO Auto-generated catch block
|
||
974 | e.printStackTrace(); |
||
975 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
976 | // TODO Auto-generated catch block
|
||
977 | e.printStackTrace(); |
||
978 | } catch (DriverLoadException e) {
|
||
979 | // TODO Auto-generated catch block
|
||
980 | e.printStackTrace(); |
||
981 | } catch (NoSuchTableException e) {
|
||
982 | // TODO Auto-generated catch block
|
||
983 | e.printStackTrace(); |
||
984 | } |
||
985 | } |
||
986 | // clip: intersect + dissolve
|
||
987 | 2864 | jmorell | private void clipMethod() { |
988 | String layerToClipName = (String)((JComboBox)geoProcessingClipPanel.getComponent(0)).getSelectedItem(); |
||
989 | FLayer layerToClip = layers.getLayer(layerToClipName); |
||
990 | boolean selected = false; |
||
991 | 3008 | jmorell | if (((JCheckBox)geoProcessingClipPanel.getComponent(1)).isSelected()) selected = true; |
992 | 2864 | jmorell | Geometry[] geometriesToClip = getJtsGeometries(layerToClip, selected);
|
993 | String clippingLayerName = (String)((JComboBox)geoProcessingClipPanel.getComponent(3)).getSelectedItem(); |
||
994 | FLayer clippingLayer = layers.getLayer(clippingLayerName); |
||
995 | 3008 | jmorell | if (((JCheckBox)geoProcessingClipPanel.getComponent(5)).isSelected()) selected = true; |
996 | 2864 | jmorell | Geometry[] clippingGeometries = getJtsGeometries(clippingLayer, selected);
|
997 | 2989 | jmorell | AlphanumericData lyr = (AlphanumericData)layerToClip; |
998 | SelectableDataSource sds; |
||
999 | try {
|
||
1000 | DataSource ds;
|
||
1001 | ds = lyr.getRecordset(); |
||
1002 | sds = lyr.getRecordset(); |
||
1003 | // Tener en cuenta que podemos estar trabajando solo con una selecci?n
|
||
1004 | 3008 | jmorell | FBitSet fBitSet = sds.getSelection(); |
1005 | // Clono porque preguntarle al FBitSet si est? lleno es una putada ...
|
||
1006 | FBitSet otherFBitSet = (FBitSet)fBitSet.clone(); |
||
1007 | if (otherFBitSet.cardinality()==0) otherFBitSet.set(0, (int)sds.getRowCount()); |
||
1008 | Value[][] selectedValues = new Value[otherFBitSet.cardinality()][ds.getFieldCount()]; |
||
1009 | int l=0; |
||
1010 | for (int i=0;i<ds.getRowCount();i++) { |
||
1011 | if (otherFBitSet.get(i)) {
|
||
1012 | selectedValues[l] = ds.getRow(i); |
||
1013 | l++; |
||
1014 | } |
||
1015 | } |
||
1016 | 2989 | jmorell | String[] fieldNames = new String[sds.getFieldCount()-1]; |
1017 | int[] fieldTypes = new int[sds.getFieldCount()-1]; |
||
1018 | for (int i = 0; i < sds.getFieldCount()-1; i++) { |
||
1019 | fieldNames[i] = sds.getFieldName(i); |
||
1020 | fieldTypes[i] = sds.getFieldType(i); |
||
1021 | } |
||
1022 | DataSourceFactory dsf = sds.getDataSourceFactory(); |
||
1023 | File file = geoProcessingClipPanel.getOutputFile();
|
||
1024 | dsf.createFileDataSource("gdbms dbf driver", "new_table", file.getAbsolutePath().replaceAll(".shp", ".dbf"), fieldNames, fieldTypes); |
||
1025 | DataSource dataSource = dsf.createRandomDataSource("new_table"); |
||
1026 | dataSource.start(); |
||
1027 | DataWare dw = dataSource.getDataWare(DataSourceFactory.MANUAL_OPENING); |
||
1028 | dw.beginTrans(); |
||
1029 | Vector values = new Vector(); |
||
1030 | Vector geometriesClipped = new Vector(); |
||
1031 | for (int i=0;i<geometriesToClip.length;i++) { |
||
1032 | Geometry geometryToClip = geometriesToClip[i]; |
||
1033 | for (int j=0;j<clippingGeometries.length;j++) { |
||
1034 | Geometry clippingGeometry = clippingGeometries[j]; |
||
1035 | if (clippingGeometry.intersects(geometryToClip)) {
|
||
1036 | geometriesClipped.add(geometryToClip.intersection(clippingGeometry)); |
||
1037 | 2994 | jmorell | Value[] row = new Value[fieldNames.length+1]; // +1 porque faltaba el PK |
1038 | 2989 | jmorell | for (int m=0;m<fieldNames.length;m++) { |
1039 | 3008 | jmorell | row[m] = selectedValues[i][m]; |
1040 | 2989 | jmorell | } |
1041 | 2994 | jmorell | row[fieldNames.length] = ValueFactory.createValue(i); |
1042 | values.add(row); |
||
1043 | 2989 | jmorell | } |
1044 | } |
||
1045 | } |
||
1046 | 2994 | jmorell | Vector resultGeometries = new Vector(); |
1047 | for (int i=0;i<values.size();i++) { |
||
1048 | Value[] rowi = ((Value[])values.get(i)); |
||
1049 | Geometry geometryi = ((Geometry)geometriesClipped.get(i)); |
||
1050 | for (int j=0;j<values.size();j++) { |
||
1051 | if (j!=i) {
|
||
1052 | Value[] rowj = ((Value[])values.get(j)); |
||
1053 | boolean areTheSameElement = true; |
||
1054 | 2999 | jmorell | for (int k=0;k<rowj.length;k++) { |
1055 | //for (int k=0;k<rowj.length-1;k++) {
|
||
1056 | 2994 | jmorell | Value valuei = rowi[k]; |
1057 | Value valuej = rowj[k]; |
||
1058 | if (!((BooleanValue)(valuej.equals(valuei))).getValue()) {
|
||
1059 | areTheSameElement = false;
|
||
1060 | break;
|
||
1061 | } |
||
1062 | } |
||
1063 | if (areTheSameElement) {
|
||
1064 | Geometry geometryj = ((Geometry)geometriesClipped.get(j)); |
||
1065 | geometryi = geometryj.union(geometryi); |
||
1066 | } |
||
1067 | } |
||
1068 | } |
||
1069 | resultGeometries.add(geometryi); |
||
1070 | 2989 | jmorell | } |
1071 | 2994 | jmorell | for (int i=0;i<resultGeometries.size();i++) { |
1072 | for (int j=0;j<resultGeometries.size();j++) { |
||
1073 | if (j>i) {
|
||
1074 | if (((Geometry)resultGeometries.get(i)).equals((Geometry)resultGeometries.get(j))) {
|
||
1075 | resultGeometries.remove(j); |
||
1076 | j--; |
||
1077 | } |
||
1078 | } |
||
1079 | } |
||
1080 | } |
||
1081 | 2996 | jmorell | for (int i=0;i<values.size();i++) { |
1082 | Value[] rowi = ((Value[])values.get(i)); |
||
1083 | for (int j=0;j<values.size();j++) { |
||
1084 | if (j>i) {
|
||
1085 | Value[] rowj = ((Value[])values.get(j)); |
||
1086 | boolean areTheSameElement = true; |
||
1087 | 2999 | jmorell | for (int k=0;k<rowj.length;k++) { |
1088 | //for (int k=0;k<rowj.length-1;k++) {
|
||
1089 | 2996 | jmorell | Value valuei = rowi[k]; |
1090 | Value valuej = rowj[k]; |
||
1091 | if (!((BooleanValue)(valuej.equals(valuei))).getValue()) {
|
||
1092 | areTheSameElement = false;
|
||
1093 | } |
||
1094 | } |
||
1095 | if (areTheSameElement) {
|
||
1096 | values.remove(j); |
||
1097 | j--; |
||
1098 | } |
||
1099 | } |
||
1100 | } |
||
1101 | 2989 | jmorell | } |
1102 | Geometry[] dissolvedGeometries = new Geometry[resultGeometries.size()]; |
||
1103 | for (int i=0;i<resultGeometries.size();i++) { |
||
1104 | dissolvedGeometries[i] = (Geometry)resultGeometries.get(i); |
||
1105 | } |
||
1106 | IGeometry[] shapes = getFmapGeometries(dissolvedGeometries);
|
||
1107 | Geometry[] clippedGeometries = new Geometry[geometriesClipped.size()]; |
||
1108 | for (int i=0;i<geometriesClipped.size();i++) { |
||
1109 | clippedGeometries[i] = (Geometry)geometriesClipped.get(i); |
||
1110 | } |
||
1111 | GeoProcessingPersistenceOperations.saveResultsToShapeFile(shapes, geoProcessingClipPanel.getOutputFile()); |
||
1112 | dataSource.stop(); |
||
1113 | sds.stop(); |
||
1114 | ds.stop(); |
||
1115 | for (int i=0;i<values.size();i++) { |
||
1116 | dw.insertFilledRow(((Value[])values.get(i)));
|
||
1117 | } |
||
1118 | dw.commitTrans(); |
||
1119 | 3008 | jmorell | //if (((AlphanumericData)layerToClip).getRecordset().getSelection().nextClearBit(0)==-1 || ((AlphanumericData)layerToClip).getRecordset().getSelection().isEmpty()) ((AlphanumericData)layerToClip).getRecordset().setSelection(new FBitSet());
|
1120 | //if (((AlphanumericData)layerToClip).getRecordset().getSelection().nextClearBit(0)==-1) ((AlphanumericData)layerToClip).getRecordset().setSelection(new FBitSet());
|
||
1121 | //if (((AlphanumericData)clippingLayer).getRecordset().getSelection().nextClearBit(0)==-1) ((AlphanumericData)clippingLayer).getRecordset().setSelection(new FBitSet());
|
||
1122 | 2989 | jmorell | } catch (DriverException e) {
|
1123 | // TODO Auto-generated catch block
|
||
1124 | e.printStackTrace(); |
||
1125 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
1126 | // TODO Auto-generated catch block
|
||
1127 | e.printStackTrace(); |
||
1128 | } catch (DriverLoadException e) {
|
||
1129 | // TODO Auto-generated catch block
|
||
1130 | e.printStackTrace(); |
||
1131 | } catch (NoSuchTableException e) {
|
||
1132 | // TODO Auto-generated catch block
|
||
1133 | e.printStackTrace(); |
||
1134 | } catch (IncompatibleTypesException e) {
|
||
1135 | // TODO Auto-generated catch block
|
||
1136 | e.printStackTrace(); |
||
1137 | } |
||
1138 | 2864 | jmorell | } |
1139 | 2989 | jmorell | // Spatial join con Intersect
|
1140 | 3015 | jmorell | // Funciona bien salvo para el caso de l?neas y puntos, donde habr?a que aumentar
|
1141 | // la precisi?n del PrecisionModel a costa probablemente de perder velocidad ...
|
||
1142 | 2402 | jmorell | private void intersectMethod() { |
1143 | 2670 | jmorell | String layerToIntersectName = (String)((JComboBox)geoProcessingIntersectPanel.getComponent(0)).getSelectedItem(); |
1144 | FLayer layerToIntersect = layers.getLayer(layerToIntersectName); |
||
1145 | 2989 | jmorell | String intersectingLayerName = (String)((JComboBox)geoProcessingIntersectPanel.getComponent(3)).getSelectedItem(); |
1146 | FLayer intersectingLayer = layers.getLayer(intersectingLayerName); |
||
1147 | 2670 | jmorell | boolean selected = false; |
1148 | 2989 | jmorell | try {
|
1149 | 3015 | jmorell | if (((JCheckBox)geoProcessingIntersectPanel.getComponent(1)).isSelected()) selected = true; |
1150 | 2989 | jmorell | AlphanumericData lyrToIntersect = (AlphanumericData)layerToIntersect; |
1151 | 3015 | jmorell | if (((JCheckBox)geoProcessingIntersectPanel.getComponent(5)).isSelected()) selected = true; |
1152 | AlphanumericData intersectingLyr = (AlphanumericData)intersectingLayer; |
||
1153 | Geometry[] geometriesToIntersect = getJtsGeometries(layerToIntersect, selected);
|
||
1154 | Geometry[] intersectingGeometries = getJtsGeometries(intersectingLayer, selected);
|
||
1155 | 2989 | jmorell | SelectableDataSource lyrToIntersectSDS = lyrToIntersect.getRecordset(); |
1156 | 3015 | jmorell | SelectableDataSource intersectingLyrSDS = intersectingLyr.getRecordset(); |
1157 | //DataSource lyrToIntersectDS;
|
||
1158 | //DataSource intersectingLyrDS;
|
||
1159 | //lyrToIntersectDS = lyrToIntersect.getRecordset();
|
||
1160 | //intersectingLyrDS = intersectingLyr.getRecordset();
|
||
1161 | // Tener en cuenta que podemos estar trabajando solo con una selecci?n
|
||
1162 | FBitSet fBitSet1 = lyrToIntersectSDS.getSelection(); |
||
1163 | FBitSet fBitSet2 = intersectingLyrSDS.getSelection(); |
||
1164 | // Clono porque preguntarle al FBitSet si est? lleno es una putada ...
|
||
1165 | FBitSet otherFBitSet1 = (FBitSet)fBitSet1.clone(); |
||
1166 | if (otherFBitSet1.cardinality()==0) otherFBitSet1.set(0, (int)lyrToIntersectSDS.getRowCount()); |
||
1167 | Value[][] selectedValues1 = new Value[otherFBitSet1.cardinality()][lyrToIntersectSDS.getFieldCount()]; |
||
1168 | int n=0; |
||
1169 | for (int i=0;i<lyrToIntersectSDS.getRowCount();i++) { |
||
1170 | if (otherFBitSet1.get(i)) {
|
||
1171 | selectedValues1[n] = lyrToIntersectSDS.getRow(i); |
||
1172 | n++; |
||
1173 | } |
||
1174 | } |
||
1175 | // Clono porque preguntarle al FBitSet si est? lleno es una putada ...
|
||
1176 | FBitSet otherFBitSet2 = (FBitSet)fBitSet2.clone(); |
||
1177 | if (otherFBitSet2.cardinality()==0) otherFBitSet2.set(0, (int)intersectingLyrSDS.getRowCount()); |
||
1178 | Value[][] selectedValues2 = new Value[otherFBitSet2.cardinality()][intersectingLyrSDS.getFieldCount()]; |
||
1179 | int m=0; |
||
1180 | for (int i=0;i<intersectingLyrSDS.getRowCount();i++) { |
||
1181 | if (otherFBitSet2.get(i)) {
|
||
1182 | selectedValues2[m] = intersectingLyrSDS.getRow(i); |
||
1183 | m++; |
||
1184 | } |
||
1185 | } |
||
1186 | 2989 | jmorell | // Los campos se a?aden siempre. Los valores solo cuando toca ...
|
1187 | 3015 | jmorell | String[] lyrToIntersectFieldNames = new String[lyrToIntersectSDS.getFieldCount()]; |
1188 | int[] lyrToIntersectFieldTypes = new int[lyrToIntersectSDS.getFieldCount()]; |
||
1189 | for (int i = 0; i < lyrToIntersectSDS.getFieldCount(); i++) { |
||
1190 | lyrToIntersectFieldNames[i] = lyrToIntersectSDS.getFieldName(i); |
||
1191 | lyrToIntersectFieldTypes[i] = lyrToIntersectSDS.getFieldType(i); |
||
1192 | 2989 | jmorell | } |
1193 | 3015 | jmorell | String[] intersectingLyrFieldNames = new String[intersectingLyrSDS.getFieldCount()]; |
1194 | int[] intersectingLyrFieldTypes = new int[intersectingLyrSDS.getFieldCount()]; |
||
1195 | for (int i = 0; i < intersectingLyrSDS.getFieldCount(); i++) { |
||
1196 | intersectingLyrFieldNames[i] = intersectingLyrSDS.getFieldName(i); |
||
1197 | intersectingLyrFieldTypes[i] = intersectingLyrSDS.getFieldType(i); |
||
1198 | 2989 | jmorell | } |
1199 | 3015 | jmorell | String[] intersectedLyrFieldNames = new String[lyrToIntersectSDS.getFieldCount()+intersectingLyrSDS.getFieldCount()-2]; // Le quito los dos PKs |
1200 | int[] intersectedLyrFieldTypes = new int[lyrToIntersectSDS.getFieldCount()+intersectingLyrSDS.getFieldCount()-2]; |
||
1201 | 2989 | jmorell | int l=0; |
1202 | for (int i=0;i<lyrToIntersectFieldNames.length-1;i++) { |
||
1203 | intersectedLyrFieldNames[i] = lyrToIntersectFieldNames[i]; |
||
1204 | intersectedLyrFieldTypes[i] = lyrToIntersectFieldTypes[i]; |
||
1205 | l++; |
||
1206 | } |
||
1207 | for (int i=0;i<intersectingLyrFieldNames.length-1;i++) { |
||
1208 | intersectedLyrFieldNames[i+l] = intersectingLyrFieldNames[i]; |
||
1209 | intersectedLyrFieldTypes[i+l] = intersectingLyrFieldTypes[i]; |
||
1210 | } |
||
1211 | DataSourceFactory dsf = lyrToIntersectSDS.getDataSourceFactory(); |
||
1212 | File file = geoProcessingIntersectPanel.getOutputFile();
|
||
1213 | dsf.createFileDataSource("gdbms dbf driver", "new_table", file.getAbsolutePath().replaceAll(".shp", ".dbf"), intersectedLyrFieldNames, intersectedLyrFieldTypes); |
||
1214 | DataSource ds = dsf.createRandomDataSource("new_table"); |
||
1215 | ds.start(); |
||
1216 | DataWare dw = ds.getDataWare(DataSourceFactory.MANUAL_OPENING); |
||
1217 | dw.beginTrans(); |
||
1218 | |||
1219 | Vector values = new Vector(); |
||
1220 | Vector geometriesIntersected = new Vector(); |
||
1221 | for (int i=0;i<geometriesToIntersect.length;i++) { |
||
1222 | Geometry geometryToIntersect = geometriesToIntersect[i]; |
||
1223 | String geometryToIntersectType = geometryToIntersect.getGeometryType();
|
||
1224 | System.out.println("geometryToIntersectType = " + geometryToIntersectType); |
||
1225 | for (int j=0;j<intersectingGeometries.length;j++) { |
||
1226 | Geometry intersectingGeometry = intersectingGeometries[j]; |
||
1227 | if (intersectingGeometry.intersects(geometryToIntersect)) {
|
||
1228 | geometriesIntersected.add(geometryToIntersect.intersection(intersectingGeometry)); |
||
1229 | Value[] rows = new Value[intersectedLyrFieldNames.length+1]; // +1 porque faltaba el PK |
||
1230 | for (int k=0;k<lyrToIntersectFieldNames.length-1;k++) { |
||
1231 | 3015 | jmorell | //rows[k] = lyrToIntersectDS.getFieldValue(i, k);
|
1232 | rows[k] = selectedValues1[i][k]; |
||
1233 | 2989 | jmorell | } |
1234 | for (int k=0;k<intersectingLyrFieldNames.length-1;k++) { |
||
1235 | 3015 | jmorell | //rows[k+l] = intersectingLyrDS.getFieldValue(j, k);
|
1236 | rows[k+l] = selectedValues2[j][k]; |
||
1237 | 2989 | jmorell | } |
1238 | rows[intersectedLyrFieldNames.length] = ValueFactory.createValue(i); |
||
1239 | values.add(rows); |
||
1240 | } |
||
1241 | } |
||
1242 | } |
||
1243 | |||
1244 | 3015 | jmorell | ds.stop(); |
1245 | lyrToIntersectSDS.stop(); |
||
1246 | intersectingLyrSDS.stop(); |
||
1247 | |||
1248 | 2989 | jmorell | for (int i=0;i<geometriesIntersected.size();i++) { |
1249 | dw.insertFilledRow(((Value[])values.get(i)));
|
||
1250 | } |
||
1251 | dw.commitTrans(); |
||
1252 | Geometry[] geometriesIntersectedArray = new Geometry[geometriesIntersected.size()]; |
||
1253 | for (int i=0;i<geometriesIntersected.size();i++) { |
||
1254 | geometriesIntersectedArray[i] = (Geometry)geometriesIntersected.get(i); |
||
1255 | } |
||
1256 | IGeometry[] shapes = getFmapGeometries(geometriesIntersectedArray);
|
||
1257 | // Guardo la tabla mediante gdbms. Guardo tambi?n las entidades JTS mediante gvSIG o usando solo gdbms (probablemente bastar? con usar gdbms)
|
||
1258 | // Guardar las viejas geometr?as.
|
||
1259 | GeoProcessingPersistenceOperations.saveResultsToShapeFile(shapes, geoProcessingIntersectPanel.getOutputFile()); |
||
1260 | } catch (DriverException e) {
|
||
1261 | // TODO Auto-generated catch block
|
||
1262 | e.printStackTrace(); |
||
1263 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
1264 | // TODO Auto-generated catch block
|
||
1265 | e.printStackTrace(); |
||
1266 | } catch (DriverLoadException e) {
|
||
1267 | // TODO Auto-generated catch block
|
||
1268 | e.printStackTrace(); |
||
1269 | } catch (NoSuchTableException e) {
|
||
1270 | // TODO Auto-generated catch block
|
||
1271 | e.printStackTrace(); |
||
1272 | } |
||
1273 | 2402 | jmorell | } |
1274 | private void unionMethod() { |
||
1275 | 2670 | jmorell | String layerToUnionName = (String)((JComboBox)geoProcessingUnionPanel.getComponent(0)).getSelectedItem(); |
1276 | FLayer layerToUnion = layers.getLayer(layerToUnionName); |
||
1277 | boolean selected = false; |
||
1278 | 2989 | jmorell | //if (((JCheckBox)geoProcessingUnionPanel.getComponent(1)).isSelected()) selected = true;
|
1279 | 2670 | jmorell | Geometry[] geometriesToUnion = getJtsGeometries(layerToUnion, selected);
|
1280 | String uningLayerName = (String)((JComboBox)geoProcessingUnionPanel.getComponent(3)).getSelectedItem(); |
||
1281 | FLayer uningLayer = layers.getLayer(uningLayerName); |
||
1282 | 2989 | jmorell | //if (((JCheckBox)geoProcessingUnionPanel.getComponent(5)).isSelected()) selected = true;
|
1283 | 2670 | jmorell | Geometry[] uningGeometries = getJtsGeometries(uningLayer, selected);
|
1284 | 2989 | jmorell | |
1285 | //if (((JCheckBox)geoProcessingIntersectPanel.getComponent(1)).isSelected()) selected = true;
|
||
1286 | AlphanumericData lyrToUnion = (AlphanumericData)layerToUnion; |
||
1287 | SelectableDataSource lyrToUnionSDS; |
||
1288 | try {
|
||
1289 | lyrToUnionSDS = lyrToUnion.getRecordset(); |
||
1290 | //if (((JCheckBox)geoProcessingIntersectPanel.getComponent(5)).isSelected()) selected = true;
|
||
1291 | AlphanumericData uningLyr = (AlphanumericData)uningLayer; |
||
1292 | DataSource lyrToUnionDS;
|
||
1293 | DataSource uningLyrDS;
|
||
1294 | lyrToUnionDS = lyrToUnion.getRecordset(); |
||
1295 | uningLyrDS = uningLyr.getRecordset(); |
||
1296 | // Los campos se a?aden siempre. Los valores solo cuando toca ...
|
||
1297 | String[] lyrToUnionFieldNames = new String[lyrToUnionDS.getFieldCount()]; |
||
1298 | int[] lyrToUnionFieldTypes = new int[lyrToUnionDS.getFieldCount()]; |
||
1299 | for (int i = 0; i < lyrToUnionDS.getFieldCount(); i++) { |
||
1300 | lyrToUnionFieldNames[i] = lyrToUnionDS.getFieldName(i); |
||
1301 | lyrToUnionFieldTypes[i] = lyrToUnionDS.getFieldType(i); |
||
1302 | } |
||
1303 | String[] uningLyrFieldNames = new String[uningLyrDS.getFieldCount()]; |
||
1304 | int[] uningLyrFieldTypes = new int[uningLyrDS.getFieldCount()]; |
||
1305 | for (int i = 0; i < uningLyrDS.getFieldCount(); i++) { |
||
1306 | uningLyrFieldNames[i] = uningLyrDS.getFieldName(i); |
||
1307 | uningLyrFieldTypes[i] = uningLyrDS.getFieldType(i); |
||
1308 | } |
||
1309 | String[] unedLyrFieldNames = new String[lyrToUnionDS.getFieldCount()+uningLyrDS.getFieldCount()-2]; // Le quito los dos PKs |
||
1310 | int[] unedLyrFieldTypes = new int[lyrToUnionDS.getFieldCount()+uningLyrDS.getFieldCount()-2]; |
||
1311 | int l=0; |
||
1312 | for (int i=0;i<lyrToUnionFieldNames.length-1;i++) { |
||
1313 | unedLyrFieldNames[i] = lyrToUnionFieldNames[i]; |
||
1314 | unedLyrFieldTypes[i] = lyrToUnionFieldTypes[i]; |
||
1315 | l++; |
||
1316 | } |
||
1317 | for (int i=0;i<uningLyrFieldNames.length-1;i++) { |
||
1318 | unedLyrFieldNames[i+l] = uningLyrFieldNames[i]; |
||
1319 | unedLyrFieldTypes[i+l] = uningLyrFieldTypes[i]; |
||
1320 | } |
||
1321 | DataSourceFactory dsf = lyrToUnionSDS.getDataSourceFactory(); |
||
1322 | File file = geoProcessingUnionPanel.getOutputFile();
|
||
1323 | dsf.createFileDataSource("gdbms dbf driver", "new_table", file.getAbsolutePath().replaceAll(".shp", ".dbf"), unedLyrFieldNames, unedLyrFieldTypes); |
||
1324 | DataSource ds = dsf.createRandomDataSource("new_table"); |
||
1325 | ds.start(); |
||
1326 | DataWare dw = ds.getDataWare(DataSourceFactory.MANUAL_OPENING); |
||
1327 | dw.beginTrans(); |
||
1328 | ds.stop(); |
||
1329 | lyrToUnionSDS.stop(); |
||
1330 | |||
1331 | Vector values = new Vector(); |
||
1332 | |||
1333 | //Geometry[] unedGeometries = GeoProcessingTopologyOperations.makeUnion(geometriesToUnion, uningGeometries);
|
||
1334 | Geometry[] result = new Geometry[geometriesToUnion.length]; |
||
1335 | Vector geometriesUned = new Vector(); |
||
1336 | //Selectable selectable = (Selectable)layerToUnion;
|
||
1337 | //FBitSet fBitSet = new FBitSet();
|
||
1338 | // Metememos en geometriesUned las intersecciones.
|
||
1339 | for (int i=0;i<geometriesToUnion.length;i++) { |
||
1340 | Geometry geometryToUnion = geometriesToUnion[i]; |
||
1341 | for (int j=0;j<uningGeometries.length;j++) { |
||
1342 | Geometry uningGeometry = uningGeometries[j]; |
||
1343 | if (uningGeometry.intersects(geometryToUnion)) {
|
||
1344 | //fBitSet.set(i);
|
||
1345 | geometriesUned.add(geometryToUnion.intersection(uningGeometry)); |
||
1346 | Value[] intersectRow = new Value[unedLyrFieldNames.length+1]; |
||
1347 | for (int k=0;k<lyrToUnionFieldNames.length-1;k++) { |
||
1348 | intersectRow[k] = lyrToUnionDS.getFieldValue(i, k); |
||
1349 | } |
||
1350 | for (int k=0;k<uningLyrFieldNames.length-1;k++) { |
||
1351 | intersectRow[k+l] = uningLyrDS.getFieldValue(j, k); |
||
1352 | } |
||
1353 | intersectRow[unedLyrFieldNames.length] = ValueFactory.createValue(i); |
||
1354 | values.add(intersectRow); |
||
1355 | //geometriesUned.add(geometryToUnion.difference(uningGeometry));
|
||
1356 | } |
||
1357 | } |
||
1358 | } |
||
1359 | // Rellenamos geometriesUned2 con estas intersecciones.
|
||
1360 | Vector geometriesUned2 = new Vector(); |
||
1361 | for (int i=0;i<geometriesUned.size();i++) { |
||
1362 | geometriesUned2.add(geometriesUned.get(i)); |
||
1363 | } |
||
1364 | //int num = geometriesUned.size();
|
||
1365 | // A?ado a geometriesUned2 las geometr?as de geometriesToUnion que no
|
||
1366 | // intersectan con uningGeometries.
|
||
1367 | for (int i=0;i<geometriesToUnion.length;i++) { |
||
1368 | Geometry geometryToUnion = geometriesToUnion[i]; |
||
1369 | boolean intersectsWithAnyGeometry = false; |
||
1370 | for (int j=0;j<geometriesUned.size();j++) { |
||
1371 | Geometry geometryUned = (Geometry)geometriesUned.get(j); |
||
1372 | if (geometryToUnion.intersects(geometryUned)) intersectsWithAnyGeometry = true; |
||
1373 | } |
||
1374 | if (intersectsWithAnyGeometry) {
|
||
1375 | //Geometry difference = geometryToUnion.difference(geometryUned);
|
||
1376 | //geometriesUned2.add(difference);
|
||
1377 | } else {
|
||
1378 | geometriesUned2.add(geometryToUnion); |
||
1379 | Value[] unionRow = new Value[unedLyrFieldNames.length+1]; |
||
1380 | for (int k=0;k<lyrToUnionFieldNames.length-1;k++) { |
||
1381 | unionRow[k] = lyrToUnionDS.getFieldValue(i, k); |
||
1382 | } |
||
1383 | for (int k=0;k<uningLyrFieldNames.length-1;k++) { |
||
1384 | unionRow[k+l] = ValueFactory.createNullValue(); |
||
1385 | } |
||
1386 | unionRow[unedLyrFieldNames.length] = ValueFactory.createValue(i); |
||
1387 | values.add(unionRow); |
||
1388 | } |
||
1389 | } |
||
1390 | // A?ado a geometriesUned2 las geometr?as de uningGeometries que no
|
||
1391 | // intersectan con geometriesToUnion.
|
||
1392 | for (int i=0;i<uningGeometries.length;i++) { |
||
1393 | Geometry uningGeometry = uningGeometries[i]; |
||
1394 | boolean intersectsWithAnyGeometry = false; |
||
1395 | for (int j=0;j<geometriesUned.size();j++) { |
||
1396 | Geometry geometryUned = (Geometry)geometriesUned.get(j); |
||
1397 | if (uningGeometry.intersects(geometryUned)) intersectsWithAnyGeometry = true; |
||
1398 | } |
||
1399 | if (intersectsWithAnyGeometry) {
|
||
1400 | //Geometry difference = jtsUningGeometry.difference(jtsGeometryUned);
|
||
1401 | //jtsGeometriesUned2.add(difference);
|
||
1402 | } else {
|
||
1403 | geometriesUned2.add(uningGeometry); |
||
1404 | Value[] uningRow = new Value[unedLyrFieldNames.length+1]; |
||
1405 | for (int k=0;k<lyrToUnionFieldNames.length-1;k++) { |
||
1406 | uningRow[k] = ValueFactory.createNullValue(); |
||
1407 | } |
||
1408 | for (int k=0;k<uningLyrFieldNames.length-1;k++) { |
||
1409 | uningRow[k+l] = uningLyrDS.getFieldValue(i, k); |
||
1410 | } |
||
1411 | uningRow[unedLyrFieldNames.length] = ValueFactory.createValue(i); |
||
1412 | values.add(uningRow); |
||
1413 | } |
||
1414 | } |
||
1415 | //System.out.println("geometriesUned2.size() = " + geometriesUned2.size());
|
||
1416 | // Le quito los cachos que ya tengo a las geometrias que faltan de
|
||
1417 | // uningGeometries.
|
||
1418 | BitSet bitSet1 = new BitSet(); |
||
1419 | bitSet1.clear(); |
||
1420 | //int k1=0;
|
||
1421 | for (int i=0;i<geometriesUned2.size();i++) { |
||
1422 | Geometry geometryUned2 = (Geometry)geometriesUned2.get(i); |
||
1423 | for (int j=0;j<uningGeometries.length;j++) { |
||
1424 | //System.out.println("!(uningGeometries[j].equals(geometryUned2)) = " + !(uningGeometries[j].equals(geometryUned2)));
|
||
1425 | if (uningGeometries[j].intersects(geometryUned2) && !(uningGeometries[j].equals(geometryUned2))) {
|
||
1426 | uningGeometries[j] = uningGeometries[j].difference(geometryUned2); |
||
1427 | //bitSet1.set(k1);
|
||
1428 | bitSet1.set(j); |
||
1429 | } |
||
1430 | //k1++;
|
||
1431 | } |
||
1432 | } |
||
1433 | // Le quito los cachos que ya tengo a las geometrias que faltan de
|
||
1434 | // geometriesToUnion.
|
||
1435 | BitSet bitSet2 = new BitSet(); |
||
1436 | bitSet2.clear(); |
||
1437 | int k2=0; |
||
1438 | for (int i=0;i<geometriesUned2.size();i++) { |
||
1439 | Geometry geometryUned2 = (Geometry)geometriesUned2.get(i); |
||
1440 | for (int j=0;j<geometriesToUnion.length;j++) { |
||
1441 | //System.out.println("!(geometriesToUnion[j].equals(geometryUned2)) = " + !(geometriesToUnion[j].equals(geometryUned2)));
|
||
1442 | if (geometriesToUnion[j].intersects(geometryUned2) && !(geometriesToUnion[j].equals(geometryUned2))) {
|
||
1443 | geometriesToUnion[j] = geometriesToUnion[j].difference(geometryUned2); |
||
1444 | bitSet2.set(k2); |
||
1445 | //bitSet2.set(j);
|
||
1446 | } |
||
1447 | k2++; |
||
1448 | } |
||
1449 | } |
||
1450 | //for (int i=0;i<bitSet2.size();i++) {
|
||
1451 | // System.out.println("bitSet2.get(" + i + ") = " + bitSet2.get(i));
|
||
1452 | //}
|
||
1453 | // Ahora que les he quitado los cachos que ya ten?a, le meto los features que
|
||
1454 | // faltaban de uningGeometries
|
||
1455 | for (int i=0;i<uningGeometries.length;i++) { |
||
1456 | if (bitSet1.get(i)) {
|
||
1457 | geometriesUned2.add(uningGeometries[i]); |
||
1458 | Value[] uningRow = new Value[unedLyrFieldNames.length+1]; |
||
1459 | for (int k=0;k<lyrToUnionFieldNames.length-1;k++) { |
||
1460 | uningRow[k] = ValueFactory.createNullValue(); |
||
1461 | } |
||
1462 | for (int k=0;k<uningLyrFieldNames.length-1;k++) { |
||
1463 | uningRow[k+l] = uningLyrDS.getFieldValue(i, k); |
||
1464 | } |
||
1465 | uningRow[unedLyrFieldNames.length] = ValueFactory.createValue(i); |
||
1466 | values.add(uningRow); |
||
1467 | } |
||
1468 | } |
||
1469 | // Ahora que les he quitado los cachos que ya ten?a, le meto los features que
|
||
1470 | // faltaban de geometriesToUnion
|
||
1471 | for (int i=0;i<geometriesToUnion.length;i++) { |
||
1472 | if (bitSet2.get(i)) {
|
||
1473 | geometriesUned2.add(geometriesToUnion[i]); |
||
1474 | Value[] unionRow = new Value[unedLyrFieldNames.length+1]; |
||
1475 | for (int k=0;k<lyrToUnionFieldNames.length-1;k++) { |
||
1476 | unionRow[k] = lyrToUnionDS.getFieldValue(i, k); |
||
1477 | } |
||
1478 | for (int k=0;k<uningLyrFieldNames.length-1;k++) { |
||
1479 | unionRow[k+l] = ValueFactory.createNullValue(); |
||
1480 | } |
||
1481 | unionRow[unedLyrFieldNames.length] = ValueFactory.createValue(i); |
||
1482 | values.add(unionRow); |
||
1483 | } |
||
1484 | } |
||
1485 | //selectable.setSelection(fBitSet);
|
||
1486 | result = new Geometry[geometriesUned2.size()];
|
||
1487 | for (int i=0;i<geometriesUned2.size();i++) { |
||
1488 | result[i] = (Geometry)geometriesUned2.get(i); |
||
1489 | } |
||
1490 | |||
1491 | for (int i=0;i<result.length;i++) { |
||
1492 | dw.insertFilledRow(((Value[])values.get(i)));
|
||
1493 | } |
||
1494 | dw.commitTrans(); |
||
1495 | |||
1496 | IGeometry[] shapes = getFmapGeometries(result);
|
||
1497 | // Guardo la tabla mediante gdbms. Guardo tambi?n las entidades JTS mediante gvSIG o usando solo gdbms (probablemente bastar? con usar gdbms)
|
||
1498 | GeoProcessingPersistenceOperations.saveResultsToShapeFile(shapes, geoProcessingUnionPanel.getOutputFile()); |
||
1499 | } catch (DriverException e) {
|
||
1500 | // TODO Auto-generated catch block
|
||
1501 | e.printStackTrace(); |
||
1502 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
1503 | // TODO Auto-generated catch block
|
||
1504 | e.printStackTrace(); |
||
1505 | } catch (DriverLoadException e) {
|
||
1506 | // TODO Auto-generated catch block
|
||
1507 | e.printStackTrace(); |
||
1508 | } catch (NoSuchTableException e) {
|
||
1509 | // TODO Auto-generated catch block
|
||
1510 | e.printStackTrace(); |
||
1511 | } |
||
1512 | 2402 | jmorell | } |
1513 | 2387 | jmorell | public double[] getBufferDistancesFromTable(FLayer bufferingLayer) { |
1514 | AlphanumericData lyr = (AlphanumericData)bufferingLayer; |
||
1515 | DataSource ds;
|
||
1516 | double[] bufferDistances = null; |
||
1517 | try {
|
||
1518 | ds = lyr.getRecordset(); |
||
1519 | int fieldId = ds.getFieldIndexByName(getSelectedField());
|
||
1520 | Value[] fieldValues = new Value[(int)ds.getRowCount()]; |
||
1521 | SelectableDataSource selectableDataSource = (SelectableDataSource)ds; |
||
1522 | FBitSet fBitSet = selectableDataSource.getSelection(); |
||
1523 | 2989 | jmorell | if (fBitSet.cardinality()==0) { |
1524 | fBitSet.set(0, (int)lyr.getRecordset().getRowCount()); |
||
1525 | } |
||
1526 | 2387 | jmorell | Value[] valuesSelected = new Value[fBitSet.cardinality()]; |
1527 | int j = 0; |
||
1528 | for (int i=0;i<ds.getRowCount();i++) { |
||
1529 | boolean isSelected = fBitSet.get(i);
|
||
1530 | fieldValues[i] = ds.getFieldValue(i, fieldId); |
||
1531 | if (isSelected) {
|
||
1532 | valuesSelected[j] = fieldValues[i]; |
||
1533 | j++; |
||
1534 | } |
||
1535 | } |
||
1536 | bufferDistances = new double[fBitSet.cardinality()]; |
||
1537 | for (int i=0;i<fBitSet.cardinality();i++) { |
||
1538 | bufferDistances[i] = new Double(valuesSelected[i].toString()).doubleValue(); |
||
1539 | } |
||
1540 | } catch (DriverException e) {
|
||
1541 | // TODO Auto-generated catch block
|
||
1542 | e.printStackTrace(); |
||
1543 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
1544 | // TODO Auto-generated catch block
|
||
1545 | e.printStackTrace(); |
||
1546 | } |
||
1547 | return bufferDistances;
|
||
1548 | } |
||
1549 | private String getSelectedField() { |
||
1550 | return ((String)((JComboBox)geoProcessingBufferPanel.getComponent(6)).getSelectedItem()); |
||
1551 | } |
||
1552 | private int getQuadrantSegments() { |
||
1553 | return (Integer.valueOf((String)((JComboBox)geoProcessingBufferPanel.getComponent(11)).getSelectedItem())).intValue(); |
||
1554 | } |
||
1555 | 2370 | jmorell | private void closeMethod() { |
1556 | if (PluginServices.getMainFrame() == null) |
||
1557 | ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
||
1558 | else
|
||
1559 | PluginServices.getMDIManager().closeView(GeoProcessingPanel.this); |
||
1560 | } |
||
1561 | } // @jve:decl-index=0:visual-constraint="10,10" |