Java Code Examples for com.vividsolutions.jts.geom.Geometry#getGeometryN()
The following examples show how to use
com.vividsolutions.jts.geom.Geometry#getGeometryN() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GamaGisFile.java From gama with GNU General Public License v3.0 | 8 votes |
protected Geometry multiPolygonManagement(final Geometry geom) { if (geom instanceof MultiPolygon) { final Polygon gs[] = new Polygon[geom.getNumGeometries()]; for (int i = 0; i < geom.getNumGeometries(); i++) { final Polygon p = (Polygon) geom.getGeometryN(i); final ICoordinates coords = GeometryUtils.getContourCoordinates(p); final LinearRing lr = GEOMETRY_FACTORY.createLinearRing(coords.toCoordinateArray()); try (final Collector.AsList<LinearRing> holes = Collector.getList()) { for (int j = 0; j < p.getNumInteriorRing(); j++) { final LinearRing h = (LinearRing) p.getInteriorRingN(j); if (!hasNullElements(h.getCoordinates())) { holes.add(h); } } LinearRing[] stockArr = new LinearRing[holes.size()]; stockArr = holes.items().toArray(stockArr); gs[i] = GEOMETRY_FACTORY.createPolygon(lr, stockArr); } } return GEOMETRY_FACTORY.createMultiPolygon(gs); } return geom; }
Example 2
Source File: GamaShape.java From gama with GNU General Public License v3.0 | 6 votes |
@Override public void setInnerGeometry(final Geometry geom) { if (geom == null) { geometry = null; return; } if (geom.isEmpty()) { // See Issue 725 return; } if (geom instanceof GeometryCollection && geom.getNumGeometries() == 1) { geometry = geom.getGeometryN(0); } else { geometry = geom; } }
Example 3
Source File: Distance3DOp.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
private void computeMinDistanceMultiMulti(Geometry g0, Geometry g1, boolean flip) { if (g0 instanceof GeometryCollection) { int n = g0.getNumGeometries(); for (int i = 0; i < n; i++) { Geometry g = g0.getGeometryN(i); computeMinDistanceMultiMulti(g, g1, flip); if (isDone) return; } } else { // handle case of multigeom component being empty if (g0.isEmpty()) return; // compute planar polygon only once for efficiency if (g0 instanceof Polygon) { computeMinDistanceOneMulti(polyPlane(g0), g1, flip); } else computeMinDistanceOneMulti(g0, g1, flip); } }
Example 4
Source File: Distance3DOp.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
private void computeMinDistanceOneMulti(PlanarPolygon3D poly, Geometry geom, boolean flip) { if (geom instanceof GeometryCollection) { int n = geom.getNumGeometries(); for (int i = 0; i < n; i++) { Geometry g = geom.getGeometryN(i); computeMinDistanceOneMulti(poly, g, flip); if (isDone) return; } } else { if (geom instanceof Point) { computeMinDistancePolygonPoint(poly, (Point) geom, flip); return; } if (geom instanceof LineString) { computeMinDistancePolygonLine(poly, (LineString) geom, flip); return; } if (geom instanceof Polygon) { computeMinDistancePolygonPolygon(poly, (Polygon) geom, flip); return; } } }
Example 5
Source File: ValidationFunctions.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
/** * Validates all geometries in a collection independently. * Errors are returned as points at the invalid location * * @param g * @return the invalid locations, if any */ public static Geometry invalidLocations(Geometry g) { List invalidLoc = new ArrayList(); for (int i = 0; i < g.getNumGeometries(); i++) { Geometry geom = g.getGeometryN(i); IsValidOp ivop = new IsValidOp(geom); TopologyValidationError err = ivop.getValidationError(); if (err != null) { invalidLoc.add(g.getFactory().createPoint(err.getCoordinate())); } } return g.getFactory().buildGeometry(invalidLoc); }
Example 6
Source File: GeometryDataUtil.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public static void setComponentDataToIndex(Geometry geom) { for (int i = 0; i < geom.getNumGeometries(); i++) { Geometry comp = geom.getGeometryN(i); comp.setUserData("Component # " + i); } }
Example 7
Source File: Distance3DOp.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private void computeMinDistanceOneMulti(Geometry g0, Geometry g1, boolean flip) { if (g1 instanceof GeometryCollection) { int n = g1.getNumGeometries(); for (int i = 0; i < n; i++) { Geometry g = g1.getGeometryN(i); computeMinDistanceOneMulti(g0, g, flip); if (isDone) return; } } else { computeMinDistance(g0, g1, flip); } }
Example 8
Source File: NominatimGeocoder.java From DataHubSystem with GNU Affero General Public License v3.0 | 4 votes |
private static Geometry clusterizeGeometry(final Geometry geometry, final double distance_ratio) { if (geometry == null) { return null; } int number_geometries = geometry.getNumGeometries(); if (number_geometries > 1) { Geometry [] clustered_geometries = new Geometry [number_geometries]; for (int igeom=0; igeom<number_geometries-1; igeom++) { Geometry current_geometry = geometry.getGeometryN(igeom); Point current_centroid = current_geometry.getCentroid(); if ((current_geometry == null) || (current_centroid == null)) { // TODO Warning continue; } ArrayList<Geometry> current_cluster = new ArrayList<Geometry>(); current_cluster.add(current_geometry); for (int jgeom=igeom+1; jgeom<number_geometries; jgeom++) { Geometry next_geometry = geometry.getGeometryN(jgeom); Point next_centroid = next_geometry.getCentroid(); if ((next_geometry == null) || (next_centroid == null)) { // TODO Warning continue; } double distance = current_geometry.distance(next_geometry); double centroids_distance = current_centroid.distance(next_centroid); if (distance < (centroids_distance * distance_ratio)) { current_cluster.add(next_geometry); } } Geometry [] current_cluster_array = new Geometry [current_cluster.size()]; clustered_geometries[igeom] = geometry.getFactory().createGeometryCollection( current_cluster.toArray(current_cluster_array)); } clustered_geometries[number_geometries-1] = geometry.getGeometryN(number_geometries-1); return convexHullOneLevel( geometry.getFactory().createGeometryCollection( clustered_geometries)).union(); } else { return geometry; } }