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

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

本文整理了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

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

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

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

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

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

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

private static FeatureStats lineStats(Geometry geom) {
  final FeatureStats featureStats = new FeatureStats();
  for(int i = 0; i < geom.getNumGeometries(); ++i) {
    final LineString lineString = (LineString) geom.getGeometryN(i);
    featureStats.totalPts += lineString.getNumPoints();
    featureStats.repeatedPts += checkRepeatedPoints2d(lineString);
  }
  return featureStats;
}

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

public void setGeom(Geometry geom) throws EmptyPolygonException, UnsupportedGeometryException {
  if (geom instanceof MultiPolygon) {
    if (geom.isEmpty()) {
      throw new EmptyPolygonException();
    }
    if (geom.getNumGeometries() > 1) {
      // LOG.warn("Multiple polygons in MultiPolygon, using only the first.");
      // TODO percolate this warning up somehow
    }
    this.geom = geom.getGeometryN(0);
  } else if( geom instanceof Point || geom instanceof Polygon){
    this.geom = geom;
  } else {
    throw new UnsupportedGeometryException( "Non-point, non-polygon Geometry, not supported." );
  }
  // cache a representative point
  Point point = geom.getCentroid();
  this.lat = point.getY();
  this.lon = point.getX();
}

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

/**
 * Computes the angle of the last segment of a LineString or MultiLineString in radians clockwise from North
 * in the range (-PI, PI).
 * @param geometry a LineString or a MultiLineString
 */
public static synchronized double getLastAngle(Geometry geometry) {
  LineString line;
  if (geometry instanceof MultiLineString) {
    line = (LineString) geometry.getGeometryN(geometry.getNumGeometries() - 1);
  } else {
    assert geometry instanceof LineString;
    line = (LineString) geometry;
  }
  int numPoints = line.getNumPoints();
  Coordinate coord0 = line.getCoordinateN(numPoints - 2);
  Coordinate coord1 = line.getCoordinateN(numPoints - 1);
  int i = numPoints - 3;
  int minDistance = 10;  // Meters        
  while (SphericalDistanceLibrary.fastDistance(coord0, coord1) < minDistance && i >= 0) {
    coord0 = line.getCoordinateN(i--);
  }
  double az = getAzimuth(coord0, coord1);
  return az * Math.PI / 180;
}

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

private static FeatureStats polyStats(Geometry geom) {
  final FeatureStats featureStats = new FeatureStats();
  for(int i = 0; i < geom.getNumGeometries(); ++i) {
    final Polygon nextPoly = (Polygon) geom.getGeometryN(i);
    // Stats: exterior ring
    final LineString exteriorRing = nextPoly.getExteriorRing();
    featureStats.totalPts += exteriorRing.getNumPoints();
    featureStats.repeatedPts += checkRepeatedPoints2d(exteriorRing);
    // Stats: interior rings
    for(int ringIndex = 0; ringIndex < nextPoly.getNumInteriorRing(); ++ringIndex) {
      final LineString nextInteriorRing = nextPoly.getInteriorRingN(ringIndex);
      featureStats.totalPts += nextInteriorRing.getNumPoints();
      featureStats.repeatedPts += checkRepeatedPoints2d(nextInteriorRing);
    }
  }
  return featureStats;
}

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

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

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

/**
   * Computes the angle from the first point to the last point of a LineString or MultiLineString. TODO: put this method into
   * org.opentripplanner.common.geometry.DirectionUtils
   * 
   * @param geometry a LineString or a MultiLineString
   * 
   * @return
   */
  public synchronized double getFirstToLastSegmentAngle(Geometry geometry) {
    LineString line;
    if (geometry instanceof MultiLineString) {
      line = (LineString) geometry.getGeometryN(geometry.getNumGeometries() - 1);
    } else {
      assert geometry instanceof LineString;
      line = (LineString) geometry;
    }
    int numPoints = line.getNumPoints();
    Coordinate coord0 = line.getCoordinateN(0);
    Coordinate coord1 = line.getCoordinateN(numPoints - 1);
    int i = numPoints - 3;
    while (SphericalDistanceLibrary.fastDistance(coord0, coord1) < 10 && i >= 0) {
      coord1 = line.getCoordinateN(i--);
    }

    geodeticCalculator.setStartingGeographicPoint(coord0.x, coord0.y);
    geodeticCalculator.setDestinationGeographicPoint(coord1.x, coord1.y);
    return geodeticCalculator.getAzimuth() * Math.PI / 180;
  }
}

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

