use of org.geotoolkit.gml.xml.AbstractRing in project geotoolkit by Geomatys.
the class JTStoGeometry method toGML.
/**
* Convert JTS Polygon to GML PolygonType
* @param jtsGeom
* @param crs Coordinate Reference System
* @return PolygonType
*
* @throws org.opengis.referencing.NoSuchAuthorityCodeException - if {@link CoordinateReferenceSystem crs}
* can't be injected into the {@link AbstractGeometry}.
* @throws org.opengis.util.FactoryException - if {@link CoordinateReferenceSystem crs} can't be injected into the
* {@link AbstractGeometry}.
*/
public static org.geotoolkit.gml.xml.Polygon toGML(final String gmlVersion, final Polygon jtsGeom, final CoordinateReferenceSystem crs) throws NoSuchAuthorityCodeException, FactoryException {
// Test if it's a 2D Geometry from CRS
isValideGeometry(crs);
final String srsName = getSRS(crs);
final int srsDimension = crs.getCoordinateSystem().getDimension();
// get exterior ring
final AbstractRing gmlExterior = toGML(gmlVersion, (LinearRing) jtsGeom.getExteriorRing(), crs);
gmlExterior.setSrsName(null);
gmlExterior.setSrsDimension(null);
// get interiors ring
final List<AbstractRing> gmlInterior = new ArrayList<>();
for (int i = 0; i < jtsGeom.getNumInteriorRing(); i++) {
org.geotoolkit.gml.xml.LinearRing interior = toGML(gmlVersion, (LinearRing) jtsGeom.getInteriorRingN(i), crs);
interior.setSrsName(null);
interior.setSrsDimension(null);
gmlInterior.add(interior);
}
return buildPolygon(gmlVersion, gmlExterior, gmlInterior, srsName, srsDimension);
}
use of org.geotoolkit.gml.xml.AbstractRing in project geotoolkit by Geomatys.
the class GeoSpatialBound method extractBoundary.
private void extractBoundary(final AbstractGeometry geom) {
if (geom instanceof Point) {
final Point p = (Point) geom;
if (p.getPos() != null) {
addXCoordinate(p.getPos().getOrdinate(0));
addYCoordinate(p.getPos().getOrdinate(1));
}
} else if (geom instanceof LineString) {
final LineString ls = (LineString) geom;
final Envelope env = ls.getBounds();
if (env != null) {
addXCoordinate(env.getMinimum(0));
addXCoordinate(env.getMaximum(0));
addYCoordinate(env.getMinimum(1));
addYCoordinate(env.getMaximum(1));
}
} else if (geom instanceof Polygon) {
final Polygon p = (Polygon) geom;
AbstractRing ext = p.getExterior().getAbstractRing();
// TODO
}
}
use of org.geotoolkit.gml.xml.AbstractRing in project geotoolkit by Geomatys.
the class GeometryTransformer method convertPolygonLike.
private Polygon convertPolygonLike(AbstractRingProperty exteriorProperty, final List<? extends AbstractRingProperty> interiorProperties) {
final AbstractRing exterior = exteriorProperty.getAbstractRing();
final Geometry extRing = new GeometryTransformer(exterior, this).get();
// Check now to avoid costly parsing of interior geometries
if (!(extRing instanceof LinearRing)) {
throw new UnconvertibleObjectException("Cannot create a polygon, because its exterior is not a ring");
}
final LinearRing[] interiors;
try {
final Stream<? extends AbstractRingProperty> interiorStream = interiorProperties == null ? Stream.empty() : interiorProperties.stream();
interiors = interiorStream.map(AbstractRingProperty::getAbstractRing).map(ring -> new GeometryTransformer(ring, this).get()).map(LinearRing.class::cast).toArray(size -> new LinearRing[size]);
} catch (ClassCastException e) {
throw new UnconvertibleObjectException("Cannot create a polygon, because some of its interior geometries are not rings", e);
}
final Polygon poly = GF.createPolygon((LinearRing) extRing, interiors);
applyCRS(poly);
return poly;
}
Aggregations