use of org.locationtech.jts.geom.LinearRing in project jena by apache.
the class WKTDatatypeTest method testReadPolygon2.
/**
* Test of read method, of class WKTReader.
*/
@Test
public void testReadPolygon2() {
String wktLiteral = "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))";
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 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 jena by apache.
the class GMLWriterTest method testWritePolygon2.
@Test
public void testWritePolygon2() {
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);
GeometryWrapper geometryWrapper = new GeometryWrapper(geometry, GML_SRS_NAMESPACE, GMLDatatype.URI, new DimensionInfo(2, 2, 0));
String result = GMLWriter.write(geometryWrapper);
String expResult = "<gml:Polygon xmlns:gml=\"http://www.opengis.net/ont/gml\" srsName=\"urn:ogc:def:crs:EPSG::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>";
assertEquals(expResult.trim(), result.trim());
}
use of org.locationtech.jts.geom.LinearRing 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.LinearRing 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.LinearRing in project ddf by codice.
the class GmdTransformer method setMetacardLocationFromBoundingPolygonPoints.
private void setMetacardLocationFromBoundingPolygonPoints(Metacard metacard) {
try (InputStream inputStream = getSourceInputStream()) {
DocumentBuilder builder = XML_UTILS.getSecureDocumentBuilder(false);
Document document = builder.parse(inputStream);
XPath xPath = XPathFactory.newInstance().newXPath();
XPathExpression dataExpression = xPath.compile(GmdConstants.BOUNDING_POLYGON_POINT_PATH);
NodeList dataList = (NodeList) dataExpression.evaluate(document, XPathConstants.NODESET);
if (dataList.getLength() > 0) {
List<Coordinate> coordinates = new ArrayList<>();
for (int i = 0; i < dataList.getLength(); i++) {
Node node = dataList.item(i);
String[] coordinateStrings = node.getTextContent().split(" ");
if (coordinateStrings.length == 2) {
Double lat = Double.parseDouble(coordinateStrings[0]);
Double lon = Double.parseDouble(coordinateStrings[1]);
Coordinate coordinate = new Coordinate(lat, lon);
coordinates.add(coordinate);
}
}
if (CollectionUtils.isNotEmpty(coordinates)) {
// Close the polygon
coordinates.add(coordinates.get(0));
LinearRing linearRing = factory.createLinearRing(coordinates.toArray(new Coordinate[coordinates.size()]));
String wkt = WKT_WRITER_THREAD_LOCAL.get().write(factory.createPolygon(linearRing, null));
if (wkt != null) {
metacard.setAttribute(new AttributeImpl(Core.LOCATION, wkt));
}
}
}
} catch (NumberFormatException | ParserConfigurationException | IOException | SAXException | XPathExpressionException e) {
LOGGER.debug("Unable to parse location in XML document. Metacard location will not be set.", e);
}
}
Aggregations