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);
}
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);
}
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);
}
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();
}
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);
}
Aggregations