/** Creates a compound curve with the given components */ public LineString createCurvedGeometry(LineString... components) { if (components == null) { // return an empty lineString? return createLineString(new Coordinate[] {}); } return createCurvedGeometry(Arrays.asList(components)); }
private LineString readCompoundCurveText() throws IOException, ParseException { List<LineString> lineStrings = getLineStrings(); return geometryFactory.createCurvedGeometry(lineStrings); }
private Geometry readCircularString() throws IOException { int size = dis.readInt(); CoordinateSequence pts = readCoordinateSequenceCircularString(size); return factory.createCurvedGeometry(pts); }
private Geometry readCompoundCurve() throws IOException, ParseException { int numGeom = dis.readInt(); List<LineString> geoms = new ArrayList<>(); for (int i = 0; i < numGeom; i++) { Geometry g = readGeometry(); if (!(g instanceof LineString)) throw new ParseException(INVALID_GEOM_TYPE_MSG + "CompoundCurve"); geoms.add((LineString) g); } return factory.createCurvedGeometry(geoms); }
/** * Creates a <code>LineString</code> using the next token in the stream. * * @return * @throws IOException * @throws ParseException */ private LineString readCircularStringText() throws IOException, ParseException { List<Coordinate> coordinates = getCoordinateList(true); if (coordinates.size() == 0) { return geometryFactory.createCurvedGeometry( new LiteCoordinateSequence(new Coordinate[0])); } else if (coordinates.size() < 3) { throw new ParseException("A CIRCULARSTRING must contain at least 3 control points"); } else { double[] controlPoints = toControlPoints(coordinates); return geometryFactory.createCurvedGeometry(2, controlPoints); } }
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); } }
@Override public Object parse(ElementInstance instance, Node node, Object value) throws Exception { List children = node.getChildren("curveMember"); List<LineString> components = new ArrayList<>(); for (Iterator it = children.iterator(); it.hasNext(); ) { Node child = (Node) it.next(); if (child.getValue() instanceof LineString) { LineString ls = (LineString) child.getValue(); components.add(ls); } } if (components.isEmpty()) { return gFactory.createLineString(new Coordinate[0]); } else { CoordinateSequence cs = components.get(0).getCoordinateSequence(); CurvedGeometryFactory factory = GML3ParsingUtils.getCurvedGeometryFactory(arcParameters, gFactory, cs); return factory.createCurvedGeometry(components); } }
public static Polygon curvePolygon() { LineString curve1 = gf.createCurvedGeometry(2, 0, 0, 2, 0, 2, 1, 2, 3, 4, 3); LineString line1 = gf.createLineString(new LiteCoordinateSequence(4, 3, 4, 5, 1, 4, 0, 0)); LinearRing shell = (LinearRing) gf.createCurvedGeometry(Arrays.asList(curve1, line1)); LinearRing hole = (LinearRing) gf.createCurvedGeometry(2, 1.7, 1, 1.4, 0.4, 1.6, 0.4, 1.6, 0.5, 1.7, 1); return gf.createPolygon(shell, new LinearRing[] {hole}); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { LineString[] segments = (LineString[]) node.getChildValue("segments"); if (segments.length == 0) { return null; } else if (segments.length == 1) { return segments[0]; } else { LineString curved = null; for (LineString ls : segments) { if (ls instanceof CurvedGeometry<?>) { curved = ls; } } CurvedGeometryFactory factory = GML3ParsingUtils.getCurvedGeometryFactory( arcParameters, gf, curved != null ? curved.getCoordinateSequence() : null); return factory.createCurvedGeometry(Arrays.asList(segments)); } }
public static LineString compoundCurve() { CurvedGeometryFactory factory = new CurvedGeometryFactory(0.1); LineString curve = factory.createCurvedGeometry( new LiteCoordinateSequence(1, 1, 2, 2, 3, 1, 5, 5, 7, 3)); LineString straight = factory.createLineString(new LiteCoordinateSequence(7, 3, 10, 15)); LineString compound = factory.createCurvedGeometry(curve, straight); return compound; }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { LineString arcLineString = GML3ParsingUtils.lineString(node, gFactory, csFactory); CoordinateSequence cs = arcLineString.getCoordinateSequence(); if (cs.size() < 3) { // maybe log this instead and return null throw new RuntimeException( "Number of coordinates in an arc string must be at least 3, " + cs.size() + " were specified: " + arcLineString); } CurvedGeometryFactory factory = GML3ParsingUtils.getCurvedGeometryFactory(arcParameters, gFactory, cs); return factory.createCurvedGeometry(cs); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ @Override public Object parse(ElementInstance instance, Node node, Object value) throws Exception { LineString arcLineString = GML3ParsingUtils.lineString(node, gFactory, csFactory); CoordinateSequence cs = arcLineString.getCoordinateSequence(); if (cs.size() < 3) { // maybe log this instead and return null throw new RuntimeException( "Number of coordinates in an arc string must be at least 3, " + cs.size() + " were specified: " + arcLineString); } CurvedGeometryFactory factory = GML3ParsingUtils.getCurvedGeometryFactory(arcParameters, gFactory, cs); return factory.createCurvedGeometry(cs); } }
Coordinate end = lastGeom.getCoordinateN((lastGeom.getNumPoints() - 1)); components.add(factory.createLineString(new Coordinate[] {start, end})); ls = factory.createCurvedGeometry(components); } else { Coordinate start = ls.getCoordinateN(0); ls = factory.createCurvedGeometry(ls, closer);
@Test public void testFlipAxisOnCurved() throws Exception { CircularString cs = (CircularString) new CurvedGeometryFactory(0.1).createCurvedGeometry(2, 0, 1, 1, 2, 2, 1); GeometryCoordinateSequenceTransformer transformer = new GeometryCoordinateSequenceTransformer(); CoordinateReferenceSystem crsLatLon = CRS.decode("urn:ogc:def:crs:EPSG:4326"); CoordinateReferenceSystem crsLonLat = CRS.decode("EPSG:4326", true); transformer.setCoordinateReferenceSystem(crsLatLon); MathTransform trans = CRS.findMathTransform(crsLonLat, crsLatLon); transformer.setMathTransform(trans); Geometry transformed = transformer.transform(cs); assertTrue(transformed instanceof CircularString); CircularString tcs = (CircularString) transformed; assertArrayEquals(new double[] {1, 0, 2, 1, 1, 2}, tcs.getControlPoints(), 0d); }
public void testEncodeSimple() throws Exception { LineString curve = new CurvedGeometryFactory(0.1) .createCurvedGeometry( new LiteCoordinateSequence( new double[] {1, 1, 2, 2, 3, 1, 5, 5, 7, 3})); Document dom = encode(curve, GML.curveProperty); // print(dom); XpathEngine xpath = XMLUnit.newXpathEngine(); String basePath = "/gml:curveProperty/gml:Curve/gml:segments/gml:ArcString"; assertEquals( 1, xpath.getMatchingNodes(basePath + "[@interpolation='circularArc3Points']", dom) .getLength()); assertEquals("1 1 2 2 3 1 5 5 7 3", xpath.evaluate(basePath + "/gml:posList", dom)); }
public void testEncodeCurve() throws Exception { LineString curve = new CurvedGeometryFactory(0.1) .createCurvedGeometry( new LiteCoordinateSequence( new double[] {1, 1, 2, 2, 3, 1, 5, 5, 7, 3})); Document dom = encode(curve, GML.geometryMember); // print(dom); XpathEngine xpath = XMLUnit.newXpathEngine(); String basePath = "/gml:geometryMember/gml:Curve/gml:segments/gml:ArcString"; assertEquals( 1, xpath.getMatchingNodes(basePath + "[@interpolation='circularArc3Points']", dom) .getLength()); assertEquals("1 1 2 2 3 1 5 5 7 3", xpath.evaluate(basePath + "/gml:posList", dom)); }
public void testEncodeSimple() throws Exception { LineString curve = new CurvedGeometryFactory(0.1) .createCurvedGeometry( new LiteCoordinateSequence( new double[] {1, 1, 2, 2, 3, 1, 5, 5, 7, 3})); Document dom = encode(curve, GML.curveProperty); // print(dom); XpathEngine xpath = XMLUnit.newXpathEngine(); String basePath = "/gml:curveProperty/gml:Curve/gml:segments/gml:ArcString"; assertEquals( 1, xpath.getMatchingNodes(basePath + "[@interpolation='circularArc3Points']", dom) .getLength()); assertEquals("1 1 2 2 3 1 5 5 7 3", xpath.evaluate(basePath + "/gml:posList", dom)); }
@Test public void testFullTransformOnCurved() throws Exception { CircularString cs = (CircularString) new CurvedGeometryFactory(0.1).createCurvedGeometry(2, 0, 1, 1, 2, 2, 1); GeometryCoordinateSequenceTransformer transformer = new GeometryCoordinateSequenceTransformer(); CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:3857"); CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326", true); transformer.setCoordinateReferenceSystem(targetCRS); MathTransform trans = CRS.findMathTransform(sourceCRS, targetCRS); transformer.setMathTransform(trans); Geometry transformed = transformer.transform(cs); assertFalse(transformed instanceof CircularString); LineString ls = (LineString) transformed; assertTrue(ls.getCoordinateSequence().size() > 3); }
public void testEncodeCompound() throws Exception { // create a compound curve CurvedGeometryFactory factory = new CurvedGeometryFactory(0.1); LineString curve = factory.createCurvedGeometry( new LiteCoordinateSequence(1, 1, 2, 2, 3, 1, 5, 5, 7, 3)); LineString straight = factory.createLineString(new LiteCoordinateSequence(7, 3, 10, 15)); LineString compound = factory.createCurvedGeometry(curve, straight); // encode Document dom = encode(compound, GML.curveProperty); // print(dom); XpathEngine xpath = XMLUnit.newXpathEngine(); // the curve portion String basePath1 = "/gml:curveProperty/gml:Curve/gml:segments/gml:ArcString"; assertEquals( 1, xpath.getMatchingNodes(basePath1 + "[@interpolation='circularArc3Points']", dom) .getLength()); assertEquals("1 1 2 2 3 1 5 5 7 3", xpath.evaluate(basePath1 + "/gml:posList", dom)); // the straight portion String basePath2 = "/gml:curveProperty/gml:Curve/gml:segments/gml:LineStringSegment"; assertEquals( 1, xpath.getMatchingNodes(basePath2 + "[@interpolation='linear']", dom).getLength()); assertEquals("7 3 10 15", xpath.evaluate(basePath2 + "/gml:posList", dom)); } }
public void testEncodeCompound() throws Exception { // create a compound curve CurvedGeometryFactory factory = new CurvedGeometryFactory(0.1); LineString curve = factory.createCurvedGeometry( new LiteCoordinateSequence(1, 1, 2, 2, 3, 1, 5, 5, 7, 3)); LineString straight = factory.createLineString(new LiteCoordinateSequence(7, 3, 10, 15)); LineString compound = factory.createCurvedGeometry(curve, straight); // encode Document dom = encode(compound, GML.curveProperty); // print(dom); XpathEngine xpath = XMLUnit.newXpathEngine(); // the curve portion String basePath1 = "/gml:curveProperty/gml:Curve/gml:segments/gml:ArcString"; assertEquals( 1, xpath.getMatchingNodes(basePath1 + "[@interpolation='circularArc3Points']", dom) .getLength()); assertEquals("1 1 2 2 3 1 5 5 7 3", xpath.evaluate(basePath1 + "/gml:posList", dom)); // the straight portion String basePath2 = "/gml:curveProperty/gml:Curve/gml:segments/gml:LineStringSegment"; assertEquals( 1, xpath.getMatchingNodes(basePath2 + "[@interpolation='linear']", dom).getLength()); assertEquals("7 3 10 15", xpath.evaluate(basePath2 + "/gml:posList", dom)); } }