use of org.locationtech.jts.geom.Polygon in project jena by apache.
the class WKTWriter method expand.
private static String expand(final Geometry geometry, final CoordinateSequenceDimensions dimensions) {
String wktString = "";
String dimensionString = CoordinateSequenceDimensions.convertDimensions(dimensions);
switch(geometry.getGeometryType()) {
case "Point":
Point point = (Point) geometry;
wktString = buildWKT("POINT", point.getCoordinateSequence(), dimensionString);
break;
case "LineString":
case "LinearRing":
LineString lineString = (LineString) geometry;
wktString = buildWKT("LINESTRING", lineString.getCoordinateSequence(), dimensionString);
break;
case "Polygon":
Polygon polygon = (Polygon) geometry;
wktString = buildPolygon(polygon, true, dimensionString);
break;
case "MultiPoint":
MultiPoint multiPoint = (MultiPoint) geometry;
wktString = buildMultiPoint(multiPoint, dimensionString);
break;
case "MultiLineString":
MultiLineString multiLineString = (MultiLineString) geometry;
wktString = buildMultiLineString(multiLineString, dimensionString);
break;
case "MultiPolygon":
MultiPolygon multiPolygon = (MultiPolygon) geometry;
wktString = buildMultiPolygon(multiPolygon, dimensionString);
break;
case "GeometryCollection":
GeometryCollection geometryCollection = (GeometryCollection) geometry;
wktString = buildGeometryCollection(geometryCollection, dimensions);
break;
}
return wktString;
}
use of org.locationtech.jts.geom.Polygon in project jena by apache.
the class WKTWriter method buildMultiPolygon.
private static String buildMultiPolygon(final MultiPolygon multiPolygon, final String dimensionString) {
StringBuilder sb = new StringBuilder("MULTIPOLYGON");
if (!multiPolygon.isEmpty()) {
sb.append(dimensionString);
sb.append("(");
// Find first polygon
Polygon polygon = (Polygon) multiPolygon.getGeometryN(0);
sb.append(buildPolygon(polygon, false, dimensionString));
// Encode remaining points
int geomCount = multiPolygon.getNumGeometries();
for (int i = 1; i < geomCount; i++) {
sb.append(", ");
polygon = (Polygon) multiPolygon.getGeometryN(i);
sb.append(buildPolygon(polygon, false, dimensionString));
}
sb.append(")");
} else {
sb.append(" EMPTY");
}
return sb.toString();
}
use of org.locationtech.jts.geom.Polygon in project jena by apache.
the class GMLWriterTest method testWriteMultiSurface2.
@Test
public void testWriteMultiSurface2() {
Polygon[] polygons = new Polygon[2];
polygons[0] = GEOMETRY_FACTORY.createPolygon(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "40 40, 20 45, 45 30, 40 40"));
LinearRing shell = GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "20 35, 10 30, 10 10, 30 5, 45 20, 20 35"));
LinearRing[] holes = new LinearRing[] { GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "30 20, 20 15, 20 25, 30 20")) };
polygons[1] = GEOMETRY_FACTORY.createPolygon(shell, holes);
Geometry geometry = GEOMETRY_FACTORY.createMultiPolygon(polygons);
GeometryWrapper geometryWrapper = new GeometryWrapper(geometry, GML_SRS_NAMESPACE, GMLDatatype.URI, new DimensionInfo(2, 2, 0));
String result = GMLWriter.write(geometryWrapper);
String expResult = "<gml:MultiSurface xmlns:gml=\"http://www.opengis.net/ont/gml\" srsName=\"urn:ogc:def:crs:EPSG::27700\"><gml:surfaceMember><gml:Polygon srsName=\"urn:ogc:def:crs:EPSG::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=\"urn:ogc:def:crs:EPSG::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:interior><gml:LinearRing><gml:posList>30 20 20 15 20 25 30 20</gml:posList></gml:LinearRing></gml:interior></gml:Polygon></gml:surfaceMember></gml:MultiSurface>";
assertEquals(expResult.trim(), result.trim());
}
use of org.locationtech.jts.geom.Polygon in project jena by apache.
the class WKTWriterTest method testWriteMultiPolygon.
/**
* Test of extract method, of class WKTWriter.
*/
@Test
public void testWriteMultiPolygon() {
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);
GeometryWrapper geometryWrapper = new GeometryWrapper(geometry, SRS_URI.WGS84_CRS, WKTDatatype.URI, new DimensionInfo(2, 2, 2));
String expResult = "<" + SRS_URI.WGS84_CRS + "> MULTIPOLYGON(((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35)))";
String result = WKTWriter.write(geometryWrapper);
//
//
assertEquals(expResult, result);
}
use of org.locationtech.jts.geom.Polygon in project series-rest-api by 52North.
the class GeoJSONTest method randomPolygon.
private Polygon randomPolygon(int srid) {
Polygon geometry = geometryFactory.createPolygon(randomLinearRing(srid), new LinearRing[] { randomLinearRing(srid), randomLinearRing(srid), randomLinearRing(srid) });
geometry.setSRID(srid);
return geometry;
}
Aggregations