use of org.locationtech.jts.geom.LinearRing 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.LinearRing in project jena by apache.
the class WKTWriterTest method testWritePolygon3.
/**
* Test of write method, of class WKTWriter.
*/
@Test
public void testWritePolygon3() {
LinearRing shell = GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "30 10 0 1, 40 40 0 1, 20 40 0 1, 10 20 0 1, 30 10 0 1"));
LinearRing[] holes = new LinearRing[] { GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "20 30 0 1, 35 35 0 1, 30 20 0 1, 20 30 0 1")) };
Geometry geometry = GEOMETRY_FACTORY.createPolygon(shell, holes);
GeometryWrapper geometryWrapper = new GeometryWrapper(geometry, SRS_URI.WGS84_CRS, WKTDatatype.URI, new DimensionInfo(4, 3, 2));
String expResult = "<" + SRS_URI.WGS84_CRS + "> POLYGON ZM((30 10 0 1, 40 40 0 1, 20 40 0 1, 10 20 0 1, 30 10 0 1), (20 30 0 1, 35 35 0 1, 30 20 0 1, 20 30 0 1))";
String result = WKTWriter.write(geometryWrapper);
//
//
assertEquals(expResult, result);
}
use of org.locationtech.jts.geom.LinearRing in project jena by apache.
the class WKTWriterTest method testWriteMultiPolygon2.
/**
* Test of write method, of class WKTWriter.
*/
@Test
public void testWriteMultiPolygon2() {
Polygon[] polygons = new Polygon[2];
polygons[0] = GEOMETRY_FACTORY.createPolygon(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "40 40 0 1, 20 45 0 1, 45 30 0 1, 40 40 0 1"));
LinearRing shell = GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "20 35 0 1, 10 30 0 1, 10 10 0 1, 30 5 0 1, 45 20 0 1, 20 35 0 1"));
LinearRing[] holes = new LinearRing[] { GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "30 20 0 1, 20 15 0 1, 20 25 0 1, 30 20 0 1")) };
polygons[1] = GEOMETRY_FACTORY.createPolygon(shell, holes);
Geometry geometry = GEOMETRY_FACTORY.createMultiPolygon(polygons);
GeometryWrapper geometryWrapper = new GeometryWrapper(geometry, SRS_URI.WGS84_CRS, WKTDatatype.URI, new DimensionInfo(4, 3, 2));
String expResult = "<" + SRS_URI.WGS84_CRS + "> MULTIPOLYGON ZM(((40 40 0 1, 20 45 0 1, 45 30 0 1, 40 40 0 1)), ((20 35 0 1, 10 30 0 1, 10 10 0 1, 30 5 0 1, 45 20 0 1, 20 35 0 1), (30 20 0 1, 20 15 0 1, 20 25 0 1, 30 20 0 1)))";
String result = WKTWriter.write(geometryWrapper);
//
//
assertEquals(expResult, result);
}
use of org.locationtech.jts.geom.LinearRing in project jena by apache.
the class WKTDatatypeTest method testReadMultiPolygon.
/**
* Test of read method, of class WKTReader.
*/
@Test
public void testReadMultiPolygon() {
String wktLiteral = "MULTIPOLYGON ZM(((40 40 0 1, 20 45 0 1, 45 30 0 1, 40 40 0 1)), ((20 35 0 1, 10 30 0 1, 10 10 0 1, 30 5 0 1, 45 20 0 1, 20 35 0 1), (30 20 0 1, 20 15 0 1, 20 25 0 1, 30 20 0 1)))";
Polygon[] polygons = new Polygon[2];
polygons[0] = GEOMETRY_FACTORY.createPolygon(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "40 40 0 1, 20 45 0 1, 45 30 0 1, 40 40 0 1"));
LinearRing shell = GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "20 35 0 1, 10 30 0 1, 10 10 0 1, 30 5 0 1, 45 20 0 1, 20 35 0 1"));
LinearRing[] holes = new LinearRing[] { GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "30 20 0 1, 20 15 0 1, 20 25 0 1, 30 20 0 1")) };
polygons[1] = GEOMETRY_FACTORY.createPolygon(shell, holes);
Geometry geometry = GEOMETRY_FACTORY.createMultiPolygon(polygons);
GeometryWrapper expResult = new GeometryWrapper(geometry, SRS_URI.DEFAULT_WKT_CRS84, WKTDatatype.URI, new DimensionInfo(4, 3, 2));
GeometryWrapper result = WKT_DATATYPE.read(wktLiteral);
//
//
assertEquals(expResult, result);
}
use of org.locationtech.jts.geom.LinearRing in project series-rest-api by 52North.
the class GeoJSONDecoder method decodePolygonCoordinates.
protected Polygon decodePolygonCoordinates(JsonNode coordinates, GeometryFactory fac) throws GeoJSONException {
if (!coordinates.isArray()) {
throwExpectedArrayException();
}
if (coordinates.size() < 1) {
throw new GeoJSONException("missing polygon shell");
}
LinearRing shell = fac.createLinearRing(decodeCoordinates(coordinates.get(0)));
LinearRing[] holes = new LinearRing[coordinates.size() - 1];
for (int i = 1; i < coordinates.size(); ++i) {
holes[i - 1] = fac.createLinearRing(decodeCoordinates(coordinates.get(i)));
}
return fac.createPolygon(shell, holes);
}
Aggregations