public static PointList fromLineString(LineString lineString) { final PointList pointList = new PointList(); for (Coordinate coordinate : lineString.getCoordinates()) { pointList.add(new GHPoint(coordinate.y, coordinate.x)); } return pointList; }
public static PointList from(LineString lineString) { final PointList pointList = new PointList(); for (Coordinate coordinate : lineString.getCoordinates()) { pointList.add(new GHPoint(coordinate.y, coordinate.x)); } return pointList; }
throw new IllegalStateException("no maximum polygon was found?"); } else { polygonShells.add(maxPolygon.getExteriorRing().getCoordinates());
public Coordinate[] getCoordinates() { return lineString.getCoordinates(); }
/** simple linestring merge - l1 points then l2 points */ private LineString mergeSimple(LineString l1, LineString l2) { List<Coordinate> clist = new ArrayList<Coordinate>(Arrays.asList(l1.getCoordinates())); clist.addAll(Arrays.asList(l2.getCoordinates())); return l1.getFactory().createLineString(clist.toArray(new Coordinate[1])); }
public Coordinate[] getCoordinates() { return linearize().getCoordinates(); }
public Coordinate[] getCoordinates() { return linearize().getCoordinates(); }
/** reverse direction of points in a line */ private LineString reverse(LineString l) { List<Coordinate> clist = Arrays.asList(l.getCoordinates()); Collections.reverse(clist); return l.getFactory().createLineString(clist.toArray(new Coordinate[1])); }
/** * Returns the perimeter of a LineString. * * @param lineString the LineString for which the perimeter is calculated. * @return the perimeter (length) of the lineString. */ protected double getPerimeter(LineString lineString) { double perimeter = 0.0d; int numberOfPoints = lineString.getNumPoints(); Coordinate[] coordinates = lineString.getCoordinates(); for (int i = 0; i < (numberOfPoints - 1); i++) { perimeter += coordinates[i].distance(coordinates[i + 1]); } return perimeter; } }
/** * Given the portion of the linestring associated with the label and label metrics, this method * will compute a proper underline. * * @param lineOffset TODO */ private LiteShape computeCurvedLine(LineString labelLineString, float lineOffset) { Coordinate[] coordinates = labelLineString.getCoordinates(); Coordinate[] parallelCoordinates = new Coordinate[coordinates.length]; double anchorOffset = getLinePlacementYAnchor() * getLineHeight(); for (int i = 0; i < coordinates.length - 1; i++) { // let's compute some basic info for the current segment Coordinate coordinateA = coordinates[i]; Coordinate coordinateB = coordinates[i + 1]; double dx = coordinateB.x - coordinateA.x; double dy = coordinateB.y - coordinateA.y; double length = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); double offset = -(anchorOffset + lineOffset); // compute the parallel coordinates double x1 = coordinateA.x + offset * (coordinateB.y - coordinateA.y) / length; double x2 = coordinateB.x + offset * (coordinateB.y - coordinateA.y) / length; double y1 = coordinateA.y + offset * (coordinateA.x - coordinateB.x) / length; double y2 = coordinateB.y + offset * (coordinateA.x - coordinateB.x) / length; parallelCoordinates[i] = new Coordinate(x1, y1); parallelCoordinates[i + 1] = new Coordinate(x2, y2); } // build the parallel linestring and wrap it in a lite shape LineString lineString = labelLineString.getFactory().createLineString(parallelCoordinates); return new LiteShape(lineString, null, true); }
private static TDWay fromLinestring(LineString l, boolean area) { return new MockTDWay(fromCoordinates(l.getCoordinates()), area); } }
Coordinate[] circleCoordinates = circleLineString.getCoordinates(); if (circleCoordinates.length != 3) {
@Test public void lineStringFromOrdinates() throws Exception { double[] ordinates = new double[] {1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 0}; LineString line = builder.lineString(ordinates); Coordinate[] coords = line.getCoordinates(); assertCoordinates(coords, ordinates, 2); }
@Test public void lineStringZFromOrdinates() throws Exception { double[] ordinates = new double[] {1, 2, -3, 4, 5, -6, 7, 8, -9}; LineString line = builder.lineStringZ(ordinates); Coordinate[] coords = line.getCoordinates(); assertCoordinates(coords, ordinates, 3); }
Coordinate[] coordinates = ls.getCoordinates(); List<Coordinate> coordinateList = Arrays.asList(coordinates);
static void encode(Element e, LineString g, PrintHandler output) throws IOException { if ((g == null) || (g.getNumPoints() == 0)) { throw new IOException("Bad LineString Data"); } AttributesImpl ai = getSrsNameAttribute(g); if (e == null) { output.startElement(GMLSchema.NAMESPACE, "LineString", ai); } else { output.startElement(e.getNamespace(), e.getName(), ai); } encodeCoords(null, g.getCoordinates(), output); if (e == null) { output.endElement(GMLSchema.NAMESPACE, "LineString"); } else { output.endElement(e.getNamespace(), e.getName()); } }
/** * Create a nice Polygon from the given Polygon. Will ensure that shells are clockwise and holes * are counter-clockwise. Capiche? * * @param p The Polygon to make "nice". * @return The "nice" Polygon. */ public static final Polygon makeGoodShapePolygon(Polygon p) { GeometryFactory factory = p.getFactory(); LinearRing outer; LinearRing[] holes = new LinearRing[p.getNumInteriorRing()]; Coordinate[] coords; coords = p.getExteriorRing().getCoordinates(); if (CGAlgorithms.isCCW(coords)) { outer = reverseRing((LinearRing) p.getExteriorRing()); } else { outer = (LinearRing) p.getExteriorRing(); } for (int t = 0, tt = p.getNumInteriorRing(); t < tt; t++) { coords = p.getInteriorRingN(t).getCoordinates(); if (!(CGAlgorithms.isCCW(coords))) { holes[t] = reverseRing((LinearRing) p.getInteriorRingN(t)); } else { holes[t] = (LinearRing) p.getInteriorRingN(t); } } return factory.createPolygon(outer, holes); }
List<?> toList(Polygon p) { BasicDBList l = new BasicDBList(); if (!CGAlgorithms.isCCW(p.getExteriorRing().getCoordinates())) { l.add(toList(p.getExteriorRing().reverse().getCoordinates())); } else { l.add(toList(p.getExteriorRing().getCoordinateSequence())); } for (int i = 0; i < p.getNumInteriorRing(); i++) { l.add(toList(p.getInteriorRingN(i).getCoordinateSequence())); } return l; } }
public void testReadLine() throws Exception { SimpleFeatureCollection fc = dataStore.getFeatureSource(tname(getLine3d())).getFeatures(); try (SimpleFeatureIterator fr = fc.features()) { assertTrue(fr.hasNext()); LineString ls = (LineString) fr.next().getDefaultGeometry(); // 1 1 0, 2 2 0, 4 2 1, 5 1 1 assertEquals(4, ls.getCoordinates().length); assertTrue(new Coordinate(1, 1, 0).equals3D(ls.getCoordinateN(0))); assertTrue(new Coordinate(2, 2, 0).equals3D(ls.getCoordinateN(1))); assertTrue(new Coordinate(4, 2, 1).equals3D(ls.getCoordinateN(2))); assertTrue(new Coordinate(5, 1, 1).equals3D(ls.getCoordinateN(3))); } }
public void testBBOX3DReadLine() throws Exception { BBOX3D bbox3d = FF.bbox("", new ReferencedEnvelope3D(2, 3, 1, 2, 0, 1, crs)); SimpleFeatureCollection fc = dataStore.getFeatureSource(tname(getLine3d())).getFeatures(bbox3d); try (SimpleFeatureIterator fr = fc.features()) { assertTrue(fr.hasNext()); LineString ls = (LineString) fr.next().getDefaultGeometry(); // 1 1 0, 2 2 0, 4 2 1, 5 1 1 assertEquals(4, ls.getCoordinates().length); assertTrue(new Coordinate(1, 1, 0).equals3D(ls.getCoordinateN(0))); assertTrue(new Coordinate(2, 2, 0).equals3D(ls.getCoordinateN(1))); assertTrue(new Coordinate(4, 2, 1).equals3D(ls.getCoordinateN(2))); assertTrue(new Coordinate(5, 1, 1).equals3D(ls.getCoordinateN(3))); } }