use of org.locationtech.jts.geom.Polygon in project jena by apache.
the class WKTReader method buildMultiPolygon.
private Geometry buildMultiPolygon(String coordinates) {
if (coordinates.isEmpty()) {
return GEOMETRY_FACTORY.createMultiPolygon(new Polygon[0]);
}
String trimmed = coordinates.replace(")) ,", ")),");
String[] multiCoordinates = trimmed.split("\\)\\),");
Polygon[] polygons = new Polygon[multiCoordinates.length];
for (int i = 0; i < multiCoordinates.length; i++) {
polygons[i] = buildPolygon(multiCoordinates[i]);
}
return GEOMETRY_FACTORY.createMultiPolygon(polygons);
}
use of org.locationtech.jts.geom.Polygon in project jena by apache.
the class GeometryReverse method reversePolygon.
private static Polygon reversePolygon(Geometry geometry, GeometryFactory factory) {
Polygon finalGeometry;
Polygon polygon = (Polygon) geometry;
if (polygon.getNumInteriorRing() == 0) {
// There are no interior rings so perform the standard reversal.
Coordinate[] coordinates = getReversedCoordinates(geometry);
finalGeometry = factory.createPolygon(coordinates);
} else {
LineString exteriorRing = polygon.getExteriorRing();
Coordinate[] reversedExteriorCoordinates = getReversedCoordinates(exteriorRing);
LinearRing reversedExteriorRing = factory.createLinearRing(reversedExteriorCoordinates);
LinearRing[] reversedInteriorRings = new LinearRing[polygon.getNumInteriorRing()];
for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
LineString interiorRing = polygon.getInteriorRingN(i);
Coordinate[] reversedInteriorCoordinates = getReversedCoordinates(interiorRing);
LinearRing reversedInteriorRing = factory.createLinearRing(reversedInteriorCoordinates);
reversedInteriorRings[i] = reversedInteriorRing;
}
finalGeometry = factory.createPolygon(reversedExteriorRing, reversedInteriorRings);
}
return finalGeometry;
}
use of org.locationtech.jts.geom.Polygon in project jena by apache.
the class GeometryReverse method unpackPolygons.
private static Polygon[] unpackPolygons(GeometryCollection geoCollection) {
GeometryFactory factory = geoCollection.getFactory();
int count = geoCollection.getNumGeometries();
Polygon[] polygons = new Polygon[count];
for (int i = 0; i < count; i++) {
Geometry geometry = geoCollection.getGeometryN(i);
Polygon polygon = reversePolygon(geometry, factory);
polygons[i] = polygon;
}
return polygons;
}
use of org.locationtech.jts.geom.Polygon in project jena by apache.
the class GeometryTransformation method transformPolygon.
private static Polygon transformPolygon(Geometry sourceGeometry, MathTransform transform) throws TransformException {
GeometryFactory geometryFactory = sourceGeometry.getFactory();
Polygon polygon = (Polygon) sourceGeometry;
LinearRing exterior = transformLinearRing(polygon.getExteriorRing(), transform);
int interiorsNumber = polygon.getNumInteriorRing();
ArrayList<LinearRing> interiors = new ArrayList<>(interiorsNumber);
for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
LinearRing interior = transformLinearRing(polygon.getInteriorRingN(i), transform);
interiors.add(interior);
}
return geometryFactory.createPolygon(exterior, interiors.toArray(new LinearRing[interiors.size()]));
}
use of org.locationtech.jts.geom.Polygon in project jena by apache.
the class GMLReaderTest method testExtractMultiSurface.
/**
* Test of extract method, of class GMLReader.
*
* @throws org.jdom2.JDOMException
* @throws java.io.IOException
*/
@Test
public void testExtractMultiSurface() throws JDOMException, IOException {
Polygon[] polygons = new Polygon[2];
polygons[0] = GEOMETRY_FACTORY.createPolygon(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "40 40, 20 45, 45 30, 40 40"));
polygons[1] = GEOMETRY_FACTORY.createPolygon(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "20 35, 10 30, 10 10, 30 5, 45 20, 20 35"));
Geometry geometry = GEOMETRY_FACTORY.createMultiPolygon(polygons);
GMLReader expResult = new GMLReader(geometry, 2, SRS_URI.OSGB36_CRS);
String gmlText = "<gml:MultiSurface xmlns:gml=\"http://www.opengis.net/ont/gml\" srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:surfaceMember><gml:Polygon srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:exterior><gml:LinearRing><gml:posList>40 40 20 45 45 30 40 40</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember><gml:surfaceMember><gml:Polygon srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:exterior><gml:LinearRing><gml:posList>20 35 10 30 10 10 30 5 45 20 20 35</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></gml:surfaceMember></gml:MultiSurface>";
GMLReader result = GMLReader.extract(gmlText);
//
//
assertEquals(expResult, result);
}
Aggregations