Revision 44099 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/util/JTSUtils.java
JTSUtils.java | ||
---|---|---|
38 | 38 |
import com.vividsolutions.jts.operation.buffer.BufferParameters; |
39 | 39 |
import com.vividsolutions.jts.operation.buffer.OffsetCurveBuilder; |
40 | 40 |
import com.vividsolutions.jts.util.GeometricShapeFactory; |
41 |
import org.cresques.cts.IProjection; |
|
41 | 42 |
|
42 | 43 |
import org.hibernate.spatial.jts.mgeom.MCoordinateSequence; |
43 | 44 |
import org.hibernate.spatial.jts.mgeom.MGeometryFactory; |
... | ... | |
79 | 80 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2DM; |
80 | 81 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3D; |
81 | 82 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3DM; |
83 |
import org.gvsig.fmap.geom.primitive.Line; |
|
82 | 84 |
import org.gvsig.fmap.geom.primitive.Point; |
83 | 85 |
import org.gvsig.fmap.geom.primitive.Polygon; |
84 | 86 |
import org.gvsig.fmap.geom.primitive.Primitive; |
... | ... | |
145 | 147 |
|
146 | 148 |
private static final com.vividsolutions.jts.geom.GeometryFactory mfactory = new MyMGeometryFactory(); |
147 | 149 |
|
148 |
public static Point createPoint(GeometryType type, Coordinate coordinate) throws CreateGeometryException { |
|
150 |
public static Point createPoint(GeometryType type, IProjection proj, Coordinate coordinate) throws CreateGeometryException {
|
|
149 | 151 |
|
152 |
Point p; |
|
150 | 153 |
switch (type.getSubType()) { |
151 | 154 |
case Geometry.SUBTYPES.GEOM2D: |
152 |
return new Point2D(coordinate); |
|
155 |
p = new Point2D(proj, coordinate); |
|
156 |
break; |
|
153 | 157 |
case Geometry.SUBTYPES.GEOM2DM: |
154 |
return new Point2DM(coordinate); |
|
158 |
p = new Point2DM(proj, coordinate); |
|
159 |
break; |
|
155 | 160 |
case Geometry.SUBTYPES.GEOM3D: |
156 |
return new Point3D(coordinate); |
|
161 |
p = new Point3D(proj, coordinate); |
|
162 |
break; |
|
157 | 163 |
case Geometry.SUBTYPES.GEOM3DM: |
158 |
return new Point3DM(coordinate); |
|
164 |
p = new Point3DM(proj, coordinate); |
|
165 |
break; |
|
159 | 166 |
default: |
160 |
Point p = null; |
|
161 | 167 |
p = (Point) type.create(); |
162 | 168 |
for (int i = 0; i < p.getDimension(); i++) { |
163 | 169 |
p.setCoordinateAt(i, coordinate.getOrdinate(i)); |
164 | 170 |
} |
171 |
p.setProjection(proj); |
|
165 | 172 |
break; |
166 | 173 |
} |
167 |
|
|
168 |
return null; |
|
174 |
return p; |
|
169 | 175 |
} |
170 | 176 |
|
171 | 177 |
public static com.vividsolutions.jts.geom.GeometryFactory getFactory(CoordinateSequence coordinates){ |
... | ... | |
204 | 210 |
return getFactory(coordinates).createMultiPoint(coordinates); |
205 | 211 |
} |
206 | 212 |
|
207 |
public static Geometry createGeometry(com.vividsolutions.jts.geom.Geometry jtsGeom) { |
|
213 |
public static Geometry createGeometry(IProjection proj, com.vividsolutions.jts.geom.Geometry jtsGeom) {
|
|
208 | 214 |
if (jtsGeom instanceof com.vividsolutions.jts.geom.Point) { |
209 | 215 |
Coordinate coordinate = jtsGeom.getCoordinate(); |
210 | 216 |
if (jtsGeom.getFactory() instanceof MyMGeometryFactory) { |
211 | 217 |
if (Double.isNaN(coordinate.z)) { |
212 |
return new Point2DM(coordinate); |
|
218 |
return new Point2DM(proj, coordinate);
|
|
213 | 219 |
} else { |
214 |
return new Point3DM(coordinate); |
|
220 |
return new Point3DM(proj, coordinate);
|
|
215 | 221 |
} |
216 | 222 |
} else { |
217 | 223 |
if (Double.isNaN(coordinate.z)) { |
218 |
return new Point2D(coordinate); |
|
224 |
return new Point2D(proj, coordinate);
|
|
219 | 225 |
} else { |
220 |
return new Point3D(coordinate); |
|
226 |
return new Point3D(proj, coordinate);
|
|
221 | 227 |
} |
222 | 228 |
} |
223 | 229 |
} |
... | ... | |
227 | 233 |
Coordinate coordinate = jtsGeom.getCoordinate(); |
228 | 234 |
com.vividsolutions.jts.geom.LineString lineString = (com.vividsolutions.jts.geom.LineString) jtsGeom; |
229 | 235 |
if (!lineString.isEmpty()) { |
236 |
Line line; |
|
230 | 237 |
if (jtsGeom.getFactory() instanceof MGeometryFactory) { |
231 | 238 |
if (coordinate!=null && Double.isNaN(coordinate.z)) { |
232 |
return new Line2DM(coordinates);
|
|
239 |
line = new Line2DM(coordinates);
|
|
233 | 240 |
} else { |
234 |
return new Line3DM(coordinates);
|
|
241 |
line = new Line3DM(coordinates);
|
|
235 | 242 |
} |
236 | 243 |
} else { |
237 | 244 |
if (coordinate!=null && Double.isNaN(coordinate.z)) { |
238 |
return new Line2D(coordinates);
|
|
245 |
line = new Line2D(coordinates);
|
|
239 | 246 |
} else { |
240 |
return new Line3D(coordinates);
|
|
247 |
line = new Line3D(coordinates);
|
|
241 | 248 |
} |
242 | 249 |
} |
250 |
line.setProjection(proj); |
|
251 |
return line; |
|
243 | 252 |
} |
244 | 253 |
} |
245 | 254 |
|
... | ... | |
261 | 270 |
polygon = new Polygon3D(coordinates); |
262 | 271 |
} |
263 | 272 |
} |
273 |
polygon.setProjection(proj); |
|
264 | 274 |
for(int i = 0; i<polygonJTS.getNumInteriorRing(); i++){ |
265 | 275 |
LineString ringJTS = polygonJTS.getInteriorRingN(i); |
266 | 276 |
coordinates = ringJTS.getCoordinates(); |
... | ... | |
279 | 289 |
ring = new Ring3D(coordinates); |
280 | 290 |
} |
281 | 291 |
} |
292 |
ring.setProjection(proj); |
|
282 | 293 |
polygon.addInteriorRing(ring); |
283 | 294 |
} |
284 | 295 |
return polygon; |
... | ... | |
338 | 349 |
if (multiprimitive != null) { |
339 | 350 |
for (int i = 0; i < collection.getNumGeometries(); i++) { |
340 | 351 |
com.vividsolutions.jts.geom.Geometry geometry = collection.getGeometryN(i); |
341 |
multiprimitive.addPrimitive((Primitive) createGeometry(geometry)); |
|
352 |
multiprimitive.addPrimitive((Primitive) createGeometry(proj, geometry));
|
|
342 | 353 |
} |
354 |
multiprimitive.setProjection(proj); |
|
343 | 355 |
} |
344 | 356 |
return multiprimitive; |
345 | 357 |
} |
... | ... | |
550 | 562 |
* @param distance |
551 | 563 |
* @return |
552 | 564 |
*/ |
553 |
public static Geometry offsetClosedLine(ArrayListCoordinateSequence coordinates, double distance) { |
|
565 |
public static Geometry offsetClosedLine(IProjection proj, ArrayListCoordinateSequence coordinates, double distance) {
|
|
554 | 566 |
com.vividsolutions.jts.geom.Geometry jtsGeom = JTSUtils.createJTSPolygon(coordinates); |
555 | 567 |
com.vividsolutions.jts.geom.Geometry geomJTS = jtsGeom.buffer(distance); |
556 | 568 |
if (geomJTS instanceof com.vividsolutions.jts.geom.Polygon) { |
... | ... | |
564 | 576 |
LineString hole = polygonJTS.getInteriorRingN(i); |
565 | 577 |
lineStrings[i + 1] = hole; |
566 | 578 |
} |
567 |
return JTSUtils.createGeometry(JTSUtils.createJTSMultiLineString(lineStrings)); |
|
579 |
return JTSUtils.createGeometry(proj, JTSUtils.createJTSMultiLineString(lineStrings));
|
|
568 | 580 |
} |
569 |
return JTSUtils.createGeometry(shell); |
|
581 |
return JTSUtils.createGeometry(proj, shell);
|
|
570 | 582 |
} else if (geomJTS instanceof com.vividsolutions.jts.geom.MultiPolygon) { |
571 | 583 |
MultiPolygon multiPolygonJTS = (com.vividsolutions.jts.geom.MultiPolygon) geomJTS; |
572 | 584 |
List<LineString> lineStringList = new ArrayList<LineString>(); |
... | ... | |
582 | 594 |
} |
583 | 595 |
} |
584 | 596 |
} |
585 |
return JTSUtils.createGeometry(JTSUtils.createJTSMultiLineString(lineStringList.toArray(new LineString[lineStringList.size()]))); |
|
597 |
return JTSUtils.createGeometry(proj, JTSUtils.createJTSMultiLineString(lineStringList.toArray(new LineString[lineStringList.size()])));
|
|
586 | 598 |
} |
587 | 599 |
//No deber?a pasar por aqu? |
588 | 600 |
logger.warn("offsetClosedLine does not return or Polygon JTS or MultiPolygon JTS"); |
... | ... | |
596 | 608 |
* @param distance |
597 | 609 |
* @return |
598 | 610 |
*/ |
599 |
public static Geometry offsetRawOpenLine(ArrayListCoordinateSequence coordinates, double distance) { |
|
611 |
public static Geometry offsetRawOpenLine(IProjection proj, ArrayListCoordinateSequence coordinates, double distance) {
|
|
600 | 612 |
com.vividsolutions.jts.geom.GeometryFactory factory = getFactory(coordinates); |
601 | 613 |
|
602 | 614 |
BufferParameters bufParams = JTSUtils.getBufferParameters(); |
... | ... | |
608 | 620 |
CoordinateSequence coordSequence = factory.getCoordinateSequenceFactory().create(coords); |
609 | 621 |
com.vividsolutions.jts.geom.Geometry offsetGeom = JTSUtils.createJTSLineString(coordSequence); |
610 | 622 |
|
611 |
return JTSUtils.createGeometry(offsetGeom); |
|
623 |
return JTSUtils.createGeometry(proj, offsetGeom);
|
|
612 | 624 |
} |
613 | 625 |
|
614 | 626 |
/* |
Also available in: Unified diff