@Override public int compare(Polygon o1, Polygon o2) { return o2.getNumPoints() - o1.getNumPoints(); } });
/** * 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); }
for (int j = 0; j < multiPolygon.getNumGeometries(); j++) { Polygon polygon = (Polygon) multiPolygon.getGeometryN(j); if (polygon.getNumPoints() > maxPoints) { maxPoints = polygon.getNumPoints(); maxPolygon = polygon;
public int getNumPoints() { return polygon.getNumPoints(); }
for (int i = 0; i < numGeometries; i++) { Polygon polygon = (Polygon) geometry.getGeometryN(i); if (polygon.getNumPoints() > 0) { numParts += polygon.getNumInteriorRing() + 1;
public void testEncode2D() throws Exception { Polygon poly = GML3MockData.polygonLite2D(); Document doc = encode(poly, GML.Polygon); checkDimension(doc, GML.Polygon.getLocalPart(), 2); checkPosListOrdinates(doc, 2 * poly.getNumPoints()); }
public void testEncode3D() throws Exception { Polygon poly = GML3MockData.polygonLite3D(); Document doc = encode(poly, GML.Polygon); checkDimension(doc, GML.Polygon.getLocalPart(), 3); checkPosListOrdinates(doc, 3 * poly.getNumPoints()); }
private static void addElemInfo( List elemInfoList, MultiPolygon polys, final int STARTING_OFFSET, final int GTYPE) { Polygon poly; int offset = STARTING_OFFSET; int LEN = D(GTYPE) + L(GTYPE); for (int i = 0; i < polys.getNumGeometries(); i++) { poly = (Polygon) polys.getGeometryN(i); if (poly != null && !poly.isEmpty()) { addElemInfo(elemInfoList, poly, offset, GTYPE); if (isRectangle(poly)) { offset += (2 * LEN); } else { offset += (poly.getNumPoints() * LEN); } } } }
PolygonNode(Polygon poly, GeometryContext context) { super(poly, poly.getNumPoints(), null, context); this.poly = poly; }
@Override public int compare(Polygon o1, Polygon o2) { return o2.getNumPoints() - o1.getNumPoints(); } });
@Test public void testMakeValid() throws Exception { // An invalid polygon similar to this one // // *----* // | | // *----*----* // | | // *----* // // Will be split into 2 separate polygons through the makeValid method final int[] xPoints = {0, 5, 5, 5, 10, 10, 5, 0}; final int[] yPoints = {0, 0, 5, 10, 10, 5, 5, 5}; final int nPoints = xPoints.length; final Shape shape = new java.awt.Polygon(xPoints, yPoints, nPoints); final LinearRing geom = (LinearRing) JTS.toGeometry(shape); final GeometryFactory factory = new GeometryFactory(); final org.locationtech.jts.geom.Polygon polygon = factory.createPolygon(geom); assertFalse(polygon.isValid()); final List<org.locationtech.jts.geom.Polygon> validPols = JTS.makeValid(polygon, false); assertEquals(2, validPols.size()); org.locationtech.jts.geom.Polygon polygon1 = validPols.get(0); org.locationtech.jts.geom.Polygon polygon2 = validPols.get(1); assertEquals(5, polygon1.getNumPoints()); assertEquals(5, polygon2.getNumPoints()); } }
/** * 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); }
static void encode(Element e, Polygon g, PrintHandler output) throws OperationNotSupportedException, IOException { if ((g == null) || (g.getNumPoints() == 0)) { throw new IOException("Bad Polygon Data");
public Coordinate[] getCoordinates() { if (isEmpty()) { return new Coordinate[]{}; } Coordinate[] coordinates = new Coordinate[getNumPoints()]; int k = -1; Coordinate[] shellCoordinates = shell.getCoordinates(); for (int x = 0; x < shellCoordinates.length; x++) { k++; coordinates[k] = shellCoordinates[x]; } for (int i = 0; i < holes.length; i++) { Coordinate[] childCoordinates = holes[i].getCoordinates(); for (int j = 0; j < childCoordinates.length; j++) { k++; coordinates[k] = childCoordinates[j]; } } return coordinates; }
for (int j = 0; j < multiPolygon.getNumGeometries(); j++) { Polygon polygon = (Polygon) multiPolygon.getGeometryN(j); if (polygon.getNumPoints() > maxPoints) { maxPoints = polygon.getNumPoints(); maxPolygon = polygon;
public Polygon simplify(Polygon p) { //best case is you're going to remove one point, don't bother with the work. //more likely to mess it up! if (p.getNumPoints() <= 5) return p; Envelope bbox = p.getEnvelopeInternal(); //its smaller than a pixel - replace with a polygon representing its bbox if ((bbox.getWidth() <= distance) && (bbox.getWidth() <= distance)) { return createBBoxPolygon(bbox); } DouglasPeuckerSimplifier tss = new DouglasPeuckerSimplifier(p); tss.setDistanceTolerance(distance); tss.setEnsureValid(false); Geometry newGeom = tss.getResultGeometry(); if (newGeom.isEmpty()) return createBBoxPolygon(bbox); // ... sometime the DP simplifier returns linear rings instead of Polygon if (newGeom instanceof LinearRing) return geometryFactory.createPolygon((LinearRing)newGeom); return (Polygon) newGeom; }
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]); }
for (int i = 0; i < numGeometries; i++) { Polygon polygon = (Polygon) geometry.getGeometryN(i); if (polygon.getNumPoints() > 0) { numParts += polygon.getNumInteriorRing() + 1;
for (int i = 0; i < numGeometries; i++) { Polygon polygon = (Polygon) geometry.getGeometryN(i); if (polygon.getNumPoints() > 0) { numParts += polygon.getNumInteriorRing() + 1;
assertEquals(0, (geometryFactory.createLinearRing((CoordinateSequence)null)).getNumPoints()); assertEquals(0, (geometryFactory.createLineString((Coordinate[])null)).getNumPoints()); assertEquals(0, (geometryFactory.createPolygon(null, null)).getNumPoints()); assertEquals(0, (geometryFactory.createMultiPolygon(null)).getNumPoints()); assertEquals(0, (geometryFactory.createMultiLineString(null)).getNumPoints());