point = (Point) geom; } else if (geom instanceof Polygon) { point = ((Polygon) geom).getCentroid(); } else if (geom instanceof MultiPolygon) { point = ((MultiPolygon) geom).getCentroid();
public Point getCentroid() { return polygon.getCentroid(); }
.getJSONArray(GeoJsonWriter.COORDINATES); Point centroid = GeoJsonWriter.getPolygonGeometry(coords).getCentroid();
/** * This will return the centroid of a given polygon. It can handle complex polygons including * multiple polygons. This will not necessarily return a location that is contained within the * original polygon. For example if you have two concentric circles forming a donut shape, one * smaller one contained within the bigger one. The centroid of that polygon will be at the * center technically outside of the polygon. This is a very different concept to a * representative point. * * @return a Location object that is the centroid of the polygon */ public Location center() { final Point point = JTS_POLYGON_CONVERTER.convert(this).getCentroid(); return new JtsLocationConverter().backwardConvert(point.getCoordinate()); }
private static void stripe(Polygon p, List<Polygon> result) { Polygon bbox = (Polygon) p.getEnvelope(); Point centroid = bbox.getCentroid(); double snapX = fileNameKeyGenerator.roundX(centroid); double minX = p.getEnvelopeInternal().getMinX(); double maxX = p.getEnvelopeInternal().getMaxX(); if(snapX > minX && snapX < maxX) { List<Polygon> splitPolygon = GeometryUtils.splitPolygon(p, factory.createLineString(new Coordinate[]{new Coordinate(snapX, 89.0), new Coordinate(snapX, -89.0)})); for(Polygon cp : splitPolygon) { stripe(cp, result); } } else { result.add(p); } }
static protected LatLng calculateCentroidOfBBox(double left, double top, double right, double bottom) { LatLng latLng; if (left == right && top == bottom) { latLng = new LatLng(top, left); } else { Coordinate[] points = {GeoUtil.getCoordinate(top, left), GeoUtil.getCoordinate(top, right), GeoUtil.getCoordinate(bottom, right), GeoUtil.getCoordinate(bottom, left), GeoUtil.getCoordinate(top, left)}; GeometryFactory geometryFactory = new GeometryFactory(); Polygon polygon = geometryFactory.createPolygon(points); Point centroid = polygon.getCentroid(); latLng = new LatLng(centroid.getCoordinate().y, centroid.getCoordinate().x); } return latLng; }
centroid = geom.getCentroid(); // this where you would do the
centroid = geom.getCentroid(); } catch (Exception e) {
.getCentroid().getCoordinate(); Point p = gf.createPoint(centre); b.add(p);