root / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / operation / tojts / Curve2DToJTS.java @ 38538
History | View | Annotate | Download (4.17 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 | 38538 | jldominguez | import com.vividsolutions.jts.geom.GeometryFactory; |
41 | 30323 | jpiera | import com.vividsolutions.jts.geom.LineString; |
42 | 38538 | jldominguez | import com.vividsolutions.jts.geom.MultiLineString; |
43 | 30323 | jpiera | |
44 | /**
|
||
45 | * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
||
46 | */
|
||
47 | public class Curve2DToJTS extends ToJTS{ |
||
48 | 38538 | jldominguez | |
49 | 30323 | jpiera | /*
|
50 | * (non-Javadoc)
|
||
51 | * @see org.gvsig.fmap.geom.operation.tojts.ToJTS#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.geom.operation.GeometryOperationContext)
|
||
52 | */
|
||
53 | public Object invoke(Geometry geom, GeometryOperationContext ctx) throws GeometryOperationException { |
||
54 | int srid = -1; |
||
55 | if (ctx != null){ |
||
56 | srid = ((JTSGeometryOperationContext)ctx).getSrid(); |
||
57 | } |
||
58 | ArrayList arrayLines = new ArrayList(); |
||
59 | PathIterator theIterator = geom.getPathIterator(null, geomManager.getFlatness()); |
||
60 | int theType;
|
||
61 | double[] theData = new double[6]; |
||
62 | ArrayList arrayCoords = null; |
||
63 | LineString lin; |
||
64 | int numParts = 0; |
||
65 | Coordinate coord; |
||
66 | |||
67 | while (!theIterator.isDone()) {
|
||
68 | //while not done
|
||
69 | theType = theIterator.currentSegment(theData); |
||
70 | |||
71 | //Populate a segment of the new
|
||
72 | // GeneralPathX object.
|
||
73 | //Process the current segment to populate a new
|
||
74 | // segment of the new GeneralPathX object.
|
||
75 | switch (theType) {
|
||
76 | case PathIterator.SEG_MOVETO: |
||
77 | |||
78 | // System.out.println("SEG_MOVETO");
|
||
79 | if (arrayCoords == null) { |
||
80 | arrayCoords = new ArrayList(); |
||
81 | } else {
|
||
82 | lin = geomFactory.createLineString(CoordinateArrays.toCoordinateArray( |
||
83 | arrayCoords)); |
||
84 | lin.setSRID(srid); |
||
85 | arrayLines.add(lin); |
||
86 | arrayCoords = new ArrayList(); |
||
87 | } |
||
88 | |||
89 | numParts++; |
||
90 | coord = new Coordinate(theData[0], theData[1]); |
||
91 | |||
92 | arrayCoords.add(coord); |
||
93 | |||
94 | break;
|
||
95 | |||
96 | case PathIterator.SEG_LINETO: |
||
97 | |||
98 | // System.out.println("SEG_LINETO");
|
||
99 | arrayCoords.add(new Coordinate(theData[0], |
||
100 | theData[1]));
|
||
101 | |||
102 | break;
|
||
103 | |||
104 | case PathIterator.SEG_QUADTO: |
||
105 | System.out.println("Not supported here"); |
||
106 | |||
107 | break;
|
||
108 | |||
109 | case PathIterator.SEG_CUBICTO: |
||
110 | System.out.println("Not supported here"); |
||
111 | |||
112 | break;
|
||
113 | |||
114 | case PathIterator.SEG_CLOSE: |
||
115 | // A�adimos el primer punto para cerrar.
|
||
116 | Coordinate firstCoord = (Coordinate) arrayCoords.get(0);
|
||
117 | // Solo anyadimos cuando no esta ya cerrado
|
||
118 | arrayCoords.add(new Coordinate(firstCoord.x,
|
||
119 | firstCoord.y)); |
||
120 | |||
121 | break;
|
||
122 | } //end switch
|
||
123 | |||
124 | theIterator.next(); |
||
125 | } //end while loop
|
||
126 | |||
127 | if (arrayCoords.size()<2) { |
||
128 | throw new GeometryOperationException(geom.getType(), geom.getGeometryType().getSubType()); |
||
129 | } |
||
130 | 38538 | jldominguez | lin = geomFactory.createLineString(CoordinateArrays.toCoordinateArray( |
131 | 30323 | jpiera | arrayCoords)); |
132 | |||
133 | lin.setSRID(srid); |
||
134 | arrayLines.add(lin); |
||
135 | 38538 | jldominguez | |
136 | LineString[] lineString = GeometryFactory.toLineStringArray(arrayLines);
|
||
137 | |||
138 | if (lineString.length == 1) { |
||
139 | return lineString[0]; |
||
140 | } else {
|
||
141 | MultiLineString resp = geomFactory.createMultiLineString(lineString); |
||
142 | resp.setSRID(srid); |
||
143 | return resp;
|
||
144 | } |
||
145 | 30323 | jpiera | } |
146 | } |