use of org.locationtech.jts.geom.LinearRing in project jena by apache.
the class WKTReader method buildPolygon.
private Polygon buildPolygon(String coordinates) {
Polygon polygon;
String[] splitCoordinates = splitCoordinates(coordinates);
if (splitCoordinates.length == 1) {
// Polygon without holes.
CustomCoordinateSequence shellSequence = new CustomCoordinateSequence(dims, clean(coordinates));
polygon = GEOMETRY_FACTORY.createPolygon(shellSequence);
} else {
// Polygon with holes
String shellCoordinates = splitCoordinates[0];
CustomCoordinateSequence shellSequence = new CustomCoordinateSequence(dims, clean(shellCoordinates));
LinearRing shellLinearRing = GEOMETRY_FACTORY.createLinearRing(shellSequence);
String[] splitHoleCoordinates = Arrays.copyOfRange(splitCoordinates, 1, splitCoordinates.length);
LinearRing[] holesLinearRing = splitLinearRings(dims, splitHoleCoordinates);
polygon = GEOMETRY_FACTORY.createPolygon(shellLinearRing, holesLinearRing);
}
return polygon;
}
use of org.locationtech.jts.geom.LinearRing in project jena by apache.
the class WKTReader method splitLinearRings.
private LinearRing[] splitLinearRings(CoordinateSequenceDimensions dims, String[] splitCoordinates) {
LinearRing[] linearRings = new LinearRing[splitCoordinates.length];
for (int i = 0; i < splitCoordinates.length; i++) {
CustomCoordinateSequence sequence = new CustomCoordinateSequence(dims, clean(splitCoordinates[i]));
LinearRing linearRing = GEOMETRY_FACTORY.createLinearRing(sequence);
linearRings[i] = linearRing;
}
return linearRings;
}
use of org.locationtech.jts.geom.LinearRing in project jena by apache.
the class GeometryTransformation method transformLinearRing.
private static LinearRing transformLinearRing(Geometry sourceGeometry, MathTransform transform) throws TransformException {
GeometryFactory geometryFactory = sourceGeometry.getFactory();
LinearRing linearRing = (LinearRing) sourceGeometry;
CoordinateSequence coordSeq = linearRing.getCoordinateSequence();
CoordinateSequence transformCoordSeq = transformCoordSeq(coordSeq, transform);
return geometryFactory.createLinearRing(transformCoordSeq);
}
use of org.locationtech.jts.geom.LinearRing in project jena by apache.
the class GMLReaderTest method testExtractPolygonHole.
/**
* Test of extract method, of class GMLReader.
*
* @throws org.jdom2.JDOMException
* @throws java.io.IOException
*/
@Test
public void testExtractPolygonHole() throws JDOMException, IOException {
LinearRing shell = GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "30 10, 40 40, 20 40, 10 20, 30 10"));
LinearRing[] holes = new LinearRing[] { GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "20 30, 35 35, 30 20, 20 30")) };
Geometry geometry = GEOMETRY_FACTORY.createPolygon(shell, holes);
GMLReader expResult = new GMLReader(geometry, 2, SRS_URI.OSGB36_CRS);
String gmlText = "<gml:Polygon xmlns:gml=\"http://www.opengis.net/ont/gml\" srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:exterior><gml:LinearRing><gml:posList>30 10 40 40 20 40 10 20 30 10</gml:posList></gml:LinearRing></gml:exterior><gml:interior><gml:LinearRing><gml:posList>20 30 35 35 30 20 20 30</gml:posList></gml:LinearRing></gml:interior></gml:Polygon>";
GMLReader result = GMLReader.extract(gmlText);
//
//
assertEquals(expResult, result);
}
use of org.locationtech.jts.geom.LinearRing in project jena by apache.
the class GMLReaderTest method testExtractMultiSurface2.
/**
* Test of extract method, of class GMLReader.
*
* @throws org.jdom2.JDOMException
* @throws java.io.IOException
*/
@Test
public void testExtractMultiSurface2() 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"));
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);
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: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>";
GMLReader result = GMLReader.extract(gmlText);
//
//
assertEquals(expResult, result);
}
Aggregations