com.vividsolutions.jts.geom.Geometry.getGeometryN()方法的使用及代码示例

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

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

Geometry.getGeometryN介绍

[英]Returns an element Geometry from a GeometryCollection(or this, if the geometry is not a collection).
[中]从GeometryCollection返回元素几何体(如果几何体不是集合,则返回this

代码示例

代码示例来源:origin: opentripplanner/OpenTripPlanner

  1. public static LinearLocation getEndLocation(Geometry linear) {
  2. //the version in LinearLocation is broken
  3. int lastComponentIndex = linear.getNumGeometries() - 1;
  4. LineString lastLine = (LineString) linear.getGeometryN(lastComponentIndex);
  5. int lastSegmentIndex = lastLine.getNumPoints() - 1;
  6. return new LinearLocation(lastComponentIndex, lastSegmentIndex, 0.0);
  7. }
  8. }

代码示例来源:origin: osmandapp/Osmand

  1. private static FeatureStats pointStats(Geometry geom) {
  2. final FeatureStats featureStats = new FeatureStats();
  3. final HashSet<Point> pointSet = new HashSet<>(geom.getNumPoints());
  4. featureStats.totalPts = geom.getNumPoints();
  5. for(int i = 0; i < geom.getNumGeometries(); ++i) {
  6. final Point p = (Point) geom.getGeometryN(i);
  7. featureStats.repeatedPts += pointSet.add(p) ? 0 : 1;
  8. }
  9. return featureStats;
  10. }

