Search in sources :

Example 1 with GeometricShapeFactory

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

the class GMLReaderTest method testExtractArc.

/**
 * Test of extract method, of class GMLReader.
 *
 * @throws org.jdom2.JDOMException
 * @throws java.io.IOException
 */
@Test
public void testExtractArc() throws JDOMException, IOException {
    GeometricShapeFactory shapeFactory = new GeometricShapeFactory(GEOMETRY_FACTORY);
    shapeFactory.setCentre(new CoordinateXY(0, 0));
    shapeFactory.setWidth(10);
    // Semi-cicle centred around 0,0 and radius 5.
    Geometry arc = shapeFactory.createArc(0, Math.PI);
    GMLReader expResult = new GMLReader(arc, 2, SRS_URI.OSGB36_CRS);
    String gmlText = "<gml:Curve xmlns:gml=\"http://www.opengis.net/ont/gml\" srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:segments><gml:Arc><gml:posList>5 0 0 5 -5 0</gml:posList></gml:Arc></gml:segments></gml:Curve>";
    GMLReader result = GMLReader.extract(gmlText);
    // 
    // 
    assertEquals(expResult, result);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometricShapeFactory(org.locationtech.jts.util.GeometricShapeFactory) CoordinateXY(org.locationtech.jts.geom.CoordinateXY) LineString(org.locationtech.jts.geom.LineString) Test(org.junit.Test)

Example 2 with GeometricShapeFactory

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

the class GMLReaderTest method testExtractCircleByCentrePoint.

/**
 * Test of extract method, of class GMLReader.
 *
 * @throws org.jdom2.JDOMException
 * @throws java.io.IOException
 */
@Test
public void testExtractCircleByCentrePoint() throws JDOMException, IOException {
    GeometricShapeFactory shapeFactory = new GeometricShapeFactory(GEOMETRY_FACTORY);
    shapeFactory.setCentre(new Coordinate(0, 0));
    shapeFactory.setSize(10);
    Geometry circle = shapeFactory.createCircle().getExteriorRing();
    GMLReader expResult = new GMLReader(circle, 2, SRS_URI.OSGB36_CRS);
    String gmlText = "<gml:Curve xmlns:gml=\"http://www.opengis.net/ont/gml\" srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:segments><gml:CircleByCenterPoint ><gml:pos>0 0</gml:pos><gml:radius uom=\"http://www.opengis.net/def/uom/OGC/1.0/metre\">5.0</gml:radius></gml:CircleByCenterPoint></gml:segments></gml:Curve>";
    GMLReader result = GMLReader.extract(gmlText);
    // 
    // 
    assertEquals(expResult, result);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometricShapeFactory(org.locationtech.jts.util.GeometricShapeFactory) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) Test(org.junit.Test)

Example 3 with GeometricShapeFactory

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

the class GMLReaderTest method testExtractCircle.

/**
 * Test of extract method, of class GMLReader.
 *
 * @throws org.jdom2.JDOMException
 * @throws java.io.IOException
 */
@Test
public void testExtractCircle() throws JDOMException, IOException {
    GeometricShapeFactory shapeFactory = new GeometricShapeFactory(GEOMETRY_FACTORY);
    shapeFactory.setCentre(new CoordinateXY(0, 0));
    shapeFactory.setWidth(10);
    Geometry circle = shapeFactory.createCircle().getExteriorRing();
    GMLReader expResult = new GMLReader(circle, 2, SRS_URI.OSGB36_CRS);
    String gmlText = "<gml:Curve xmlns:gml=\"http://www.opengis.net/ont/gml\" srsName=\"http://www.opengis.net/def/crs/EPSG/0/27700\"><gml:segments><gml:Circle><gml:posList>5 0 0 5 -5 0</gml:posList></gml:Circle></gml:segments></gml:Curve>";
    GMLReader result = GMLReader.extract(gmlText);
    // 
    // 
    assertEquals(expResult, result);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometricShapeFactory(org.locationtech.jts.util.GeometricShapeFactory) CoordinateXY(org.locationtech.jts.geom.CoordinateXY) LineString(org.locationtech.jts.geom.LineString) Test(org.junit.Test)

Example 4 with GeometricShapeFactory

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

the class GMLReader method buildCircle.

private static LineString buildCircle(List<Element> segments, CoordinateSequenceDimensions dims) {
    int srsDimension = CoordinateSequenceDimensions.convertToInt(dims);
    // Already ensured that non-zero length. gml:Circle only has single posList.
    Element posListElement = segments.get(0);
    List<Coordinate> coordinates = buildCoordinateList(posListElement, srsDimension);
    if (coordinates.size() != 3) {
        throw new DatatypeFormatException("GML Circle posList does not contain 3 coordinates: " + posListElement);
    }
    Coordinate centre = findCentre(coordinates);
    Coordinate coord = coordinates.get(0);
    double radius = Math.hypot(centre.x - coord.x, centre.y - coord.y);
    GeometricShapeFactory geometricShapeFactory = new GeometricShapeFactory(GEOMETRY_FACTORY);
    geometricShapeFactory.setCentre(centre);
    geometricShapeFactory.setWidth(radius * 2);
    Polygon circlePolygon = geometricShapeFactory.createCircle();
    return circlePolygon.getExteriorRing();
}
Also used : DatatypeFormatException(org.apache.jena.datatypes.DatatypeFormatException) GeometricShapeFactory(org.locationtech.jts.util.GeometricShapeFactory) Element(org.jdom2.Element)

Example 5 with GeometricShapeFactory

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

the class GMLReader method buildArc.

private static final LineString buildArc(List<Element> segments, CoordinateSequenceDimensions dims) {
    int srsDimension = CoordinateSequenceDimensions.convertToInt(dims);
    // Already ensured that non-zero length. gml:Arc only has single posList.
    Element posListElement = segments.get(0);
    List<Coordinate> coordinates = buildCoordinateList(posListElement, srsDimension);
    if (coordinates.size() != 3) {
        throw new DatatypeFormatException("GML Arc posList does not contain 3 coordinates: " + posListElement);
    }
    Coordinate centre = findCentre(coordinates);
    Coordinate coord0 = coordinates.get(0);
    // All coordinates on the arc are radius distance from centre point.
    double radius = Math.hypot(centre.x - coord0.x, centre.y - coord0.y);
    GeometricShapeFactory geometricShapeFactory = new GeometricShapeFactory(GEOMETRY_FACTORY);
    geometricShapeFactory.setCentre(centre);
    geometricShapeFactory.setWidth(radius * 2);
    double startAng = findAngle(centre, coord0);
    double angExtent = findAngle(centre, coordinates.get(2));
    return geometricShapeFactory.createArc(startAng, angExtent);
}
Also used : DatatypeFormatException(org.apache.jena.datatypes.DatatypeFormatException) 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