use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPrimitiveFactory in project geotoolkit by Geomatys.
the class GeometryUtils method createPolygon.
public static Polygon createPolygon(final DirectPosition[] exteriorRingPoints, final DirectPosition[][] interiorRingsPoints) {
final CoordinateReferenceSystem crs = exteriorRingPoints[0].getCoordinateReferenceSystem();
final GeometryFactory geometryFactory = new JTSGeometryFactory(crs);
final PrimitiveFactory primitiveFactory = new JTSPrimitiveFactory(crs);
final Ring exteriorRing = createRing(primitiveFactory, exteriorRingPoints);
List interiorRingList = interiorRingsPoints.length == 0 ? Collections.EMPTY_LIST : new ArrayList(interiorRingsPoints.length);
for (int i = 0; i < interiorRingsPoints.length; i++) {
final DirectPosition[] interiorRingPoints = interiorRingsPoints[i];
interiorRingList.add(createRing(primitiveFactory, interiorRingPoints));
}
final SurfaceBoundary surfaceBoundary = primitiveFactory.createSurfaceBoundary(exteriorRing, interiorRingList);
return geometryFactory.createPolygon(surfaceBoundary);
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPrimitiveFactory in project geotoolkit by Geomatys.
the class GeometryUtils method createRing.
public static Ring createRing(final DirectPosition[] points) {
final CoordinateReferenceSystem crs = points[0].getCoordinateReferenceSystem();
final PrimitiveFactory primitiveFactory = new JTSPrimitiveFactory(crs);
return createRing(primitiveFactory, points);
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPrimitiveFactory in project geotoolkit by Geomatys.
the class JTSUtils method toISO.
/**
* Creates a 19107 primitive geometry from the given JTS geometry.
*/
public static Geometry toISO(final org.locationtech.jts.geom.Geometry jtsGeom, CoordinateReferenceSystem crs) {
if (jtsGeom == null) {
return null;
}
if (crs == null) {
// try to extract the crs from the srid
final int srid = jtsGeom.getSRID();
if (srid != 0) {
final String strCRS = SRIDGenerator.toSRS(srid, SRIDGenerator.Version.V1);
try {
crs = CRS.forCode(strCRS);
} catch (FactoryException ex) {
Logger.getLogger("org.geotoolkit.geometry.isoonjts").log(Level.SEVERE, null, ex);
}
}
}
// TODO use factory finder when primitive factory and geometry factory are ready.
// FactoryFinder.getPrimitiveFactory(hints);
final PrimitiveFactory pf = new JTSPrimitiveFactory(crs);
// FactoryFinder.getGeometryFactory(hints);
final GeometryFactory gf = new JTSGeometryFactory(crs);
if (jtsGeom instanceof org.locationtech.jts.geom.Point) {
org.locationtech.jts.geom.Point candidate = (org.locationtech.jts.geom.Point) jtsGeom;
DirectPosition dp = pointToDirectPosition(candidate, crs);
return pf.createPoint(dp);
} else if (jtsGeom instanceof org.locationtech.jts.geom.LineString) {
org.locationtech.jts.geom.LineString candidate = (org.locationtech.jts.geom.LineString) jtsGeom;
LineString ls = gf.createLineString(new ArrayList<Position>());
PointArray pointList = ls.getControlPoints();
for (int i = 0, n = candidate.getNumPoints(); i < n; i++) {
pointList.add(coordinateToDirectPosition(candidate.getCoordinateN(i), crs));
}
return (JTSLineString) ls;
} else if (jtsGeom instanceof org.locationtech.jts.geom.LinearRing) {
return linearRingToRing((org.locationtech.jts.geom.LinearRing) jtsGeom, crs);
} else if (jtsGeom instanceof org.locationtech.jts.geom.Polygon) {
org.locationtech.jts.geom.Polygon jtsPolygon = (org.locationtech.jts.geom.Polygon) jtsGeom;
Ring externalRing = linearRingToRing((org.locationtech.jts.geom.LinearRing) jtsPolygon.getExteriorRing(), crs);
ArrayList internalRings = new ArrayList();
for (int i = 0, n = jtsPolygon.getNumInteriorRing(); i < n; i++) {
internalRings.add(linearRingToRing((org.locationtech.jts.geom.LinearRing) jtsPolygon.getInteriorRingN(i), crs));
}
SurfaceBoundary boundary = pf.createSurfaceBoundary(externalRing, internalRings);
Polygon polygon = gf.createPolygon(boundary);
return (JTSPolygon) polygon;
/*ArrayList<Polygon> patches = new ArrayList<Polygon>();
patches.add(polygon);
PolyhedralSurface result = gf.createPolyhedralSurface(patches);
return result;*/
} else if (jtsGeom instanceof GeometryCollection) {
org.locationtech.jts.geom.GeometryCollection jtsCollection = (org.locationtech.jts.geom.GeometryCollection) jtsGeom;
boolean multiPoint = jtsGeom instanceof MultiPoint;
boolean multiCurve = jtsGeom instanceof MultiLineString;
boolean multiSurface = jtsGeom instanceof MultiPolygon;
// determine it by analyzing its content.
if (!(multiPoint || multiCurve || multiSurface || jtsGeom.isEmpty())) {
multiPoint = multiCurve = multiSurface = true;
for (int i = 0, n = jtsCollection.getNumGeometries(); i < n && (multiPoint || multiCurve || multiSurface); i++) {
if (!(jtsCollection.getGeometryN(i) instanceof org.locationtech.jts.geom.Point)) {
multiPoint = false;
}
if (!(jtsCollection.getGeometryN(i) instanceof org.locationtech.jts.geom.LineString)) {
multiCurve = false;
}
if (!(jtsCollection.getGeometryN(i) instanceof org.locationtech.jts.geom.Polygon)) {
multiSurface = false;
}
}
}
AbstractJTSAggregate result;
if (multiPoint) {
result = new JTSMultiPoint(crs);
Set elements = result.getElements();
for (int i = 0, n = jtsCollection.getNumGeometries(); i < n; i++) {
// result.getElements().add(jtsToGo1(jtsCollection.getGeometryN(i), crs));
elements.add(toISO(jtsCollection.getGeometryN(i), crs));
}
} else if (multiCurve) {
result = new JTSMultiCurve(crs);
Set elements = result.getElements();
for (int i = 0, n = jtsCollection.getNumGeometries(); i < n; i++) {
// result.getElements().add(jtsToGo1(jtsCollection.getGeometryN(i), crs));
Geometry element = toISO(jtsCollection.getGeometryN(i), crs);
if (element instanceof JTSLineString) {
JTSCurve curve = new JTSCurve(crs);
curve.getSegments().add((JTSLineString) element);
element = curve;
}
elements.add(element);
}
} else if (multiSurface) {
result = new JTSMultiSurface(crs);
Set elements = result.getElements();
for (int i = 0, n = jtsCollection.getNumGeometries(); i < n; i++) {
// result.getElements().add(jtsToGo1(jtsCollection.getGeometryN(i), crs));
elements.add(toISO(jtsCollection.getGeometryN(i), crs));
}
} else {
result = new JTSMultiPrimitive();
Set elements = result.getElements();
for (int i = 0, n = jtsCollection.getNumGeometries(); i < n; i++) {
// result.getElements().add(jtsToGo1(jtsCollection.getGeometryN(i), crs));
elements.add(toISO(jtsCollection.getGeometryN(i), crs));
}
}
return result;
} else {
throw new IllegalArgumentException("Unsupported geometry type: " + jtsGeom.getGeometryType());
}
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPrimitiveFactory in project geotoolkit by Geomatys.
the class ISOGeometryJ2D method createRectangle.
/**
* Creates a jts Geometry object representing a rectangle with the given
* parameters
*
* @param x left coordinate
* @param y bottom coordinate
* @param w width
* @param h height
* @return a rectangle with the specified position and size
*/
private Geometry createRectangle(final double x, final double y, final double w, final double h) {
final GeometryFactory gf = new JTSGeometryFactory(geometry.getCoordinateReferenceSystem());
final PrimitiveFactory pf = new JTSPrimitiveFactory(geometry.getCoordinateReferenceSystem());
final List<Position> points = new ArrayList<Position>();
points.add(new DirectPosition2D(x, y));
points.add(new DirectPosition2D(x + w, y));
points.add(new DirectPosition2D(x + w, y + h));
points.add(new DirectPosition2D(x, y + h));
points.add(new DirectPosition2D(x, y));
CurveSegment segment = gf.createLineString(points);
OrientableCurve curve = pf.createCurve(Collections.singletonList(segment));
Ring exterior = pf.createRing(Collections.singletonList(curve));
SurfaceBoundary boundary = pf.createSurfaceBoundary(exterior, null);
return boundary;
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSPrimitiveFactory in project geotoolkit by Geomatys.
the class GeometryUtils method createSurfaceBoundary.
public static SurfaceBoundary createSurfaceBoundary(final DirectPosition[] exteriorRingPoints, final DirectPosition[][] interiorRingsPoints) {
final CoordinateReferenceSystem crs = exteriorRingPoints[0].getCoordinateReferenceSystem();
final PrimitiveFactory primitiveFactory = new JTSPrimitiveFactory(crs);
return createSurfaceBoundary(primitiveFactory, exteriorRingPoints, interiorRingsPoints);
}
Aggregations