int dim = getDimension(); if (dim == 0) { CentroidPoint cent = new CentroidPoint(); cent.add(this); centPt = cent.getCentroid();
/** * Adds the point(s) defined by a Geometry to the centroid total. * If the geometry is not of dimension 0 it does not contribute to the centroid. * @param geom the geometry to add */ public void add(Geometry geom) { if (geom instanceof Point) { add(geom.getCoordinate()); } else if (geom instanceof GeometryCollection) { GeometryCollection gc = (GeometryCollection) geom; for (int i = 0; i < gc.getNumGeometries(); i++) { add(gc.getGeometryN(i)); } } }
/** * Adds the point(s) defined by a Geometry to the centroid total. * If the geometry is not of dimension 0 it does not contribute to the centroid. * @param geom the geometry to add */ public void add(Geometry geom) { if (geom instanceof Point) { add(geom.getCoordinate()); } else if (geom instanceof GeometryCollection) { GeometryCollection gc = (GeometryCollection) geom; for (int i = 0; i < gc.getNumGeometries(); i++) { add(gc.getGeometryN(i)); } } }