root / trunk / libraries / libTopology / src-test / org / gvsig / topology / util / LayerFactory.java @ 19992
History | View | Annotate | Download (19.1 KB)
1 |
/*
|
---|---|
2 |
* Created on 24-sep-2007
|
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 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id$
|
47 |
* $Log$
|
48 |
*
|
49 |
*/
|
50 |
package org.gvsig.topology.util; |
51 |
|
52 |
import java.util.ArrayList; |
53 |
import java.util.List; |
54 |
|
55 |
import com.hardcode.gdbms.engine.values.StringValue; |
56 |
import com.hardcode.gdbms.engine.values.Value; |
57 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
58 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
59 |
import com.iver.cit.gvsig.fmap.core.FMultiPoint2D; |
60 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
61 |
import com.iver.cit.gvsig.fmap.core.FShape; |
62 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
63 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
64 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
65 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
66 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
67 |
import com.iver.cit.gvsig.fmap.drivers.FeatureCollectionMemoryDriver; |
68 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
69 |
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition; |
70 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
71 |
import com.vividsolutions.jts.geom.Coordinate; |
72 |
import com.vividsolutions.jts.geom.Geometry; |
73 |
import com.vividsolutions.jts.geom.GeometryFactory; |
74 |
import com.vividsolutions.jts.geom.MultiPoint; |
75 |
import com.vividsolutions.jts.geom.Point; |
76 |
import com.vividsolutions.jts.geom.PrecisionModel; |
77 |
import com.vividsolutions.jts.io.ParseException; |
78 |
import com.vividsolutions.jts.io.WKTReader; |
79 |
|
80 |
public class LayerFactory { |
81 |
static PrecisionModel pm = new PrecisionModel(10000); |
82 |
static GeometryFactory factory = new GeometryFactory(pm); |
83 |
static WKTReader wktReader = new WKTReader(factory); |
84 |
|
85 |
|
86 |
public static FLyrVect getLineLayerWithCollapsedCoords() throws ParseException{ |
87 |
Geometry ln1 = wktReader.read("LINESTRING(500 500, 510 500)");
|
88 |
Geometry ln2 = wktReader.read("LINESTRING(700 100, 720 120, 800 600)");
|
89 |
|
90 |
LayerDefinition definition = createTestLayerDefinition(); |
91 |
definition.setShapeType(FShape.LINE); |
92 |
|
93 |
//feature 1
|
94 |
int index = 0; |
95 |
IFeature f1 = createTestFeature(ln1, index); |
96 |
index++; |
97 |
IFeature f2 = createTestFeature(ln2, index); |
98 |
|
99 |
ArrayList<IFeature> features = new ArrayList<IFeature>(); |
100 |
features.add(f1); |
101 |
features.add(f2); |
102 |
|
103 |
FeatureCollectionMemoryDriver driver = |
104 |
new FeatureCollectionMemoryDriver("multipuntos", |
105 |
features, |
106 |
definition); |
107 |
|
108 |
return (FLyrVect) com.iver.cit.gvsig.fmap.layers.LayerFactory.createLayer("multipuntos", |
109 |
driver, |
110 |
null);
|
111 |
} |
112 |
|
113 |
public static FLyrVect getLyrWithRepeatedCoords() throws ParseException{ |
114 |
Geometry multiPoint = wktReader.read("MULTIPOINT (520 160, 540 180, 540 180, 540 180, 600 180, 580 140, 640 140, 640 140, 640 160)");
|
115 |
Geometry multiPoint2 = wktReader.read("MULTIPOINT (520 160, 540 180, 600 180, 580 140, 640 140, 640 160)");
|
116 |
LayerDefinition definition = createTestLayerDefinition(); |
117 |
definition.setShapeType(FShape.MULTIPOINT); |
118 |
|
119 |
Coordinate[] coords = ((MultiPoint)multiPoint).getCoordinates();
|
120 |
double[] x = new double[coords.length]; |
121 |
double[] y = new double[coords.length]; |
122 |
for(int i = 0; i < coords.length; i++){ |
123 |
x[i] = coords[i].x; |
124 |
y[i] = coords[i].y; |
125 |
} |
126 |
FMultiPoint2D m1 = new FMultiPoint2D(x, y);
|
127 |
StringValue value = ValueFactory.createValue("s1");
|
128 |
Value[] values = {value};
|
129 |
DefaultFeature f1 = new DefaultFeature(m1, values, "id1"); |
130 |
|
131 |
Coordinate[] coords2 = ((MultiPoint)multiPoint2).getCoordinates();
|
132 |
double[] x2 = new double[coords2.length]; |
133 |
double[] y2 = new double[coords2.length]; |
134 |
for(int i = 0; i < coords2.length; i++){ |
135 |
x2[i] = coords2[i].x; |
136 |
y2[i] = coords2[i].y; |
137 |
} |
138 |
FMultiPoint2D m2 = new FMultiPoint2D(x2, y2);
|
139 |
StringValue value2 = ValueFactory.createValue("s2");
|
140 |
Value[] values2 = {value2};
|
141 |
DefaultFeature f2 = new DefaultFeature(m2, values2, "id2"); |
142 |
|
143 |
ArrayList<IFeature> features = new ArrayList<IFeature>(); |
144 |
features.add(f1); |
145 |
features.add(f2); |
146 |
|
147 |
|
148 |
FeatureCollectionMemoryDriver driver = |
149 |
new FeatureCollectionMemoryDriver("multipuntos", |
150 |
features, |
151 |
definition); |
152 |
|
153 |
return (FLyrVect) com.iver.cit.gvsig.fmap.layers.LayerFactory.createLayer("multipuntos", |
154 |
driver, |
155 |
null);
|
156 |
} |
157 |
|
158 |
public static FLyrVect createPointLyrWhichDontPasJtsValidRule(){ |
159 |
LayerDefinition definition = createTestLayerDefinition(); |
160 |
definition.setShapeType(FShape.POINT); |
161 |
FeatureCollectionMemoryDriver driver = null;
|
162 |
|
163 |
Coordinate coord1 = new Coordinate(Double.NaN, Double.POSITIVE_INFINITY); |
164 |
Point pt1 = factory.createPoint(coord1);
|
165 |
int index = 0; |
166 |
IFeature f1 = createTestFeature(pt1, index); |
167 |
index++; |
168 |
|
169 |
Coordinate coord2 = new Coordinate(100d, 100d); |
170 |
Point pt2 = factory.createPoint(coord2);
|
171 |
IFeature f2 = createTestFeature(pt2, index); |
172 |
index++; |
173 |
|
174 |
Coordinate coord3 = new Coordinate(50d, 75d); |
175 |
Point pt3 = factory.createPoint(coord3);
|
176 |
IFeature f3 = createTestFeature(pt3, index); |
177 |
index++; |
178 |
|
179 |
Coordinate coord4 = new Coordinate(Double.NaN, Double.NEGATIVE_INFINITY); |
180 |
Point pt4 = factory.createPoint(coord4);
|
181 |
IFeature f4 = createTestFeature(pt4, index); |
182 |
index++; |
183 |
|
184 |
List<IFeature> features = new ArrayList<IFeature>(); |
185 |
features.add(f1); |
186 |
features.add(f2); |
187 |
features.add(f3); |
188 |
features.add(f4); |
189 |
|
190 |
driver = new FeatureCollectionMemoryDriver("puntos no validos jts", |
191 |
features, |
192 |
definition); |
193 |
|
194 |
return (FLyrVect) com.iver.cit.gvsig.fmap.layers.LayerFactory.createLayer("puntosJtsInvalidos", |
195 |
driver, |
196 |
null);
|
197 |
} |
198 |
|
199 |
|
200 |
public static FLyrVect createLineLyrWhichDontPasJtsValidRule(){ |
201 |
LayerDefinition definition = createTestLayerDefinition(); |
202 |
definition.setShapeType(FShape.LINE); |
203 |
FeatureCollectionMemoryDriver driver = null;
|
204 |
|
205 |
Coordinate coord1 = new Coordinate(100d, 230.342d); |
206 |
Coordinate[] coords = {coord1, coord1};
|
207 |
Geometry geom1 = factory.createLineString(coords); |
208 |
int index = 0; |
209 |
IFeature f1 = createTestFeature(geom1, index); |
210 |
|
211 |
Coordinate coord2 = new Coordinate(139d, 2021.0d); |
212 |
Coordinate[] coords2 = {coord1, coord2};
|
213 |
Geometry geom2 = factory.createLineString(coords2); |
214 |
IFeature f2 = createTestFeature(geom2, index); |
215 |
|
216 |
Coordinate coord3 = new Coordinate(212d, Double.NaN); |
217 |
Coordinate[] coords3 = {coord2, coord3};
|
218 |
Geometry geom3 = factory.createLineString(coords3); |
219 |
IFeature f3 = createTestFeature(geom3, index); |
220 |
|
221 |
List<IFeature> features = new ArrayList<IFeature>(); |
222 |
features.add(f1); |
223 |
features.add(f2); |
224 |
features.add(f3); |
225 |
|
226 |
driver = new FeatureCollectionMemoryDriver("lineas no validos jts", |
227 |
features, |
228 |
definition); |
229 |
|
230 |
return (FLyrVect) com.iver.cit.gvsig.fmap.layers.LayerFactory.
|
231 |
createLayer("puntosJtsInvalidos",
|
232 |
driver, |
233 |
null);
|
234 |
} |
235 |
|
236 |
//TODO Create test cases to probe SNAP functions
|
237 |
public static FLyrVect createPolygonLayerWhichDontPassJtsValidRule() throws ParseException{ |
238 |
LayerDefinition definition = createTestLayerDefinition(); |
239 |
definition.setShapeType(FShape.POLYGON); |
240 |
FeatureCollectionMemoryDriver driver = null;
|
241 |
List<IFeature> features = new ArrayList<IFeature>(); |
242 |
int index = 0; |
243 |
|
244 |
//A polygon with a hole which shell has a self-intersection->TODO el paso jts->fmap->jts hace cosas raras
|
245 |
Geometry pol1 = wktReader.read("POLYGON ((80 140, 360 60, 180 340, 200 60, 240 20, 80 140), (220 200, 220 140, 300 100, 260 180, 220 200))");
|
246 |
IFeature f1 = createTestFeature(pol1, index); |
247 |
index++; |
248 |
|
249 |
|
250 |
//Non error polygon
|
251 |
Geometry pol2 = wktReader.read("POLYGON ((200 260, 440 80, 500 360, 380 380, 200 260))");
|
252 |
IFeature f2 = createTestFeature(pol2, index); |
253 |
index++; |
254 |
|
255 |
//Polygon with selintersecting hole
|
256 |
Geometry pol3 = wktReader.read("POLYGON ((100 80, 240 20, 460 200, 400 380, 220 400, 60 360, 0 220, 100 80), (100 320, 380 220, 60 180, 320 340, 100 320))");
|
257 |
IFeature f3 = createTestFeature(pol3, index); |
258 |
index++; |
259 |
|
260 |
//unclosed polygon Por definicion JTS si comprueba que los linearRing sean cerrados en su construccion
|
261 |
// Geometry pol4 = wktReader.read("POLYGON ((200 260, 440 80, 500 360, 380 380))");
|
262 |
GeneralPathX gpx = new GeneralPathX();
|
263 |
gpx.moveTo(200, 260); |
264 |
gpx.lineTo(440, 80); |
265 |
gpx.lineTo(500, 360); |
266 |
gpx.lineTo(380, 380); |
267 |
FPolygon2D polygon = new FPolygon2D(gpx);
|
268 |
IGeometry pol4 = ShapeFactory.createGeometry(polygon); |
269 |
StringValue value = ValueFactory.createValue("s4");
|
270 |
Value[] values = {value};
|
271 |
DefaultFeature f4 = new DefaultFeature(pol4, values, "id4"); |
272 |
|
273 |
index++; |
274 |
|
275 |
//it isnt a polygon. its a line (three collinear points: collapsed polygon)
|
276 |
// Geometry pol5 = wktReader.read("POLYGON ((200 260, 440 80, 200 260))");
|
277 |
// IFeature f5 = createTestFeature(pol5, index);
|
278 |
GeneralPathX gpx2 = new GeneralPathX();
|
279 |
gpx2.moveTo(200, 260); |
280 |
gpx2.lineTo(440, 80); |
281 |
gpx2.lineTo(200, 260); |
282 |
FPolygon2D polygon2 = new FPolygon2D(gpx2);
|
283 |
IGeometry pol5 = ShapeFactory.createGeometry(polygon2); |
284 |
StringValue value2 = ValueFactory.createValue("s5");
|
285 |
Value[] values2 = {value2};
|
286 |
DefaultFeature f5 = new DefaultFeature(pol5, values2, "id5"); |
287 |
index++; |
288 |
|
289 |
//Polygon with shell points in CCW order
|
290 |
Geometry pol6 = wktReader.read("POLYGON ((100 320, 380 220, 60 180, 320 340, 100 320))");
|
291 |
IFeature f6 = createTestFeature(pol6, index); |
292 |
index++; |
293 |
|
294 |
//Polygon with hole in CCW order
|
295 |
Geometry pol7 = wktReader.read("POLYGON ((0 0, 1000 0, 1000 1000, 0 1000, 0 0), (100 80, 240 20, 460 200, 400 380, 220 400, 60 360, 0 220, 100 80))");
|
296 |
IFeature f7 = createTestFeature(pol7, index); |
297 |
index++; |
298 |
|
299 |
//Polygon with two holes that touch in more than a point
|
300 |
Geometry pol8 = wktReader.read("POLYGON ((40 380, 40 20, 500 20, 500 380, 40 380),"+
|
301 |
"(140 320, 160 200, 240 160, 400 220, 300 340, 140 320),"+
|
302 |
"(300 140, 420 300, 460 100, 300 140))");
|
303 |
|
304 |
IFeature f8 = createTestFeature(pol8, index); |
305 |
index++; |
306 |
|
307 |
//the hole is ccw
|
308 |
Geometry pol9 = wktReader.read("POLYGON ((160 320, 740 80, 740 340, 400 380, 160 320), (440 260, 600 200, 660 300, 500 300, 440 260))");
|
309 |
IFeature f9 = createTestFeature(pol9, index); |
310 |
index++; |
311 |
|
312 |
//hole is not full contained by shell
|
313 |
Geometry pol10 = wktReader.read("POLYGON ((160 320, 740 80, 740 340, 400 380, 160 320), (440 260, 500 300, 660 300, 600 200, 440 260))");
|
314 |
IFeature f10 = createTestFeature(pol10, index); |
315 |
index++; |
316 |
|
317 |
//shell and hole have the same coordinate sequence
|
318 |
Geometry pol11 = wktReader.read("POLYGON((440 260, 600 200, 660 300, 500 300, 440 260),(440 260, 500 300, 660 300, 600 200, 440 260))");
|
319 |
IFeature f11 = createTestFeature(pol11, index); |
320 |
index++; |
321 |
|
322 |
features.add(f1); |
323 |
features.add(f2); |
324 |
features.add(f3); |
325 |
features.add(f4);//jts no permite linearRing no cerrados (esto si lo chequea)
|
326 |
features.add(f5);//jts no permite linearRings con < 3 puntos diferentes y no colineales
|
327 |
features.add(f6); |
328 |
features.add(f7); |
329 |
features.add(f8); |
330 |
features.add(f9); |
331 |
features.add(f10); |
332 |
features.add(f11); |
333 |
|
334 |
driver = new FeatureCollectionMemoryDriver("poligonos no validos jts", |
335 |
features, |
336 |
definition); |
337 |
|
338 |
return (FLyrVect) com.iver.cit.gvsig.fmap.layers.LayerFactory.
|
339 |
createLayer("poligonos no validos jts",
|
340 |
driver, |
341 |
null);
|
342 |
|
343 |
} |
344 |
|
345 |
|
346 |
public static FLyrVect createLyrForIGeometryMustBeClosedTest() throws ParseException{ |
347 |
|
348 |
LayerDefinition definition = createTestLayerDefinition(); |
349 |
definition.setShapeType(FShape.LINE); |
350 |
FeatureCollectionMemoryDriver driver = null;
|
351 |
List<IFeature> features = new ArrayList<IFeature>(); |
352 |
int index = 0; |
353 |
|
354 |
|
355 |
Geometry unclosedLine = wktReader.read("LINESTRING (280 80, 320 140, 360 220, 520 260, 560 200, 600 140, 500 80, 400 80, 260 60)");
|
356 |
IFeature f1 = createTestFeature(unclosedLine, index++); |
357 |
|
358 |
Geometry overShootLine = wktReader.read("LINESTRING (140 220, 420 280, 320 380, 160 380, 80 300, 280 180)");
|
359 |
IFeature f2 = createTestFeature(overShootLine, index++); |
360 |
|
361 |
features.add(f1); |
362 |
features.add(f2); |
363 |
|
364 |
driver = new FeatureCollectionMemoryDriver("lineas no cerradas", |
365 |
features, |
366 |
definition); |
367 |
|
368 |
return (FLyrVect) com.iver.cit.gvsig.fmap.layers.LayerFactory.
|
369 |
createLayer("lineas no cerradas",
|
370 |
driver, |
371 |
null);
|
372 |
|
373 |
} |
374 |
|
375 |
public static FLyrVect createLyrForLineMustNotHavePseudonodesTest() throws ParseException{ |
376 |
LayerDefinition definition = createTestLayerDefinition(); |
377 |
definition.setShapeType(FShape.LINE); |
378 |
FeatureCollectionMemoryDriver driver = null;
|
379 |
List<IFeature> features = new ArrayList<IFeature>(); |
380 |
int index = 0; |
381 |
|
382 |
Geometry line1 = wktReader.read("LINESTRING (10 10, 100 10)");
|
383 |
IFeature f1 = createTestFeature(line1, index++); |
384 |
|
385 |
//pseudonode is point (100 10)
|
386 |
Geometry line2 = wktReader.read("LINESTRING (100.01 10, 200 10)");
|
387 |
IFeature f2 = createTestFeature(line2, index++); |
388 |
|
389 |
Geometry line3 = wktReader.read("LINESTRING (200 10, 300 300)");
|
390 |
IFeature f3 = createTestFeature(line3, index++); |
391 |
|
392 |
Geometry line4 = wktReader.read("LINESTRING (200 10, 100 -150)");
|
393 |
IFeature f4 = createTestFeature(line4, index++); |
394 |
|
395 |
features.add(f1); |
396 |
features.add(f2); |
397 |
features.add(f3); |
398 |
features.add(f4); |
399 |
|
400 |
driver = new FeatureCollectionMemoryDriver("lineas con pseudonodo en 100 10", |
401 |
features, |
402 |
definition); |
403 |
|
404 |
return (FLyrVect) com.iver.cit.gvsig.fmap.layers.LayerFactory.
|
405 |
createLayer("lineas con pseudonodo en 100 10",
|
406 |
driver, |
407 |
null);
|
408 |
|
409 |
} |
410 |
|
411 |
public static FLyrVect createPolygonForNoSelfIntersectTest() throws ParseException{ |
412 |
LayerDefinition definition = createTestLayerDefinition(); |
413 |
definition.setShapeType(FShape.POLYGON); |
414 |
FeatureCollectionMemoryDriver driver = null;
|
415 |
List<IFeature> features = new ArrayList<IFeature>(); |
416 |
int index = 0; |
417 |
|
418 |
Geometry line1 = wktReader.read("POLYGON ((-13900 -920, -8300 120, -5020 3460, -9480 5660, -15320 2620, -19420 4960, -19300 7600, -14620 8500, -13180 6840, -16380 5460, -22020 6280, -22340 3060, -18860 2120, -14820 4880, -10200 4460, -8680 2640, -8240 1780, -4420 -420, -5140 -2560, -9480 -3640, -12940 -2740, -13900 -920))");
|
419 |
IFeature f1 = createTestFeature(line1, index++); |
420 |
features.add(f1); |
421 |
driver = new FeatureCollectionMemoryDriver("poligonos con autointersecciones", |
422 |
features, |
423 |
definition); |
424 |
|
425 |
return (FLyrVect) com.iver.cit.gvsig.fmap.layers.LayerFactory.
|
426 |
createLayer("poligonos con autointersecciones",
|
427 |
driver, |
428 |
null);
|
429 |
} |
430 |
|
431 |
public static FLyrVect createPolygonForMustNotOverlapTest() throws ParseException{ |
432 |
LayerDefinition definition = createTestLayerDefinition(); |
433 |
definition.setShapeType(FShape.POLYGON); |
434 |
FeatureCollectionMemoryDriver driver = null;
|
435 |
List<IFeature> features = new ArrayList<IFeature>(); |
436 |
int index = 0; |
437 |
|
438 |
Geometry poly1 = wktReader.read("POLYGON ((290 340, 180 280, 610 230, 720 330, 530 400, 300 380, 290 340))");
|
439 |
IFeature f1 = createTestFeature(poly1, index++); |
440 |
features.add(f1); |
441 |
|
442 |
Geometry poly2 = wktReader.read("POLYGON ((180 210, 550 210, 200 390, 180 210))");
|
443 |
IFeature f2 = createTestFeature(poly2, index++); |
444 |
features.add(f2); |
445 |
|
446 |
Geometry poly3 = wktReader.read("POLYGON ((820 180, 820 30, 980 30, 1000 180, 820 180))");
|
447 |
IFeature f3 = createTestFeature(poly3, index++); |
448 |
features.add(f3); |
449 |
|
450 |
|
451 |
|
452 |
driver = new FeatureCollectionMemoryDriver("poligonos que solapan", |
453 |
features, |
454 |
definition); |
455 |
|
456 |
return (FLyrVect) com.iver.cit.gvsig.fmap.layers.LayerFactory.
|
457 |
createLayer("poligonos que solapan",
|
458 |
driver, |
459 |
null);
|
460 |
} |
461 |
|
462 |
|
463 |
public static FLyrVect[] createPolygonForMustNotOverlapWithTest() throws ParseException{ |
464 |
|
465 |
FLyrVect[] solution = new FLyrVect[2]; |
466 |
|
467 |
LayerDefinition definition = createTestLayerDefinition(); |
468 |
definition.setShapeType(FShape.POLYGON); |
469 |
|
470 |
FeatureCollectionMemoryDriver driver = null;
|
471 |
List<IFeature> features = new ArrayList<IFeature>(); |
472 |
int index = 0; |
473 |
|
474 |
|
475 |
Geometry poly1 = wktReader.read("POLYGON ((290 340, 180 280, 610 230, 720 330, 530 400, 300 380, 290 340))");
|
476 |
IFeature f1 = createTestFeature(poly1, index++); |
477 |
features.add(f1); |
478 |
|
479 |
Geometry poly3 = wktReader.read("POLYGON ((820 180, 820 30, 980 30, 1000 180, 820 180))");
|
480 |
IFeature f3 = createTestFeature(poly3, index++); |
481 |
features.add(f3); |
482 |
driver = new FeatureCollectionMemoryDriver("poligonos 1", |
483 |
features, |
484 |
definition); |
485 |
|
486 |
solution[0] = (FLyrVect) com.iver.cit.gvsig.fmap.layers.LayerFactory.
|
487 |
createLayer("poligonos que solapan",
|
488 |
driver, |
489 |
null);
|
490 |
|
491 |
|
492 |
|
493 |
FeatureCollectionMemoryDriver driver2 = null;
|
494 |
ArrayList<IFeature> features2 = new ArrayList<IFeature>(); |
495 |
index = 0;
|
496 |
Geometry poly11= wktReader.read("POLYGON ((20 210, 30 50, 320 30, 330 180, 20 210))");
|
497 |
IFeature f11 = createTestFeature(poly11, index++); |
498 |
features2.add(f11); |
499 |
|
500 |
Geometry poly22= wktReader.read("POLYGON ((880 380, 920 230, 1000 210, 840 10, 880 380))");
|
501 |
IFeature f22 = createTestFeature(poly22, index++); |
502 |
features.add(f22); |
503 |
driver2 = new FeatureCollectionMemoryDriver("poligonos 1", |
504 |
features2, |
505 |
definition); |
506 |
|
507 |
solution[1] = (FLyrVect) com.iver.cit.gvsig.fmap.layers.LayerFactory.
|
508 |
createLayer("poligonos que solapan",
|
509 |
driver2, |
510 |
null);
|
511 |
|
512 |
return solution;
|
513 |
} |
514 |
|
515 |
private static LayerDefinition createTestLayerDefinition() { |
516 |
FieldDescription fieldDescription = new FieldDescription();
|
517 |
fieldDescription.setFieldName("str1");
|
518 |
fieldDescription.setFieldType(FieldDescription.stringToType("String"));
|
519 |
fieldDescription.setFieldLength(10);
|
520 |
FieldDescription[] fields = {fieldDescription};
|
521 |
LayerDefinition definition = new LayerDefinition();
|
522 |
definition.setFieldsDesc(fields); |
523 |
return definition;
|
524 |
} |
525 |
|
526 |
private static IFeature createTestFeature(Geometry geometry, int index){ |
527 |
StringValue value = ValueFactory.createValue("s"+index);
|
528 |
Value[] values = {value};
|
529 |
IGeometry iln1 = FConverter.jts_to_igeometry(geometry); |
530 |
DefaultFeature f1 = new DefaultFeature(iln1, values, "id"+index); |
531 |
return f1;
|
532 |
} |
533 |
|
534 |
|
535 |
} |
536 |
|