svn-gvsig-desktop / tags / v2_0_0_Build_2020 / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / operation / tojts / Curve2DToJTS.java @ 33847
History | View | Annotate | Download (3.97 KB)
1 | 30323 | jpiera | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2009 {Iver T.I.} {Task}
|
||
26 | */
|
||
27 | |||
28 | package org.gvsig.fmap.geom.operation.tojts; |
||
29 | |||
30 | import java.awt.geom.PathIterator; |
||
31 | import java.util.ArrayList; |
||
32 | |||
33 | import org.gvsig.fmap.geom.Geometry; |
||
34 | import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
||
35 | import org.gvsig.fmap.geom.operation.GeometryOperationException; |
||
36 | import org.gvsig.fmap.geom.primitive.Point; |
||
37 | |||
38 | import com.vividsolutions.jts.geom.Coordinate; |
||
39 | import com.vividsolutions.jts.geom.CoordinateArrays; |
||
40 | import com.vividsolutions.jts.geom.LineString; |
||
41 | |||
42 | /**
|
||
43 | * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
||
44 | */
|
||
45 | public class Curve2DToJTS extends ToJTS{ |
||
46 | /*
|
||
47 | * (non-Javadoc)
|
||
48 | * @see org.gvsig.fmap.geom.operation.tojts.ToJTS#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.geom.operation.GeometryOperationContext)
|
||
49 | */
|
||
50 | public Object invoke(Geometry geom, GeometryOperationContext ctx) throws GeometryOperationException { |
||
51 | int srid = -1; |
||
52 | if (ctx != null){ |
||
53 | srid = ((JTSGeometryOperationContext)ctx).getSrid(); |
||
54 | } |
||
55 | ArrayList arrayLines = new ArrayList(); |
||
56 | PathIterator theIterator = geom.getPathIterator(null, geomManager.getFlatness()); |
||
57 | int theType;
|
||
58 | double[] theData = new double[6]; |
||
59 | ArrayList arrayCoords = null; |
||
60 | LineString lin; |
||
61 | int numParts = 0; |
||
62 | Coordinate coord; |
||
63 | |||
64 | while (!theIterator.isDone()) {
|
||
65 | //while not done
|
||
66 | theType = theIterator.currentSegment(theData); |
||
67 | |||
68 | //Populate a segment of the new
|
||
69 | // GeneralPathX object.
|
||
70 | //Process the current segment to populate a new
|
||
71 | // segment of the new GeneralPathX object.
|
||
72 | switch (theType) {
|
||
73 | case PathIterator.SEG_MOVETO: |
||
74 | |||
75 | // System.out.println("SEG_MOVETO");
|
||
76 | if (arrayCoords == null) { |
||
77 | arrayCoords = new ArrayList(); |
||
78 | } else {
|
||
79 | lin = geomFactory.createLineString(CoordinateArrays.toCoordinateArray( |
||
80 | arrayCoords)); |
||
81 | lin.setSRID(srid); |
||
82 | arrayLines.add(lin); |
||
83 | arrayCoords = new ArrayList(); |
||
84 | } |
||
85 | |||
86 | numParts++; |
||
87 | coord = new Coordinate(theData[0], theData[1]); |
||
88 | |||
89 | arrayCoords.add(coord); |
||
90 | |||
91 | break;
|
||
92 | |||
93 | case PathIterator.SEG_LINETO: |
||
94 | |||
95 | // System.out.println("SEG_LINETO");
|
||
96 | arrayCoords.add(new Coordinate(theData[0], |
||
97 | theData[1]));
|
||
98 | |||
99 | break;
|
||
100 | |||
101 | case PathIterator.SEG_QUADTO: |
||
102 | System.out.println("Not supported here"); |
||
103 | |||
104 | break;
|
||
105 | |||
106 | case PathIterator.SEG_CUBICTO: |
||
107 | System.out.println("Not supported here"); |
||
108 | |||
109 | break;
|
||
110 | |||
111 | case PathIterator.SEG_CLOSE: |
||
112 | // A�adimos el primer punto para cerrar.
|
||
113 | Coordinate firstCoord = (Coordinate) arrayCoords.get(0);
|
||
114 | // Solo anyadimos cuando no esta ya cerrado
|
||
115 | arrayCoords.add(new Coordinate(firstCoord.x,
|
||
116 | firstCoord.y)); |
||
117 | |||
118 | break;
|
||
119 | } //end switch
|
||
120 | |||
121 | theIterator.next(); |
||
122 | } //end while loop
|
||
123 | |||
124 | if (arrayCoords.size()<2) { |
||
125 | throw new GeometryOperationException(geom.getType(), geom.getGeometryType().getSubType()); |
||
126 | } |
||
127 | lin = new com.vividsolutions.jts.geom.GeometryFactory().createLineString(CoordinateArrays.toCoordinateArray(
|
||
128 | arrayCoords)); |
||
129 | |||
130 | lin.setSRID(srid); |
||
131 | |||
132 | arrayLines.add(lin); |
||
133 | LineString[] lineString = com.vividsolutions.jts.geom.GeometryFactory.toLineStringArray(arrayLines);
|
||
134 | lineString[0].setSRID(srid);
|
||
135 | return lineString[0]; |
||
136 | } |
||
137 | } |