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; }
private GeometryCollection readGeometryCollection() throws IOException, ParseException { int numGeom = dis.readInt(); Geometry[] geoms = new Geometry[numGeom]; for (int i = 0; i < numGeom; i++) { geoms[i] = readGeometry(); } return factory.createGeometryCollection(geoms); }
/** * Creates a <code>Polygon</code> using the next token in the stream. * * @return a <code>Polygon</code> specified by the next token in the stream * @throws ParseException if the coordinates used to create the <code>Polygon</code> shell and * holes do not form closed linestrings, or if an unexpected token was encountered. * @throws IOException if an I/O error occurs */ private Polygon readPolygonText() throws IOException, ParseException { String nextToken = getNextEmptyOrOpener(); if (nextToken.equals(EMPTY)) { return geometryFactory.createPolygon( geometryFactory.createLinearRing(new Coordinate[] {}), new LinearRing[] {}); } ArrayList holes = new ArrayList(); LinearRing shell = readLinearRingText(); nextToken = getNextCloserOrComma(); while (nextToken.equals(COMMA)) { LinearRing hole = readLinearRingText(); holes.add(hole); nextToken = getNextCloserOrComma(); } LinearRing[] array = new LinearRing[holes.size()]; return geometryFactory.createPolygon(shell, (LinearRing[]) holes.toArray(array)); }
/** 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)); }
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}); }
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)); }
/** * Casts the provided geometry factory to a curved one if possible, or wraps it into one with * infinite tolerance (the linearization will happen using the default base segments number set * in {@link CircularArc} * * @param gf * @return */ private static CurvedGeometryFactory getCurvedGeometryFactory(GeometryFactory gf) { CurvedGeometryFactory curvedFactory; if (gf instanceof CurvedGeometryFactory) { curvedFactory = (CurvedGeometryFactory) gf; } else { curvedFactory = new CurvedGeometryFactory(gf, Double.MAX_VALUE); } return curvedFactory; }
private LineString readCompoundCurveText() throws IOException, ParseException { List<LineString> lineStrings = getLineStrings(); return geometryFactory.createCurvedGeometry(lineStrings); }
ring = (LinearRing) gf.createCurvedGeometry(components); } else if (INTERPRETATION == 1) { CoordinateSequence coordSeq = subList( gf.getCoordinateSequenceFactory(), coords, GTYPE, coordSeq = CoordinateSequences.ensureValidRing( gf.getCoordinateSequenceFactory(), coordSeq); ring = gf.createLinearRing(coordSeq); } else if (INTERPRETATION == 2) { CoordinateSequence coordSeq = subList( gf.getCoordinateSequenceFactory(), coords, GTYPE, ring = (LinearRing) gf.createCurvedGeometry(coordSeq); } else if (INTERPRETATION == 3) { gf.getCoordinateSequenceFactory(), coords, GTYPE, Coordinate max = ext.getCoordinate(1); ring = gf.createLinearRing(
CoordinateSequence subList = subList( gf.getCoordinateSequenceFactory(), coords, GTYPE, triplet, compoundElement); result = gf.createLineString(subList); } else if (etype == ETYPE.LINE && INTERPRETATION == 2) { CoordinateSequence subList = subList( gf.getCoordinateSequenceFactory(), coords, GTYPE, triplet, compoundElement); result = gf.createCurvedGeometry(subList); } else if (etype == ETYPE.COMPOUND) { int triplets = INTERPRETATION; components.add(component); result = gf.createCurvedGeometry(components); } else { throw new IllegalArgumentException(
/** * Extracts a {@link CurvedGeometryFactory} from the provided geometry, either by just returning * the one that is held by the geometry, if consistent with its tolerance, or by creating a new * one * * @param curved * @return */ public static CurvedGeometryFactory getFactory(CurvedGeometry<?> curved) { GeometryFactory factory = ((Geometry) curved).getFactory(); if (factory instanceof CurvedGeometryFactory) { CurvedGeometryFactory cf = (CurvedGeometryFactory) factory; if (cf.getTolerance() == curved.getTolerance()) { return cf; } } return new CurvedGeometryFactory(factory, curved.getTolerance()); } }
protected Polygon readCurvePolygon() throws IOException, ParseException { int numRings = dis.readInt(); LinearRing[] holes = null; if (numRings > 1) holes = new LinearRing[numRings - 1]; LinearRing shell = readRing(); for (int i = 0; i < numRings - 1; i++) { holes[i] = readRing(); } return factory.createPolygon(shell, holes); }
/** * Creates a <code>MultiLineString</code> using the next token in the stream. * * @return a <code>MultiLineString</code> specified by the next token in the stream * @throws IOException if an I/O error occurs * @throws ParseException if an unexpected token was encountered */ private org.locationtech.jts.geom.MultiLineString readMultiLineStringText() throws IOException, ParseException { String nextToken = getNextEmptyOrOpener(); if (nextToken.equals(EMPTY)) { return geometryFactory.createMultiLineString(new LineString[] {}); } ArrayList lineStrings = new ArrayList(); LineString lineString = readLineStringText(); lineStrings.add(lineString); nextToken = getNextCloserOrComma(); while (nextToken.equals(COMMA)) { lineString = readLineStringText(); lineStrings.add(lineString); nextToken = getNextCloserOrComma(); } LineString[] array = new LineString[lineStrings.size()]; return geometryFactory.createMultiLineString((LineString[]) lineStrings.toArray(array)); }
/** * Creates a <code>LineString</code> using the next token in the stream, the provided dimension * and measures will be used to create the <code>LineString</code>. */ private LineString readLineStringText(int dimension, int measures) throws IOException, ParseException { if (measures == 0) { // default situation, capable of handle elevations but no measures return geometryFactory.createLineString(getCoordinates()); } // handle linestring subtypes with measures (elevation and measures) return geometryFactory.createLineString( buildCoordinateSequence(getCoordinates(true), dimension, measures)); }
/** * Creates a <code>MultiPolygon</code> using the next token in the stream. * * @return a <code>MultiPolygon</code> specified by the next token in the stream, or if if the * coordinates used to create the <code>Polygon</code> shells and holes do not form closed * linestrings. * @throws IOException if an I/O error occurs * @throws ParseException if an unexpected token was encountered */ private MultiPolygon readMultiPolygonText() throws IOException, ParseException { String nextToken = getNextEmptyOrOpener(); if (nextToken.equals(EMPTY)) { return geometryFactory.createMultiPolygon(new Polygon[] {}); } ArrayList polygons = new ArrayList(); Polygon polygon = readPolygonText(); polygons.add(polygon); nextToken = getNextCloserOrComma(); while (nextToken.equals(COMMA)) { polygon = readPolygonText(); polygons.add(polygon); nextToken = getNextCloserOrComma(); } Polygon[] array = new Polygon[polygons.size()]; return geometryFactory.createMultiPolygon((Polygon[]) polygons.toArray(array)); }
/** * Creates a <code>LinearRing</code> using the next token in the stream. * * @return a <code>LinearRing</code> specified by the next token in the stream * @throws IOException if an I/O error occurs * @throws ParseException if the coordinates used to create the <code>LinearRing</code> do not * form a closed linestring, or if an unexpected token was encountered */ private LinearRing readLinearRingText() throws IOException, ParseException { return geometryFactory.createLinearRing(getCoordinates()); }
private Polygon readCurvePolygonText() throws IOException, ParseException { String nextToken = getNextEmptyOrOpener(); if (nextToken.equals(EMPTY)) { return geometryFactory.createCurvePolygon( geometryFactory.createLinearRing(new Coordinate[] {}), new LinearRing[] {}); } if (!nextToken.equals(L_PAREN)) { parseError("Ring expected"); } LinearRing shell = readCurvedLinearRingText(); ArrayList holes = new ArrayList(); nextToken = getNextCloserOrComma(); while (nextToken.equals(COMMA)) { LinearRing hole = readCurvedLinearRingText(); holes.add(hole); nextToken = getNextCloserOrComma(); } LinearRing[] array = new LinearRing[holes.size()]; return geometryFactory.createCurvePolygon(shell, (LinearRing[]) holes.toArray(array)); }
/** * Creates an array of <code>Point</code>s having the given <code>Coordinate</code> s. * * @param coordinates the <code>Coordinate</code>s with which to create the <code>Point</code>s * @return <code>Point</code>s created using this <code>WKTReader</code> s <code>GeometryFactory * </code> */ private Point[] toPoints(Coordinate[] coordinates) { ArrayList points = new ArrayList(); for (int i = 0; i < coordinates.length; i++) { points.add(geometryFactory.createPoint(coordinates[i])); } return (Point[]) points.toArray(new Point[] {}); }
/** * Creates a <code>MultiPoint</code> using the next token in the stream. * * @return a <code>MultiPoint</code> specified by the next token in the stream * @throws IOException if an I/O error occurs * @throws ParseException if an unexpected token was encountered */ private MultiPoint readMultiPointText() throws IOException, ParseException { return geometryFactory.createMultiPoint(toPoints(getCoordinatesForMultiPoint())); }
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)); }