CentroidLine cent = new CentroidLine(); cent.add(this); centPt = cent.getCentroid();
/** * Adds the linear components of by a Geometry to the centroid total. * If the geometry has no linear components it does not contribute to the centroid, * * @param geom the geometry to add */ public void add(Geometry geom) { if (geom instanceof LineString) { add(geom.getCoordinates()); } else if (geom instanceof Polygon) { Polygon poly = (Polygon) geom; // add linear components of a polygon add(poly.getExteriorRing().getCoordinates()); for (int i = 0; i < poly.getNumInteriorRing(); i++) { add(poly.getInteriorRingN(i).getCoordinates()); } } else if (geom instanceof GeometryCollection) { GeometryCollection gc = (GeometryCollection) geom; for (int i = 0; i < gc.getNumGeometries(); i++) { add(gc.getGeometryN(i)); } } }
/** * Adds the linear components of by a Geometry to the centroid total. * If the geometry has no linear components it does not contribute to the centroid, * * @param geom the geometry to add */ public void add(Geometry geom) { if (geom instanceof LineString) { add(geom.getCoordinates()); } else if (geom instanceof Polygon) { Polygon poly = (Polygon) geom; // add linear components of a polygon add(poly.getExteriorRing().getCoordinates()); for (int i = 0; i < poly.getNumInteriorRing(); i++) { add(poly.getInteriorRingN(i).getCoordinates()); } } else if (geom instanceof GeometryCollection) { GeometryCollection gc = (GeometryCollection) geom; for (int i = 0; i < gc.getNumGeometries(); i++) { add(gc.getGeometryN(i)); } } }