Search in sources :

Example 6 with GeometricShapeFactory

use of org.locationtech.jts.util.GeometricShapeFactory in project jena by apache.

the class GMLReader method buildCircleByCentrePoint.

private static LineString buildCircleByCentrePoint(List<Element> segments, CoordinateSequenceDimensions dims, SRSInfo srsInfo) {
    Element circleElement = segments.get(0);
    Point point = buildPoint(circleElement, dims);
    Coordinate centre = point.getCoordinate();
    // Get radius and convert units of measure if required.
    Element radiusElement = circleElement.getChild("radius", GML_NAMESPACE);
    double radius = Double.parseDouble(radiusElement.getTextNormalize());
    // Extract units of measure uri. Use SRS units of measure if absent.
    String uomURI = radiusElement.getAttributeValue("uom");
    if (uomURI != null) {
        UnitsOfMeasure uom = new UnitsOfMeasure(uomURI);
        // Convert the radius if the specified units of measure don't match.
        radius = UnitsOfMeasure.conversion(radius, uom, srsInfo.getUnitsOfMeasure());
    }
    GeometricShapeFactory geometricShapeFactory = new GeometricShapeFactory(GEOMETRY_FACTORY);
    geometricShapeFactory.setCentre(centre);
    // Set the width and height, i.e. the diameter.
    geometricShapeFactory.setSize(radius * 2);
    Polygon circlePolygon = geometricShapeFactory.createCircle();
    return circlePolygon.getExteriorRing();
}
Also used : UnitsOfMeasure(org.apache.jena.geosparql.implementation.UnitsOfMeasure) GeometricShapeFactory(org.locationtech.jts.util.GeometricShapeFactory) Element(org.jdom2.Element)

Aggregations

GeometricShapeFactory (org.locationtech.jts.util.GeometricShapeFactory)6 Element (org.jdom2.Element)3 Test (org.junit.Test)3 Geometry (org.locationtech.jts.geom.Geometry)3 LineString (org.locationtech.jts.geom.LineString)3 DatatypeFormatException (org.apache.jena.datatypes.DatatypeFormatException)2 CoordinateXY (org.locationtech.jts.geom.CoordinateXY)2 UnitsOfMeasure (org.apache.jena.geosparql.implementation.UnitsOfMeasure)1 Coordinate (org.locationtech.jts.geom.Coordinate)1