/** * Lossy conversion to a GraphHopper Polygon. */ public static Polygon create(org.locationtech.jts.geom.Polygon polygon) { double[] lats = new double[polygon.getNumPoints()]; double[] lons = new double[polygon.getNumPoints()]; for (int i = 0; i < polygon.getNumPoints(); i++) { lats[i] = polygon.getCoordinates()[i].y; lons[i] = polygon.getCoordinates()[i].x; } return new Polygon(lats, lons); }
public Coordinate[] getCoordinates() { return polygon.getCoordinates(); }
Coordinate[] coords = polygon.getCoordinates();
private static MultiPoint convertToMultiPoint(final Polygon pt){ return GF.createMultiPoint(pt.getCoordinates()); }
private static LineString convertToLineString(final Polygon pt){ return GF.createLineString(pt.getCoordinates()); }
/** * Lossy conversion to a GraphHopper Polygon. */ public static Polygon create(org.locationtech.jts.geom.Polygon polygon) { double[] lats = new double[polygon.getNumPoints()]; double[] lons = new double[polygon.getNumPoints()]; for (int i = 0; i < polygon.getNumPoints(); i++) { lats[i] = polygon.getCoordinates()[i].y; lons[i] = polygon.getCoordinates()[i].x; } return new Polygon(lats, lons); }
private static MultiLineString convertToMultiLineString(final Polygon pt){ return convertToMultiLineString(GF.createLineString(pt.getCoordinates())); }
private static int[] getTilingSchemeBoundingBox(int z, Geometry geometry) { Geometry geometryEnvelope = geometry.getEnvelope(); if (geometryEnvelope instanceof Polygon) { Polygon polygon = (Polygon) geometryEnvelope; Coordinate[] coordinates = polygon.getCoordinates(); int minx = Integer.MAX_VALUE; int maxx = Integer.MIN_VALUE; int miny = Integer.MAX_VALUE; int maxy = Integer.MIN_VALUE; for (int i = 0; i < coordinates.length - 1; i++) { Coordinate coordinate = coordinates[i]; int[] tilecoords = CoordinateConversion.toTileCoordinates(new double[]{ coordinate.y, coordinate.x}, z); minx = Math.min(minx, tilecoords[1]); maxx = Math.max(maxx, tilecoords[1]); miny = Math.min(miny, tilecoords[2]); maxy = Math.max(maxy, tilecoords[2]); } return new int[]{minx, miny, maxx, maxy}; } else if (geometryEnvelope instanceof Point) { // TODO design out Point point = (Point) geometryEnvelope; int[] tilecoords = CoordinateConversion.toTileCoordinates(new double[]{ point.getCoordinate().y, point.getCoordinate().x}, z); return new int[]{tilecoords[1], tilecoords[2], tilecoords[1], tilecoords[2]}; } throw new IllegalArgumentException("unsupported geometry type"); }
final Polygon polygon = (Polygon) geometry; final List<List<Double>> points = new ArrayList<>(); for (final Coordinate coordinate : polygon.getCoordinates()) { points.add(ImmutableList.of(coordinate.x, coordinate.y));
public void testPolygonGetCoordinates() throws Exception { Polygon p = (Polygon) reader.read( "POLYGON ( (0 0, 100 0, 100 100, 0 100, 0 0), " + " (20 20, 20 80, 80 80, 80 20, 20 20)) "); Coordinate[] coordinates = p.getCoordinates(); assertEquals(10, p.getNumPoints()); assertEquals(10, coordinates.length); assertEquals(new Coordinate(0, 0), coordinates[0]); assertEquals(new Coordinate(20, 20), coordinates[9]); }
Polygon polygon = (Polygon) geometry; builder.setType(Geobuf.Data.Geometry.Type.POLYGON); Coordinate[] coords = polygon.getCoordinates(); addCoords(builder, coords); } else if (geometry instanceof MultiPoint) {
assertEquals(0, (geometryFactory.createLinearRing((CoordinateSequence)null)).getCoordinates().length); assertEquals(0, (geometryFactory.createLineString((Coordinate[])null)).getCoordinates().length); assertEquals(0, (geometryFactory.createPolygon(null, null)).getCoordinates().length); assertEquals(0, (geometryFactory.createMultiPolygon(null)).getCoordinates().length); assertEquals(0, (geometryFactory.createMultiLineString(null)).getCoordinates().length);