Revision 38392
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/util/Converter.java | ||
---|---|---|
59 | 59 |
import org.gvsig.fmap.geom.aggregate.MultiPrimitive; |
60 | 60 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
61 | 61 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
62 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
62 | 63 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
63 | 64 |
import org.gvsig.fmap.geom.primitive.Surface; |
64 | 65 |
import org.slf4j.Logger; |
... | ... | |
78 | 79 |
import com.vividsolutions.jts.geom.Polygon; |
79 | 80 |
|
80 | 81 |
/** |
81 |
* Clase con varios m�todos est�ticos utilizados para pasar de java2d a jts
|
|
82 |
* Clase con varios metodos estaticos utilizados para pasar de java2d a jts
|
|
82 | 83 |
* y viceversa. |
83 | 84 |
* |
84 | 85 |
* @author fjp |
85 | 86 |
* @deprecated to be removed or moved from API to implementation in gvSIG 2.1.0 |
86 | 87 |
*/ |
87 | 88 |
public class Converter { |
88 |
private static final GeometryManager geomManager = GeometryLocator |
|
89 |
.getGeometryManager(); |
|
90 |
private static final Logger logger = LoggerFactory |
|
91 |
.getLogger(Converter.class); |
|
92 |
|
|
93 |
// private static Logger logger = Logger.getLogger(Converter.class); |
|
94 |
|
|
95 |
/** |
|
96 |
* �QU� PODEMOS HACER CON LOS MULTIPOINT??? => DEBER�AMOS TRABAJAR CON |
|
97 |
* UN ARRAY DE PUNTOS EN FShape.....Pensarlo bien. |
|
98 |
*/ |
|
89 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
90 |
private static final Logger logger = LoggerFactory.getLogger(Converter.class); |
|
99 | 91 |
public final static com.vividsolutions.jts.geom.GeometryFactory geomFactory = new com.vividsolutions.jts.geom.GeometryFactory(); |
100 | 92 |
public static CGAlgorithms cga = new RobustCGAlgorithms(); |
101 |
// private final static AffineTransform at = new AffineTransform(); |
|
102 |
// private static double POINT_MARKER_SIZE = 3.0; |
|
103 | 93 |
|
104 |
private static GeometryManager manager = GeometryLocator |
|
105 |
.getGeometryManager(); |
|
94 |
private static GeometryManager manager = GeometryLocator.getGeometryManager(); |
|
106 | 95 |
|
107 |
// returns true if testPoint is a point in the pointList list.
|
|
96 |
//returns true if testPoint is a point in the pointList list. |
|
108 | 97 |
static boolean pointInList(Coordinate testPoint, Coordinate[] pointList) { |
109 | 98 |
int t; |
110 | 99 |
int numpoints; |
... | ... | |
115 | 104 |
for (t = 0; t < numpoints; t++) { |
116 | 105 |
p = pointList[t]; |
117 | 106 |
|
118 |
if ((testPoint.x == p.x) |
|
119 |
&& (testPoint.y == p.y) |
|
120 |
&& ((testPoint.z == p.z) || (!(testPoint.z == testPoint.z))) // nan |
|
121 |
// test; |
|
122 |
// x!=x |
|
123 |
// iff |
|
124 |
// x |
|
125 |
// is |
|
126 |
// nan |
|
107 |
if ((testPoint.x == p.x) && (testPoint.y == p.y) && |
|
108 |
((testPoint.z == p.z) || (!(testPoint.z == testPoint.z))) //nan test; x!=x iff x is nan |
|
127 | 109 |
) { |
128 | 110 |
return true; |
129 | 111 |
} |
... | ... | |
134 | 116 |
|
135 | 117 |
/** |
136 | 118 |
* Receives a JTS Geometry and returns a fmap IGeometry |
137 |
* |
|
138 |
* @param jtsGeometry |
|
139 |
* jts Geometry |
|
119 |
* @param jtsGeometry jts Geometry |
|
140 | 120 |
* @return IGeometry of FMap |
141 | 121 |
* @author azabala |
142 |
* @throws CreateGeometryException |
|
122 |
* @throws CreateGeometryException
|
|
143 | 123 |
*/ |
144 |
public static Geometry jtsToGeometry( |
|
145 |
com.vividsolutions.jts.geom.Geometry geo) |
|
146 |
throws CreateGeometryException { |
|
124 |
public static Geometry jtsToGeometry(com.vividsolutions.jts.geom.Geometry geo) throws CreateGeometryException{ |
|
147 | 125 |
Geometry shpNew = null; |
148 | 126 |
|
149 | 127 |
try { |
150 | 128 |
if (geo instanceof Point) { |
151 |
shpNew = geomManager.createPoint(((Point) geo).getX(), |
|
152 |
((Point) geo).getY(), SUBTYPES.GEOM2D); |
|
129 |
shpNew = geomManager.createPoint(((Point) geo).getX(),((Point) geo).getY(), SUBTYPES.GEOM2D); |
|
153 | 130 |
} |
154 |
|
|
155 |
if (geo instanceof com.vividsolutions.jts.geom.MultiPoint) { |
|
156 |
shpNew = (MultiPoint)geomManager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D); |
|
157 |
Coordinate[] coord = ((com.vividsolutions.jts.geom.MultiPoint)geo).getCoordinates(); |
|
158 |
for (int i = 0; i < coord.length; i++) { |
|
159 |
((MultiPoint)shpNew).addPoint(geomManager.createPoint(coord[i].x, coord[i].y, SUBTYPES.GEOM2D)); |
|
160 |
} |
|
161 |
} |
|
162 | 131 |
|
163 | 132 |
if (geo.isEmpty()) { |
164 | 133 |
shpNew = null; |
165 | 134 |
} |
166 | 135 |
|
167 |
try { |
|
136 |
try{ |
|
137 |
if (geo instanceof com.vividsolutions.jts.geom.MultiPoint) { |
|
138 |
shpNew = geomManager.create(TYPES.MULTIPOINT, SUBTYPES.GEOM2D); |
|
139 |
for (int i = 0; i < geo.getNumGeometries(); i++) { |
|
140 |
Point point = (Point) geo.getGeometryN(i); |
|
141 |
((MultiPoint)shpNew).addPoint((org.gvsig.fmap.geom.primitive.Point) jtsToGeometry(point)); |
|
142 |
} |
|
143 |
|
|
144 |
} |
|
145 |
|
|
168 | 146 |
if (geo instanceof Polygon) { |
169 |
shpNew = geomManager.createSurface(toShape((Polygon) geo), |
|
170 |
SUBTYPES.GEOM2D); |
|
147 |
shpNew = geomManager.createSurface(toShape((Polygon) geo), SUBTYPES.GEOM2D); |
|
171 | 148 |
} |
172 | 149 |
|
173 | 150 |
if (geo instanceof MultiPolygon) { |
174 |
shpNew = geomManager.createSurface( |
|
175 |
toShape((MultiPolygon) geo), SUBTYPES.GEOM2D); |
|
151 |
shpNew = geomManager.createSurface(toShape((MultiPolygon) geo), SUBTYPES.GEOM2D); |
|
176 | 152 |
} |
177 | 153 |
|
178 | 154 |
if (geo instanceof LineString) { |
179 |
shpNew = geomManager.createCurve(toShape((LineString) geo), |
|
180 |
SUBTYPES.GEOM2D); |
|
155 |
shpNew = geomManager.createCurve(toShape((LineString) geo), SUBTYPES.GEOM2D); |
|
181 | 156 |
} |
182 | 157 |
|
183 | 158 |
if (geo instanceof MultiLineString) { |
184 |
shpNew = geomManager.createCurve( |
|
185 |
toShape((MultiLineString) geo), SUBTYPES.GEOM2D); |
|
159 |
shpNew = geomManager.create(TYPES.MULTICURVE, SUBTYPES.GEOM2D); |
|
160 |
for (int i = 0; i < ((MultiLineString)geo).getNumGeometries(); i++) { |
|
161 |
com.vividsolutions.jts.geom.Geometry g = ((MultiLineString)geo).getGeometryN(i); |
|
162 |
Curve c = geomManager.createCurve(toShape((LineString) g), SUBTYPES.GEOM2D); |
|
163 |
((MultiCurve)shpNew).addCurve(c); |
|
164 |
} |
|
186 | 165 |
} |
187 |
} catch (CreateGeometryException e) {
|
|
166 |
}catch(CreateGeometryException e){
|
|
188 | 167 |
logger.error("Error creating a geometry", e); |
189 | 168 |
} |
190 | 169 |
|
191 |
/* |
|
192 |
* OJO: CON ALGO COMO FSHAPE NO S� C�MO PODEMOS IMPLEMENTAR UN |
|
193 |
* GeometryCollection No sabremos si queremos una l�nea o un |
|
194 |
* pol�gono..... if (geometry instanceof GeometryCollection) { |
|
195 |
* return toShape((GeometryCollection) geometry); } |
|
196 |
*/ |
|
197 | 170 |
return shpNew; |
198 | 171 |
} catch (NoninvertibleTransformException e) { |
199 | 172 |
// TODO Auto-generated catch block |
... | ... | |
203 | 176 |
return null; |
204 | 177 |
|
205 | 178 |
// |
206 |
// FShape shape = Converter.jts_to_java2d(jtsGeometry);
|
|
207 |
// return factory.createGeometry(shape);
|
|
179 |
// FShape shape = Converter.jts_to_java2d(jtsGeometry);
|
|
180 |
// return factory.createGeometry(shape);
|
|
208 | 181 |
} |
209 | 182 |
|
210 | 183 |
/** |
211 | 184 |
* Convierte un MultiPoint2D a un MultiPoint de JTS |
212 |
* |
|
213 | 185 |
* @param geom |
214 | 186 |
* @return |
215 | 187 |
*/ |
216 |
public com.vividsolutions.jts.geom.Geometry geometryToJts(MultiPoint geom) { |
|
188 |
public static com.vividsolutions.jts.geom.Geometry geometryToJts(MultiPoint geom) {
|
|
217 | 189 |
Coordinate[] theGeoms = new Coordinate[geom.getPrimitivesNumber()]; |
218 | 190 |
for (int i = 0; i < theGeoms.length; i++) { |
219 |
java.awt.geom.Point2D p = geom.getPrimitiveAt(i).getHandlers(
|
|
220 |
Geometry.SELECTHANDLER)[0].getPoint();
|
|
191 |
java.awt.geom.Point2D p = geom.getPrimitiveAt(i) |
|
192 |
.getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
|
|
221 | 193 |
Coordinate c = new Coordinate(p.getX(), p.getY()); |
222 | 194 |
theGeoms[i] = c; |
223 | 195 |
} |
224 | 196 |
com.vividsolutions.jts.geom.MultiPoint geomCol = new com.vividsolutions.jts.geom.GeometryFactory() |
225 |
.createMultiPoint(theGeoms);
|
|
197 |
.createMultiPoint(theGeoms); |
|
226 | 198 |
return geomCol; |
227 | 199 |
} |
228 | 200 |
|
229 | 201 |
/** |
230 | 202 |
* Convierte una MultiCurve2D en una MultiLineString de JTS |
231 |
* |
|
232 | 203 |
* @param geom |
233 | 204 |
* @return |
234 | 205 |
*/ |
235 |
public static com.vividsolutions.jts.geom.Geometry geometryToJts( |
|
236 |
MultiCurve geom) { |
|
206 |
public static com.vividsolutions.jts.geom.Geometry geometryToJts(MultiCurve geom) { |
|
237 | 207 |
LineString[] lines = new LineString[geom.getPrimitivesNumber()]; |
238 |
for (int i = 0; i < lines.length; i++) {
|
|
208 |
for (int i = 0; i < lines.length; i++){ |
|
239 | 209 |
lines[i] = (LineString) geometryToJts((geom.getPrimitiveAt(i))); |
240 | 210 |
} |
241 |
return new com.vividsolutions.jts.geom.GeometryFactory() |
|
242 |
.createMultiLineString(lines); |
|
211 |
return new com.vividsolutions.jts.geom.GeometryFactory().createMultiLineString(lines); |
|
243 | 212 |
} |
244 | 213 |
|
245 | 214 |
/** |
246 | 215 |
* Convierte una MultiSurface2D en un MultiPolygon de JTS |
247 |
* |
|
248 | 216 |
* @return |
249 | 217 |
*/ |
250 |
public com.vividsolutions.jts.geom.Geometry geometryToJts(MultiSurface geom) { |
|
218 |
public static com.vividsolutions.jts.geom.Geometry geometryToJts(MultiSurface geom) {
|
|
251 | 219 |
Polygon[] polygons = new Polygon[geom.getPrimitivesNumber()]; |
252 |
for (int i = 0; i < polygons.length; i++) {
|
|
220 |
for (int i = 0; i < polygons.length; i++){ |
|
253 | 221 |
polygons[i] = (Polygon) geometryToJts((geom.getPrimitiveAt(i))); |
254 | 222 |
} |
255 |
return new com.vividsolutions.jts.geom.GeometryFactory() |
|
256 |
.createMultiPolygon(polygons); |
|
223 |
return new com.vividsolutions.jts.geom.GeometryFactory().createMultiPolygon(polygons); |
|
257 | 224 |
} |
258 | 225 |
|
259 | 226 |
/** |
260 | 227 |
* Convierte una BaseMultiPrimitive en una GeometryCollection de JTS |
261 |
* |
|
262 | 228 |
* @return |
263 | 229 |
*/ |
264 |
public com.vividsolutions.jts.geom.Geometry geometryToJts( |
|
265 |
MultiPrimitive geom) { |
|
266 |
com.vividsolutions.jts.geom.Geometry[] geometriesAux = new LineString[geom |
|
267 |
.getPrimitivesNumber()]; |
|
230 |
public com.vividsolutions.jts.geom.Geometry geometryToJts(MultiPrimitive geom) { |
|
231 |
com.vividsolutions.jts.geom.Geometry[] geometriesAux = new LineString[geom.getPrimitivesNumber()]; |
|
268 | 232 |
for (int i = 0; i < geometriesAux.length; i++) { |
269 | 233 |
geometriesAux[i] = geometryToJts((geom.getPrimitiveAt(i))); |
270 | 234 |
} |
271 |
return new com.vividsolutions.jts.geom.GeometryFactory() |
|
272 |
.createGeometryCollection(geometriesAux); |
|
235 |
return new com.vividsolutions.jts.geom.GeometryFactory().createGeometryCollection(geometriesAux); |
|
273 | 236 |
} |
274 | 237 |
|
275 | 238 |
public static com.vividsolutions.jts.geom.Geometry geometryToJtsWithSRID( |
... | ... | |
279 | 242 |
return geometryToJts(geom, geom.getType(), srid); |
280 | 243 |
} |
281 | 244 |
|
282 |
public static com.vividsolutions.jts.geom.Geometry geometryToJts( |
|
283 |
Geometry geom) {
|
|
284 |
// logger.debug(geom.getClass());
|
|
285 |
// logger.debug(new Integer(geom.getShapeType()));
|
|
245 |
|
|
246 |
public static com.vividsolutions.jts.geom.Geometry geometryToJts(Geometry geom) {
|
|
247 |
//logger.debug(geom.getClass()); |
|
248 |
//logger.debug(new Integer(geom.getShapeType())); |
|
286 | 249 |
return geometryToJts(geom, geom.getType(), -1); |
287 | 250 |
} |
288 | 251 |
|
289 |
// public static com.vividsolutions.jts.geom.Geometry java2d_to_jts(FShape |
|
290 |
// shp) { |
|
291 |
// return java2d_to_jts(shp, shp.getShapeType()); |
|
292 |
// } |
|
252 |
// public static com.vividsolutions.jts.geom.Geometry java2d_to_jts(FShape shp) { |
|
253 |
// return java2d_to_jts(shp, shp.getShapeType()); |
|
254 |
// } |
|
293 | 255 |
|
294 |
private static boolean isClosed(Coordinate firstCoordinate, |
|
295 |
Coordinate lastCoordinate) { |
|
256 |
private static boolean isClosed(Coordinate firstCoordinate, Coordinate lastCoordinate){ |
|
296 | 257 |
double diff = Math.abs(lastCoordinate.x - firstCoordinate.x); |
297 | 258 |
if (diff > 0.000001) { |
298 | 259 |
return false; |
... | ... | |
304 | 265 |
return true; |
305 | 266 |
} |
306 | 267 |
|
268 |
public static com.vividsolutions.jts.geom.Geometry multiCurveToJts(MultiCurve geom, int srid) { |
|
269 |
LineString[] lines = new LineString[geom.getPrimitivesNumber()]; |
|
270 |
for (int i = 0; i < lines.length; i++){ |
|
271 |
lines[i] = (LineString) curveToJts((geom.getPrimitiveAt(i)), srid); |
|
272 |
} |
|
273 |
return new com.vividsolutions.jts.geom.GeometryFactory().createMultiLineString(lines); |
|
274 |
} |
|
275 |
|
|
276 |
private static com.vividsolutions.jts.geom.Geometry curveToJts(Geometry shp, int srid){ |
|
277 |
|
|
278 |
ArrayList arrayLines; |
|
279 |
LineString lin = null; |
|
280 |
PathIterator theIterator; |
|
281 |
int theType; |
|
282 |
int numParts = 0; |
|
283 |
double[] theData = new double[6]; |
|
284 |
ArrayList arrayCoords = null; |
|
285 |
Coordinate coord; |
|
286 |
|
|
287 |
arrayLines = new ArrayList(); |
|
288 |
theIterator = shp.getPathIterator(null, manager.getFlatness()); |
|
289 |
|
|
290 |
while (!theIterator.isDone()) { |
|
291 |
//while not done |
|
292 |
theType = theIterator.currentSegment(theData); |
|
293 |
|
|
294 |
//Populate a segment of the new |
|
295 |
// GeneralPathX object. |
|
296 |
//Process the current segment to populate a new |
|
297 |
// segment of the new GeneralPathX object. |
|
298 |
switch (theType) { |
|
299 |
case PathIterator.SEG_MOVETO: |
|
300 |
if (arrayCoords == null) { |
|
301 |
arrayCoords = new ArrayList(); |
|
302 |
} else { |
|
303 |
lin = geomFactory.createLineString(CoordinateArrays.toCoordinateArray( |
|
304 |
arrayCoords)); |
|
305 |
lin.setSRID(srid); |
|
306 |
arrayLines.add(lin); |
|
307 |
arrayCoords = new ArrayList(); |
|
308 |
} |
|
309 |
|
|
310 |
numParts++; |
|
311 |
coord = new Coordinate(theData[0], theData[1]); |
|
312 |
|
|
313 |
arrayCoords.add(coord); |
|
314 |
|
|
315 |
break; |
|
316 |
|
|
317 |
case PathIterator.SEG_LINETO: |
|
318 |
arrayCoords.add(new Coordinate(theData[0], |
|
319 |
theData[1])); |
|
320 |
|
|
321 |
break; |
|
322 |
|
|
323 |
case PathIterator.SEG_QUADTO: |
|
324 |
System.out.println("Not supported here"); |
|
325 |
|
|
326 |
break; |
|
327 |
|
|
328 |
case PathIterator.SEG_CUBICTO: |
|
329 |
System.out.println("Not supported here"); |
|
330 |
|
|
331 |
break; |
|
332 |
|
|
333 |
case PathIterator.SEG_CLOSE: |
|
334 |
Coordinate firstCoord = (Coordinate) arrayCoords.get(0); |
|
335 |
arrayCoords.add(new Coordinate(firstCoord.x, |
|
336 |
firstCoord.y)); |
|
337 |
|
|
338 |
break; |
|
339 |
} //end switch |
|
340 |
|
|
341 |
theIterator.next(); |
|
342 |
} //end while loop |
|
343 |
|
|
344 |
if (arrayCoords.size()<2) { |
|
345 |
|
|
346 |
}else{ |
|
347 |
|
|
348 |
lin = new com.vividsolutions.jts.geom.GeometryFactory().createLineString(CoordinateArrays.toCoordinateArray( |
|
349 |
arrayCoords)); |
|
350 |
|
|
351 |
lin.setSRID(srid); |
|
352 |
|
|
353 |
} |
|
354 |
|
|
355 |
return lin; |
|
356 |
} |
|
357 |
|
|
307 | 358 |
/** |
308 | 359 |
* Convierte un FShape a una Geometry del JTS. Para ello, utilizamos un |
309 |
* "flattened PathIterator". El flattened indica que las curvas las pasa a |
|
310 |
* segmentos de l�nea recta AUTOMATICAMENTE!!!. |
|
311 |
* |
|
312 |
* @param shp |
|
313 |
* FShape que se quiere convertir. |
|
314 |
* |
|
360 |
* flattened PathIterator. El flattened indica que las curvas las pasa a |
|
361 |
* segmentos de linea recta AUTOMATICAMENTE!!!. |
|
362 |
* |
|
363 |
* @param shp FShape que se quiere convertir. |
|
364 |
* |
|
315 | 365 |
* @return Geometry de JTS. |
316 | 366 |
*/ |
317 | 367 |
private static com.vividsolutions.jts.geom.Geometry geometryToJts( |
318 | 368 |
Geometry shp, int shapeType, int srid) { |
319 | 369 |
|
370 |
|
|
320 | 371 |
com.vividsolutions.jts.geom.Geometry geoJTS = null; |
321 | 372 |
Coordinate coord; |
322 |
// Coordinate[] coords;
|
|
373 |
//Coordinate[] coords; |
|
323 | 374 |
ArrayList arrayCoords = null; |
324 | 375 |
ArrayList arrayLines; |
325 | 376 |
LineString lin; |
326 |
// LinearRing linRing;
|
|
327 |
// LinearRing linRingExt = null;
|
|
377 |
//LinearRing linRing; |
|
378 |
//LinearRing linRingExt = null; |
|
328 | 379 |
int theType; |
329 | 380 |
int numParts = 0; |
330 | 381 |
|
331 |
// Use this array to store segment coordinate data
|
|
382 |
// Use this array to store segment coordinate data
|
|
332 | 383 |
double[] theData = new double[6]; |
333 | 384 |
PathIterator theIterator; |
334 | 385 |
|
335 |
// logger.debug(shp.toString());
|
|
386 |
//logger.debug(shp.toString()); |
|
336 | 387 |
|
388 |
|
|
337 | 389 |
switch (shapeType) { |
338 | 390 |
case Geometry.TYPES.POINT: |
339 | 391 |
org.gvsig.fmap.geom.primitive.impl.Point2D p = (org.gvsig.fmap.geom.primitive.impl.Point2D) shp; |
... | ... | |
343 | 395 |
|
344 | 396 |
break; |
345 | 397 |
|
346 |
case Geometry.TYPES.MULTIPOINT: |
|
347 |
org.gvsig.fmap.geom.aggregate.impl.MultiPoint2D mp = (org.gvsig.fmap.geom.aggregate.impl.MultiPoint2D) shp;
|
|
348 |
int numPoints = mp.getPrimitivesNumber();
|
|
349 |
Coordinate[] coordinates = new Coordinate[numPoints];
|
|
350 |
for (int i = 0; i < numPoints; i++) {
|
|
351 |
p = mp.getPoint(i);
|
|
352 |
coordinates[i] = new Coordinate(p.getX(), p.getY());
|
|
353 |
}
|
|
354 |
geoJTS = geomFactory.createMultiPoint(coordinates);
|
|
355 |
geoJTS.setSRID(srid);
|
|
398 |
/*case Geometry.TYPES.MULTIPOINT:
|
|
399 |
org.gvsig.fmap.geom.aggregate.impl.MultiPoint2D mp = (org.gvsig.fmap.geom.aggregate.impl.MultiPoint2D) shp;
|
|
400 |
int numPoints = mp.getPrimitivesNumber();
|
|
401 |
Coordinate[] coordinates = new Coordinate[numPoints];
|
|
402 |
for(int i=0; i<numPoints; i++){
|
|
403 |
p = mp.getPoint(i);
|
|
404 |
coordinates[i]=new Coordinate(p.getX(), p.getY());
|
|
405 |
}
|
|
406 |
geoJTS = geomFactory.createMultiPoint(coordinates);
|
|
407 |
geoJTS.setSRID(srid);
|
|
356 | 408 |
|
357 |
break;
|
|
409 |
break;*/
|
|
358 | 410 |
|
359 | 411 |
case Geometry.TYPES.CURVE: |
360 | 412 |
case Geometry.TYPES.ARC: |
361 |
case Geometry.TYPES.SPLINE: |
|
362 | 413 |
arrayLines = new ArrayList(); |
363 | 414 |
theIterator = shp.getPathIterator(null, manager.getFlatness()); |
364 | 415 |
|
365 | 416 |
while (!theIterator.isDone()) { |
366 |
// while not done
|
|
417 |
//while not done |
|
367 | 418 |
theType = theIterator.currentSegment(theData); |
368 | 419 |
|
369 |
// Populate a segment of the new
|
|
420 |
//Populate a segment of the new |
|
370 | 421 |
// GeneralPathX object. |
371 |
// Process the current segment to populate a new
|
|
422 |
//Process the current segment to populate a new |
|
372 | 423 |
// segment of the new GeneralPathX object. |
373 | 424 |
switch (theType) { |
374 | 425 |
case PathIterator.SEG_MOVETO: |
375 |
|
|
376 |
// System.out.println("SEG_MOVETO"); |
|
377 | 426 |
if (arrayCoords == null) { |
378 | 427 |
arrayCoords = new ArrayList(); |
379 | 428 |
} else { |
380 |
lin = geomFactory.createLineString(CoordinateArrays |
|
381 |
.toCoordinateArray(arrayCoords));
|
|
429 |
lin = geomFactory.createLineString(CoordinateArrays.toCoordinateArray(
|
|
430 |
arrayCoords)); |
|
382 | 431 |
lin.setSRID(srid); |
383 | 432 |
arrayLines.add(lin); |
384 | 433 |
arrayCoords = new ArrayList(); |
... | ... | |
392 | 441 |
break; |
393 | 442 |
|
394 | 443 |
case PathIterator.SEG_LINETO: |
444 |
arrayCoords.add(new Coordinate(theData[0], |
|
445 |
theData[1])); |
|
395 | 446 |
|
396 |
// System.out.println("SEG_LINETO"); |
|
397 |
arrayCoords.add(new Coordinate(theData[0], theData[1])); |
|
398 |
|
|
399 | 447 |
break; |
400 | 448 |
|
401 | 449 |
case PathIterator.SEG_QUADTO: |
... | ... | |
409 | 457 |
break; |
410 | 458 |
|
411 | 459 |
case PathIterator.SEG_CLOSE: |
412 |
// A�adimos el primer punto para cerrar. |
|
413 | 460 |
Coordinate firstCoord = (Coordinate) arrayCoords.get(0); |
414 |
// Solo anyadimos cuando no esta ya cerrado
|
|
415 |
arrayCoords.add(new Coordinate(firstCoord.x, firstCoord.y));
|
|
461 |
arrayCoords.add(new Coordinate(firstCoord.x,
|
|
462 |
firstCoord.y));
|
|
416 | 463 |
|
417 | 464 |
break; |
418 |
} // end switch
|
|
465 |
} //end switch |
|
419 | 466 |
|
420 | 467 |
theIterator.next(); |
421 |
} // end while loop
|
|
468 |
} //end while loop |
|
422 | 469 |
|
423 |
if (arrayCoords.size() < 2) {
|
|
470 |
if (arrayCoords.size()<2) {
|
|
424 | 471 |
break; |
425 | 472 |
} |
426 |
lin = new com.vividsolutions.jts.geom.GeometryFactory() |
|
427 |
.createLineString(CoordinateArrays |
|
428 |
.toCoordinateArray(arrayCoords)); |
|
473 |
lin = new com.vividsolutions.jts.geom.GeometryFactory().createLineString(CoordinateArrays.toCoordinateArray( |
|
474 |
arrayCoords)); |
|
429 | 475 |
|
430 | 476 |
lin.setSRID(srid); |
431 | 477 |
// CAMBIO: ENTREGAMOS SIEMPRE MULTILINESTRING, QUE ES |
432 | 478 |
// LO QUE HACE TODO EL MUNDO CUANDO ESCRIBE EN POSTGIS |
433 | 479 |
// O CON GEOTOOLS |
434 | 480 |
// if (numParts > 1) // Generamos una MultiLineString |
435 |
// { |
|
481 |
// {
|
|
436 | 482 |
arrayLines.add(lin); |
437 |
geoJTS = geomFactory |
|
438 |
.createMultiLineString(com.vividsolutions.jts.geom.GeometryFactory |
|
439 |
.toLineStringArray(arrayLines)); |
|
483 |
geoJTS = geomFactory.createMultiLineString(com.vividsolutions.jts.geom.GeometryFactory.toLineStringArray( |
|
484 |
arrayLines)); |
|
440 | 485 |
geoJTS.setSRID(srid); |
441 |
/* |
|
442 |
* } else { geoJTS = lin; }
|
|
443 |
*/ |
|
486 |
/* } else {
|
|
487 |
geoJTS = lin;
|
|
488 |
} */
|
|
444 | 489 |
|
445 | 490 |
break; |
446 | 491 |
|
... | ... | |
456 | 501 |
theIterator = shp.getPathIterator(null, manager.getFlatness()); |
457 | 502 |
|
458 | 503 |
while (!theIterator.isDone()) { |
459 |
// while not done
|
|
504 |
//while not done |
|
460 | 505 |
theType = theIterator.currentSegment(theData); |
461 | 506 |
|
462 |
// Populate a segment of the new
|
|
507 |
//Populate a segment of the new |
|
463 | 508 |
// GeneralPathX object. |
464 |
// Process the current segment to populate a new
|
|
509 |
//Process the current segment to populate a new |
|
465 | 510 |
// segment of the new GeneralPathX object. |
466 | 511 |
switch (theType) { |
467 | 512 |
case PathIterator.SEG_MOVETO: |
468 |
|
|
469 |
// System.out.println("SEG_MOVETO"); |
|
470 | 513 |
if (arrayCoords == null) { |
471 | 514 |
arrayCoords = new ArrayList(); |
472 | 515 |
} else { |
473 |
points = CoordinateArrays |
|
474 |
.toCoordinateArray(arrayCoords); |
|
516 |
points = CoordinateArrays.toCoordinateArray(arrayCoords); |
|
475 | 517 |
|
476 | 518 |
try { |
477 |
LinearRing ring = geomFactory |
|
478 |
.createLinearRing(points); |
|
519 |
LinearRing ring = geomFactory.createLinearRing(points); |
|
479 | 520 |
|
480 | 521 |
if (CGAlgorithms.isCCW(points)) { |
481 | 522 |
holes.add(ring); |
... | ... | |
483 | 524 |
shells.add(ring); |
484 | 525 |
} |
485 | 526 |
} catch (Exception e) { |
486 |
/* |
|
487 |
* (jaume) caso cuando todos los puntos son iguales |
|
488 |
* devuelvo el propio punto |
|
489 |
*/ |
|
490 | 527 |
boolean same = true; |
491 |
for (int i = 0; i < points.length - 1 && same; i++) { |
|
492 |
if (points[i].x != points[i + 1].x |
|
493 |
|| points[i].y != points[i + 1].y /* |
|
494 |
* || |
|
495 |
* points |
|
496 |
* [i].z |
|
497 |
* != |
|
498 |
* points |
|
499 |
* [ |
|
500 |
* i+1]. |
|
501 |
* z |
|
502 |
*/ |
|
528 |
for (int i = 0; i < points.length-1 && same; i++) { |
|
529 |
if (points[i].x != points[i+1].x || |
|
530 |
points[i].y != points[i+1].y /*|| |
|
531 |
points[i].z != points[i+1].z*/ |
|
503 | 532 |
) { |
504 | 533 |
same = false; |
505 | 534 |
} |
... | ... | |
507 | 536 |
if (same) { |
508 | 537 |
return geomFactory.createPoint(points[0]); |
509 | 538 |
} |
510 |
/* |
|
511 |
* caso cuando es una l�nea de 3 puntos, no creo |
|
512 |
* un LinearRing, sino una linea |
|
513 |
*/ |
|
514 |
if (points.length > 1 && points.length <= 3) { |
|
539 |
if (points.length>1 && points.length<=3) { |
|
515 | 540 |
// return geomFactory.createLineString(points); |
516 |
return geomFactory |
|
517 |
.createMultiLineString(new LineString[] { geomFactory |
|
518 |
.createLineString(points) }); |
|
541 |
return geomFactory.createMultiLineString(new LineString[] {geomFactory.createLineString(points)}); |
|
519 | 542 |
} |
520 | 543 |
|
521 |
System.err |
|
522 |
.println("Caught Topology exception in GMLLinearRingHandler");
|
|
544 |
System.err.println(
|
|
545 |
"Caught Topology exception in GMLLinearRingHandler"); |
|
523 | 546 |
|
524 | 547 |
return null; |
525 | 548 |
} |
526 | 549 |
|
527 |
/* |
|
528 |
* if (numParts == 1) { linRingExt = new |
|
529 |
* GeometryFactory().createLinearRing( |
|
530 |
* CoordinateArrays.toCoordinateArray(arrayCoords)); } |
|
531 |
* else { linRing = new |
|
532 |
* GeometryFactory().createLinearRing( |
|
533 |
* CoordinateArrays.toCoordinateArray(arrayCoords)); |
|
534 |
* arrayLines.add(linRing); } |
|
535 |
*/ |
|
550 |
/* if (numParts == 1) |
|
551 |
{ |
|
552 |
linRingExt = new GeometryFactory().createLinearRing( |
|
553 |
CoordinateArrays.toCoordinateArray(arrayCoords)); |
|
554 |
} |
|
555 |
else |
|
556 |
{ |
|
557 |
linRing = new GeometryFactory().createLinearRing( |
|
558 |
CoordinateArrays.toCoordinateArray(arrayCoords)); |
|
559 |
arrayLines.add(linRing); |
|
560 |
} */ |
|
536 | 561 |
arrayCoords = new ArrayList(); |
537 | 562 |
} |
538 | 563 |
|
539 | 564 |
numParts++; |
540 |
arrayCoords.add(new Coordinate(theData[0], theData[1])); |
|
565 |
arrayCoords.add(new Coordinate(theData[0], |
|
566 |
theData[1])); |
|
541 | 567 |
|
542 | 568 |
break; |
543 | 569 |
|
544 | 570 |
case PathIterator.SEG_LINETO: |
571 |
arrayCoords.add(new Coordinate(theData[0], |
|
572 |
theData[1])); |
|
545 | 573 |
|
546 |
// System.out.println("SEG_LINETO"); |
|
547 |
arrayCoords.add(new Coordinate(theData[0], theData[1])); |
|
548 |
|
|
549 | 574 |
break; |
550 | 575 |
|
551 | 576 |
case PathIterator.SEG_QUADTO: |
... | ... | |
559 | 584 |
break; |
560 | 585 |
|
561 | 586 |
case PathIterator.SEG_CLOSE: |
562 |
|
|
563 |
// A�adimos el primer punto para cerrar. |
|
564 | 587 |
Coordinate firstCoord = (Coordinate) arrayCoords.get(0); |
565 |
arrayCoords.add(new Coordinate(firstCoord.x, firstCoord.y)); |
|
588 |
arrayCoords.add(new Coordinate(firstCoord.x, |
|
589 |
firstCoord.y)); |
|
566 | 590 |
|
567 | 591 |
break; |
568 |
} // end switch
|
|
592 |
} //end switch |
|
569 | 593 |
|
570 |
// System.out.println("theData[0] = " + theData[0] + |
|
571 |
// " theData[1]=" + theData[1]); |
|
594 |
// System.out.println("theData[0] = " + theData[0] + " theData[1]=" + theData[1]); |
|
572 | 595 |
theIterator.next(); |
573 |
} // end while loop
|
|
596 |
} //end while loop |
|
574 | 597 |
|
598 |
|
|
575 | 599 |
Coordinate firstCoord = (Coordinate) arrayCoords.get(0); |
576 | 600 |
Coordinate lastCoord = (Coordinate) arrayCoords.get(arrayCoords |
577 | 601 |
.size() - 1); |
... | ... | |
590 | 614 |
} |
591 | 615 |
ring.setSRID(srid); |
592 | 616 |
} catch (Exception e) { |
593 |
/* |
|
594 |
* (jaume) caso cuando todos los puntos son iguales devuelvo el |
|
595 |
* propio punto |
|
596 |
*/ |
|
597 | 617 |
boolean same = true; |
598 |
for (int i = 0; i < points.length - 1 && same; i++) { |
|
599 |
if (points[i].x != points[i + 1].x |
|
600 |
|| points[i].y != points[i + 1].y /* |
|
601 |
* || points[i].z != |
|
602 |
* points[i+1].z |
|
603 |
*/ |
|
618 |
for (int i = 0; i < points.length-1 && same; i++) { |
|
619 |
if (points[i].x != points[i+1].x || |
|
620 |
points[i].y != points[i+1].y /*|| |
|
621 |
points[i].z != points[i+1].z*/ |
|
604 | 622 |
) { |
605 | 623 |
same = false; |
606 | 624 |
} |
... | ... | |
611 | 629 |
return geoJTS; |
612 | 630 |
} |
613 | 631 |
/* |
614 |
* caso cuando es una l�nea de 3 puntos, no creo un
|
|
615 |
* LinearRing, sino una linea
|
|
632 |
* caso cuando es una linea de 3 puntos, no creo un LinearRing, sino
|
|
633 |
* una linea |
|
616 | 634 |
*/ |
617 |
if (points.length > 1 && points.length <= 3) {
|
|
635 |
if (points.length>1 && points.length<=3) {
|
|
618 | 636 |
// return geomFactory.createLineString(points); |
619 | 637 |
geoJTS = geomFactory |
620 |
.createMultiLineString(new LineString[] { geomFactory
|
|
621 |
.createLineString(points) });
|
|
638 |
.createMultiLineString(new LineString[] { geomFactory |
|
639 |
.createLineString(points) }); |
|
622 | 640 |
geoJTS.setSRID(srid); |
623 | 641 |
return geoJTS; |
624 | 642 |
} |
625 |
System.err |
|
626 |
.println("Caught Topology exception in GMLLinearRingHandler");
|
|
643 |
System.err.println(
|
|
644 |
"Caught Topology exception in GMLLinearRingHandler"); |
|
627 | 645 |
|
628 | 646 |
return null; |
629 | 647 |
} |
630 | 648 |
|
631 |
/* |
|
632 |
* linRing = new GeometryFactory().createLinearRing( |
|
633 |
* CoordinateArrays.toCoordinateArray(arrayCoords)); |
|
634 |
*/ |
|
649 |
/* linRing = new GeometryFactory().createLinearRing( |
|
650 |
CoordinateArrays.toCoordinateArray(arrayCoords)); */ |
|
635 | 651 |
|
636 | 652 |
// System.out.println("NumParts = " + numParts); |
637 |
// now we have a list of all shells and all holes
|
|
653 |
//now we have a list of all shells and all holes |
|
638 | 654 |
ArrayList holesForShells = new ArrayList(shells.size()); |
639 | 655 |
|
640 | 656 |
for (int i = 0; i < shells.size(); i++) { |
641 | 657 |
holesForShells.add(new ArrayList()); |
642 | 658 |
} |
643 | 659 |
|
644 |
// find homes
|
|
660 |
//find homes |
|
645 | 661 |
for (int i = 0; i < holes.size(); i++) { |
646 | 662 |
LinearRing testRing = (LinearRing) holes.get(i); |
647 | 663 |
LinearRing minShell = null; |
... | ... | |
662 | 678 |
boolean isContained = false; |
663 | 679 |
Coordinate[] coordList = tryRing.getCoordinates(); |
664 | 680 |
|
665 |
if (tryEnv.contains(testEnv) |
|
666 |
&& (CGAlgorithms.isPointInRing(testPt, coordList) || (pointInList(
|
|
667 |
testPt, coordList)))) { |
|
681 |
if (tryEnv.contains(testEnv) &&
|
|
682 |
(CGAlgorithms.isPointInRing(testPt, coordList) ||
|
|
683 |
(pointInList(testPt, coordList)))) {
|
|
668 | 684 |
isContained = true; |
669 | 685 |
} |
670 | 686 |
|
671 |
// check if this new containing ring is smaller than the |
|
672 |
// current minimum ring |
|
687 |
// check if this new containing ring is smaller than the current minimum ring |
|
673 | 688 |
if (isContained) { |
674 | 689 |
if ((minShell == null) || minEnv.contains(tryEnv)) { |
675 | 690 |
minShell = tryRing; |
... | ... | |
678 | 693 |
} |
679 | 694 |
|
680 | 695 |
if (minShell == null) { |
681 |
// System.out.println( |
|
682 |
// "polygon found with a hole thats not inside a shell"); |
|
683 |
// azabala: we do the assumption that this hole is really a |
|
684 |
// shell (polygon) |
|
685 |
// whose point werent digitized in the right order |
|
696 |
// System.out.println( |
|
697 |
// polygon found with a hole thats not inside a shell); |
|
698 |
// azabala: we do the assumption that this hole is really a shell (polygon) |
|
699 |
// whose point werent digitized in the right order |
|
686 | 700 |
Coordinate[] cs = testRing.getCoordinates(); |
687 | 701 |
Coordinate[] reversed = new Coordinate[cs.length]; |
688 | 702 |
int pointIndex = 0; |
689 |
for (int z = cs.length - 1; z >= 0; z--) {
|
|
703 |
for(int z = cs.length-1; z >= 0; z--){
|
|
690 | 704 |
reversed[pointIndex] = cs[z]; |
691 | 705 |
pointIndex++; |
692 | 706 |
} |
... | ... | |
694 | 708 |
shells.add(newRing); |
695 | 709 |
holesForShells.add(new ArrayList()); |
696 | 710 |
} else { |
697 |
((ArrayList) holesForShells.get(shells.indexOf(minShell))) |
|
698 |
.add(testRing); |
|
711 |
((ArrayList) holesForShells.get(shells.indexOf(minShell))).add(testRing); |
|
699 | 712 |
} |
700 | 713 |
} |
701 | 714 |
|
702 | 715 |
Polygon[] polygons = new Polygon[shells.size()]; |
703 | 716 |
|
704 | 717 |
for (int i = 0; i < shells.size(); i++) { |
705 |
polygons[i] = geomFactory.createPolygon((LinearRing) shells |
|
706 |
.get(i), (LinearRing[]) ((ArrayList) holesForShells |
|
707 |
.get(i)).toArray(new LinearRing[0])); |
|
718 |
polygons[i] = geomFactory.createPolygon((LinearRing) shells.get( |
|
719 |
i), |
|
720 |
(LinearRing[]) ((ArrayList) holesForShells.get(i)).toArray( |
|
721 |
new LinearRing[0])); |
|
708 | 722 |
polygons[i].setSRID(srid); |
709 | 723 |
} |
710 | 724 |
// CAMBIO: ENTREGAMOS SIEMPRE MULTILINESTRING, QUE ES |
... | ... | |
712 | 726 |
// O CON GEOTOOLS |
713 | 727 |
// if (numParts > 1) // Generamos una MultiLineString |
714 | 728 |
|
715 |
/* |
|
716 |
* if (polygons.length == 1) { return polygons[0]; }
|
|
717 |
*/ |
|
729 |
/* if (polygons.length == 1) {
|
|
730 |
return polygons[0];
|
|
731 |
} */
|
|
718 | 732 |
|
719 | 733 |
// FIN CAMBIO |
720 | 734 |
|
... | ... | |
729 | 743 |
geoJTS = geomFactory.createMultiPolygon(polygons); |
730 | 744 |
} |
731 | 745 |
geoJTS.setSRID(srid); |
746 |
//its a multi part |
|
747 |
//geoJTS = geomFactory.createMultiPolygon(polygons); |
|
748 |
//geoJTS.setSRID(srid); |
|
732 | 749 |
|
733 |
/* |
|
734 |
* if (numParts > 1) // Generamos un Polygon con agujeros { |
|
735 |
* arrayLines.add(linRing); // geoJTS = new |
|
736 |
* GeometryFactory().createPolygon(linRingExt, // |
|
737 |
* GeometryFactory.toLinearRingArray(arrayLines)); geoJTS = new |
|
738 |
* GeometryFactory().buildGeometry(arrayLines); |
|
739 |
* |
|
740 |
* // geoJTS = Polygonizer.class. } else { geoJTS = new |
|
741 |
* GeometryFactory().createPolygon(linRing,null); } |
|
742 |
*/ |
|
743 | 750 |
break; |
751 |
|
|
752 |
case Geometry.TYPES.MULTICURVE: |
|
753 |
geoJTS = multiCurveToJts((MultiCurve)shp, srid); |
|
754 |
geoJTS.setSRID(srid); |
|
755 |
break; |
|
756 |
|
|
757 |
case Geometry.TYPES.MULTIPOINT: |
|
758 |
geoJTS = geometryToJts((MultiPoint)shp); |
|
759 |
geoJTS.setSRID(srid); |
|
760 |
break; |
|
761 |
|
|
762 |
case Geometry.TYPES.MULTISURFACE: |
|
763 |
geoJTS = multiSurfaceToJts((MultiSurface)shp, srid); |
|
764 |
geoJTS.setSRID(srid); |
|
765 |
break; |
|
766 |
|
|
744 | 767 |
} |
745 | 768 |
|
746 | 769 |
geoJTS.setSRID(srid); |
... | ... | |
749 | 772 |
|
750 | 773 |
/** |
751 | 774 |
* Converts JTS Geometry objects into Java 2D Shape objects |
752 |
* |
|
753 |
* @param geo |
|
754 |
* Geometry de JTS. |
|
755 |
* |
|
775 |
* |
|
776 |
* @param geo Geometry de JTS. |
|
777 |
* |
|
756 | 778 |
* @return FShape. |
757 | 779 |
*/ |
758 |
// public static FShape jts_to_java2d(com.vividsolutions.jts.geom.Geometry |
|
759 |
// geo) { |
|
760 |
// FShape shpNew = null; |
|
780 |
// public static FShape jts_to_java2d(com.vividsolutions.jts.geom.Geometry geo) { |
|
781 |
// FShape shpNew = null; |
|
761 | 782 |
// |
762 |
// try { |
|
763 |
// if (geo instanceof Point) { |
|
764 |
// shpNew = new org.gvsig.fmap.geom.primitive.Point2D(null, null, ((Point) |
|
765 |
// geo).getX(), ((Point) geo).getY()); |
|
766 |
// } |
|
783 |
// try { |
|
784 |
// if (geo instanceof Point) { |
|
785 |
// shpNew = new org.gvsig.fmap.geom.primitive.Point2D(null, null, ((Point) geo).getX(), ((Point) geo).getY()); |
|
786 |
// } |
|
767 | 787 |
// |
768 |
// if (geo.isEmpty()) {
|
|
769 |
// shpNew = null;
|
|
770 |
// }
|
|
788 |
// if (geo.isEmpty()) {
|
|
789 |
// shpNew = null;
|
|
790 |
// }
|
|
771 | 791 |
// |
772 |
// if (geo instanceof Polygon) {
|
|
773 |
// shpNew = new Surface2D(null, null, toShape((Polygon) geo));
|
|
774 |
// }
|
|
792 |
// if (geo instanceof Polygon) {
|
|
793 |
// shpNew = new Surface2D(null, null, toShape((Polygon) geo));
|
|
794 |
// }
|
|
775 | 795 |
// |
776 |
// if (geo instanceof MultiPolygon) {
|
|
777 |
// shpNew = new Surface2D(null, null, toShape((MultiPolygon) geo));
|
|
778 |
// }
|
|
796 |
// if (geo instanceof MultiPolygon) {
|
|
797 |
// shpNew = new Surface2D(null, null, toShape((MultiPolygon) geo));
|
|
798 |
// }
|
|
779 | 799 |
// |
780 |
// if (geo instanceof LineString) {
|
|
781 |
// shpNew = new Curve2D(null, null, toShape((LineString) geo));
|
|
782 |
// }
|
|
800 |
// if (geo instanceof LineString) {
|
|
801 |
// shpNew = new Curve2D(null, null, toShape((LineString) geo));
|
|
802 |
// }
|
|
783 | 803 |
// |
784 |
// if (geo instanceof MultiLineString) {
|
|
785 |
// shpNew = new Curve2D(null, null, toShape((MultiLineString) geo));
|
|
786 |
// }
|
|
804 |
// if (geo instanceof MultiLineString) {
|
|
805 |
// shpNew = new Curve2D(null, null, toShape((MultiLineString) geo));
|
|
806 |
// }
|
|
787 | 807 |
// |
788 |
// /* OJO: CON ALGO COMO FSHAPE NO S� C�MO PODEMOS IMPLEMENTAR UN |
|
789 |
// GeometryCollection |
|
790 |
// * No sabremos si queremos una l�nea o un pol�gono..... |
|
791 |
// * if (geometry instanceof GeometryCollection) { |
|
792 |
// return toShape((GeometryCollection) geometry); |
|
793 |
// } */ |
|
794 |
// return shpNew; |
|
795 |
// } catch (NoninvertibleTransformException e) { |
|
796 |
// // TODO Auto-generated catch block |
|
797 |
// e.printStackTrace(); |
|
798 |
// } |
|
808 |
// return shpNew; |
|
809 |
// } catch (NoninvertibleTransformException e) { |
|
810 |
// // TODO Auto-generated catch block |
|
811 |
// e.printStackTrace(); |
|
812 |
// } |
|
799 | 813 |
// |
800 |
// return null;
|
|
801 |
// }
|
|
814 |
// return null;
|
|
815 |
// }
|
|
802 | 816 |
|
803 | 817 |
/** |
804 | 818 |
* DOCUMENT ME! |
805 |
* |
|
806 |
* @param p |
|
807 |
* DOCUMENT ME! |
|
808 |
* |
|
819 |
* |
|
820 |
* @param p DOCUMENT ME! |
|
821 |
* |
|
809 | 822 |
* @return DOCUMENT ME! |
810 | 823 |
*/ |
811 | 824 |
private static GeneralPathX toShape(Polygon p) { |
... | ... | |
841 | 854 |
|
842 | 855 |
/** |
843 | 856 |
* DOCUMENT ME! |
844 |
* |
|
845 |
* @param modelCoordinates |
|
846 |
* DOCUMENT ME! |
|
847 |
* |
|
857 |
* |
|
858 |
* @param modelCoordinates DOCUMENT ME! |
|
859 |
* |
|
848 | 860 |
* @return DOCUMENT ME! |
849 |
* |
|
850 |
* @throws NoninvertibleTransformException |
|
851 |
* DOCUMENT ME! |
|
852 |
* |
|
853 |
* private Coordinate[] toViewCoordinates(Coordinate[] |
|
854 |
* modelCoordinates) throws NoninvertibleTransformException { |
|
855 |
* Coordinate[] viewCoordinates = new |
|
856 |
* Coordinate[modelCoordinates.length]; |
|
857 |
* |
|
858 |
* for (int i = 0; i < modelCoordinates.length; i++) { FPoint2D |
|
859 |
* point2D = coordinate2FPoint2D(modelCoordinates[i]); |
|
860 |
* viewCoordinates[i] = new Coordinate(point2D.getX(), |
|
861 |
* point2D.getY()); } |
|
862 |
* |
|
863 |
* return viewCoordinates; } |
|
864 |
* @throws CreateGeometryException |
|
865 |
*/ |
|
861 |
* |
|
862 |
* @throws NoninvertibleTransformException DOCUMENT ME! |
|
863 |
* |
|
864 |
private Coordinate[] toViewCoordinates(Coordinate[] modelCoordinates) |
|
865 |
throws NoninvertibleTransformException { |
|
866 |
Coordinate[] viewCoordinates = new Coordinate[modelCoordinates.length]; |
|
866 | 867 |
|
867 |
/* |
|
868 |
* private Shape toShape(GeometryCollection gc) throws |
|
869 |
* NoninvertibleTransformException { GeometryCollectionShape shape = new |
|
870 |
* GeometryCollectionShape(); for (int i = 0; i < gc.getNumGeometries(); |
|
871 |
* i++) { Geometry g = (Geometry) gc.getGeometryN(i); shape.add(toShape(g)); |
|
872 |
* } return shape; } |
|
873 |
*/ |
|
868 |
for (int i = 0; i < modelCoordinates.length; i++) { |
|
869 |
FPoint2D point2D = coordinate2FPoint2D(modelCoordinates[i]); |
|
870 |
viewCoordinates[i] = new Coordinate(point2D.getX(), point2D.getY()); |
|
871 |
} |
|
872 |
|
|
873 |
return viewCoordinates; |
|
874 |
} |
|
875 |
* @throws CreateGeometryException */ |
|
876 |
|
|
877 |
/* private Shape toShape(GeometryCollection gc) |
|
878 |
throws NoninvertibleTransformException { |
|
879 |
GeometryCollectionShape shape = new GeometryCollectionShape(); |
|
880 |
for (int i = 0; i < gc.getNumGeometries(); i++) { |
|
881 |
Geometry g = (Geometry) gc.getGeometryN(i); |
|
882 |
shape.add(toShape(g)); |
|
883 |
} |
|
884 |
return shape; |
|
885 |
} */ |
|
874 | 886 |
private static GeneralPathX toShape(MultiLineString mls) |
875 |
throws NoninvertibleTransformException, CreateGeometryException {
|
|
887 |
throws NoninvertibleTransformException, CreateGeometryException { |
|
876 | 888 |
GeneralPathX path = new GeneralPathX(); |
877 | 889 |
|
878 | 890 |
for (int i = 0; i < mls.getNumGeometries(); i++) { |
... | ... | |
880 | 892 |
path.append(toShape(lineString).getPathIterator(null), false); |
881 | 893 |
} |
882 | 894 |
|
883 |
// BasicFeatureRenderer expects LineStrings and MultiLineStrings to be
|
|
884 |
// converted to GeneralPathXs. [Jon Aquino]
|
|
895 |
//BasicFeatureRenderer expects LineStrings and MultiLineStrings to be |
|
896 |
//converted to GeneralPathXs. [Jon Aquino] |
|
885 | 897 |
return path; |
886 | 898 |
} |
887 | 899 |
|
888 | 900 |
/** |
889 | 901 |
* DOCUMENT ME! |
890 |
* |
|
891 |
* @param lineString |
|
892 |
* DOCUMENT ME! |
|
893 |
* |
|
902 |
* |
|
903 |
* @param lineString DOCUMENT ME! |
|
904 |
* |
|
894 | 905 |
* @return DOCUMENT ME! |
895 |
* |
|
896 |
* @throws NoninvertibleTransformException |
|
897 |
* DOCUMENT ME! |
|
898 |
* @throws CreateGeometryException |
|
906 |
* |
|
907 |
* @throws NoninvertibleTransformException DOCUMENT ME! |
|
908 |
* @throws CreateGeometryException |
|
899 | 909 |
*/ |
900 | 910 |
private static GeneralPathX toShape(LineString lineString) |
901 |
throws NoninvertibleTransformException, CreateGeometryException {
|
|
911 |
throws NoninvertibleTransformException, CreateGeometryException { |
|
902 | 912 |
GeneralPathX shape = new GeneralPathX(); |
903 |
org.gvsig.fmap.geom.primitive.Point viewPoint = coordinate2FPoint2D(lineString |
|
904 |
.getCoordinateN(0)); |
|
913 |
org.gvsig.fmap.geom.primitive.Point viewPoint = coordinate2FPoint2D(lineString.getCoordinateN(0)); |
|
905 | 914 |
shape.moveTo(viewPoint.getX(), viewPoint.getY()); |
906 | 915 |
|
907 | 916 |
for (int i = 1; i < lineString.getNumPoints(); i++) { |
... | ... | |
909 | 918 |
shape.lineTo(viewPoint.getX(), viewPoint.getY()); |
910 | 919 |
} |
911 | 920 |
|
912 |
// BasicFeatureRenderer expects LineStrings and MultiLineStrings to be
|
|
913 |
// converted to GeneralPathXs. [Jon Aquino]
|
|
921 |
//BasicFeatureRenderer expects LineStrings and MultiLineStrings to be |
|
922 |
//converted to GeneralPathXs. [Jon Aquino] |
|
914 | 923 |
return shape; |
915 | 924 |
} |
916 | 925 |
|
917 |
/* |
|
918 |
* TODO No se usa DOCUMENT ME! |
|
919 |
* |
|
920 |
* @param point DOCUMENT ME! |
|
921 |
* |
|
922 |
* @return DOCUMENT ME! |
|
923 |
* |
|
924 |
* @throws NoninvertibleTransformException DOCUMENT ME! |
|
925 |
* |
|
926 |
* private static Point2D toShape(Point point) throws |
|
927 |
* NoninvertibleTransformException { Point2D viewPoint = |
|
928 |
* coordinate2FPoint2D(point.getCoordinate()); |
|
929 |
* |
|
930 |
* return viewPoint; } |
|
931 |
*/ |
|
932 | 926 |
|
933 | 927 |
/** |
934 | 928 |
* |
935 | 929 |
*/ |
936 | 930 |
private static GeneralPathX toShape(MultiPolygon mp) |
937 |
throws NoninvertibleTransformException {
|
|
931 |
throws NoninvertibleTransformException { |
|
938 | 932 |
GeneralPathX path = new GeneralPathX(); |
939 | 933 |
|
940 | 934 |
for (int i = 0; i < mp.getNumGeometries(); i++) { |
... | ... | |
942 | 936 |
path.append(toShape(polygon).getPathIterator(null), false); |
943 | 937 |
} |
944 | 938 |
|
945 |
// BasicFeatureRenderer expects LineStrings and MultiLineStrings to be
|
|
946 |
// converted to GeneralPathXs. [Jon Aquino]
|
|
939 |
//BasicFeatureRenderer expects LineStrings and MultiLineStrings to be |
|
940 |
//converted to GeneralPathXs. [Jon Aquino] |
|
947 | 941 |
return path; |
948 | 942 |
} |
949 |
|
|
950 | 943 |
/** |
951 | 944 |
* DOCUMENT ME! |
952 |
* |
|
953 |
* @param coord |
|
954 |
* DOCUMENT ME! |
|
955 |
* |
|
945 |
* |
|
946 |
* @param coord DOCUMENT ME! |
|
947 |
* |
|
956 | 948 |
* @return DOCUMENT ME! |
957 |
* @throws CreateGeometryException |
|
949 |
* @throws CreateGeometryException
|
|
958 | 950 |
*/ |
959 |
public static org.gvsig.fmap.geom.primitive.Point coordinate2FPoint2D( |
|
960 |
Coordinate coord) throws CreateGeometryException { |
|
961 |
return geomManager.createPoint(coord.x, coord.y, SUBTYPES.GEOM2D); // ,coord.z); |
|
951 |
public static org.gvsig.fmap.geom.primitive.Point coordinate2FPoint2D(Coordinate coord) throws CreateGeometryException { |
|
952 |
return geomManager.createPoint(coord.x, coord.y, SUBTYPES.GEOM2D); //,coord.z); |
|
962 | 953 |
} |
963 | 954 |
|
964 | 955 |
/** |
965 | 956 |
* Convierte una Geometry de JTS a GeneralPathX. |
966 |
* |
|
967 |
* @param geometry |
|
968 |
* Geometry a convertir. |
|
969 |
* |
|
957 |
* |
|
958 |
* @param geometry Geometry a convertir. |
|
959 |
* |
|
970 | 960 |
* @return GeneralPathX. |
971 |
*
|
|
961 |
* |
|
972 | 962 |
* @throws NoninvertibleTransformException |
973 |
* @throws CreateGeometryException |
|
963 |
* @throws CreateGeometryException
|
|
974 | 964 |
* @throws IllegalArgumentException |
975 | 965 |
*/ |
976 |
public static GeneralPathX toShape( |
|
977 |
com.vividsolutions.jts.geom.Geometry geometry) |
|
978 |
throws NoninvertibleTransformException, CreateGeometryException { |
|
966 |
public static GeneralPathX toShape(com.vividsolutions.jts.geom.Geometry geometry) |
|
967 |
throws NoninvertibleTransformException, CreateGeometryException { |
|
979 | 968 |
if (geometry.isEmpty()) { |
980 | 969 |
return new GeneralPathX(); |
981 | 970 |
} |
... | ... | |
1000 | 989 |
return toShape(geometry); |
1001 | 990 |
} |
1002 | 991 |
|
1003 |
throw new IllegalArgumentException("Unrecognized Geometry class: " |
|
1004 |
+ geometry.getClass());
|
|
992 |
throw new IllegalArgumentException("Unrecognized Geometry class: " +
|
|
993 |
geometry.getClass()); |
|
1005 | 994 |
} |
1006 | 995 |
|
1007 |
public static GeneralPathX transformToInts(GeneralPathX gp, |
|
1008 |
AffineTransform at) {
|
|
996 |
|
|
997 |
public static GeneralPathX transformToInts(GeneralPathX gp, AffineTransform at) {
|
|
1009 | 998 |
GeneralPathX newGp = new GeneralPathX(); |
1010 | 999 |
PathIterator theIterator; |
1011 | 1000 |
int theType; |
... | ... | |
1016 | 1005 |
boolean bFirst = true; |
1017 | 1006 |
int xInt, yInt, antX = -1, antY = -1; |
1018 | 1007 |
|
1019 |
theIterator = gp.getPathIterator(null); // , flatness);
|
|
1008 |
theIterator = gp.getPathIterator(null); //, flatness); |
|
1020 | 1009 |
|
1021 | 1010 |
while (!theIterator.isDone()) { |
1022 | 1011 |
theType = theIterator.currentSegment(theData); |
... | ... | |
1036 | 1025 |
at.transform(ptSrc, ptDst); |
1037 | 1026 |
xInt = (int) ptDst.getX(); |
1038 | 1027 |
yInt = (int) ptDst.getY(); |
1039 |
if ((bFirst) || ((xInt != antX) || (yInt != antY))) { |
|
1028 |
if ((bFirst) || ((xInt != antX) || (yInt != antY))) |
|
1029 |
{ |
|
1040 | 1030 |
newGp.lineTo(xInt, yInt); |
1041 | 1031 |
antX = xInt; |
1042 | 1032 |
antY = yInt; |
... | ... | |
1058 | 1048 |
newGp.closePath(); |
1059 | 1049 |
|
1060 | 1050 |
break; |
1061 |
} // end switch
|
|
1051 |
} //end switch |
|
1062 | 1052 |
|
1063 | 1053 |
theIterator.next(); |
1064 |
} // end while loop
|
|
1054 |
} //end while loop |
|
1065 | 1055 |
|
1066 | 1056 |
return newGp; |
1067 | 1057 |
} |
1068 |
|
|
1069 |
public static Geometry transformToInts(Geometry gp, AffineTransform at) |
|
1070 |
throws CreateGeometryException { |
|
1058 |
public static Geometry transformToInts(Geometry gp, AffineTransform at) throws CreateGeometryException { |
|
1071 | 1059 |
GeneralPathX newGp = new GeneralPathX(); |
1072 | 1060 |
double[] theData = new double[6]; |
1073 | 1061 |
double[] aux = new double[6]; |
... | ... | |
1082 | 1070 |
boolean bFirst = true; |
1083 | 1071 |
int xInt, yInt, antX = -1, antY = -1; |
1084 | 1072 |
|
1085 |
theIterator = gp.getPathIterator(null); // , flatness); |
|
1073 |
|
|
1074 |
theIterator = gp.getPathIterator(null); //, flatness); |
|
1086 | 1075 |
int numSegmentsAdded = 0; |
1087 | 1076 |
while (!theIterator.isDone()) { |
1088 | 1077 |
theType = theIterator.currentSegment(theData); |
... | ... | |
1104 | 1093 |
at.transform(ptSrc, ptDst); |
1105 | 1094 |
xInt = (int) ptDst.getX(); |
1106 | 1095 |
yInt = (int) ptDst.getY(); |
1107 |
if ((bFirst) || ((xInt != antX) || (yInt != antY))) { |
|
1096 |
if ((bFirst) || ((xInt != antX) || (yInt != antY))) |
|
1097 |
{ |
|
1108 | 1098 |
newGp.lineTo(xInt, yInt); |
1109 | 1099 |
antX = xInt; |
1110 | 1100 |
antY = yInt; |
... | ... | |
1114 | 1104 |
break; |
1115 | 1105 |
|
1116 | 1106 |
case PathIterator.SEG_QUADTO: |
1117 |
at.transform(theData, 0, aux, 0, 2);
|
|
1107 |
at.transform(theData,0,aux,0,2);
|
|
1118 | 1108 |
newGp.quadTo(aux[0], aux[1], aux[2], aux[3]); |
1119 | 1109 |
numSegmentsAdded++; |
1120 | 1110 |
break; |
1121 | 1111 |
|
1122 | 1112 |
case PathIterator.SEG_CUBICTO: |
1123 |
at.transform(theData, 0, aux, 0, 3);
|
|
1113 |
at.transform(theData,0,aux,0,3);
|
|
1124 | 1114 |
newGp.curveTo(aux[0], aux[1], aux[2], aux[3], aux[4], aux[5]); |
1125 | 1115 |
numSegmentsAdded++; |
1126 | 1116 |
break; |
... | ... | |
1132 | 1122 |
newGp.closePath(); |
1133 | 1123 |
|
1134 | 1124 |
break; |
1135 |
} // end switch
|
|
1125 |
} //end switch |
|
1136 | 1126 |
|
1137 | 1127 |
theIterator.next(); |
1138 |
} // end while loop
|
|
1128 |
} //end while loop |
|
1139 | 1129 |
|
1140 | 1130 |
Geometry shp = null; |
1141 |
switch (gp.getType()) { |
|
1131 |
switch (gp.getType()) |
|
1132 |
{ |
|
1142 | 1133 |
case Geometry.TYPES.POINT: |
1143 |
shp = geomManager.createPoint(ptDst.getX(), ptDst.getY(), |
|
1144 |
SUBTYPES.GEOM2D); |
|
1134 |
shp = geomManager.createPoint(ptDst.getX(), ptDst.getY(), SUBTYPES.GEOM2D); |
|
1145 | 1135 |
break; |
1146 | 1136 |
|
1147 | 1137 |
case Geometry.TYPES.CURVE: |
... | ... | |
1173 | 1163 |
return r; |
1174 | 1164 |
} |
1175 | 1165 |
|
1176 |
public static Envelope convertEnvelopeToJTS( |
|
1177 |
org.gvsig.fmap.geom.primitive.Envelope r) { |
|
1178 |
Envelope e = new Envelope(r.getMinimum(0), r.getMaximum(0), |
|
1179 |
r.getMinimum(1), r.getMaximum(1)); |
|
1166 |
public static Envelope convertEnvelopeToJTS(org.gvsig.fmap.geom.primitive.Envelope r) { |
|
1167 |
Envelope e = new Envelope(r.getMinimum(0), r.getMaximum(0), r.getMinimum(1), |
|
1168 |
r.getMaximum(1)); |
|
1180 | 1169 |
return e; |
1181 | 1170 |
} |
1182 | 1171 |
|
1183 | 1172 |
/** |
1184 | 1173 |
* Return a correct polygon (no hole) |
1185 |
* |
|
1186 | 1174 |
* @param coordinates |
1187 | 1175 |
* @return |
1188 | 1176 |
*/ |
... | ... | |
1190 | 1178 |
// isCCW = true => it's a hole |
1191 | 1179 |
Coordinate[] vs = new Coordinate[coordinates.length]; |
1192 | 1180 |
if (CGAlgorithms.isCCW(coordinates)) { |
1193 |
for (int i = vs.length - 1; i >= 0; i--) {
|
|
1181 |
for (int i = vs.length-1;i >= 0; i--){
|
|
1194 | 1182 |
vs[i] = coordinates[i]; |
1195 | 1183 |
} |
1196 | 1184 |
} else { |
... | ... | |
1199 | 1187 |
LinearRing ring = geomFactory.createLinearRing(vs); |
1200 | 1188 |
|
1201 | 1189 |
try { |
1202 |
Surface surface = (Surface) manager.create(TYPES.SURFACE, |
|
1203 |
SUBTYPES.GEOM2D); |
|
1190 |
Surface surface = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM2D); |
|
1204 | 1191 |
surface.setGeneralPath(toShape(ring)); |
1205 | 1192 |
return surface; |
1206 | 1193 |
} catch (NoninvertibleTransformException e) { |
... | ... | |
1214 | 1201 |
public static boolean isCCW(Point[] points) { |
1215 | 1202 |
int length = points.length; |
1216 | 1203 |
Coordinate[] vs; |
1217 |
// CGAlgorithms.isCCW asume que la lista de puntos tienen el primer |
|
1218 |
// y el ultimo puntos iguales.... y que este algoritmo est? solo |
|
1219 |
// garantizado con anillos v?lidos. |
|
1220 |
if (points[0].getX() != points[length - 1].getX() |
|
1221 |
|| points[0].getY() != points[length - 1].getY()) { |
|
1222 |
vs = new Coordinate[length + 1]; |
|
1223 |
vs[points.length] = new Coordinate(points[0].getX(), |
|
1224 |
points[0].getY()); |
|
1204 |
|
|
1205 |
if (points[0].getX() != points[length-1].getX() || points[0].getY() != points[length-1].getY()) { |
|
1206 |
vs=new Coordinate[length+1]; |
|
1207 |
vs[points.length] = new Coordinate(points[0].getX(), points[0].getY()); |
|
1225 | 1208 |
} else { |
1226 |
vs = new Coordinate[length];
|
|
1209 |
vs=new Coordinate[length];
|
|
1227 | 1210 |
} |
1228 | 1211 |
for (int i = 0; i < length; i++) { |
1229 | 1212 |
vs[i] = new Coordinate(points[i].getX(), points[i].getY()); |
... | ... | |
1233 | 1216 |
} |
1234 | 1217 |
|
1235 | 1218 |
public static boolean isCCW(Surface pol) { |
1236 |
com.vividsolutions.jts.geom.Geometry jtsGeom = Converter |
|
1237 |
.geometryToJts(pol); |
|
1219 |
com.vividsolutions.jts.geom.Geometry jtsGeom = Converter.geometryToJts(pol); |
|
1238 | 1220 |
if (jtsGeom.getNumGeometries() == 1) { |
1239 | 1221 |
Coordinate[] coords = jtsGeom.getCoordinates(); |
1240 | 1222 |
return CGAlgorithms.isCCW(coords); |
1241 | 1223 |
} |
1242 | 1224 |
return false; |
1243 |
|
|
1244 | 1225 |
} |
1245 | 1226 |
|
1246 | 1227 |
/** |
1247 | 1228 |
* Return a hole (CCW ordered points) |
1248 |
* |
|
1249 | 1229 |
* @param coordinates |
1250 | 1230 |
* @return |
1251 | 1231 |
*/ |
1252 | 1232 |
public static Geometry getHole(Coordinate[] coordinates) { |
1253 |
// isCCW = true => it's a hole |
|
1254 | 1233 |
Coordinate[] vs = new Coordinate[coordinates.length]; |
1255 | 1234 |
if (CGAlgorithms.isCCW(coordinates)) { |
1256 |
vs = coordinates;
|
|
1235 |
vs=coordinates;
|
|
1257 | 1236 |
|
1258 |
} else {
|
|
1259 |
for (int i = vs.length - 1; i >= 0; i--) {
|
|
1237 |
}else{
|
|
1238 |
for (int i = vs.length-1; i >= 0; i--) {
|
|
1260 | 1239 |
vs[i] = coordinates[i]; |
1261 | 1240 |
} |
1262 | 1241 |
} |
1263 | 1242 |
LinearRing ring = geomFactory.createLinearRing(vs); |
1264 | 1243 |
|
1265 | 1244 |
try { |
1266 |
Surface surface = (Surface) manager.create(TYPES.SURFACE, |
|
1267 |
SUBTYPES.GEOM2D); |
|
1245 |
Surface surface = (Surface)manager.create(TYPES.SURFACE, SUBTYPES.GEOM2D); |
|
1268 | 1246 |
surface.setGeneralPath(toShape(ring)); |
1269 | 1247 |
return surface; |
1270 | 1248 |
} catch (NoninvertibleTransformException e) { |
... | ... | |
1279 | 1257 |
Area area = new Area(gp); |
1280 | 1258 |
area.isSingular(); |
1281 | 1259 |
return area; |
1282 |
|
|
1283 | 1260 |
} |
1284 |
|
|
1261 |
|
|
1285 | 1262 |
/** |
1286 | 1263 |
* Use it ONLY for NOT multipart polygons. |
1287 |
* |
|
1288 | 1264 |
* @param pol |
1289 | 1265 |
* @return |
1290 | 1266 |
*/ |
... | ... | |
1295 | 1271 |
int theType; |
1296 | 1272 |
int numParts = 0; |
1297 | 1273 |
|
1298 |
// Use this array to store segment coordinate data
|
|
1274 |
// Use this array to store segment coordinate data
|
|
1299 | 1275 |
double[] theData = new double[6]; |
1300 | 1276 |
PathIterator theIterator; |
1301 | 1277 |
|
... | ... | |
1306 | 1282 |
theIterator = pol.getPathIterator(null, manager.getFlatness()); |
1307 | 1283 |
|
1308 | 1284 |
while (!theIterator.isDone()) { |
1309 |
// while not done
|
|
1285 |
//while not done |
|
1310 | 1286 |
theType = theIterator.currentSegment(theData); |
1311 | 1287 |
|
1312 |
// Populate a segment of the new
|
|
1288 |
//Populate a segment of the new |
|
1313 | 1289 |
// GeneralPathX object. |
1314 |
// Process the current segment to populate a new
|
|
1290 |
//Process the current segment to populate a new |
|
1315 | 1291 |
// segment of the new GeneralPathX object. |
1316 | 1292 |
switch (theType) { |
1317 | 1293 |
case PathIterator.SEG_MOVETO: |
... | ... | |
1331 | 1307 |
shells.add(ring); |
1332 | 1308 |
} |
1333 | 1309 |
} catch (Exception e) { |
1334 |
System.err |
|
1335 |
.println("Caught Topology exception in GMLLinearRingHandler");
|
|
1310 |
System.err.println(
|
|
1311 |
"Caught Topology exception in GMLLinearRingHandler"); |
|
1336 | 1312 |
|
1337 | 1313 |
return null; |
1338 | 1314 |
} |
1315 |
arrayCoords = new ArrayList(); |
|
1316 |
} |
|
1339 | 1317 |
|
1340 |
/* |
|
1341 |
* if (numParts == 1) { linRingExt = new |
|
1342 |
* GeometryFactory().createLinearRing( |
|
1343 |
* CoordinateArrays.toCoordinateArray(arrayCoords)); } else |
|
1344 |
* { linRing = new GeometryFactory().createLinearRing( |
|
1345 |
* CoordinateArrays.toCoordinateArray(arrayCoords)); |
|
1346 |
* arrayLines.add(linRing); } |
|
1347 |
*/ |
|
1318 |
numParts++; |
|
1319 |
arrayCoords.add(new Coordinate(theData[0], |
|
1320 |
theData[1])); |
|
1321 |
|
|
1322 |
break; |
|
1323 |
|
|
1324 |
case PathIterator.SEG_LINETO: |
|
1325 |
arrayCoords.add(new Coordinate(theData[0], |
|
1326 |
theData[1])); |
|
1327 |
break; |
|
1328 |
case PathIterator.SEG_QUADTO: |
|
1329 |
System.out.println("SEG_QUADTO Not supported here"); |
|
1330 |
break; |
|
1331 |
case PathIterator.SEG_CUBICTO: |
|
1332 |
System.out.println("SEG_CUBICTO Not supported here"); |
|
1333 |
break; |
|
1334 |
case PathIterator.SEG_CLOSE: |
|
1335 |
Coordinate firstCoord = (Coordinate) arrayCoords.get(0); |
|
1336 |
arrayCoords.add(new Coordinate(firstCoord.x, |
|
1337 |
firstCoord.y)); |
|
1338 |
break; |
|
1339 |
} //end switch |
|
1340 |
|
|
1341 |
// System.out.println("theData[0] = " + theData[0] + " theData[1]=" + theData[1]); |
|
1342 |
theIterator.next(); |
|
1343 |
} //end while loop |
|
1344 |
|
|
1345 |
arrayCoords.add(arrayCoords.get(0)); |
|
1346 |
coords = CoordinateArrays.toCoordinateArray(arrayCoords); |
|
1347 |
|
|
1348 |
if (numParts == 1) { |
|
1349 |
return getExteriorPolygon(coords); |
|
1350 |
} |
|
1351 |
return pol; |
|
1352 |
} |
|
1353 |
|
|
1354 |
/** |
|
1355 |
* Metodo creado para construir un MultiSurface formado por varias surface |
|
1356 |
* |
|
1357 |
* @author Leticia Riestra |
|
1358 |
* @param geom |
|
1359 |
* @return |
|
1360 |
*/ |
|
1361 |
public static com.vividsolutions.jts.geom.Geometry multiSurfaceToJts(MultiSurface geom, int srid) { |
|
1362 |
Polygon[] polygons = new Polygon[geom.getPrimitivesNumber()]; |
|
1363 |
for (int i = 0; i < polygons.length; i++){ |
|
1364 |
MultiPolygon polygon = (MultiPolygon)surfaceToJts((geom.getPrimitiveAt(i)), srid); |
|
1365 |
|
Also available in: Unified diff