代码示例来源:origin: osmandapp/Osmand

  1. nextGeomCount = nextGeom.getNumGeometries();
  2. for(int i = 0; i < nextGeomCount; ++i) {
  3. geomStack.push(nextGeom.getGeometryN(i));

代码示例来源:origin: osmandapp/Osmand

  1. private static FeatureStats lineStats(Geometry geom) {
  2. final FeatureStats featureStats = new FeatureStats();
  3. for(int i = 0; i < geom.getNumGeometries(); ++i) {
  4. final LineString lineString = (LineString) geom.getGeometryN(i);
  5. featureStats.totalPts += lineString.getNumPoints();
  6. featureStats.repeatedPts += checkRepeatedPoints2d(lineString);
  7. }
  8. return featureStats;
  9. }

代码示例来源:origin: opentripplanner/OpenTripPlanner

  1. public void setGeom(Geometry geom) throws EmptyPolygonException, UnsupportedGeometryException {
  2. if (geom instanceof MultiPolygon) {
  3. if (geom.isEmpty()) {
  4. throw new EmptyPolygonException();
  5. }
  6. if (geom.getNumGeometries() > 1) {
  7. // LOG.warn("Multiple polygons in MultiPolygon, using only the first.");
  8. // TODO percolate this warning up somehow
  9. }
  10. this.geom = geom.getGeometryN(0);
  11. } else if( geom instanceof Point || geom instanceof Polygon){
  12. this.geom = geom;
  13. } else {
  14. throw new UnsupportedGeometryException( "Non-point, non-polygon Geometry, not supported." );
  15. }
  16. // cache a representative point
  17. Point point = geom.getCentroid();
  18. this.lat = point.getY();
  19. this.lon = point.getX();
  20. }

代码示例来源:origin: opentripplanner/OpenTripPlanner

  1. /**
  2. * Computes the angle of the last segment of a LineString or MultiLineString in radians clockwise from North
  3. * in the range (-PI, PI).
  4. * @param geometry a LineString or a MultiLineString
  5. */
  6. public static synchronized double getLastAngle(Geometry geometry) {
  7. LineString line;
  8. if (geometry instanceof MultiLineString) {
  9. line = (LineString) geometry.getGeometryN(geometry.getNumGeometries() - 1);
  10. } else {
  11. assert geometry instanceof LineString;
  12. line = (LineString) geometry;
  13. }
  14. int numPoints = line.getNumPoints();
  15. Coordinate coord0 = line.getCoordinateN(numPoints - 2);
  16. Coordinate coord1 = line.getCoordinateN(numPoints - 1);
  17. int i = numPoints - 3;
  18. int minDistance = 10; // Meters
  19. while (SphericalDistanceLibrary.fastDistance(coord0, coord1) < minDistance && i >= 0) {
  20. coord0 = line.getCoordinateN(i--);
  21. }
  22. double az = getAzimuth(coord0, coord1);
  23. return az * Math.PI / 180;
  24. }

代码示例来源:origin: osmandapp/Osmand

  1. private static FeatureStats polyStats(Geometry geom) {
  2. final FeatureStats featureStats = new FeatureStats();
  3. for(int i = 0; i < geom.getNumGeometries(); ++i) {
  4. final Polygon nextPoly = (Polygon) geom.getGeometryN(i);
  5. // Stats: exterior ring
  6. final LineString exteriorRing = nextPoly.getExteriorRing();
  7. featureStats.totalPts += exteriorRing.getNumPoints();
  8. featureStats.repeatedPts += checkRepeatedPoints2d(exteriorRing);
  9. // Stats: interior rings
  10. for(int ringIndex = 0; ringIndex < nextPoly.getNumInteriorRing(); ++ringIndex) {
  11. final LineString nextInteriorRing = nextPoly.getInteriorRingN(ringIndex);
  12. featureStats.totalPts += nextInteriorRing.getNumPoints();
  13. featureStats.repeatedPts += checkRepeatedPoints2d(nextInteriorRing);
  14. }
  15. }
  16. return featureStats;
  17. }

代码示例来源:origin: osmandapp/Osmand

  1. for (int i = 0; i < geom.getNumGeometries(); ++i) {
  2. mvtGeom.addAll(linesToGeomCmds(geom.getGeometryN(i), mvtClosePath, cursor, 1));
  3. for(int i = 0; i < geom.getNumGeometries(); ++i) {
  4. final Polygon nextPoly = (Polygon) geom.getGeometryN(i);
  5. final List<Integer> nextPolyGeom = new ArrayList<>();
  6. boolean valid = true;

代码示例来源:origin: opentripplanner/OpenTripPlanner

  1. /**
  2. * Computes the angle from the first point to the last point of a LineString or MultiLineString. TODO: put this method into
  3. * org.opentripplanner.common.geometry.DirectionUtils
  4. *
  5. * @param geometry a LineString or a MultiLineString
  6. *
  7. * @return
  8. */
  9. public synchronized double getFirstToLastSegmentAngle(Geometry geometry) {
  10. LineString line;
  11. if (geometry instanceof MultiLineString) {
  12. line = (LineString) geometry.getGeometryN(geometry.getNumGeometries() - 1);
  13. } else {
  14. assert geometry instanceof LineString;
  15. line = (LineString) geometry;
  16. }
  17. int numPoints = line.getNumPoints();
  18. Coordinate coord0 = line.getCoordinateN(0);
  19. Coordinate coord1 = line.getCoordinateN(numPoints - 1);
  20. int i = numPoints - 3;
  21. while (SphericalDistanceLibrary.fastDistance(coord0, coord1) < 10 && i >= 0) {
  22. coord1 = line.getCoordinateN(i--);
  23. }
  24. geodeticCalculator.setStartingGeographicPoint(coord0.x, coord0.y);
  25. geodeticCalculator.setDestinationGeographicPoint(coord1.x, coord1.y);
  26. return geodeticCalculator.getAzimuth() * Math.PI / 180;
  27. }
  28. }

代码示例来源:origin: com.vividsolutions/jts

  1. private void computeInteracting()
  2. {
  3. for (int i = 0; i < g0.getNumGeometries(); i++) {
  4. Geometry elem = g0.getGeometryN(i);
  5. interacts0[i] = computeInteracting(elem);
  6. }
  7. }

代码示例来源:origin: com.vividsolutions/jts

  1. private Geometry extractElements(Geometry geom,
  2. boolean[] interacts, boolean isInteracting)
  3. {
  4. List extractedGeoms = new ArrayList();
  5. for (int i = 0; i < geom.getNumGeometries(); i++) {
  6. Geometry elem = geom.getGeometryN(i);
  7. if (interacts[i] == isInteracting)
  8. extractedGeoms.add(elem);
  9. }
  10. return geomFactory.buildGeometry(extractedGeoms);
  11. }

代码示例来源:origin: com.vividsolutions/jts

  1. private void extractElements(Geometry geom, List elems)
  2. {
  3. if (geom == null)
  4. return;
  5. for (int i = 0; i < geom.getNumGeometries(); i++) {
  6. Geometry elemGeom = geom.getGeometryN(i);
  7. if (skipEmpty && elemGeom.isEmpty())
  8. continue;
  9. elems.add(elemGeom);
  10. }
  11. }

代码示例来源:origin: com.vividsolutions/jts

  1. /**
  2. * Sets the value of this location to
  3. * refer to the end of a linear geometry.
  4. *
  5. * @param linear the linear geometry to use to set the end
  6. */
  7. public void setToEnd(Geometry linear)
  8. {
  9. componentIndex = linear.getNumGeometries() - 1;
  10. LineString lastLine = (LineString) linear.getGeometryN(componentIndex);
  11. segmentIndex = lastLine.getNumPoints() - 1;
  12. segmentFraction = 1.0;
  13. }

代码示例来源:origin: com.vividsolutions/jts

  1. /**
  2. * Tests whether a geometry consists of a single polygon with no holes.
  3. *
  4. * @return true if the geometry is a single polygon with no holes
  5. */
  6. private boolean isSingleShell(Geometry geom)
  7. {
  8. // handles single-element MultiPolygons, as well as Polygons
  9. if (geom.getNumGeometries() != 1) return false;
  10. Polygon poly = (Polygon) geom.getGeometryN(0);
  11. int numHoles = poly.getNumInteriorRing();
  12. if (numHoles == 0) return true;
  13. return false;
  14. }

代码示例来源:origin: com.vividsolutions/jts

  1. /**
  2. * Semantics for GeometryCollection is
  3. * simple iff all components are simple.
  4. *
  5. * @param geom
  6. * @return true if the geometry is simple
  7. */
  8. private boolean isSimpleGeometryCollection(Geometry geom)
  9. {
  10. for (int i = 0; i < geom.getNumGeometries(); i++ ) {
  11. Geometry comp = geom.getGeometryN(i);
  12. if (! computeSimple(comp))
  13. return false;
  14. }
  15. return true;
  16. }

代码示例来源:origin: com.vividsolutions/jts

  1. private void computeMinDistanceOneMulti(Geometry g0, Geometry g1, boolean flip) {
  2. if (g1 instanceof GeometryCollection) {
  3. int n = g1.getNumGeometries();
  4. for (int i = 0; i < n; i++) {
  5. Geometry g = g1.getGeometryN(i);
  6. computeMinDistanceOneMulti(g0, g, flip);
  7. if (isDone) return;
  8. }
  9. }
  10. else {
  11. computeMinDistance(g0, g1, flip);
  12. }
  13. }

代码示例来源:origin: com.vividsolutions/jts

  1. private Geometry extractByEnvelope(Envelope env, Geometry geom,
  2. List disjointGeoms)
  3. {
  4. List intersectingGeoms = new ArrayList();
  5. for (int i = 0; i < geom.getNumGeometries(); i++) {
  6. Geometry elem = geom.getGeometryN(i);
  7. if (elem.getEnvelopeInternal().intersects(env))
  8. intersectingGeoms.add(elem);
  9. else
  10. disjointGeoms.add(elem);
  11. }
  12. return geomFactory.buildGeometry(intersectingGeoms);
  13. }

代码示例来源:origin: com.vividsolutions/jts

  1. /**
  2. * Input is assumed to be a multiGeometry
  3. * in which every component has its userData
  4. * set to be a Coordinate which is the key to the output data.
  5. * The Coordinate is used to determine
  6. * the output data object to be written back into the component.
  7. *
  8. * @param targetGeom
  9. */
  10. public void transferData(Geometry targetGeom)
  11. {
  12. for (int i = 0; i < targetGeom.getNumGeometries(); i++) {
  13. Geometry geom = targetGeom.getGeometryN(i);
  14. Coordinate vertexKey = (Coordinate) geom.getUserData();
  15. if (vertexKey == null) continue;
  16. geom.setUserData(coordDataMap.get(vertexKey));
  17. }
  18. }
  19. }

代码示例来源:origin: com.vividsolutions/jts

  1. private boolean computeInteracting(Geometry elem0)
  2. {
  3. boolean interactsWithAny = false;
  4. for (int i = 0; i < g1.getNumGeometries(); i++) {
  5. Geometry elem1 = g1.getGeometryN(i);
  6. boolean interacts = elem1.getEnvelopeInternal().intersects(elem0.getEnvelopeInternal());
  7. if (interacts) interacts1[i] = true;
  8. if (interacts)
  9. interactsWithAny = true;
  10. }
  11. return interactsWithAny;
  12. }

代码示例来源:origin: com.vividsolutions/jts

  1. public void loadSourceGeometries(Geometry geomColl)
  2. {
  3. for (int i = 0; i < geomColl.getNumGeometries(); i++) {
  4. Geometry geom = geomColl.getGeometryN(i);
  5. loadVertices(geom.getCoordinates(), geom.getUserData());
  6. }
  7. }

相关文章