Revision 27133 trunk/extensions/extGPE-gvSIG/src/org/gvsig/fmap/drivers/gpe/writer/ExportGeometry.java
ExportGeometry.java | ||
---|---|---|
102 | 102 |
reproject(shp); |
103 | 103 |
if (shp.getShapeType() == FShape.POINT){ |
104 | 104 |
writePoint((FPoint2D)shp, crs); |
105 |
}else if ((shp.getShapeType()==FShape.LINE)|| |
|
106 |
(shp.getShapeType()==FShape.POLYGON)){ |
|
107 |
writeGeneralPath(shp, crs); |
|
105 |
}else if (shp.getShapeType()==FShape.LINE){ |
|
106 |
writeLine((FPolyline2D)shp, crs); |
|
107 |
}else if (shp.getShapeType()==FShape.POLYGON){ |
|
108 |
writePolygon((FPolygon2D)shp, crs); |
|
108 | 109 |
} |
109 | 110 |
} |
110 | 111 |
|
... | ... | |
127 | 128 |
} |
128 | 129 |
|
129 | 130 |
/** |
130 |
* It writes a geometry based on a General path |
|
131 |
* @param shp |
|
132 |
* @param crs |
|
133 |
*/ |
|
134 |
private void writeGeneralPath(FShape shp, String crs){ |
|
135 |
PathIterator it = shp.getPathIterator(null); |
|
136 |
if (shp.getShapeType()==FShape.LINE){ |
|
137 |
writeLine((FPolyline2D)shp, crs, new CoordinatesSequenceGeneralPath(it)); |
|
138 |
}else if (shp.getShapeType()==FShape.POLYGON){ |
|
139 |
writePolygon((FPolygon2D)shp, crs, new CoordinatesSequenceGeneralPath(it)); |
|
140 |
} |
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 | 131 |
* Writes a point in 2D |
145 | 132 |
* @param point |
146 | 133 |
* The point to write |
... | ... | |
177 | 164 |
* @param geometries |
178 | 165 |
* The parsed geometries |
179 | 166 |
*/ |
180 |
private void writeLine(FPolyline2D line, String crs, CoordinatesSequenceGeneralPath sequence){ |
|
167 |
private void writeLine(FPolyline2D line, String crs){ |
|
168 |
boolean isMultipleGeometry = false; |
|
181 | 169 |
if (isMultiple){ |
182 | 170 |
writer.startMultiLineString(null, crs); |
171 |
}else{ |
|
172 |
isMultipleGeometry = isMultiple(line.getPathIterator(null)); |
|
173 |
if (isMultipleGeometry){ |
|
174 |
writer.startMultiLineString(null, crs); |
|
175 |
} |
|
183 | 176 |
} |
177 |
CoordinatesSequenceGeneralPath sequence = new CoordinatesSequenceGeneralPath(line.getPathIterator(null)); |
|
184 | 178 |
writer.startLineString(null, sequence, crs); |
185 |
writer.endLineString(); |
|
186 |
if (isMultiple){ |
|
179 |
writer.endLineString(); |
|
180 |
if (isMultiple || isMultipleGeometry){ |
|
181 |
while (sequence.hasMoreGeometries()){ |
|
182 |
sequence.initialize(); |
|
183 |
writer.startLineString(null, sequence, crs); |
|
184 |
writer.endLineString(); |
|
185 |
} |
|
187 | 186 |
writer.endMultiLineString(); |
188 | 187 |
} |
189 | 188 |
} |
... | ... | |
197 | 196 |
* @param geometries |
198 | 197 |
* The parsed geometries |
199 | 198 |
*/ |
200 |
private void writePolygon(FPolygon2D polygon, String crs, CoordinatesSequenceGeneralPath sequence){ |
|
199 |
private void writePolygon(FPolygon2D polygon, String crs){ |
|
200 |
boolean isMultipleGeometry = false; |
|
201 | 201 |
if (isMultiple){ |
202 | 202 |
writer.startMultiPolygon(null, crs); |
203 |
} |
|
204 |
writer.startPolygon(null, sequence, crs); |
|
205 |
writer.endPolygon(); |
|
206 |
if (isMultiple){ |
|
203 |
}else{ |
|
204 |
isMultipleGeometry = isMultiple(polygon.getPathIterator(null)); |
|
205 |
if (isMultipleGeometry){ |
|
206 |
writer.startMultiPolygon(null, crs); |
|
207 |
} |
|
208 |
} |
|
209 |
CoordinatesSequenceGeneralPath sequence = new CoordinatesSequenceGeneralPath(polygon.getPathIterator(null)); |
|
210 |
writer.startPolygon(null, sequence ,crs); |
|
211 |
writer.endPolygon(); |
|
212 |
if (isMultiple || isMultipleGeometry){ |
|
213 |
while (sequence.hasMoreGeometries()){ |
|
214 |
sequence.initialize(); |
|
215 |
writer.startPolygon(null, sequence ,crs); |
|
216 |
writer.endPolygon(); |
|
217 |
} |
|
207 | 218 |
writer.endMultiPolygon(); |
208 | 219 |
} |
209 | 220 |
} |
221 |
|
|
222 |
/** |
|
223 |
* Return if the geometry is multiple |
|
224 |
* @param path |
|
225 |
* @return |
|
226 |
*/ |
|
227 |
public boolean isMultiple(PathIterator path){ |
|
228 |
double[] coords = new double[2]; |
|
229 |
int type = 0; |
|
230 |
int numGeometries = 0; |
|
231 |
while (!path.isDone()){ |
|
232 |
type = path.currentSegment(coords); |
|
233 |
switch (type) { |
|
234 |
case PathIterator.SEG_MOVETO: |
|
235 |
numGeometries++; |
|
236 |
if (numGeometries == 2){ |
|
237 |
return true; |
|
238 |
} |
|
239 |
break; |
|
240 |
case PathIterator.SEG_CLOSE: |
|
241 |
return false; |
|
242 |
default: |
|
243 |
break; |
|
244 |
} |
|
245 |
path.next(); |
|
246 |
} |
|
247 |
return false; |
|
248 |
} |
|
210 | 249 |
|
211 | 250 |
/** |
212 | 251 |
* @param projOrig the projOrig to set |
Also available in: Unified diff