root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / v02 / FConverter.java @ 2183
History | View | Annotate | Download (18.6 KB)
1 |
/*
|
---|---|
2 |
* Created on 08-jun-2004
|
3 |
*
|
4 |
* TODO To change the template for this generated file go to
|
5 |
* Window - Preferences - Java - Code Generation - Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package com.iver.cit.gvsig.fmap.core.v02; |
48 |
|
49 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
50 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
51 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
52 |
import com.iver.cit.gvsig.fmap.core.FShape; |
53 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
54 |
|
55 |
import com.vividsolutions.jts.algorithm.CGAlgorithms; |
56 |
import com.vividsolutions.jts.algorithm.RobustCGAlgorithms; |
57 |
import com.vividsolutions.jts.geom.Coordinate; |
58 |
import com.vividsolutions.jts.geom.CoordinateArrays; |
59 |
import com.vividsolutions.jts.geom.Envelope; |
60 |
import com.vividsolutions.jts.geom.Geometry; |
61 |
import com.vividsolutions.jts.geom.GeometryCollection; |
62 |
import com.vividsolutions.jts.geom.GeometryFactory; |
63 |
import com.vividsolutions.jts.geom.LineString; |
64 |
import com.vividsolutions.jts.geom.LinearRing; |
65 |
import com.vividsolutions.jts.geom.MultiLineString; |
66 |
import com.vividsolutions.jts.geom.MultiPolygon; |
67 |
import com.vividsolutions.jts.geom.Point; |
68 |
import com.vividsolutions.jts.geom.Polygon; |
69 |
|
70 |
import java.awt.geom.AffineTransform; |
71 |
import java.awt.geom.NoninvertibleTransformException; |
72 |
import java.awt.geom.PathIterator; |
73 |
import java.awt.geom.Point2D; |
74 |
|
75 |
import java.lang.reflect.Array; |
76 |
|
77 |
import java.util.ArrayList; |
78 |
|
79 |
|
80 |
/**
|
81 |
* Clase con varios m?todos est?ticos utilizados para pasar de java2d a jts y
|
82 |
* viceversa.
|
83 |
*
|
84 |
* @author fjp
|
85 |
*/
|
86 |
public class FConverter { |
87 |
/**
|
88 |
* ?QU? PODEMOS HACER CON LOS MULTIPOINT??? => DEBER?AMOS TRABAJAR CON UN
|
89 |
* ARRAY DE PUNTOS EN FShape.....Pensarlo bien.
|
90 |
*/
|
91 |
private final static GeometryFactory geomFactory = new GeometryFactory(); |
92 |
protected static CGAlgorithms cga = new RobustCGAlgorithms(); |
93 |
private final static AffineTransform at = new AffineTransform(); |
94 |
private static double POINT_MARKER_SIZE = 3.0; |
95 |
private static PointConverter pointConverter = new PointConverter() { |
96 |
/* (non-Javadoc)
|
97 |
* @see com.iver.cit.opensig.fmap.FConverter.PointConverter#toViewPoint(com.vividsolutions.jts.geom.Coordinate)
|
98 |
*/
|
99 |
public Point2D toViewPoint(Coordinate modelCoordinate) |
100 |
throws NoninvertibleTransformException { |
101 |
// TODO Auto-generated method stub
|
102 |
return null; |
103 |
} |
104 |
}; |
105 |
|
106 |
//returns true if testPoint is a point in the pointList list.
|
107 |
static boolean pointInList(Coordinate testPoint, Coordinate[] pointList) { |
108 |
int t;
|
109 |
int numpoints;
|
110 |
Coordinate p; |
111 |
|
112 |
numpoints = Array.getLength(pointList);
|
113 |
|
114 |
for (t = 0; t < numpoints; t++) { |
115 |
p = pointList[t]; |
116 |
|
117 |
if ((testPoint.x == p.x) && (testPoint.y == p.y) &&
|
118 |
((testPoint.z == p.z) || (!(testPoint.z == testPoint.z))) //nan test; x!=x iff x is nan
|
119 |
) { |
120 |
return true; |
121 |
} |
122 |
} |
123 |
|
124 |
return false; |
125 |
} |
126 |
|
127 |
/**
|
128 |
* Convierte un FShape a una Geometry del JTS. Para ello, utilizamos un
|
129 |
* "flattened PathIterator". El flattened indica que las curvas las pasa a
|
130 |
* segmentos de l?nea recta AUTOMATICAMENTE!!!.
|
131 |
*
|
132 |
* @param shp FShape que se quiere convertir.
|
133 |
*
|
134 |
* @return Geometry de JTS.
|
135 |
*/
|
136 |
public static Geometry java2d_to_jts(FShape shp) { |
137 |
double flatness = 0.8; // Por ejemplo. Cuanto m?s peque?o, m?s segmentos necesitar? la curva |
138 |
|
139 |
// Es la m?xima distancia que permitimos que el trazo aproximado
|
140 |
// difiera del trazo real.
|
141 |
Geometry geoJTS = null;
|
142 |
Coordinate coord; |
143 |
Coordinate[] coords;
|
144 |
ArrayList arrayCoords = null; |
145 |
ArrayList arrayLines;
|
146 |
LineString lin; |
147 |
LinearRing linRing; |
148 |
LinearRing linRingExt = null;
|
149 |
int theType;
|
150 |
int numParts = 0; |
151 |
|
152 |
// Use this array to store segment coordinate data
|
153 |
double[] theData = new double[6]; |
154 |
PathIterator theIterator;
|
155 |
|
156 |
switch (shp.getShapeType()) {
|
157 |
case FShape.POINT:
|
158 |
|
159 |
FPoint2D p = (FPoint2D) shp; |
160 |
coord = new Coordinate(p.getX(), p.getY());
|
161 |
geoJTS = new GeometryFactory().createPoint(coord);
|
162 |
|
163 |
break;
|
164 |
|
165 |
case FShape.LINE:
|
166 |
arrayLines = new ArrayList(); |
167 |
theIterator = shp.getPathIterator(null); //, flatness); |
168 |
|
169 |
while (!theIterator.isDone()) {
|
170 |
//while not done
|
171 |
theType = theIterator.currentSegment(theData); |
172 |
|
173 |
//Populate a segment of the new
|
174 |
// GeneralPathX object.
|
175 |
//Process the current segment to populate a new
|
176 |
// segment of the new GeneralPathX object.
|
177 |
switch (theType) {
|
178 |
case PathIterator.SEG_MOVETO: |
179 |
|
180 |
// System.out.println("SEG_MOVETO");
|
181 |
if (arrayCoords == null) { |
182 |
arrayCoords = new ArrayList(); |
183 |
} else {
|
184 |
lin = new GeometryFactory().createLineString(CoordinateArrays.toCoordinateArray(
|
185 |
arrayCoords)); |
186 |
arrayLines.add(lin); |
187 |
arrayCoords = new ArrayList(); |
188 |
} |
189 |
|
190 |
numParts++; |
191 |
arrayCoords.add(new Coordinate(theData[0], |
192 |
theData[1]));
|
193 |
|
194 |
break;
|
195 |
|
196 |
case PathIterator.SEG_LINETO: |
197 |
|
198 |
// System.out.println("SEG_LINETO");
|
199 |
arrayCoords.add(new Coordinate(theData[0], |
200 |
theData[1]));
|
201 |
|
202 |
break;
|
203 |
|
204 |
case PathIterator.SEG_QUADTO: |
205 |
System.out.println("Not supported here"); |
206 |
|
207 |
break;
|
208 |
|
209 |
case PathIterator.SEG_CUBICTO: |
210 |
System.out.println("Not supported here"); |
211 |
|
212 |
break;
|
213 |
|
214 |
case PathIterator.SEG_CLOSE: |
215 |
System.out.println("SEG_CLOSE"); |
216 |
|
217 |
// A?adimos el primer punto para cerrar.
|
218 |
Coordinate firstCoord = (Coordinate) arrayCoords.get(0);
|
219 |
arrayCoords.add(new Coordinate(firstCoord.x,
|
220 |
firstCoord.y)); |
221 |
|
222 |
break;
|
223 |
} //end switch
|
224 |
|
225 |
theIterator.next(); |
226 |
} //end while loop
|
227 |
|
228 |
lin = new GeometryFactory().createLineString(CoordinateArrays.toCoordinateArray(
|
229 |
arrayCoords)); |
230 |
|
231 |
if (numParts > 1) // Generamos una MultiLineString |
232 |
{ |
233 |
arrayLines.add(lin); |
234 |
geoJTS = new GeometryFactory().createMultiLineString(GeometryFactory.toLineStringArray(
|
235 |
arrayLines)); |
236 |
} else {
|
237 |
geoJTS = lin; |
238 |
} |
239 |
|
240 |
break;
|
241 |
|
242 |
case FShape.POLYGON:
|
243 |
arrayLines = new ArrayList(); |
244 |
|
245 |
ArrayList shells = new ArrayList(); |
246 |
ArrayList holes = new ArrayList(); |
247 |
Coordinate[] points = null; |
248 |
|
249 |
theIterator = shp.getPathIterator(at, flatness); |
250 |
|
251 |
while (!theIterator.isDone()) {
|
252 |
//while not done
|
253 |
theType = theIterator.currentSegment(theData); |
254 |
|
255 |
//Populate a segment of the new
|
256 |
// GeneralPathX object.
|
257 |
//Process the current segment to populate a new
|
258 |
// segment of the new GeneralPathX object.
|
259 |
switch (theType) {
|
260 |
case PathIterator.SEG_MOVETO: |
261 |
|
262 |
// System.out.println("SEG_MOVETO");
|
263 |
if (arrayCoords == null) { |
264 |
arrayCoords = new ArrayList(); |
265 |
} else {
|
266 |
points = CoordinateArrays.toCoordinateArray(arrayCoords); |
267 |
|
268 |
try {
|
269 |
LinearRing ring = geomFactory.createLinearRing(points); |
270 |
|
271 |
if (CGAlgorithms.isCCW(points)) {
|
272 |
holes.add(ring); |
273 |
} else {
|
274 |
shells.add(ring); |
275 |
} |
276 |
} catch (Exception e) { |
277 |
System.err.println(
|
278 |
"Caught Topology exception in GMLLinearRingHandler");
|
279 |
|
280 |
return null; |
281 |
} |
282 |
|
283 |
/* if (numParts == 1)
|
284 |
{
|
285 |
linRingExt = new GeometryFactory().createLinearRing(
|
286 |
CoordinateArrays.toCoordinateArray(arrayCoords));
|
287 |
}
|
288 |
else
|
289 |
{
|
290 |
linRing = new GeometryFactory().createLinearRing(
|
291 |
CoordinateArrays.toCoordinateArray(arrayCoords));
|
292 |
arrayLines.add(linRing);
|
293 |
} */
|
294 |
arrayCoords = new ArrayList(); |
295 |
} |
296 |
|
297 |
numParts++; |
298 |
arrayCoords.add(new Coordinate(theData[0], |
299 |
theData[1]));
|
300 |
|
301 |
break;
|
302 |
|
303 |
case PathIterator.SEG_LINETO: |
304 |
|
305 |
// System.out.println("SEG_LINETO");
|
306 |
arrayCoords.add(new Coordinate(theData[0], |
307 |
theData[1]));
|
308 |
|
309 |
break;
|
310 |
|
311 |
case PathIterator.SEG_QUADTO: |
312 |
System.out.println("SEG_QUADTO Not supported here"); |
313 |
|
314 |
break;
|
315 |
|
316 |
case PathIterator.SEG_CUBICTO: |
317 |
System.out.println("SEG_CUBICTO Not supported here"); |
318 |
|
319 |
break;
|
320 |
|
321 |
case PathIterator.SEG_CLOSE: |
322 |
|
323 |
// A?adimos el primer punto para cerrar.
|
324 |
Coordinate firstCoord = (Coordinate) arrayCoords.get(0);
|
325 |
arrayCoords.add(new Coordinate(firstCoord.x,
|
326 |
firstCoord.y)); |
327 |
|
328 |
break;
|
329 |
} //end switch
|
330 |
|
331 |
// System.out.println("theData[0] = " + theData[0] + " theData[1]=" + theData[1]);
|
332 |
theIterator.next(); |
333 |
} //end while loop
|
334 |
|
335 |
// arrayCoords.add(arrayCoords.get(0));
|
336 |
points = CoordinateArrays.toCoordinateArray(arrayCoords); |
337 |
|
338 |
try {
|
339 |
LinearRing ring = geomFactory.createLinearRing(points); |
340 |
|
341 |
if (CGAlgorithms.isCCW(points)) {
|
342 |
holes.add(ring); |
343 |
} else {
|
344 |
shells.add(ring); |
345 |
} |
346 |
} catch (Exception e) { |
347 |
System.err.println(
|
348 |
"Caught Topology exception in GMLLinearRingHandler");
|
349 |
|
350 |
return null; |
351 |
} |
352 |
|
353 |
/* linRing = new GeometryFactory().createLinearRing(
|
354 |
CoordinateArrays.toCoordinateArray(arrayCoords)); */
|
355 |
|
356 |
// System.out.println("NumParts = " + numParts);
|
357 |
//now we have a list of all shells and all holes
|
358 |
ArrayList holesForShells = new ArrayList(shells.size()); |
359 |
|
360 |
for (int i = 0; i < shells.size(); i++) { |
361 |
holesForShells.add(new ArrayList()); |
362 |
} |
363 |
|
364 |
//find homes
|
365 |
for (int i = 0; i < holes.size(); i++) { |
366 |
LinearRing testRing = (LinearRing) holes.get(i); |
367 |
LinearRing minShell = null;
|
368 |
Envelope minEnv = null;
|
369 |
Envelope testEnv = testRing.getEnvelopeInternal(); |
370 |
Coordinate testPt = testRing.getCoordinateN(0);
|
371 |
LinearRing tryRing; |
372 |
|
373 |
for (int j = 0; j < shells.size(); j++) { |
374 |
tryRing = (LinearRing) shells.get(j); |
375 |
|
376 |
Envelope tryEnv = tryRing.getEnvelopeInternal(); |
377 |
|
378 |
if (minShell != null) { |
379 |
minEnv = minShell.getEnvelopeInternal(); |
380 |
} |
381 |
|
382 |
boolean isContained = false; |
383 |
Coordinate[] coordList = tryRing.getCoordinates();
|
384 |
|
385 |
if (tryEnv.contains(testEnv) &&
|
386 |
(CGAlgorithms.isPointInRing(testPt, coordList) || |
387 |
(pointInList(testPt, coordList)))) { |
388 |
isContained = true;
|
389 |
} |
390 |
|
391 |
// check if this new containing ring is smaller than the current minimum ring
|
392 |
if (isContained) {
|
393 |
if ((minShell == null) || minEnv.contains(tryEnv)) { |
394 |
minShell = tryRing; |
395 |
} |
396 |
} |
397 |
} |
398 |
|
399 |
if (minShell == null) { |
400 |
System.out.println(
|
401 |
"polygon found with a hole thats not inside a shell");
|
402 |
} else {
|
403 |
((ArrayList) holesForShells.get(shells.indexOf(minShell))).add(testRing);
|
404 |
} |
405 |
} |
406 |
|
407 |
Polygon[] polygons = new Polygon[shells.size()]; |
408 |
|
409 |
for (int i = 0; i < shells.size(); i++) { |
410 |
polygons[i] = geomFactory.createPolygon((LinearRing) shells.get( |
411 |
i), |
412 |
(LinearRing[]) ((ArrayList) holesForShells.get(i)).toArray( |
413 |
new LinearRing[0])); |
414 |
} |
415 |
|
416 |
if (polygons.length == 1) { |
417 |
return polygons[0]; |
418 |
} |
419 |
|
420 |
holesForShells = null;
|
421 |
shells = null;
|
422 |
holes = null;
|
423 |
|
424 |
//its a multi part
|
425 |
geoJTS = geomFactory.createMultiPolygon(polygons); |
426 |
|
427 |
/* if (numParts > 1) // Generamos un Polygon con agujeros
|
428 |
{
|
429 |
arrayLines.add(linRing);
|
430 |
// geoJTS = new GeometryFactory().createPolygon(linRingExt,
|
431 |
// GeometryFactory.toLinearRingArray(arrayLines));
|
432 |
geoJTS = new GeometryFactory().buildGeometry(arrayLines);
|
433 |
|
434 |
// geoJTS = Polygonizer.class.
|
435 |
}
|
436 |
else
|
437 |
{
|
438 |
geoJTS = new GeometryFactory().createPolygon(linRing,null);
|
439 |
} */
|
440 |
break;
|
441 |
} |
442 |
|
443 |
return geoJTS;
|
444 |
} |
445 |
|
446 |
/**
|
447 |
* Converts JTS Geometry objects into Java 2D Shape objects
|
448 |
*
|
449 |
* @param geo Geometry de JTS.
|
450 |
*
|
451 |
* @return FShape.
|
452 |
*/
|
453 |
public static FShape jts_to_java2d(Geometry geo) { |
454 |
FShape shpNew = null;
|
455 |
|
456 |
try {
|
457 |
if (geo instanceof Point) { |
458 |
shpNew = new FPoint2D(((Point) geo).getX(), ((Point) geo).getY()); |
459 |
} |
460 |
|
461 |
if (geo.isEmpty()) {
|
462 |
shpNew = null;
|
463 |
} |
464 |
|
465 |
if (geo instanceof Polygon) { |
466 |
shpNew = new FPolygon2D(toShape((Polygon) geo)); |
467 |
} |
468 |
|
469 |
if (geo instanceof MultiPolygon) { |
470 |
shpNew = new FPolygon2D(toShape((MultiPolygon) geo));
|
471 |
} |
472 |
|
473 |
if (geo instanceof LineString) { |
474 |
shpNew = new FPolyline2D(toShape((LineString) geo));
|
475 |
} |
476 |
|
477 |
if (geo instanceof MultiLineString) { |
478 |
shpNew = new FPolyline2D(toShape((MultiLineString) geo));
|
479 |
} |
480 |
|
481 |
/* OJO: CON ALGO COMO FSHAPE NO S? C?MO PODEMOS IMPLEMENTAR UN GeometryCollection
|
482 |
* No sabremos si queremos una l?nea o un pol?gono.....
|
483 |
* if (geometry instanceof GeometryCollection) {
|
484 |
return toShape((GeometryCollection) geometry);
|
485 |
} */
|
486 |
return shpNew;
|
487 |
} catch (NoninvertibleTransformException e) { |
488 |
// TODO Auto-generated catch block
|
489 |
e.printStackTrace(); |
490 |
} |
491 |
|
492 |
return null; |
493 |
} |
494 |
|
495 |
/**
|
496 |
* DOCUMENT ME!
|
497 |
*
|
498 |
* @param p DOCUMENT ME!
|
499 |
*
|
500 |
* @return DOCUMENT ME!
|
501 |
*/
|
502 |
private static GeneralPathX toShape(Polygon p) { |
503 |
GeneralPathX resul = new GeneralPathX();
|
504 |
Coordinate coord; |
505 |
|
506 |
for (int i = 0; i < p.getExteriorRing().getNumPoints(); i++) { |
507 |
coord = p.getExteriorRing().getCoordinateN(i); |
508 |
|
509 |
if (i == 0) { |
510 |
resul.moveTo((float) coord.x, (float) coord.y); |
511 |
} else {
|
512 |
resul.lineTo((float) coord.x, (float) coord.y); |
513 |
} |
514 |
} |
515 |
|
516 |
for (int j = 0; j < p.getNumInteriorRing(); j++) { |
517 |
LineString hole = p.getInteriorRingN(j); |
518 |
|
519 |
for (int k = 0; k < hole.getNumPoints(); k++) { |
520 |
coord = hole.getCoordinateN(k); |
521 |
|
522 |
if (k == 0) { |
523 |
resul.moveTo((float) coord.x, (float) coord.y); |
524 |
} else {
|
525 |
resul.lineTo((float) coord.x, (float) coord.y); |
526 |
} |
527 |
} |
528 |
} |
529 |
|
530 |
return resul;
|
531 |
} |
532 |
|
533 |
/**
|
534 |
* DOCUMENT ME!
|
535 |
*
|
536 |
* @param modelCoordinates DOCUMENT ME!
|
537 |
*
|
538 |
* @return DOCUMENT ME!
|
539 |
*
|
540 |
* @throws NoninvertibleTransformException DOCUMENT ME!
|
541 |
*/
|
542 |
private Coordinate[] toViewCoordinates(Coordinate[] modelCoordinates) |
543 |
throws NoninvertibleTransformException { |
544 |
Coordinate[] viewCoordinates = new Coordinate[modelCoordinates.length]; |
545 |
|
546 |
for (int i = 0; i < modelCoordinates.length; i++) { |
547 |
FPoint2D point2D = toViewPoint(modelCoordinates[i]); |
548 |
viewCoordinates[i] = new Coordinate(point2D.getX(), point2D.getY());
|
549 |
} |
550 |
|
551 |
return viewCoordinates;
|
552 |
} |
553 |
|
554 |
/* private Shape toShape(GeometryCollection gc)
|
555 |
throws NoninvertibleTransformException {
|
556 |
GeometryCollectionShape shape = new GeometryCollectionShape();
|
557 |
for (int i = 0; i < gc.getNumGeometries(); i++) {
|
558 |
Geometry g = (Geometry) gc.getGeometryN(i);
|
559 |
shape.add(toShape(g));
|
560 |
}
|
561 |
return shape;
|
562 |
} */
|
563 |
private static GeneralPathX toShape(MultiLineString mls) |
564 |
throws NoninvertibleTransformException { |
565 |
GeneralPathX path = new GeneralPathX();
|
566 |
|
567 |
for (int i = 0; i < mls.getNumGeometries(); i++) { |
568 |
LineString lineString = (LineString) mls.getGeometryN(i); |
569 |
path.append(toShape(lineString), false);
|
570 |
} |
571 |
|
572 |
//BasicFeatureRenderer expects LineStrings and MultiLineStrings to be
|
573 |
//converted to GeneralPathXs. [Jon Aquino]
|
574 |
return path;
|
575 |
} |
576 |
|
577 |
/**
|
578 |
* DOCUMENT ME!
|
579 |
*
|
580 |
* @param lineString DOCUMENT ME!
|
581 |
*
|
582 |
* @return DOCUMENT ME!
|
583 |
*
|
584 |
* @throws NoninvertibleTransformException DOCUMENT ME!
|
585 |
*/
|
586 |
private static GeneralPathX toShape(LineString lineString) |
587 |
throws NoninvertibleTransformException { |
588 |
GeneralPathX shape = new GeneralPathX();
|
589 |
FPoint2D viewPoint = toViewPoint(lineString.getCoordinateN(0));
|
590 |
shape.moveTo((float) viewPoint.getX(), (float) viewPoint.getY()); |
591 |
|
592 |
for (int i = 1; i < lineString.getNumPoints(); i++) { |
593 |
viewPoint = toViewPoint(lineString.getCoordinateN(i)); |
594 |
shape.lineTo((float) viewPoint.getX(), (float) viewPoint.getY()); |
595 |
} |
596 |
|
597 |
//BasicFeatureRenderer expects LineStrings and MultiLineStrings to be
|
598 |
//converted to GeneralPathXs. [Jon Aquino]
|
599 |
return shape;
|
600 |
} |
601 |
|
602 |
/**
|
603 |
* DOCUMENT ME!
|
604 |
*
|
605 |
* @param point DOCUMENT ME!
|
606 |
*
|
607 |
* @return DOCUMENT ME!
|
608 |
*
|
609 |
* @throws NoninvertibleTransformException DOCUMENT ME!
|
610 |
*/
|
611 |
private static FPoint2D toShape(Point point) |
612 |
throws NoninvertibleTransformException { |
613 |
FPoint2D viewPoint = toViewPoint(point.getCoordinate()); |
614 |
|
615 |
return viewPoint;
|
616 |
} |
617 |
|
618 |
private static GeneralPathX toShape(MultiPolygon mp) |
619 |
throws NoninvertibleTransformException { |
620 |
GeneralPathX path = new GeneralPathX();
|
621 |
|
622 |
for (int i = 0; i < mp.getNumGeometries(); i++) { |
623 |
Polygon polygon = (Polygon) mp.getGeometryN(i); |
624 |
path.append(toShape(polygon), false);
|
625 |
} |
626 |
|
627 |
//BasicFeatureRenderer expects LineStrings and MultiLineStrings to be
|
628 |
//converted to GeneralPathXs. [Jon Aquino]
|
629 |
return path;
|
630 |
} |
631 |
/**
|
632 |
* DOCUMENT ME!
|
633 |
*
|
634 |
* @param coord DOCUMENT ME!
|
635 |
*
|
636 |
* @return DOCUMENT ME!
|
637 |
*/
|
638 |
private static FPoint2D toViewPoint(Coordinate coord) { |
639 |
return new FPoint2D(coord.x, coord.y); //,coord.z); |
640 |
} |
641 |
|
642 |
/**
|
643 |
* Convierte una Geometry de JTS a GeneralPathX.
|
644 |
*
|
645 |
* @param geometry Geometry a convertir.
|
646 |
*
|
647 |
* @return GeneralPathX.
|
648 |
*
|
649 |
* @throws NoninvertibleTransformException
|
650 |
* @throws IllegalArgumentException
|
651 |
*/
|
652 |
public static GeneralPathX toShape(Geometry geometry) |
653 |
throws NoninvertibleTransformException { |
654 |
if (geometry.isEmpty()) {
|
655 |
return new GeneralPathX(); |
656 |
} |
657 |
|
658 |
if (geometry instanceof Polygon) { |
659 |
return toShape((Polygon) geometry); |
660 |
} |
661 |
|
662 |
if (geometry instanceof MultiPolygon) { |
663 |
return toShape((MultiPolygon) geometry);
|
664 |
} |
665 |
|
666 |
if (geometry instanceof LineString) { |
667 |
return toShape((LineString) geometry);
|
668 |
} |
669 |
|
670 |
if (geometry instanceof MultiLineString) { |
671 |
return toShape((MultiLineString) geometry);
|
672 |
} |
673 |
|
674 |
if (geometry instanceof GeometryCollection) { |
675 |
return toShape((GeometryCollection) geometry);
|
676 |
} |
677 |
|
678 |
throw new IllegalArgumentException("Unrecognized Geometry class: " + |
679 |
geometry.getClass()); |
680 |
} |
681 |
|
682 |
/**
|
683 |
* Interfazaz para convertir una Coordinate de JTS a Point2D.
|
684 |
*
|
685 |
*/
|
686 |
public static interface PointConverter { |
687 |
/**
|
688 |
* DOCUMENT ME!
|
689 |
*
|
690 |
* @param modelCoordinate DOCUMENT ME!
|
691 |
*
|
692 |
* @return DOCUMENT ME!
|
693 |
*
|
694 |
* @throws NoninvertibleTransformException DOCUMENT ME!
|
695 |
*/
|
696 |
public Point2D toViewPoint(Coordinate modelCoordinate) |
697 |
throws NoninvertibleTransformException; |
698 |
} |
699 |
} |