/** * Converts a <code>Polygon</code> to <Polygon Text> format, then * appends it to the writer. * *@param polygon the <code>Polygon</code> to process *@param writer the output writer to append to */ private void appendPolygonText(Polygon polygon, int level, boolean indentFirst, Writer writer) throws IOException { if (polygon.isEmpty()) { writer.write("EMPTY"); } else { if (indentFirst) indent(level, writer); writer.write("("); appendLineStringText(polygon.getExteriorRing(), level, false, writer); for (int i = 0; i < polygon.getNumInteriorRing(); i++) { writer.write(", "); appendLineStringText(polygon.getInteriorRingN(i), level + 1, true, writer); } writer.write(")"); } }
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; }
public static boolean containsPointInPolygon(Coordinate p, Polygon poly) { if (poly.isEmpty()) return false; LinearRing shell = (LinearRing) poly.getExteriorRing(); if (! isPointInRing(p, shell)) return false; // now test if the point lies in or on the holes for (int i = 0; i < poly.getNumInteriorRing(); i++) { LinearRing hole = (LinearRing) poly.getInteriorRingN(i); if (isPointInRing(p, hole)) return false; } return true; }
private int locate(Coordinate p, Polygon poly) { if (poly.isEmpty()) return Location.EXTERIOR; LinearRing shell = (LinearRing) poly.getExteriorRing(); int shellLoc = locateInPolygonRing(p, shell); if (shellLoc == Location.EXTERIOR) return Location.EXTERIOR; if (shellLoc == Location.BOUNDARY) return Location.BOUNDARY; // now test if the point lies in or on the holes for (int i = 0; i < poly.getNumInteriorRing(); i++) { LinearRing hole = (LinearRing) poly.getInteriorRingN(i); int holeLoc = locateInPolygonRing(p, hole); if (holeLoc == Location.INTERIOR) return Location.EXTERIOR; if (holeLoc == Location.BOUNDARY) return Location.BOUNDARY; } return Location.INTERIOR; }
private Polygon editPolygon(Polygon polygon, GeometryEditorOperation operation) { Polygon newPolygon = (Polygon) operation.edit(polygon, factory); // create one if needed if (newPolygon == null) newPolygon = factory.createPolygon((CoordinateSequence) null); if (newPolygon.isEmpty()) { //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino] return newPolygon; } LinearRing shell = (LinearRing) edit(newPolygon.getExteriorRing(), operation); if (shell == null || shell.isEmpty()) { //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino] return factory.createPolygon(null, null); } ArrayList holes = new ArrayList(); for (int i = 0; i < newPolygon.getNumInteriorRing(); i++) { LinearRing hole = (LinearRing) edit(newPolygon.getInteriorRingN(i), operation); if (hole == null || hole.isEmpty()) { continue; } holes.add(hole); } return factory.createPolygon(shell, (LinearRing[]) holes.toArray(new LinearRing[] { })); }
/** * Computes the boundary of this geometry * * @return a lineal geometry (which may be empty) * @see Geometry#getBoundary */ public Geometry getBoundary() { if (isEmpty()) { return getFactory().createMultiLineString(null); } LinearRing[] rings = new LinearRing[holes.length + 1]; rings[0] = shell; for (int i = 0; i < holes.length; i++) { rings[i + 1] = holes[i]; } // create LineString or MultiLineString as appropriate if (rings.length <= 1) return getFactory().createLinearRing(rings[0].getCoordinateSequence()); return getFactory().createMultiLineString(rings); }
public boolean isEmpty() { return polygon.isEmpty(); }
/** * Simplifies a polygon, fixing it if required. */ protected Geometry transformPolygon(Polygon geom, Geometry parent) { // empty geometries are simply removed if (geom.isEmpty()) return null; Geometry rawGeom = super.transformPolygon(geom, parent); // don't try and correct if the parent is going to do this if (parent instanceof MultiPolygon) { return rawGeom; } return createValidArea(rawGeom); }
/** * Simplifies a polygon, fixing it if required. */ protected Geometry transformPolygon(Polygon geom, Geometry parent) { // empty geometries are simply removed if (geom.isEmpty()) return null; Geometry rawGeom = super.transformPolygon(geom, parent); // don't try and correct if the parent is going to do this if (parent instanceof MultiPolygon) { return rawGeom; } return createValidArea(rawGeom); }
/** * Converts a <code>Polygon</code> to <Polygon Text> format, then * appends it to the writer. * *@param polygon the <code>Polygon</code> to process *@param writer the output writer to append to */ private void appendPolygonText(Polygon polygon, int level, boolean indentFirst, Writer writer) throws IOException { if (polygon.isEmpty()) { writer.write("EMPTY"); } else { if (indentFirst) indent(level, writer); writer.write("("); appendLineStringText(polygon.getExteriorRing(), level, false, writer); for (int i = 0; i < polygon.getNumInteriorRing(); i++) { writer.write(", "); appendLineStringText(polygon.getInteriorRingN(i), level + 1, true, writer); } writer.write(")"); } }
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; }
public static Area toShape(Polygon polygon, CoordinateState state) { if (!polygon.isEmpty()) { Area exterior = getArea(polygon.getExteriorRing(), state); for (int i = 0; i < polygon.getNumInteriorRing(); i++) { Area interior = getArea(polygon.getInteriorRingN(i), state); exterior.subtract(interior); } return exterior; } return new Area(); }
if(!polygon.isEmpty() && polygon.isValid()) { for(String ppId : (List<String>)cityesIndex.query(polygon.getEnvelopeInternal())) { JSONObject pp = getCityById(ppId);
public static boolean containsPointInPolygon(Coordinate p, Polygon poly) { if (poly.isEmpty()) return false; LinearRing shell = (LinearRing) poly.getExteriorRing(); if (! isPointInRing(p, shell)) return false; // now test if the point lies in or on the holes for (int i = 0; i < poly.getNumInteriorRing(); i++) { LinearRing hole = (LinearRing) poly.getInteriorRingN(i); if (isPointInRing(p, hole)) return false; } return true; }
private static MultiPolygon substract(MultiPolygon outer, MultiPolygon inner) { List<Polygon> polygons = new ArrayList<Polygon>(); if(inner != null && !inner.isEmpty()) { for(int j = 0; j < outer.getNumGeometries(); j++) { Polygon outerN = (Polygon) outer.getGeometryN(j); for(int i = 0; i < inner.getNumGeometries(); i++) { Polygon innerN = (Polygon) inner.getGeometryN(i); if(outerN.intersects(innerN)) { outerN = (Polygon) outerN.difference(innerN); } } if(!outerN.isEmpty()) { polygons.add(outerN); } } } Polygon[] ps = polygons.toArray(new Polygon[polygons.size()]); MultiPolygon mp = geometryFactory.createMultiPolygon(ps); if(mp.isValid()) { return mp; } return null; }
private int locate(Coordinate p, Polygon poly) { if (poly.isEmpty()) return Location.EXTERIOR; LinearRing shell = (LinearRing) poly.getExteriorRing(); int shellLoc = locateInPolygonRing(p, shell); if (shellLoc == Location.EXTERIOR) return Location.EXTERIOR; if (shellLoc == Location.BOUNDARY) return Location.BOUNDARY; // now test if the point lies in or on the holes for (int i = 0; i < poly.getNumInteriorRing(); i++) { LinearRing hole = (LinearRing) poly.getInteriorRingN(i); int holeLoc = locateInPolygonRing(p, hole); if (holeLoc == Location.INTERIOR) return Location.EXTERIOR; if (holeLoc == Location.BOUNDARY) return Location.BOUNDARY; } return Location.INTERIOR; }
private Polygon editPolygon(Polygon polygon, GeometryEditorOperation operation) { Polygon newPolygon = (Polygon) operation.edit(polygon, factory); // create one if needed if (newPolygon == null) newPolygon = factory.createPolygon((CoordinateSequence) null); if (newPolygon.isEmpty()) { //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino] return newPolygon; } LinearRing shell = (LinearRing) edit(newPolygon.getExteriorRing(), operation); if (shell == null || shell.isEmpty()) { //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino] return factory.createPolygon(null, null); } ArrayList holes = new ArrayList(); for (int i = 0; i < newPolygon.getNumInteriorRing(); i++) { LinearRing hole = (LinearRing) edit(newPolygon.getInteriorRingN(i), operation); if (hole == null || hole.isEmpty()) { continue; } holes.add(hole); } return factory.createPolygon(shell, (LinearRing[]) holes.toArray(new LinearRing[] { })); }
if (!intersection.isEmpty()) { String neighbourId = neighbours.get(neighbourPolygon .getUserData());
/** * Computes the boundary of this geometry * * @return a lineal geometry (which may be empty) * @see Geometry#getBoundary */ public Geometry getBoundary() { if (isEmpty()) { return getFactory().createMultiLineString(null); } LinearRing[] rings = new LinearRing[holes.length + 1]; rings[0] = shell; for (int i = 0; i < holes.length; i++) { rings[i + 1] = holes[i]; } // create LineString or MultiLineString as appropriate if (rings.length <= 1) return getFactory().createLinearRing(rings[0].getCoordinateSequence()); return getFactory().createMultiLineString(rings); }
@Override public double[][][] createCoordinates(Polygon polygon) throws MarshallException { if (polygon == null) { return null; } else if (polygon.isEmpty()) { return new double[0][0][0]; } else { int numberOfPoints = polygon.getExteriorRing().getNumPoints(); double[][][] coordinates = new double[1 + polygon.getNumInteriorRing()][numberOfPoints][]; for (int index = 0; index < numberOfPoints; index++) { coordinates[0][index] = pointConverter.createCoordinates(polygon .getExteriorRing() .getPointN(index)); } for (int i = 0; i < polygon.getNumInteriorRing(); i++) { LineString interiorRingN = polygon.getInteriorRingN(i); double[][] holeCoordinates = new double[interiorRingN.getNumPoints()][]; for (int j = 0; j < interiorRingN.getNumPoints(); j++) { holeCoordinates[j] = pointConverter.createCoordinates(interiorRingN.getPointN(j)); } coordinates[i + 1] = holeCoordinates; } return coordinates; } }