/** * Returns a curved geometry factory given the linearization constraints, the original factory, * and a coordinate sequence representing the control points of a curved geometry * * @param arcParameters * @param gFactory * @param cs * @return */ public static CurvedGeometryFactory getCurvedGeometryFactory( ArcParameters arcParameters, GeometryFactory gFactory, CoordinateSequence cs) { CurvedGeometryFactory factory; if (gFactory instanceof CurvedGeometryFactory) { factory = (CurvedGeometryFactory) gFactory; } else if (arcParameters != null && arcParameters.getLinearizationTolerance() != null) { double tolerance = Double.MAX_VALUE; if (cs != null) { CircularArc arc = CurvedGeometries.getArc(cs, 0); Circle c = new Circle(arc.getCenter(), arc.getRadius()); tolerance = arcParameters.getLinearizationTolerance().getTolerance(c); } factory = new CurvedGeometryFactory(gFactory, tolerance); } else { factory = new CurvedGeometryFactory(gFactory, Double.MAX_VALUE); } return factory; } }
private LineString transformCurvedLineString(CurvedGeometry<?> curved, GeometryFactory gf) throws TransformException { CurvedGeometryFactory cf = CurvedGeometries.getFactory(curved); if (curved instanceof SingleCurvedGeometry<?>) { SingleCurvedGeometry<?> single = (SingleCurvedGeometry<?>) curved; double[] controlPoints = single.getControlPoints(); double[] target = new double[controlPoints.length]; transform.transform(controlPoints, 0, target, 0, controlPoints.length / 2); return cf.createCurvedGeometry(2, target); } else { CompoundCurvedGeometry<?> compound = (CompoundCurvedGeometry<?>) curved; List<LineString> reprojected = new ArrayList<>(); for (LineString component : compound.getComponents()) { LineString ls = transformLineString(component, gf); reprojected.add(ls); } return cf.createCurvedGeometry(reprojected); } }
public void testCirclePolygon() throws Exception { Parser p = new Parser(gml); Object g = p.parse(GML3CurveParsingTest.class.getResourceAsStream("v3_2/circlePolygon.xml")); assertThat(g, instanceOf(CurvePolygon.class)); CurvePolygon cp = (CurvePolygon) g; assertEquals(TOLERANCE, cp.getTolerance()); assertEquals(0, cp.getNumInteriorRing()); // exterior ring checks assertTrue(cp.getExteriorRing() instanceof CircularRing); CircularRing shell = (CircularRing) cp.getExteriorRing(); assertTrue(CurvedGeometries.isCircle(shell)); CircularArc arc = shell.getArcN(0); assertEquals(5, arc.getRadius(), 0d); assertEquals(new Coordinate(15, 150), arc.getCenter()); }
ring = CurvedGeometries.toCircle(arc, gf, gf.getTolerance()); } else { throw new IllegalArgumentException(
assertTrue(CurvedGeometries.isCircle(hole)); CircularArc arc = hole.getArcN(0); assertEquals(5, arc.getRadius(), 0d);
@Test public void testInsertCurvePolygon() throws Exception { String xml = IOUtils.toString(getClass().getResourceAsStream("insertCurvePolygon.xml")); Document dom = postAsDOM("wfs", xml); // print(dom); checkSuccesfulTransaction(dom, 1, 0, 0); SimpleFeature first = getSingleFeature(CURVEPOLYGONS, "Circle2"); Geometry g = (Geometry) first.getDefaultGeometry(); assertNotNull(g); assertTrue(g instanceof Polygon); Polygon p = (Polygon) g; assertEquals(0, p.getNumInteriorRing()); // exterior ring checks assertTrue(p.getExteriorRing() instanceof CircularRing); CircularRing shell = (CircularRing) p.getExteriorRing(); assertTrue(CurvedGeometries.isCircle(shell)); CircularArc arc = shell.getArcN(0); assertEquals(5, arc.getRadius(), 0d); assertEquals(new Coordinate(15, 50), arc.getCenter()); }