Revision 3062
tags/Root_gvSIGGeoProcessingPlugin_PreRefactoring/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/operations/GeoProcessingTopologyOperations.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 02-jun-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.operations; |
|
45 |
|
|
46 |
import java.util.BitSet; |
|
47 |
import java.util.Vector; |
|
48 |
|
|
49 |
import com.vividsolutions.jts.geom.Geometry; |
|
50 |
import com.vividsolutions.jts.geom.GeometryCollection; |
|
51 |
import com.vividsolutions.jts.geom.GeometryFactory; |
|
52 |
import com.vividsolutions.jts.geom.LineSegment; |
|
53 |
import com.vividsolutions.jts.geom.LineString; |
|
54 |
import com.vividsolutions.jts.geom.LinearRing; |
|
55 |
|
|
56 |
/** |
|
57 |
* @author jmorell |
|
58 |
*/ |
|
59 |
public final class GeoProcessingTopologyOperations { |
|
60 |
public static Geometry[] makeBuffers(Geometry[] geometries, double[] bufferDistances, int quadrantSegments) { |
|
61 |
Geometry[] buffers = new Geometry[geometries.length]; |
|
62 |
for (int i=0;i<geometries.length;i++) { |
|
63 |
Geometry geometry = geometries[i]; |
|
64 |
buffers[i] = geometry.buffer(bufferDistances[i], quadrantSegments); |
|
65 |
} |
|
66 |
return buffers; |
|
67 |
} |
|
68 |
public static Geometry makeDissolveBuffer(Geometry[] geometries, double bufferDistance, int quadrantSegments) { |
|
69 |
GeometryFactory geometryFactory = new GeometryFactory(); |
|
70 |
GeometryCollection geometryCollection = new GeometryCollection(geometries, |
|
71 |
geometryFactory); |
|
72 |
Geometry geometryCollectionBuffer = geometryCollection.buffer(bufferDistance, quadrantSegments); |
|
73 |
return geometryCollectionBuffer; |
|
74 |
} |
|
75 |
public static Geometry makeDissolveBuffer(Geometry[] geometries, double[] bufferDistances, int quadrantSegments) { |
|
76 |
Geometry[] buffers = new Geometry[geometries.length]; |
|
77 |
for (int i=0;i<geometries.length;i++) { |
|
78 |
Geometry geometry = geometries[i]; |
|
79 |
buffers[i] = geometry.buffer(bufferDistances[i], quadrantSegments); |
|
80 |
} |
|
81 |
GeometryFactory geometryFactory = new GeometryFactory(); |
|
82 |
GeometryCollection geometryCollection = new GeometryCollection(buffers, |
|
83 |
geometryFactory); |
|
84 |
// Hago un buffer con d=0 solo para poder devolver un POLYGON y no una GEOMETRYCOLLECTION |
|
85 |
// Molar?a conseguir el mismo efecto de una manera m?s ortodoxa ... investigar ... |
|
86 |
Geometry geometryCollectionBuffer = geometryCollection.buffer(0); |
|
87 |
System.out.println("geometryCollection = " + geometryCollection); |
|
88 |
return geometryCollectionBuffer; |
|
89 |
} |
|
90 |
/*public static Geometry[] makeDissolve(Geometry[] geometriesToDissolve, AlphanumericData lyr, String dissolveAttributeName) { |
|
91 |
Vector resultGeometries = new Vector(); |
|
92 |
DataSource ds; |
|
93 |
try { |
|
94 |
ds = lyr.getRecordset(); |
|
95 |
int fieldId = ds.getFieldIndexByName(dissolveAttributeName); |
|
96 |
Value[] fieldValues = new Value[(int)ds.getRowCount()]; |
|
97 |
//int j = 0; |
|
98 |
for (int i=0;i<ds.getRowCount();i++) { |
|
99 |
fieldValues[i] = ds.getFieldValue(i, fieldId); |
|
100 |
} |
|
101 |
for (int i=0;i<fieldValues.length;i++) { |
|
102 |
Value valuei = fieldValues[i]; |
|
103 |
Geometry geometryi = geometriesToDissolve[i]; |
|
104 |
//Geometry jtsGeometryi = geometryi.toJTSGeometry(); |
|
105 |
for (int j=0;j<ds.getRowCount();j++) { |
|
106 |
if (j!=i) { |
|
107 |
Value valuej = ds.getFieldValue(j, fieldId); |
|
108 |
if (((BooleanValue)(valuej.equals(valuei))).getValue()) { |
|
109 |
Geometry geometryj = geometriesToDissolve[j]; |
|
110 |
//Geometry jtsGeometryj = geometryj.toJTSGeometry(); |
|
111 |
//if (jtsGeometryj.intersection(jtsGeometryi) instanceof LineString || |
|
112 |
// jtsGeometryj.intersection(jtsGeometryi) instanceof LinearRing) { |
|
113 |
geometryi = geometryj.union(geometryi); |
|
114 |
//FPolygon2D union = (FPolygon2D)FConverter.jts_to_java2d(jtsUnion); |
|
115 |
//resultGeometries.add(ShapeFactory.createGeometry(union)); |
|
116 |
//} |
|
117 |
} |
|
118 |
} |
|
119 |
} |
|
120 |
resultGeometries.add(geometryi); |
|
121 |
} |
|
122 |
} catch (DriverException e) { |
|
123 |
// TODO Auto-generated catch block |
|
124 |
e.printStackTrace(); |
|
125 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) { |
|
126 |
// TODO Auto-generated catch block |
|
127 |
e.printStackTrace(); |
|
128 |
} catch (IncompatibleTypesException e) { |
|
129 |
// TODO Auto-generated catch block |
|
130 |
e.printStackTrace(); |
|
131 |
} |
|
132 |
Geometry[] result = new Geometry[resultGeometries.size()]; |
|
133 |
for (int i=0;i<resultGeometries.size();i++) { |
|
134 |
result[i] = (Geometry)resultGeometries.get(i); |
|
135 |
} |
|
136 |
return result; |
|
137 |
}*/ |
|
138 |
/*public static Geometry[] makeClip(Geometry[] geometriesToClip, Geometry[] clippingGeometries) { |
|
139 |
Vector geometriesClipped = new Vector(); |
|
140 |
int l=0; |
|
141 |
for (int i=0;i<geometriesToClip.length;i++) { |
|
142 |
Geometry geometryToClip = geometriesToClip[i]; |
|
143 |
int k=0; |
|
144 |
for (int j=0;j<clippingGeometries.length;j++) { |
|
145 |
Geometry clippingGeometry = clippingGeometries[j]; |
|
146 |
if (clippingGeometry.intersects(geometryToClip)) { |
|
147 |
geometriesClipped.add(geometryToClip.intersection(clippingGeometry)); |
|
148 |
// Para hacer un clip y no un intersect ... |
|
149 |
if (k>0) { |
|
150 |
geometriesClipped.set(l, ((Geometry)geometriesClipped.get(l)).union((Geometry)geometriesClipped.get(l-1))); |
|
151 |
} |
|
152 |
k++; |
|
153 |
l++; |
|
154 |
} |
|
155 |
} |
|
156 |
} |
|
157 |
Geometry[] result = new Geometry[geometriesClipped.size()]; |
|
158 |
for (int i=0;i<geometriesClipped.size();i++) { |
|
159 |
result[i] = (Geometry)geometriesClipped.get(i); |
|
160 |
} |
|
161 |
return result; |
|
162 |
}*/ |
|
163 |
//public static Geometry[] makeIntersect(Geometry[] geometriesToIntersect, Geometry[] intersectingGeometries) { |
|
164 |
/*Vector jtsGeometriesIntersected = new Vector(); |
|
165 |
IGeometry[] result = new IGeometry[geometriesToIntersect.length]; |
|
166 |
Geometry[] jtsGeometriesToClip = new Geometry[geometriesToIntersect.length]; |
|
167 |
for (int i=0;i<geometriesToIntersect.length;i++) { |
|
168 |
IGeometry geometryToClip = geometriesToIntersect[i]; |
|
169 |
jtsGeometriesToClip[i] = geometryToClip.toJTSGeometry(); |
|
170 |
} |
|
171 |
Geometry[] jtsClippingGeometries = new Geometry[intersectingGeometries.length]; |
|
172 |
for (int i=0;i<intersectingGeometries.length;i++) { |
|
173 |
IGeometry clippingGeometry = intersectingGeometries[i]; |
|
174 |
jtsClippingGeometries[i] = clippingGeometry.toJTSGeometry(); |
|
175 |
} |
|
176 |
Selectable selectable = (Selectable)layerToIntersect; |
|
177 |
FBitSet fBitSet = new FBitSet(); |
|
178 |
for (int i=0;i<jtsGeometriesToClip.length;i++) { |
|
179 |
Geometry jtsGeometryToClip = jtsGeometriesToClip[i]; |
|
180 |
for (int j=0;j<jtsClippingGeometries.length;j++) { |
|
181 |
Geometry jtsClippingGeometry = jtsClippingGeometries[j]; |
|
182 |
if (jtsClippingGeometry.intersects(jtsGeometryToClip)) { |
|
183 |
fBitSet.set(i); |
|
184 |
jtsGeometriesIntersected.add(jtsGeometryToClip.intersection(jtsClippingGeometry)); |
|
185 |
} |
|
186 |
} |
|
187 |
} |
|
188 |
selectable.setSelection(fBitSet); |
|
189 |
result = new IGeometry[jtsGeometriesIntersected.size()]; |
|
190 |
for (int i=0;i<jtsGeometriesIntersected.size();i++) { |
|
191 |
FShape shapeResult = (FShape)FConverter.jts_to_java2d((Geometry)jtsGeometriesIntersected.get(i)); |
|
192 |
result[i] = ShapeFactory.createGeometry(shapeResult); |
|
193 |
} |
|
194 |
return result;*/ |
|
195 |
/*Vector geometriesIntersected = new Vector(); |
|
196 |
//FBitSet fBitSet = new FBitSet(); |
|
197 |
// Convertimos a JTS |
|
198 |
//int l=0; |
|
199 |
for (int i=0;i<geometriesToIntersect.length;i++) { |
|
200 |
Geometry geometryToIntersect = geometriesToIntersect[i]; |
|
201 |
//int k=0; |
|
202 |
for (int j=0;j<intersectingGeometries.length;j++) { |
|
203 |
Geometry intersectingGeometry = intersectingGeometries[j]; |
|
204 |
if (intersectingGeometry.intersects(geometryToIntersect)) { |
|
205 |
//fBitSet.set(i); |
|
206 |
geometriesIntersected.add(geometryToIntersect.intersection(intersectingGeometry)); |
|
207 |
// Para hacer un clip y no un intersect ... |
|
208 |
//if (k>0) { |
|
209 |
// geometriesIntersected.set(l, ((Geometry)geometriesIntersected.get(l)).union((Geometry)geometriesIntersected.get(l-1))); |
|
210 |
//} |
|
211 |
//k++; |
|
212 |
//l++; |
|
213 |
} |
|
214 |
} |
|
215 |
} |
|
216 |
Geometry[] result = new Geometry[geometriesIntersected.size()]; |
|
217 |
for (int i=0;i<geometriesIntersected.size();i++) { |
|
218 |
result[i] = (Geometry)geometriesIntersected.get(i); |
|
219 |
} |
|
220 |
return result; |
|
221 |
}*/ |
|
222 |
/*public static Geometry[] makeUnion(Geometry[] geometriesToUnion, Geometry[] uningGeometries) { |
|
223 |
Geometry[] result = new Geometry[geometriesToUnion.length]; |
|
224 |
Vector geometriesUned = new Vector(); |
|
225 |
//Selectable selectable = (Selectable)layerToUnion; |
|
226 |
//FBitSet fBitSet = new FBitSet(); |
|
227 |
for (int i=0;i<geometriesToUnion.length;i++) { |
|
228 |
Geometry geometryToUnion = geometriesToUnion[i]; |
|
229 |
for (int j=0;j<uningGeometries.length;j++) { |
|
230 |
Geometry uningGeometry = uningGeometries[j]; |
|
231 |
if (uningGeometry.intersects(geometryToUnion)) { |
|
232 |
//fBitSet.set(i); |
|
233 |
geometriesUned.add(geometryToUnion.intersection(uningGeometry)); |
|
234 |
//geometriesUned.add(geometryToUnion.difference(uningGeometry)); |
|
235 |
} |
|
236 |
} |
|
237 |
} |
|
238 |
Vector geometriesUned2 = new Vector(); |
|
239 |
for (int i=0;i<geometriesUned.size();i++) { |
|
240 |
geometriesUned2.add(geometriesUned.get(i)); |
|
241 |
} |
|
242 |
int num = geometriesUned.size(); |
|
243 |
for (int i=0;i<geometriesToUnion.length;i++) { |
|
244 |
Geometry geometryToUnion = geometriesToUnion[i]; |
|
245 |
boolean intersectsWithAnyGeometry = false; |
|
246 |
for (int j=0;j<num;j++) { |
|
247 |
Geometry geometryUned = (Geometry)geometriesUned.get(j); |
|
248 |
if (geometryToUnion.intersects(geometryUned)) intersectsWithAnyGeometry = true; |
|
249 |
} |
|
250 |
if (intersectsWithAnyGeometry) { |
|
251 |
//Geometry difference = geometryToUnion.difference(geometryUned); |
|
252 |
//geometriesUned2.add(difference); |
|
253 |
} else { |
|
254 |
geometriesUned2.add(geometryToUnion); |
|
255 |
} |
|
256 |
} |
|
257 |
for (int i=0;i<uningGeometries.length;i++) { |
|
258 |
Geometry uningGeometry = uningGeometries[i]; |
|
259 |
boolean intersectsWithAnyGeometry = false; |
|
260 |
for (int j=0;j<num;j++) { |
|
261 |
Geometry geometryUned = (Geometry)geometriesUned.get(j); |
|
262 |
if (uningGeometry.intersects(geometryUned)) intersectsWithAnyGeometry = true; |
|
263 |
} |
|
264 |
if (intersectsWithAnyGeometry) { |
|
265 |
//Geometry difference = jtsUningGeometry.difference(jtsGeometryUned); |
|
266 |
//jtsGeometriesUned2.add(difference); |
|
267 |
} else { |
|
268 |
geometriesUned2.add(uningGeometry); |
|
269 |
} |
|
270 |
} |
|
271 |
System.out.println("geometriesUned2.size() = " + geometriesUned2.size()); |
|
272 |
// Le quito los cachos que ya tengo a los features que faltan |
|
273 |
BitSet bitSet1 = new BitSet(); |
|
274 |
bitSet1.clear(); |
|
275 |
//int k1=0; |
|
276 |
for (int i=0;i<geometriesUned2.size();i++) { |
|
277 |
Geometry geometryUned2 = (Geometry)geometriesUned2.get(i); |
|
278 |
for (int j=0;j<uningGeometries.length;j++) { |
|
279 |
System.out.println("!(uningGeometries[j].equals(geometryUned2)) = " + !(uningGeometries[j].equals(geometryUned2))); |
|
280 |
if (uningGeometries[j].intersects(geometryUned2) && !(uningGeometries[j].equals(geometryUned2))) { |
|
281 |
uningGeometries[j] = uningGeometries[j].difference(geometryUned2); |
|
282 |
//bitSet1.set(k1); |
|
283 |
bitSet1.set(j); |
|
284 |
} |
|
285 |
//k1++; |
|
286 |
} |
|
287 |
} |
|
288 |
// Le quito los cachos que ya tengo a los features que faltan |
|
289 |
BitSet bitSet2 = new BitSet(); |
|
290 |
bitSet2.clear(); |
|
291 |
int k2=0; |
|
292 |
for (int i=0;i<geometriesUned2.size();i++) { |
|
293 |
Geometry geometryUned2 = (Geometry)geometriesUned2.get(i); |
|
294 |
for (int j=0;j<geometriesToUnion.length;j++) { |
|
295 |
System.out.println("!(geometriesToUnion[j].equals(geometryUned2)) = " + !(geometriesToUnion[j].equals(geometryUned2))); |
|
296 |
if (geometriesToUnion[j].intersects(geometryUned2) && !(geometriesToUnion[j].equals(geometryUned2))) { |
|
297 |
geometriesToUnion[j] = geometriesToUnion[j].difference(geometryUned2); |
|
298 |
bitSet2.set(k2); |
|
299 |
} |
|
300 |
k2++; |
|
301 |
} |
|
302 |
} |
|
303 |
for (int i=0;i<bitSet2.size();i++) { |
|
304 |
System.out.println("bitSet2.get(" + i + ") = " + bitSet2.get(i)); |
|
305 |
} |
|
306 |
// Ahora que les he quitado los cachos que ya ten?a, le meto los features que |
|
307 |
// faltaban |
|
308 |
for (int i=0;i<uningGeometries.length;i++) { |
|
309 |
if (bitSet1.get(i)) { |
|
310 |
geometriesUned2.add(uningGeometries[i]); |
|
311 |
} |
|
312 |
} |
|
313 |
// Ahora que les he quitado los cachos que ya ten?a, le meto los features que |
|
314 |
// faltaban |
|
315 |
for (int i=0;i<geometriesToUnion.length;i++) { |
|
316 |
if (bitSet2.get(i)) { |
|
317 |
geometriesUned2.add(geometriesToUnion[i]); |
|
318 |
} |
|
319 |
} |
|
320 |
//selectable.setSelection(fBitSet); |
|
321 |
result = new Geometry[geometriesUned2.size()]; |
|
322 |
for (int i=0;i<geometriesUned2.size();i++) { |
|
323 |
result[i] = (Geometry)geometriesUned2.get(i); |
|
324 |
} |
|
325 |
return result; |
|
326 |
}*/ |
|
327 |
/*public static Geometry[] makeDissolve() { |
|
328 |
Vector geometriesDissolved = new Vector(); |
|
329 |
for (int i=0;i<geometriesToDissolve.length;i++) { |
|
330 |
Geometry geometryToDissolvei = geometriesToDissolve[i]; |
|
331 |
for (int j=0;j<geometriesToDissolve.length;j++) { |
|
332 |
Geometry geometryToDissolvej = geometriesToDissolve[j]; |
|
333 |
if (i!=j && intersectingGeometry.intersects(geometryToIntersect)) { |
|
334 |
geometriesIntersected.add(geometryToIntersect.intersection(intersectingGeometry)); |
|
335 |
} |
|
336 |
} |
|
337 |
} |
|
338 |
Geometry[] result = new Geometry[geometriesIntersected.size()]; |
|
339 |
for (int i=0;i<geometriesIntersected.size();i++) { |
|
340 |
result[i] = (Geometry)geometriesIntersected.get(i); |
|
341 |
} |
|
342 |
return result;*/ |
|
343 |
// Conseguimos las geometr?as |
|
344 |
/*IGeometry[] geometries = new IGeometry[0]; |
|
345 |
Selectable inputSelectable = (Selectable)input; |
|
346 |
SingleLayer inputLayer = (SingleLayer)input; |
|
347 |
VectorialAdapter inputLayerVectorialAdapter = inputLayer.getSource(); |
|
348 |
try { |
|
349 |
geometries = new IGeometry[inputLayerVectorialAdapter.getShapeCount()]; |
|
350 |
for (int i=0;i<inputLayerVectorialAdapter.getShapeCount();i++) { |
|
351 |
geometries[i] = (IGeometry)inputLayerVectorialAdapter.getShape(i); |
|
352 |
} |
|
353 |
} catch (DriverIOException e1) { |
|
354 |
// TODO Auto-generated catch block |
|
355 |
e1.printStackTrace(); |
|
356 |
} |
|
357 |
// Convertimos a JTS |
|
358 |
Geometry[] jtsGeometries = new Geometry[geometries.length]; |
|
359 |
System.out.println("geometries.length = " + geometries.length); |
|
360 |
for (int i=0;i<geometries.length;i++) { |
|
361 |
IGeometry geometry = geometries[i]; |
|
362 |
jtsGeometries[i] = geometry.toJTSGeometry(); |
|
363 |
} |
|
364 |
// |
|
365 |
Vector resultGeometries = new Vector(); |
|
366 |
AlphanumericData lyr = (AlphanumericData)input; |
|
367 |
DataSource ds; |
|
368 |
try { |
|
369 |
ds = lyr.getRecordset(); |
|
370 |
int fieldId = ds.getFieldIndexByName(fieldSelectedString); |
|
371 |
Value[] fieldValues = new Value[(int)ds.getRowCount()]; |
|
372 |
int j = 0; |
|
373 |
for (int i=0;i<ds.getRowCount();i++) { |
|
374 |
fieldValues[i] = ds.getFieldValue(i, fieldId); |
|
375 |
} |
|
376 |
for (int i=0;i<fieldValues.length;i++) { |
|
377 |
Value valuei = fieldValues[i]; |
|
378 |
IGeometry geometryi = geometries[i]; |
|
379 |
Geometry jtsGeometryi = geometryi.toJTSGeometry(); |
|
380 |
for (j=0;j<ds.getRowCount();j++) { |
|
381 |
if (j!=i) { |
|
382 |
Value valuej = ds.getFieldValue(j, fieldId); |
|
383 |
if (((BooleanValue)(valuej.equals(valuei))).getValue()) { |
|
384 |
IGeometry geometryj = geometries[j]; |
|
385 |
Geometry jtsGeometryj = geometryj.toJTSGeometry(); |
|
386 |
if (jtsGeometryj.intersection(jtsGeometryi) instanceof LineString || |
|
387 |
jtsGeometryj.intersection(jtsGeometryi) instanceof LinearRing) { |
|
388 |
Geometry jtsUnion = jtsGeometryj.union(jtsGeometryi); |
|
389 |
FPolygon2D union = (FPolygon2D)FConverter.jts_to_java2d(jtsUnion); |
|
390 |
resultGeometries.add(ShapeFactory.createGeometry(union)); |
|
391 |
} |
|
392 |
} |
|
393 |
} |
|
394 |
} |
|
395 |
} |
|
396 |
} catch (DriverException e) { |
|
397 |
// TODO Auto-generated catch block |
|
398 |
e.printStackTrace(); |
|
399 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) { |
|
400 |
// TODO Auto-generated catch block |
|
401 |
e.printStackTrace(); |
|
402 |
} catch (IncompatibleTypesException e) { |
|
403 |
// TODO Auto-generated catch block |
|
404 |
e.printStackTrace(); |
|
405 |
} |
|
406 |
IGeometry[] result = new IGeometry[resultGeometries.size()]; |
|
407 |
for (int i=0;i<resultGeometries.size();i++) { |
|
408 |
result[i] = (IGeometry)resultGeometries.get(i); |
|
409 |
} |
|
410 |
return result;*/ |
|
411 |
//} |
|
412 |
/*public static IGeometry[] makeMerge(FLayer[] inputLayers, FLayer fixedLayer) { |
|
413 |
int geometryCount = 0; |
|
414 |
for (int i=0;i<inputLayers.length;i++) { |
|
415 |
VectorialAdapter inputLayerVectorialAdapter = ((SingleLayer)inputLayers[i]).getSource(); |
|
416 |
try { |
|
417 |
geometryCount = geometryCount + inputLayerVectorialAdapter.getShapeCount(); |
|
418 |
} catch (DriverIOException e) { |
|
419 |
// TODO Auto-generated catch block |
|
420 |
e.printStackTrace(); |
|
421 |
} |
|
422 |
} |
|
423 |
IGeometry[] geometries = new IGeometry[geometryCount]; |
|
424 |
int k=0; |
|
425 |
for (int i=0;i<inputLayers.length;i++) { |
|
426 |
VectorialAdapter inputLayerVectorialAdapter = ((SingleLayer)inputLayers[i]).getSource(); |
|
427 |
try { |
|
428 |
for (int j=0;j<inputLayerVectorialAdapter.getShapeCount();j++) { |
|
429 |
geometries[k] = inputLayerVectorialAdapter.getShape(j); |
|
430 |
k++; |
|
431 |
} |
|
432 |
} catch (DriverIOException e) { |
|
433 |
// TODO Auto-generated catch block |
|
434 |
e.printStackTrace(); |
|
435 |
} |
|
436 |
} |
|
437 |
return geometries; |
|
438 |
}*/ |
|
439 |
/*public static IGeometry[] makeSpatialJoin(FLayer layerToSJ, FLayer SJLayer) { |
|
440 |
VectorialAdapter inputLayerVectorialAdapter = ((SingleLayer)layerToSJ).getSource(); |
|
441 |
int geometryCount=0; |
|
442 |
IGeometry[] geometries = null; |
|
443 |
try { |
|
444 |
geometryCount = inputLayerVectorialAdapter.getShapeCount(); |
|
445 |
geometries = new IGeometry[geometryCount]; |
|
446 |
for (int j=0;j<inputLayerVectorialAdapter.getShapeCount();j++) { |
|
447 |
geometries[j] = inputLayerVectorialAdapter.getShape(j); |
|
448 |
} |
|
449 |
} catch (DriverIOException e) { |
|
450 |
// TODO Auto-generated catch block |
|
451 |
e.printStackTrace(); |
|
452 |
} |
|
453 |
return geometries; |
|
454 |
}*/ |
|
455 |
/*private static FPolygon2D points2DToFPolygon2D(Point2D[] pts) { |
|
456 |
GeneralPathX genPathX = new GeneralPathX(); |
|
457 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
|
458 |
for (int i=1; i<pts.length; i++) { |
|
459 |
genPathX.lineTo(pts[i].getX(), pts[i].getY()); |
|
460 |
} |
|
461 |
genPathX.closePath(); |
|
462 |
return new FPolygon2D(genPathX); |
|
463 |
}*/ |
|
464 |
} |
|
0 | 465 |
tags/Root_gvSIGGeoProcessingPlugin_PreRefactoring/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/operations/strategies/SelectedShapeToJTSVisitor.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 06-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.operations.strategies; |
|
45 |
|
|
46 |
import java.util.BitSet; |
|
47 |
|
|
48 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
49 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
50 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
|
51 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
|
52 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
|
53 |
import com.vividsolutions.jts.geom.Geometry; |
|
54 |
|
|
55 |
public class SelectedShapeToJTSVisitor implements FeatureVisitor { |
|
56 |
private BitSet bitSet = null; |
|
57 |
private int selectedIndex; |
|
58 |
private Geometry[] jtsGeometries = null; |
|
59 |
|
|
60 |
public void visit(IGeometry g, int index) throws VisitException { |
|
61 |
// TODO Auto-generated method stub |
|
62 |
if (bitSet.get(index)){ |
|
63 |
jtsGeometries[selectedIndex] = g.toJTSGeometry(); |
|
64 |
selectedIndex++; |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
public void stop(FLayer layer) { |
|
69 |
// TODO Auto-generated method stub |
|
70 |
|
|
71 |
} |
|
72 |
|
|
73 |
public boolean start(FLayer layer) { |
|
74 |
// TODO Auto-generated method stub |
|
75 |
if (layer instanceof Selectable) { |
|
76 |
bitSet = ((Selectable)layer).getSelection(); |
|
77 |
selectedIndex = 0; |
|
78 |
jtsGeometries = new Geometry[bitSet.cardinality()]; |
|
79 |
return true; |
|
80 |
} |
|
81 |
return false; |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* @return Returns the jtsGeometries. |
|
86 |
*/ |
|
87 |
public Geometry[] getJtsGeometries() { |
|
88 |
return jtsGeometries; |
|
89 |
} |
|
90 |
|
|
91 |
} |
|
0 | 92 |
tags/Root_gvSIGGeoProcessingPlugin_PreRefactoring/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/operations/GeoProcessingPersistenceOperations.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 05-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.operations; |
|
45 |
|
|
46 |
import java.io.File; |
|
47 |
|
|
48 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
49 |
import com.iver.cit.gvsig.fmap.drivers.shp.SHP; |
|
50 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
51 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
|
52 |
|
|
53 |
public class GeoProcessingPersistenceOperations { |
|
54 |
/*public static void saveBufferResultsToShapeFile(IGeometry[] geometries, File file) { |
|
55 |
if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){ |
|
56 |
file=new File(file.getPath()+".shp"); |
|
57 |
} |
|
58 |
SHP.SHPOnlyFromGeometries(geometries,file); |
|
59 |
} |
|
60 |
public static void saveMergeResultsToShapeFile(IGeometry[] geometries, File file) { |
|
61 |
if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){ |
|
62 |
file=new File(file.getPath()+".shp"); |
|
63 |
} |
|
64 |
SHP.SHPOnlyFromGeometries(geometries,file); |
|
65 |
} |
|
66 |
public static void saveDissolveResultsToShapeFile(IGeometry[] geometries, File file) { |
|
67 |
if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){ |
|
68 |
file=new File(file.getPath()+".shp"); |
|
69 |
} |
|
70 |
SHP.SHPOnlyFromGeometries(geometries,file); |
|
71 |
} |
|
72 |
public static void saveSpatialjoinResultsToShapeFile(IGeometry[] geometries, File file) { |
|
73 |
if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){ |
|
74 |
file=new File(file.getPath()+".shp"); |
|
75 |
} |
|
76 |
SHP.SHPOnlyFromGeometries(geometries,file); |
|
77 |
} |
|
78 |
public static void saveClipResultsToShapeFile(IGeometry[] geometries, File file) { |
|
79 |
if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){ |
|
80 |
file=new File(file.getPath()+".shp"); |
|
81 |
} |
|
82 |
SHP.SHPOnlyFromGeometries(geometries,file); |
|
83 |
} |
|
84 |
public static void saveIntersectResultsToShapeFile(IGeometry[] geometries, File file) { |
|
85 |
if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){ |
|
86 |
file=new File(file.getPath()+".shp"); |
|
87 |
} |
|
88 |
SHP.SHPOnlyFromGeometries(geometries,file); |
|
89 |
} |
|
90 |
public static void saveUnionResultsToShapeFile(IGeometry[] geometries, File file) { |
|
91 |
if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){ |
|
92 |
file=new File(file.getPath()+".shp"); |
|
93 |
} |
|
94 |
SHP.SHPOnlyFromGeometries(geometries,file); |
|
95 |
}*/ |
|
96 |
/*public static void saveResultsToShapeFile(IGeometry[] geometries, File file) { |
|
97 |
if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){ |
|
98 |
file=new File(file.getPath()+".shp"); |
|
99 |
} |
|
100 |
SHP.SHPFileFromGeometries(geometries,null,null,file); |
|
101 |
}*/ |
|
102 |
public static void saveResultsToShapeFile(IGeometry[] geometries, File file) { |
|
103 |
if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){ |
|
104 |
file=new File(file.getPath()+".shp"); |
|
105 |
} |
|
106 |
SHP.SHPOnlyFromGeometries(geometries,file); |
|
107 |
} |
|
108 |
} |
|
0 | 109 |
tags/Root_gvSIGGeoProcessingPlugin_PreRefactoring/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/operations/GeoProcessingTableOperations.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 06-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.operations; |
|
45 |
|
|
46 |
import java.io.File; |
|
47 |
import java.util.BitSet; |
|
48 |
import java.util.Vector; |
|
49 |
|
|
50 |
import com.hardcode.driverManager.DriverLoadException; |
|
51 |
import com.hardcode.gdbms.engine.data.DataSource; |
|
52 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
|
53 |
import com.hardcode.gdbms.engine.data.NoSuchTableException; |
|
54 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
|
55 |
import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException; |
|
56 |
import com.hardcode.gdbms.engine.values.BooleanValue; |
|
57 |
import com.hardcode.gdbms.engine.values.Value; |
|
58 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
|
59 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
60 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
|
61 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
|
62 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
|
63 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
|
64 |
|
|
65 |
public class GeoProcessingTableOperations { |
|
66 |
|
|
67 |
/** |
|
68 |
* Creates the .dbf result file for the buffer operation. This .dbf file |
|
69 |
* corresponds to the .shp that have been created with the |
|
70 |
* saveBufferResultsToShapeFile() method. |
|
71 |
* @param file, output file. |
|
72 |
* @param lyr, input theme table. |
|
73 |
* @param dissolveBuffer, boolean that informs about if the dissolve option is |
|
74 |
* active. |
|
75 |
* @param selection, boolean that informs about if we are working with a selection |
|
76 |
* only. |
|
77 |
* @throws DriverException |
|
78 |
* @throws com.hardcode.gdbms.engine.data.driver.DriverException |
|
79 |
* @throws IncompatibleTypesException |
|
80 |
* @throws DriverLoadException |
|
81 |
* @throws NoSuchTableException |
|
82 |
*/ |
|
83 |
public static void saveBufferResultsToDbaseFile(File file, AlphanumericData lyr, boolean dissolveBuffer, boolean isDbfFile) |
|
84 |
throws DriverException, |
|
85 |
com.hardcode.gdbms.engine.data.driver.DriverException, |
|
86 |
IncompatibleTypesException, DriverLoadException, NoSuchTableException { |
|
87 |
SelectableDataSource sds = lyr.getRecordset(); |
|
88 |
// Tener en cuenta que podemos estar trabajando solo con una selecci?n |
|
89 |
FBitSet fBitSet = ((Selectable)lyr).getSelection(); |
|
90 |
if (fBitSet.cardinality()==0) fBitSet.set(0, (int)lyr.getRecordset().getRowCount()); |
|
91 |
if (dissolveBuffer) saveOnlyCommonFields(sds, fBitSet, file); |
|
92 |
else saveAllFieldsAndRows(sds, fBitSet, file, isDbfFile); |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* This method is executed when we are making a buffer with the dissolve option. |
|
97 |
* Result table will be the same that the input table. |
|
98 |
* @param sds, table of the input theme. |
|
99 |
* @param fBitSet, items selected. |
|
100 |
* @param file, output file. |
|
101 |
* @throws com.hardcode.gdbms.engine.data.driver.DriverException |
|
102 |
* @throws IncompatibleTypesException |
|
103 |
* @throws NoSuchTableException |
|
104 |
* @throws DriverLoadException |
|
105 |
*/ |
|
106 |
// TODO: Provisional. Hasta que Fernando le meta PKs al resto de ficheros. |
|
107 |
private static void saveAllFieldsAndRows(SelectableDataSource sds, FBitSet fBitSet, File file, boolean isDbfFile) |
|
108 |
throws com.hardcode.gdbms.engine.data.driver.DriverException, |
|
109 |
IncompatibleTypesException, DriverLoadException, NoSuchTableException { |
|
110 |
// Esto cambia si pasamos del dissolve |
|
111 |
String[] fieldNames = new String[sds.getFieldCount()]; |
|
112 |
int[] fieldTypes = new int[sds.getFieldCount()]; |
|
113 |
for (int i = 0; i < sds.getFieldCount(); i++) { |
|
114 |
fieldNames[i] = sds.getFieldName(i); |
|
115 |
fieldTypes[i] = sds.getFieldType(i); |
|
116 |
} |
|
117 |
// |
|
118 |
DataSourceFactory dsf = sds.getDataSourceFactory(); |
|
119 |
dsf.createFileDataSource("gdbms dbf driver", "new_table", file.getAbsolutePath().replaceAll(".shp", ".dbf"), fieldNames, fieldTypes); |
|
120 |
DataSource ds = dsf.createRandomDataSource("new_table"); |
|
121 |
ds.start(); |
|
122 |
DataWare dw = ds.getDataWare(DataSourceFactory.MANUAL_OPENING); |
|
123 |
dw.beginTrans(); |
|
124 |
ds.stop(); |
|
125 |
sds.stop(); |
|
126 |
// Los DS que vienen de un DBF vienen con PK y los que vienen de un DXF todav?a no. Mientras esto |
|
127 |
// est? as?, hay que distinguir entre estos or?genes. Ahora solo se mete PK en los DBFs. |
|
128 |
int fieldCount = 0; |
|
129 |
if (isDbfFile) fieldCount = sds.getFieldCount(); |
|
130 |
else fieldCount = sds.getFieldCount()+1; |
|
131 |
Value[][] values = new Value[(int)fBitSet.cardinality()][fieldCount]; |
|
132 |
int k=0; |
|
133 |
for (int i=0;i<sds.getRowCount();i++) { |
|
134 |
if (fBitSet.get(i)) { |
|
135 |
for (int j=0;j<fieldCount-1;j++) { |
|
136 |
values[k][j] = sds.getFieldValue(i, j); |
|
137 |
} |
|
138 |
k++; |
|
139 |
} |
|
140 |
} |
|
141 |
//for (int i=0;i<sds.getRowCount();i++) { |
|
142 |
for (int i=0;i<fBitSet.cardinality();i++) { |
|
143 |
values[i][fieldCount-1] = ValueFactory.createValue(i); |
|
144 |
} |
|
145 |
// |
|
146 |
// Aqu? habr? que hacer un for o algo as? ... |
|
147 |
//for (int i=0;i<dw.getRowCount();i++) { |
|
148 |
for (int i=0;i<fBitSet.cardinality();i++) { |
|
149 |
dw.insertFilledRow(values[i]); |
|
150 |
} |
|
151 |
// |
|
152 |
dw.commitTrans(); |
|
153 |
} |
|
154 |
|
|
155 |
/** |
|
156 |
* This method is executed when we are making a buffer without the dissolve option. |
|
157 |
* Result table will have one row corresponding to the only one buffer polygon and |
|
158 |
* only the fields that have common values. |
|
159 |
* @param sds, table of the input theme. |
|
160 |
* @param fBitSet, items selected. |
|
161 |
* @param file, output file. |
|
162 |
* @throws com.hardcode.gdbms.engine.data.driver.DriverException |
|
163 |
* @throws IncompatibleTypesException |
|
164 |
* @throws NoSuchTableException |
|
165 |
* @throws DriverLoadException |
|
166 |
*/ |
|
167 |
private static void saveOnlyCommonFields(SelectableDataSource sds, FBitSet fBitSet, File file) |
|
168 |
throws com.hardcode.gdbms.engine.data.driver.DriverException, |
|
169 |
IncompatibleTypesException, DriverLoadException, NoSuchTableException { |
|
170 |
// Esto cambia si pasamos del dissolve |
|
171 |
Vector fieldNames = new Vector(); |
|
172 |
Vector fieldTypes = new Vector(); |
|
173 |
BitSet bitset = new BitSet(sds.getFieldCount()); |
|
174 |
for (int i = 0; i < sds.getFieldCount(); i++) { |
|
175 |
//Value[] values = new Value[(int)sds.getRowCount()]; |
|
176 |
Value[] values = new Value[(int)fBitSet.cardinality()]; |
|
177 |
boolean hasTheSameRowValues = true; |
|
178 |
//for (int j=0;j<sds.getRowCount();j++) { |
|
179 |
//for (int j=0;j<fBitSet.cardinality();j++) { |
|
180 |
int k=0; |
|
181 |
int l=0; |
|
182 |
for (int j=0;j<sds.getRowCount();j++) { |
|
183 |
if (fBitSet.get(j)) { |
|
184 |
Value value = sds.getFieldValue(j, i); |
|
185 |
values[l] = value; |
|
186 |
if (j>0) { |
|
187 |
if (!((BooleanValue)value.equals(values[j-k])).getValue()) { |
|
188 |
hasTheSameRowValues = false; |
|
189 |
break; |
|
190 |
} |
|
191 |
} |
|
192 |
l++; |
|
193 |
} |
|
194 |
k++; |
|
195 |
} |
|
196 |
if (hasTheSameRowValues) { |
|
197 |
fieldNames.add(sds.getFieldName(i)); |
|
198 |
fieldTypes.add(new Integer(sds.getFieldType(i))); |
|
199 |
bitset.set(i); |
|
200 |
} |
|
201 |
} |
|
202 |
// |
|
203 |
String[] fieldNamesArray = new String[fieldNames.size()]; |
|
204 |
int[] fieldTypesArray = new int[fieldNames.size()]; |
|
205 |
for (int i=0;i<fieldNames.size();i++) { |
|
206 |
fieldNamesArray[i] = ((String)fieldNames.get(i)); |
|
207 |
fieldTypesArray[i] = (((Integer)fieldTypes.get(i)).intValue()); |
|
208 |
} |
|
209 |
DataSourceFactory dsf = sds.getDataSourceFactory(); |
|
210 |
dsf.createFileDataSource("gdbms dbf driver", "new_table", file.getAbsolutePath().replaceAll(".shp", ".dbf"), fieldNamesArray, fieldTypesArray); |
|
211 |
DataSource ds = dsf.createRandomDataSource("new_table"); |
|
212 |
ds.start(); |
|
213 |
DataWare dw = ds.getDataWare(DataSourceFactory.MANUAL_OPENING); |
|
214 |
dw.beginTrans(); |
|
215 |
ds.stop(); |
|
216 |
sds.stop(); |
|
217 |
// Esto tb cambia |
|
218 |
Vector values = new Vector(); |
|
219 |
for (int i=0;i<sds.getFieldCount();i++) { |
|
220 |
if (bitset.get(i)) { |
|
221 |
values.add(sds.getFieldValue(0, i)); |
|
222 |
} |
|
223 |
} |
|
224 |
values.add(ValueFactory.createValue(0)); |
|
225 |
Value[] valuesArray = new Value[values.size()];//+1]; |
|
226 |
for (int i=0;i<values.size();i++) { |
|
227 |
valuesArray[i] = ((Value)values.get(i)); |
|
228 |
} |
|
229 |
//valuesArray[values.size()] = ValueFactory.createValue(0L); |
|
230 |
// |
|
231 |
// Aqu? habr? que hacer un for o algo as? ... |
|
232 |
dw.insertFilledRow(valuesArray); |
|
233 |
// |
|
234 |
dw.commitTrans(); |
|
235 |
} |
|
236 |
|
|
237 |
/** |
|
238 |
* Creates the .dbf result file for the merge operation. This .dbf file |
|
239 |
* corresponds to the .shp that have been created with the |
|
240 |
* saveMergeResultsToShapeFile() method. |
|
241 |
* @param file, output file. |
|
242 |
* @param lyrs, the layers to merge. |
|
243 |
* @param lyr, the fields of the resulting .dbf will be the fields of lyr. |
|
244 |
* @throws DriverException |
|
245 |
* @throws com.hardcode.gdbms.engine.data.driver.DriverException |
|
246 |
* @throws IncompatibleTypesException |
|
247 |
* @throws DriverLoadException |
|
248 |
* @throws NoSuchTableException |
|
249 |
*/ |
|
250 |
// TODO: Provisional. Hasta que Fernando le meta PKs al resto de ficheros. |
|
251 |
public static void saveMergeResultsToDbaseFile(File file, AlphanumericData[] lyrs, AlphanumericData lyr, boolean isDbfFile) |
|
252 |
throws DriverException, |
|
253 |
com.hardcode.gdbms.engine.data.driver.DriverException, |
|
254 |
IncompatibleTypesException, DriverLoadException, NoSuchTableException { |
|
255 |
SelectableDataSource sds = lyr.getRecordset(); |
|
256 |
// Los DS que vienen de un DBF vienen con PK y los que vienen de un DXF todav?a no. Mientras esto |
|
257 |
// est? as?, hay que distinguir entre estos or?genes. Ahora solo se mete PK en los DBFs. |
|
258 |
int fieldCount = 0; |
|
259 |
if (isDbfFile) fieldCount = sds.getFieldCount(); |
|
260 |
else fieldCount = sds.getFieldCount()+1; |
|
261 |
String[] fieldNames = new String[fieldCount]; |
|
262 |
int[] fieldTypes = new int[fieldCount]; |
|
263 |
for (int i=0;i<fieldCount;i++) { |
|
264 |
fieldNames[i] = sds.getFieldName(i); |
|
265 |
fieldTypes[i] = sds.getFieldType(i); |
|
266 |
} |
|
267 |
DataSourceFactory dsf = sds.getDataSourceFactory(); |
|
268 |
dsf.createFileDataSource("gdbms dbf driver", "new_table", file.getAbsolutePath().replaceAll(".shp", ".dbf"), fieldNames, fieldTypes); |
|
269 |
DataSource ds = dsf.createRandomDataSource("new_table"); |
|
270 |
ds.start(); |
|
271 |
DataWare dw = ds.getDataWare(DataSourceFactory.MANUAL_OPENING); |
|
272 |
dw.beginTrans(); |
|
273 |
ds.stop(); |
|
274 |
sds.stop(); |
|
275 |
// Tener en cuenta que podemos estar trabajando con selecciones y no con capas |
|
276 |
// enteras. |
|
277 |
FBitSet[] fBitSets = new FBitSet[lyrs.length];//((Selectable)lyr).getSelection(); |
|
278 |
for (int i=0;i<lyrs.length;i++) { |
|
279 |
fBitSets[i] = lyrs[i].getRecordset().getSelection(); |
|
280 |
if (fBitSets[i].cardinality()==0) { |
|
281 |
fBitSets[i].set(0, (int)lyrs[i].getRecordset().getRowCount()); |
|
282 |
} |
|
283 |
} |
|
284 |
int rowNumber = 0; |
|
285 |
for (int i=0;i<lyrs.length;i++) { |
|
286 |
rowNumber = rowNumber + (int)lyrs[i].getRecordset().getSelection().cardinality(); |
|
287 |
} |
|
288 |
Value[][] values = new Value[rowNumber][fieldCount]; |
|
289 |
// Voy rellenando la tabla por columnas |
|
290 |
int n=0; |
|
291 |
int m=0; |
|
292 |
boolean hasField = false; |
|
293 |
for (int i=0;i<lyrs.length;i++) { |
|
294 |
for (int j=0;j<fieldCount-1;j++) { |
|
295 |
hasField = false; |
|
296 |
for (int k=0;k<lyrs[i].getRecordset().getFieldCount()-1;k++) { |
|
297 |
m=n; |
|
298 |
if (fieldNames[j].equals(lyrs[i].getRecordset().getFieldName(k))) { |
|
299 |
hasField = true; |
|
300 |
for (int l=0;l<(int)lyrs[i].getRecordset().getRowCount();l++) { |
|
301 |
if (fBitSets[i].get(l)) { |
|
302 |
values[m][j] = lyrs[i].getRecordset().getFieldValue(l, lyrs[i].getRecordset().getFieldIndexByName(fieldNames[j])); // ?fieldNames[k] o fieldNames[j]? |
|
303 |
m++; |
|
304 |
} |
|
305 |
} |
|
306 |
} |
|
307 |
} |
|
308 |
if (!hasField) { |
|
309 |
// rellena con nulls ese cacho de columna |
|
310 |
m=n; |
|
311 |
for (int l=0;l<(int)lyrs[i].getRecordset().getRowCount();l++) { |
|
312 |
if (fBitSets[i].get(l)) { |
|
313 |
values[m][j] = ValueFactory.createNullValue(); |
|
314 |
m++; |
|
315 |
} |
|
316 |
} |
|
317 |
} |
|
318 |
} |
|
319 |
//n=(int)lyrs[i].getRecordset().getRowCount(); |
|
320 |
n=(int)lyrs[i].getRecordset().getSelection().cardinality(); |
|
321 |
} |
|
322 |
for (int i=0;i<rowNumber;i++) { |
|
323 |
values[i][fieldCount-1] = ValueFactory.createValue(i); |
|
324 |
} |
|
325 |
// Chapando todos los SDS antes de rellenar ... |
|
326 |
/*for (int i=0;i<lyrs.length;i++) { |
|
327 |
lyrs[i].getRecordset().stop(); |
|
328 |
}*/ |
|
329 |
for (int i=0;i<rowNumber;i++) { |
|
330 |
dw.insertFilledRow(values[i]); |
|
331 |
} |
|
332 |
dw.commitTrans(); |
|
333 |
} |
|
334 |
|
|
335 |
/** |
|
336 |
* Creates the .dbf result file for the dissolve operation. This .dbf file |
|
337 |
* corresponds to the .shp that have been created with the |
|
338 |
* saveDissolveResultsToShapeFile() method. |
|
339 |
* @param file, output file. |
|
340 |
* @param lyr, input theme table. |
|
341 |
* @param dissolveAttributeName, the name of the attribute for doing the dissolve |
|
342 |
* operation. |
|
343 |
* @throws DriverException |
|
344 |
* @throws com.hardcode.gdbms.engine.data.driver.DriverException |
|
345 |
* @throws IncompatibleTypesException |
|
346 |
* @throws DriverLoadException |
|
347 |
* @throws NoSuchTableException |
|
348 |
*/ |
|
349 |
public static void saveDissolveResultsToDbaseFile(File file, AlphanumericData lyr, String dissolveAttributeName) |
|
350 |
throws DriverException, |
|
351 |
com.hardcode.gdbms.engine.data.driver.DriverException, |
|
352 |
IncompatibleTypesException, DriverLoadException, NoSuchTableException { |
|
353 |
SelectableDataSource sds = lyr.getRecordset(); |
|
354 |
// Tener en cuenta que podemos estar trabajando solo con una selecci?n |
|
355 |
FBitSet fBitSet = ((Selectable)lyr).getSelection(); |
|
356 |
String[] fieldNames = new String[]{dissolveAttributeName}; |
|
357 |
int[] fieldTypes = new int[]{sds.getFieldType(sds.getFieldIndexByName(dissolveAttributeName))}; |
|
358 |
Vector values = new Vector(); |
|
359 |
for (int i=0;i<sds.getRowCount();i++) { |
|
360 |
if (fBitSet.get(i)) { |
|
361 |
values.add(sds.getFieldValue(i, sds.getFieldIndexByName(dissolveAttributeName))); |
|
362 |
} |
|
363 |
} |
|
364 |
for (int i=0;i<values.size();i++) { |
|
365 |
for (int j=0;j<values.size();j++) { |
|
366 |
if (j>i) { |
|
367 |
if (((BooleanValue)((Value)values.get(i)).equals((Value)values.get(j))).getValue()) { |
|
368 |
values.remove(j); |
|
369 |
j--; |
|
370 |
} |
|
371 |
} |
|
372 |
} |
|
373 |
} |
|
374 |
Value[][] valuesTable = new Value[values.size()][2]; |
|
375 |
DataSourceFactory dsf = sds.getDataSourceFactory(); |
|
376 |
dsf.createFileDataSource("gdbms dbf driver", "new_table", file.getAbsolutePath().replaceAll(".shp", ".dbf"), fieldNames, fieldTypes); |
|
377 |
DataSource ds = dsf.createRandomDataSource("new_table"); |
|
378 |
ds.start(); |
|
379 |
DataWare dw = ds.getDataWare(DataSourceFactory.MANUAL_OPENING); |
|
380 |
dw.beginTrans(); |
|
381 |
ds.stop(); |
|
382 |
sds.stop(); |
|
383 |
for (int i=0;i<valuesTable.length;i++) { |
|
384 |
valuesTable[i][0] = ((Value)values.get(i)); |
|
385 |
valuesTable[i][1] = ValueFactory.createValue(i); |
|
386 |
} |
|
387 |
for (int i=0;i<valuesTable.length;i++) { |
|
388 |
dw.insertFilledRow(valuesTable[i]); |
|
389 |
} |
|
390 |
dw.commitTrans(); |
|
391 |
} |
|
392 |
|
|
393 |
/** |
|
394 |
* Creates the .dbf result file for the spatial join operation. This .dbf file |
|
395 |
* corresponds to the .shp that have been created with the |
|
396 |
* saveSpatialjoinResultsToShapeFile() method. |
|
397 |
* @param file, output file. |
|
398 |
* @param lyr, output theme table to write. |
|
399 |
* @throws DriverException |
|
400 |
* @throws com.hardcode.gdbms.engine.data.driver.DriverException |
|
401 |
* @throws IncompatibleTypesException |
|
402 |
* @throws DriverLoadException |
|
403 |
* @throws NoSuchTableException |
|
404 |
*/ |
|
405 |
/*public static void saveSpatialjoinResultsToDbaseFile(File file, AlphanumericData lyr) |
|
406 |
throws DriverException, |
|
407 |
com.hardcode.gdbms.engine.data.driver.DriverException, |
|
408 |
IncompatibleTypesException, DriverLoadException, NoSuchTableException { |
|
409 |
}*/ |
|
410 |
|
|
411 |
/** |
|
412 |
* Creates the .dbf result file for the clip operation. This .dbf file |
|
413 |
* corresponds to the .shp that have been created with the |
|
414 |
* saveClipResultsToShapeFile() method. |
|
415 |
* @param file, output file. |
|
416 |
* @param lyr, output theme table to write. |
|
417 |
* @throws DriverException |
|
418 |
* @throws com.hardcode.gdbms.engine.data.driver.DriverException |
|
419 |
* @throws IncompatibleTypesException |
|
420 |
* @throws DriverLoadException |
|
421 |
* @throws NoSuchTableException |
|
422 |
*/ |
|
423 |
/*public static void saveClipResultsToDbaseFile(File file, AlphanumericData lyr) |
|
424 |
throws DriverException, |
|
425 |
com.hardcode.gdbms.engine.data.driver.DriverException, |
|
426 |
IncompatibleTypesException, DriverLoadException, NoSuchTableException { |
|
427 |
SelectableDataSource sds = lyr.getRecordset(); |
|
428 |
// Tener en cuenta que podemos estar trabajando solo con una selecci?n |
|
429 |
FBitSet fBitSet = ((Selectable)lyr).getSelection(); |
|
430 |
}*/ |
|
431 |
|
|
432 |
} |
|
0 | 433 |
tags/Root_gvSIGGeoProcessingPlugin_PreRefactoring/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/GeoProcessingExtension.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 22-jun-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; |
|
45 |
|
|
46 |
import com.iver.andami.PluginServices; |
|
47 |
import com.iver.andami.plugins.Extension; |
|
48 |
import com.iver.cit.gvsig.fmap.FMap; |
|
49 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
|
50 |
import com.iver.cit.gvsig.gui.View; |
|
51 |
import com.iver.cit.gvsig.project.ProjectView; |
|
52 |
import com.iver.gvsig.geoprocessing.gui.GeoProcessingPanel; |
|
53 |
|
|
54 |
/** |
|
55 |
* GeoProcessingExtension class |
|
56 |
* |
|
57 |
* @author jmorell |
|
58 |
*/ |
|
59 |
public class GeoProcessingExtension implements Extension { |
|
60 |
|
|
61 |
/* (non-Javadoc) |
|
62 |
* @see com.iver.andami.plugins.Extension#inicializar() |
|
63 |
*/ |
|
64 |
public void inicializar() { |
|
65 |
// TODO Auto-generated method stub |
|
66 |
|
|
67 |
} |
|
68 |
|
|
69 |
/* (non-Javadoc) |
|
70 |
* @see com.iver.andami.plugins.Extension#execute(java.lang.String) |
|
71 |
*/ |
|
72 |
public void execute(String actionCommand) { |
|
73 |
View vista = (View)PluginServices.getMDIManager().getActiveView(); |
|
74 |
FMap mapContext = vista.getModel().getMapContext(); |
|
75 |
FLayers layers = mapContext.getLayers(); |
|
76 |
GeoProcessingPanel dataSelectionPanel = new GeoProcessingPanel(layers); |
|
77 |
//GeoProcessingPanel dataSelectionPanel = new GeoProcessingPanel(); |
|
78 |
PluginServices.getMDIManager().addView(dataSelectionPanel); |
|
79 |
} |
|
80 |
|
|
81 |
/* (non-Javadoc) |
|
82 |
* @see com.iver.andami.plugins.Extension#isEnabled() |
|
83 |
*/ |
|
84 |
public boolean isEnabled() { |
|
85 |
return true; |
|
86 |
} |
|
87 |
|
|
88 |
/* (non-Javadoc) |
|
89 |
* @see com.iver.andami.plugins.Extension#isVisible() |
|
90 |
*/ |
|
91 |
public boolean isVisible() { |
|
92 |
com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
|
93 |
.getActiveView(); |
|
94 |
if (f == null) { |
|
95 |
return false; |
|
96 |
} |
|
97 |
if (f.getClass() == View.class) { |
|
98 |
View vista = (View) f; |
|
99 |
ProjectView model = vista.getModel(); |
|
100 |
FMap mapa = model.getMapContext(); |
|
101 |
return mapa.getLayers().getLayersCount() > 0; |
|
102 |
} else { |
|
103 |
return false; |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
} |
|
0 | 108 |
tags/Root_gvSIGGeoProcessingPlugin_PreRefactoring/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/gui/GeoProcessingPanel.java | ||
---|---|---|
1 |
/* |
|
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 |
import javax.swing.JList; |
|
50 |
import javax.swing.JPanel; |
|
51 |
import javax.swing.JRadioButton; |
|
52 |
import javax.swing.JTextField; |
|
53 |
import javax.swing.JScrollPane; |
|
54 |
|
|
55 |
import com.hardcode.driverManager.DriverLoadException; |
|
56 |
import com.hardcode.gdbms.engine.data.DataSource; |
|
57 |
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 |
import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException; |
|
61 |
import com.hardcode.gdbms.engine.values.BooleanValue; |
|
62 |
import com.hardcode.gdbms.engine.values.Value; |
|
63 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
|
64 |
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 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
70 |
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 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
74 |
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 |
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 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
|
81 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
|
82 |
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 |
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 |
import com.iver.gvsig.geoprocessing.operations.GeoProcessingPersistenceOperations; |
|
94 |
import com.iver.gvsig.geoprocessing.operations.GeoProcessingTableOperations; |
|
95 |
import com.iver.gvsig.geoprocessing.operations.GeoProcessingTopologyOperations; |
|
96 |
import com.iver.gvsig.geoprocessing.operations.strategies.SelectedShapeToJTSVisitor; |
|
97 |
import com.vividsolutions.jts.geom.Coordinate; |
|
98 |
import com.vividsolutions.jts.geom.Geometry; |
|
99 |
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.geom.PrecisionModel; |
|
106 |
import com.vividsolutions.jts.operation.distance.DistanceOp; |
|
107 |
|
|
108 |
import java.awt.Component; |
|
109 |
import java.awt.GridLayout; |
|
110 |
import java.awt.GridBagLayout; |
|
111 |
import java.awt.GridBagConstraints; |
|
112 |
import java.awt.FlowLayout; |
|
113 |
import java.awt.CardLayout; |
|
114 |
import javax.swing.BoxLayout; |
|
115 |
import java.awt.BorderLayout; |
|
116 |
import java.io.File; |
|
117 |
import java.sql.Types; |
|
118 |
import java.util.BitSet; |
|
119 |
import java.util.Vector; |
|
120 |
|
|
121 |
import javax.swing.JButton; |
|
122 |
|
|
123 |
public class GeoProcessingPanel extends JPanel implements View { |
|
124 |
|
|
125 |
/** |
|
126 |
* |
|
127 |
*/ |
|
128 |
private static final long serialVersionUID = 1L; |
|
129 |
private GeoProcessingOperationSelectorPanel geoProcessingOperationSelectorPanel = null; |
|
130 |
private GeoProcessingBufferPanel geoProcessingBufferPanel = null; |
|
131 |
private GeoProcessingClipPanel geoProcessingClipPanel = null; |
|
132 |
private GeoProcessingDissolvePanel geoProcessingDissolvePanel = null; |
|
133 |
private GeoProcessingMergePanel geoProcessingMergePanel = null; |
|
134 |
private GeoProcessingIntersectPanel geoProcessingIntersectPanel = null; |
|
135 |
private GeoProcessingUnionPanel geoProcessingUnionPanel = null; |
|
136 |
private GeoProcessingSpatialjoinPanel geoProcessingSpatialjoinPanel = null; |
|
137 |
private JPanel buttonsPanel = null; |
|
138 |
|
|
139 |
private JButton jButton = null; |
|
140 |
private JButton jButton1 = null; |
|
141 |
private JButton jButton2 = null; |
|
142 |
private ViewInfo viewInfo = null; |
|
143 |
private FLayers layers = null; |
|
144 |
/** |
|
145 |
* This constructor initializes the set of layers |
|
146 |
*/ |
|
147 |
public GeoProcessingPanel(FLayers layers) { |
|
148 |
super(); |
|
149 |
this.layers = layers; |
|
150 |
initialize(); |
|
151 |
} |
|
152 |
|
|
153 |
/** |
|
154 |
* This method initializes this |
|
155 |
* |
|
156 |
* @return void |
|
157 |
*/ |
|
158 |
private void initialize() { |
|
159 |
this.setLayout(new BorderLayout()); |
|
160 |
this.setSize(416, 271); |
|
161 |
this.add(getButtonsPanel(), java.awt.BorderLayout.SOUTH); |
|
162 |
this.add(getGeoProcessingOperationSelectorPanel(), java.awt.BorderLayout.NORTH); |
|
163 |
this.add(getGeoProcessingBufferPanel(), java.awt.BorderLayout.NORTH); |
|
164 |
this.add(getGeoProcessingClipPanel(), java.awt.BorderLayout.NORTH); |
|
165 |
this.add(getGeoProcessingDissolvePanel(), java.awt.BorderLayout.NORTH); |
|
166 |
this.add(getGeoProcessingMergePanel(), java.awt.BorderLayout.NORTH); |
|
167 |
this.add(getGeoProcessingIntersectPanel(), java.awt.BorderLayout.NORTH); |
|
168 |
this.add(getGeoProcessingUnionPanel(), java.awt.BorderLayout.NORTH); |
|
169 |
this.add(getGeoProcessingSpatialjoinPanel(), java.awt.BorderLayout.NORTH); |
|
170 |
geoProcessingOperationSelectorPanel.setVisible(true); |
|
171 |
geoProcessingBufferPanel.setVisible(false); |
|
172 |
geoProcessingClipPanel.setVisible(false); |
|
173 |
geoProcessingDissolvePanel.setVisible(false); |
|
174 |
geoProcessingMergePanel.setVisible(false); |
|
175 |
geoProcessingIntersectPanel.setVisible(false); |
|
176 |
geoProcessingUnionPanel.setVisible(false); |
|
177 |
geoProcessingSpatialjoinPanel.setVisible(false); |
|
178 |
jButton1.setEnabled(false); |
|
179 |
} |
|
180 |
|
|
181 |
public ViewInfo getViewInfo() { |
|
182 |
// TODO Auto-generated method stub |
|
183 |
if (viewInfo == null) { |
|
184 |
viewInfo=new ViewInfo(ViewInfo.MODALDIALOG); |
|
185 |
viewInfo.setTitle(PluginServices.getText(this,"Herramientas_de_analisis")); |
|
186 |
} |
|
187 |
return viewInfo; |
|
188 |
} |
|
189 |
|
|
190 |
/** |
|
191 |
* This method initializes geoProcessingOperationSelectorPanel |
|
192 |
* |
|
193 |
* @return javax.swing.JPanel |
|
194 |
*/ |
|
195 |
private JPanel getGeoProcessingOperationSelectorPanel() { |
|
196 |
if (geoProcessingOperationSelectorPanel == null) { |
|
197 |
geoProcessingOperationSelectorPanel = new GeoProcessingOperationSelectorPanel(); |
|
198 |
geoProcessingOperationSelectorPanel.setName("geoProcessingOperationSelectorPanel"); |
|
199 |
} |
|
200 |
return geoProcessingOperationSelectorPanel; |
|
201 |
} |
|
202 |
|
|
203 |
/** |
|
204 |
* This method initializes geoProcessingBufferPanel |
|
205 |
* |
|
206 |
* @return javax.swing.JPanel |
|
207 |
*/ |
|
208 |
private JPanel getGeoProcessingBufferPanel() { |
|
209 |
if (geoProcessingBufferPanel == null) { |
|
210 |
geoProcessingBufferPanel = new GeoProcessingBufferPanel(layers); |
|
211 |
geoProcessingBufferPanel.setName("geoProcessingBufferPanel"); |
|
212 |
} |
|
213 |
return geoProcessingBufferPanel; |
|
214 |
} |
|
215 |
|
|
216 |
/** |
|
217 |
* This method initializes geoProcessingClipPanel |
|
218 |
* |
|
219 |
* @return javax.swing.JPanel |
|
220 |
*/ |
|
221 |
private JPanel getGeoProcessingClipPanel() { |
|
222 |
if (geoProcessingClipPanel == null) { |
|
223 |
geoProcessingClipPanel = new GeoProcessingClipPanel(layers); |
|
224 |
geoProcessingClipPanel.setName("geoProcessingClipPanel"); |
|
225 |
// Si no le meto esta l?nea, no se visualiza el men?. Ver que puede |
|
226 |
// estar pasando ... |
|
227 |
geoProcessingClipPanel.setPreferredSize(new java.awt.Dimension(300,300)); |
|
228 |
} |
|
229 |
return geoProcessingClipPanel; |
Also available in: Unified diff