Java Code Examples for org.locationtech.jts.geom.Geometry#getCentroid()
The following examples show how to use
org.locationtech.jts.geom.Geometry#getCentroid() .
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: TrackLayerType.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private void drawTrackPointConnections0(Rendering rendering) { // todo - get these styles from vector data node. (nf) rendering.getGraphics().setPaint(strokePaint); float scalingFactor = (float) rendering.getViewport().getViewToModelTransform().getScaleX(); float effectiveStrokeWidth = (float) (scalingFactor * STROKE_WIDTH); float effectiveDash = Math.max(1.0F, scalingFactor * 5.0F); float effectiveMeterLimit = Math.max(1.0F, scalingFactor * 10.0F); BasicStroke basicStroke = new BasicStroke(effectiveStrokeWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, effectiveMeterLimit, new float[]{ effectiveDash, effectiveDash}, 0.0f); rendering.getGraphics().setStroke(basicStroke); // FeatureCollection.toArray() returns the feature in original order // todo - must actually sort using some (timestamp) attribute (nf) SimpleFeature[] features = getVectorDataNode().getFeatureCollection().toArray(new SimpleFeature[0]); double lastX = 0; double lastY = 0; for (int i = 0; i < features.length; i++) { SimpleFeature feature = features[i]; Geometry geometry = (Geometry) feature.getDefaultGeometry(); org.locationtech.jts.geom.Point centroid = geometry.getCentroid(); try { final Point2D.Double sceneCoords = new Point2D.Double(centroid.getX(), centroid.getY()); final Point2D.Double modelCoords = new Point2D.Double(); sceneTransformProvider.getSceneToModelTransform().transform(sceneCoords, modelCoords); if (i > 0) { rendering.getGraphics().draw(new Line2D.Double(lastX, lastY, centroid.getX(), centroid.getY())); } lastX = modelCoords.getX(); lastY = modelCoords.getY(); } catch (TransformException e) { //continue loop } } }
Example 2
Source File: PolygonAreaCalculator.java From geowave with Apache License 2.0 | 5 votes |
public double getAreaSimple(final Geometry polygon) throws Exception { final Point centroid = polygon.getCentroid(); final CoordinateReferenceSystem equalAreaCRS = lookupUtmCrs(centroid.getY(), centroid.getX()); final MathTransform transform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, equalAreaCRS, true); final Geometry transformedPolygon = JTS.transform(polygon, transform); return transformedPolygon.getArea() * SQM_2_SQKM; }
Example 3
Source File: PolygonAreaCalculator.java From geowave with Apache License 2.0 | 5 votes |
public double getAreaDensify(final Geometry polygon) throws Exception { final Point centroid = polygon.getCentroid(); final CoordinateReferenceSystem equalAreaCRS = lookupUtmCrs(centroid.getY(), centroid.getX()); final double vertexSpacing = polygon.getLength() / densifyVertexCount; final Geometry densePolygon = Densifier.densify(polygon, vertexSpacing); final MathTransform transform = CRS.findMathTransform(DefaultGeographicCRS.WGS84, equalAreaCRS, true); final Geometry transformedPolygon = JTS.transform(densePolygon, transform); return transformedPolygon.getArea() * SQM_2_SQKM; }
Example 4
Source File: CentroidManagerGeoWave.java From geowave with Apache License 2.0 | 5 votes |
private static Geometry convert( final Geometry value, final Class<? extends Geometry> shapeClass) { if (shapeClass.isInstance(value)) { return value; } if (shapeClass.isAssignableFrom(Point.class)) { return value.getCentroid(); } final Geometry hull = value.convexHull(); if (shapeClass.isInstance(hull)) { return hull; } return null; }
Example 5
Source File: SimpleFeatureCentroidExtractor.java From geowave with Apache License 2.0 | 5 votes |
@Override public Point getCentroid(final SimpleFeature anObject) { final FeatureGeometryHandler handler = new FeatureGeometryHandler(anObject.getDefaultGeometryProperty().getDescriptor()); final Geometry geometry = handler.toIndexValue(anObject).getGeometry(); final int srid = SimpleFeatureGeometryExtractor.getSRID(anObject); final Point point = geometry.getCentroid(); point.setSRID(srid); return point; }
Example 6
Source File: JTS.java From sis with Apache License 2.0 | 5 votes |
/** * If the given object is a JTS geometry, returns its centroid. Otherwise returns {@code null}. */ @Override final Object tryGetCentroid(final Object geometry) { if (geometry instanceof Geometry) { final Geometry jts = (Geometry) geometry; final Point centroid = jts.getCentroid(); copyMetadata(jts, centroid); return centroid; } return null; }
Example 7
Source File: GeoUtils.java From elasticsearch-plugin-geoshape with MIT License | 4 votes |
public static GeoPoint getCentroidFromGeom(Geometry geom) { Geometry geom_centroid = geom.getCentroid(); return new GeoPoint(geom_centroid.getCoordinate().y, geom_centroid.getCoordinate().x); }
Example 8
Source File: TestUtils.java From geowave with Apache License 2.0 | 4 votes |
public static long hashCentroid(final Geometry geometry) { final Point centroid = geometry.getCentroid(); return Double.doubleToLongBits(centroid.getX()) + Double.doubleToLongBits(centroid.getY() * 31); }