org.locationtech.jts.geom.Geometry.getCoordinate()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(239)

本文整理了Java中org.locationtech.jts.geom.Geometry.getCoordinate()方法的一些代码示例,展示了Geometry.getCoordinate()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Geometry.getCoordinate()方法的具体详情如下:
包路径:org.locationtech.jts.geom.Geometry
类名称:Geometry
方法名:getCoordinate

Geometry.getCoordinate介绍

[英]Returns a vertex of this Geometry (usually, but not necessarily, the first one). The returned coordinate should not be assumed to be an actual Coordinate object used in the internal representation.
[中]返回此Geometry的顶点(通常,但不一定是第一个)。不应假定返回的坐标是内部表示中使用的实际坐标对象。

代码示例

代码示例来源:origin: prestodb/presto

  1. @SqlNullable
  2. @Description("Returns a float between 0 and 1 representing the location of the closest point on the LineString to the given Point, as a fraction of total 2d line length.")
  3. @ScalarFunction("line_locate_point")
  4. @SqlType(DOUBLE)
  5. public static Double lineLocatePoint(@SqlType(GEOMETRY_TYPE_NAME) Slice lineSlice, @SqlType(GEOMETRY_TYPE_NAME) Slice pointSlice)
  6. {
  7. Geometry line = JtsGeometrySerde.deserialize(lineSlice);
  8. Geometry point = JtsGeometrySerde.deserialize(pointSlice);
  9. if (line.isEmpty() || point.isEmpty()) {
  10. return null;
  11. }
  12. GeometryType lineType = GeometryType.getForJtsGeometryType(line.getGeometryType());
  13. if (lineType != GeometryType.LINE_STRING && lineType != GeometryType.MULTI_LINE_STRING) {
  14. throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("First argument to line_locate_point must be a LineString or a MultiLineString. Got: %s", line.getGeometryType()));
  15. }
  16. GeometryType pointType = GeometryType.getForJtsGeometryType(point.getGeometryType());
  17. if (pointType != GeometryType.POINT) {
  18. throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Second argument to line_locate_point must be a Point. Got: %s", point.getGeometryType()));
  19. }
  20. return new LengthIndexedLine(line).indexOf(point.getCoordinate()) / line.getLength();
  21. }

代码示例来源:origin: geotools/geotools

  1. public Coordinate getCoordinate() {
  2. return geometry.getCoordinate();
  3. }

代码示例来源:origin: geotools/geotools

  1. public Number getX(int series, int item) {
  2. // TODO: return the centroid
  3. return geometries.get(series).getCoordinate().x;
  4. }