private void computeInteracting()
{
  for (int i = 0; i < g0.getNumGeometries(); i++) {
    Geometry elem = g0.getGeometryN(i);
    interacts0[i] = computeInteracting(elem);
  }
}

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

private Geometry extractElements(Geometry geom, 
    boolean[] interacts, boolean isInteracting)
{
  List extractedGeoms = new ArrayList();
  for (int i = 0; i < geom.getNumGeometries(); i++) { 
    Geometry elem = geom.getGeometryN(i);
    if (interacts[i] == isInteracting)
      extractedGeoms.add(elem);
  }
  return geomFactory.buildGeometry(extractedGeoms);
}

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

private void extractElements(Geometry geom, List elems)
{
 if (geom == null)
  return;
 
 for (int i = 0; i < geom.getNumGeometries(); i++) {
  Geometry elemGeom = geom.getGeometryN(i);
  if (skipEmpty && elemGeom.isEmpty())
   continue;
  elems.add(elemGeom);
 }
}

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

/**
 * Sets the value of this location to
 * refer to the end of a linear geometry.
 *
 * @param linear the linear geometry to use to set the end
 */
public void setToEnd(Geometry linear)
{
 componentIndex = linear.getNumGeometries() - 1;
 LineString lastLine = (LineString) linear.getGeometryN(componentIndex);
 segmentIndex = lastLine.getNumPoints() - 1;
 segmentFraction = 1.0;
}

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

/**
 * Tests whether a geometry consists of a single polygon with no holes.
 *  
 * @return true if the geometry is a single polygon with no holes
 */
 private boolean isSingleShell(Geometry geom)
 {
 // handles single-element MultiPolygons, as well as Polygons
   if (geom.getNumGeometries() != 1) return false;
   
   Polygon poly = (Polygon) geom.getGeometryN(0);
   int numHoles = poly.getNumInteriorRing();
   if (numHoles == 0) return true;
   return false;
 }

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

/**
 * Semantics for GeometryCollection is 
 * simple iff all components are simple.
 * 
 * @param geom
 * @return true if the geometry is simple
 */
private boolean isSimpleGeometryCollection(Geometry geom)
{
 for (int i = 0; i < geom.getNumGeometries(); i++ ) {
  Geometry comp = geom.getGeometryN(i);
  if (! computeSimple(comp))
   return false;
 }
 return true;
}

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

private void computeMinDistanceOneMulti(Geometry g0, Geometry g1, boolean flip) {
  if (g1 instanceof GeometryCollection) {
    int n = g1.getNumGeometries();
    for (int i = 0; i < n; i++) {
      Geometry g = g1.getGeometryN(i);
      computeMinDistanceOneMulti(g0, g, flip);
      if (isDone)	return;
    }
  }
  else {
    computeMinDistance(g0, g1, flip);
  }
}

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

private Geometry extractByEnvelope(Envelope env, Geometry geom, 
    List disjointGeoms)
{
  List intersectingGeoms = new ArrayList();
  for (int i = 0; i < geom.getNumGeometries(); i++) { 
    Geometry elem = geom.getGeometryN(i);
    if (elem.getEnvelopeInternal().intersects(env))
      intersectingGeoms.add(elem);
    else
      disjointGeoms.add(elem);
  }
  return geomFactory.buildGeometry(intersectingGeoms);
}

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

/**
   * Input is assumed to be a multiGeometry
   * in which every component has its userData
   * set to be a Coordinate which is the key to the output data.
   * The Coordinate is used to determine
   * the output data object to be written back into the component. 
   * 
   * @param targetGeom
   */
  public void transferData(Geometry targetGeom)
  {
    for (int i = 0; i < targetGeom.getNumGeometries(); i++) {
      Geometry geom = targetGeom.getGeometryN(i);
      Coordinate vertexKey = (Coordinate) geom.getUserData();
      if (vertexKey == null) continue;
      geom.setUserData(coordDataMap.get(vertexKey));
    }
  }
}

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

private boolean computeInteracting(Geometry elem0)
{
  boolean interactsWithAny = false;
  for (int i = 0; i < g1.getNumGeometries(); i++) {
    Geometry elem1 = g1.getGeometryN(i);
    boolean interacts = elem1.getEnvelopeInternal().intersects(elem0.getEnvelopeInternal());
    if (interacts) interacts1[i] = true;
    if (interacts) 
      interactsWithAny = true;
  }
  return interactsWithAny;
}

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

public void loadSourceGeometries(Geometry geomColl)
{
  for (int i = 0; i < geomColl.getNumGeometries(); i++) {
    Geometry geom = geomColl.getGeometryN(i);
    loadVertices(geom.getCoordinates(), geom.getUserData());
  }
}

相关文章