代码示例来源:origin: geotools/geotools

  1. public Number getY(int series, int item) {
  2. return geometries.get(series).getCoordinate().x;
  3. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Return D as defined by SDO_GTYPE (either 2,3 or 4).
  3. *
  4. * <p>For normal JTS Geometry this will be 2 or 3 depending if geom.getCoordinate.z is
  5. * Double.NaN.
  6. *
  7. * <p>Subclasses may override as required.
  8. *
  9. * @param geom
  10. * @return <code>3</code>
  11. */
  12. public static int D(Geometry geom) {
  13. CoordinateSequenceFactory f = geom.getFactory().getCoordinateSequenceFactory();
  14. if (f instanceof CoordinateAccessFactory) {
  15. return ((CoordinateAccessFactory) f).getDimension();
  16. } else if (geom == null || geom.getCoordinate() == null || geom.isEmpty()) {
  17. return 2;
  18. } else {
  19. // return 3;
  20. return Double.isNaN(geom.getCoordinate().z) ? 2 : 3;
  21. }
  22. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Gets a point to represent the Geometry. If the Geometry is a point, this is returned.
  3. * Otherwise, the centroid is used.
  4. *
  5. * @param g the geometry to find a point for
  6. * @return a point representing the Geometry
  7. */
  8. private static Coordinate getPoint(Geometry g) {
  9. if (g.getNumPoints() == 1) return g.getCoordinate();
  10. return g.getCentroid().getCoordinate();
  11. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Gets a point to represent the Geometry. If the Geometry is a point, this is returned.
  3. * Otherwise, the centroid is used.
  4. *
  5. * @param g the geometry to find a point for
  6. * @return a point representing the Geometry
  7. */
  8. private static Coordinate getRepresentativePoint(Geometry g) {
  9. if (g.getNumPoints() == 1) return g.getCoordinate();
  10. return g.getCentroid().getCoordinate();
  11. }

代码示例来源:origin: geotools/geotools

  1. Coordinate c = (mp.getGeometryN(t)).getCoordinate();
  2. buffer.putDouble(c.x);
  3. buffer.putDouble(c.y);
  4. Coordinate c = (mp.getGeometryN(t)).getCoordinate();
  5. double z = c.z;

代码示例来源:origin: geotools/geotools

  1. private static Geometry pointInGeometry(Geometry g) {
  2. Point p = g.getCentroid();
  3. if (g instanceof Polygon) {
  4. // if the geometry is heavily generalized centroid computation may fail and return NaN
  5. if (Double.isNaN(p.getX()) || Double.isNaN(p.getY()))
  6. return g.getFactory().createPoint(g.getCoordinate());
  7. // otherwise let's check if the point is inside. Again, this check and
  8. // "getInteriorPoint"
  9. // will work only if the geometry is valid
  10. if (g.isValid() && !g.contains(p)) {
  11. try {
  12. p = g.getInteriorPoint();
  13. } catch (Exception e) {
  14. // generalized geometries might make interior point go bye bye
  15. return p;
  16. }
  17. } else {
  18. return p;
  19. }
  20. }
  21. return p;
  22. }

代码示例来源:origin: geotools/geotools

  1. Coordinate p = geom.getCoordinate();
  2. srcPt[0] = p.x;
  3. srcPt[1] = p.y;

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Finds the centroid of the input geometry if input = point, line, polygon --> return a point
  3. * that represents the centroid of that geom if input = geometry collection --> return a
  4. * multipoint that represents the centoid of each sub-geom
  5. *
  6. * @param g
  7. */
  8. public static Geometry getCentroid(Geometry g) {
  9. if (g instanceof Point || g instanceof MultiPoint) {
  10. return g;
  11. } else if (g instanceof GeometryCollection) {
  12. final GeometryCollection gc = (GeometryCollection) g;
  13. final Coordinate[] pts = new Coordinate[gc.getNumGeometries()];
  14. final int length = gc.getNumGeometries();
  15. for (int t = 0; t < length; t++) {
  16. pts[t] = pointInGeometry(gc.getGeometryN(t)).getCoordinate();
  17. }
  18. return g.getFactory().createMultiPoint(pts);
  19. } else if (g != null) {
  20. return pointInGeometry(g);
  21. }
  22. return null;
  23. }

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void multiPointWithInnerParens() throws Exception {
  3. String WKT = "MULTIPOINT ((111 -47), (110 -46.5))";
  4. WKTReader reader = new WKTReader2();
  5. Geometry geometry = reader.read(WKT);
  6. assertNotNull(geometry);
  7. assertTrue(geometry instanceof MultiPoint);
  8. MultiPoint mp = (MultiPoint) geometry;
  9. assertEquals(2, mp.getNumGeometries());
  10. assertEquals(new Coordinate(111, -47), mp.getGeometryN(0).getCoordinate());
  11. assertEquals(new Coordinate(110, -46.5), mp.getGeometryN(1).getCoordinate());
  12. }

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void multiPoint() throws Exception {
  3. String WKT = "MULTIPOINT (111 -47, 110 -46.5)";
  4. WKTReader reader = new WKTReader2();
  5. Geometry geometry = reader.read(WKT);
  6. assertNotNull(geometry);
  7. assertTrue(geometry instanceof MultiPoint);
  8. MultiPoint mp = (MultiPoint) geometry;
  9. assertEquals(2, mp.getNumGeometries());
  10. assertEquals(new Coordinate(111, -47), mp.getGeometryN(0).getCoordinate());
  11. assertEquals(new Coordinate(110, -46.5), mp.getGeometryN(1).getCoordinate());
  12. }

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void testToGeographic() throws Exception {
  3. String wkt =
  4. "GEOGCS[\"GDA94\","
  5. + " DATUM[\"Geocentric Datum of Australia 1994\","
  6. + " SPHEROID[\"GRS 1980\", 6378137.0, 298.257222101, AUTHORITY[\"EPSG\",\"7019\"]],"
  7. + " TOWGS84[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], "
  8. + " AUTHORITY[\"EPSG\",\"6283\"]], "
  9. + " PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]],"
  10. + " UNIT[\"degree\", 0.017453292519943295], "
  11. + " AXIS[\"Geodetic longitude\", EAST], "
  12. + " AXIS[\"Geodetic latitude\", NORTH], "
  13. + " AXIS[\"Ellipsoidal height\", UP], "
  14. + " AUTHORITY[\"EPSG\",\"4939\"]]";
  15. CoordinateReferenceSystem gda94 = CRS.parseWKT(wkt);
  16. GeometryFactory gf = new GeometryFactory();
  17. Point point = gf.createPoint(new Coordinate(130.875825803896, -16.4491956225999, 0.0));
  18. Geometry worldPoint = JTS.toGeographic(point, gda94);
  19. assertTrue(worldPoint instanceof Point);
  20. assertEquals(point.getX(), worldPoint.getCoordinate().x, 0.00000001);
  21. }

代码示例来源:origin: geotools/geotools

  1. public void testDifferentCRS() throws Exception {
  2. CoordinateReferenceSystem srcCRS = DefaultGeographicCRS.WGS84;
  3. GeometryFactory fac = new GeometryFactory();
  4. Point p = fac.createPoint(new Coordinate(10, 10));
  5. SimpleFeatureCollection features = createTestFeatureCollection(srcCRS, p);
  6. FeatureReader<SimpleFeatureType, SimpleFeature> original = DataUtilities.reader(features);
  7. CoordinateReferenceSystem destCRS = DefaultEngineeringCRS.CARTESIAN_2D;
  8. try (ForceCoordinateSystemFeatureReader modified =
  9. new ForceCoordinateSystemFeatureReader(DataUtilities.reader(features), destCRS); ) {
  10. SimpleFeature f1 = original.next();
  11. SimpleFeature f2 = modified.next();
  12. assertEquals(
  13. ((Geometry) f1.getDefaultGeometry()).getCoordinate(),
  14. ((Geometry) f2.getDefaultGeometry()).getCoordinate());
  15. SimpleFeatureType f1Type = f1.getFeatureType();
  16. SimpleFeatureType f2Type = f2.getFeatureType();
  17. assertFalse(
  18. f1Type.getCoordinateReferenceSystem()
  19. .equals(f2Type.getCoordinateReferenceSystem()));
  20. assertEquals(srcCRS, f1Type.getCoordinateReferenceSystem());
  21. assertEquals(srcCRS, f1Type.getGeometryDescriptor().getCoordinateReferenceSystem());
  22. assertEquals(destCRS, f2Type.getCoordinateReferenceSystem());
  23. assertEquals(destCRS, f2Type.getGeometryDescriptor().getCoordinateReferenceSystem());
  24. assertFalse(original.hasNext());
  25. assertFalse(modified.hasNext());
  26. assertNotNull(modified.builder);
  27. }
  28. }

代码示例来源:origin: geotools/geotools

  1. public void testBounds() throws Exception {
  2. GeometryFactory gf = new GeometryFactory();
  3. Geometry[] g = new Geometry[4];
  4. g[0] = gf.createPoint(new Coordinate(0, 0));
  5. g[1] = gf.createPoint(new Coordinate(0, 10));
  6. g[2] = gf.createPoint(new Coordinate(10, 0));
  7. g[3] = gf.createPoint(new Coordinate(10, 10));
  8. GeometryCollection gc = gf.createGeometryCollection(g);
  9. SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
  10. tb.setName("bounds");
  11. tb.setCRS(null);
  12. tb.add("p1", Point.class);
  13. tb.add("p2", Point.class);
  14. tb.add("p3", Point.class);
  15. tb.add("p4", Point.class);
  16. SimpleFeatureType t = tb.buildFeatureType();
  17. SimpleFeature f = SimpleFeatureBuilder.build(t, g, null);
  18. assertEquals(gc.getEnvelopeInternal(), f.getBounds());
  19. g[1].getCoordinate().y = 20;
  20. g[2].getCoordinate().x = 20;
  21. f.setAttribute(1, g[1]);
  22. f.setAttribute(2, g[2]);
  23. gc = gf.createGeometryCollection(g);
  24. assertEquals(gc.getEnvelopeInternal(), f.getBounds());
  25. }

代码示例来源:origin: geotools/geotools

  1. ((Geometry) f1.getDefaultGeometry()).getCoordinate(),
  2. ((Geometry) f2.getDefaultGeometry()).getCoordinate());
  3. SimpleFeatureType f1Type = f1.getFeatureType();
  4. SimpleFeatureType f2Type = f2.getFeatureType();

代码示例来源:origin: geotools/geotools

  1. public void testDifferentCRS() throws Exception {
  2. CoordinateReferenceSystem srcCRS = DefaultGeographicCRS.WGS84;
  3. GeometryFactory fac = new GeometryFactory();
  4. Point p = fac.createPoint(new Coordinate(10, 10));
  5. SimpleFeatureCollection collection = createDatastore(srcCRS, p);
  6. SimpleFeatureIterator original = collection.features();
  7. CoordinateReferenceSystem destCRS = DefaultEngineeringCRS.CARTESIAN_2D;
  8. ForceCoordinateSystemIterator modified =
  9. new ForceCoordinateSystemIterator(
  10. collection.features(), collection.getSchema(), destCRS);
  11. SimpleFeature f1 = original.next();
  12. SimpleFeature f2 = modified.next();
  13. assertEquals(
  14. ((Geometry) f1.getDefaultGeometry()).getCoordinate(),
  15. ((Geometry) f2.getDefaultGeometry()).getCoordinate());
  16. assertFalse(
  17. f1.getFeatureType()
  18. .getCoordinateReferenceSystem()
  19. .equals(f2.getFeatureType().getCoordinateReferenceSystem()));
  20. assertEquals(srcCRS, f1.getFeatureType().getCoordinateReferenceSystem());
  21. assertEquals(
  22. srcCRS, f1.getFeatureType().getGeometryDescriptor().getCoordinateReferenceSystem());
  23. assertEquals(destCRS, f2.getFeatureType().getCoordinateReferenceSystem());
  24. assertEquals(
  25. destCRS,
  26. f2.getFeatureType().getGeometryDescriptor().getCoordinateReferenceSystem());
  27. assertFalse(original.hasNext());
  28. assertFalse(modified.hasNext());
  29. assertNotNull(modified.builder);
  30. }

代码示例来源:origin: geotools/geotools

  1. ((Geometry) f1.getDefaultGeometry()).getCoordinate(),
  2. ((Geometry) f2.getDefaultGeometry()).getCoordinate());
  3. assertFalse(
  4. f2.getFeatureType()

代码示例来源:origin: geotools/geotools

  1. assertEquals("geom", 2.0, geometry.getCoordinate().y);
  2. assertEquals("fid preservation", "fid1", feature1.getID());

相关文章