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

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

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

Geometry.getEnvelopeInternal介绍

[英]Gets an Envelope containing the minimum and maximum x and y values in this Geometry. If the geometry is empty, an empty Envelope is returned.

The returned object is a copy of the one maintained internally, to avoid aliasing issues. For best performance, clients which access this envelope frequently should cache the return value.
[中]获取一个信封,其中包含此Geometry中的最小和最大x和y值。如果几何体为空,则返回空Envelope
返回的对象是内部维护的对象的副本,以避免别名问题。为了获得最佳性能,经常访问此信封的客户端应该缓存返回值。

代码示例

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

/**
 * JTS 1.14 does not support intersection on a {@link GeometryCollection}. This function works around this
 * by performing intersection on a flat list of geometry. The resulting list is pre-filtered for invalid
 * or empty geometry (outside of bounds). Invalid geometry are logged as errors.
 *
 * @param envelope non-list geometry defines bounding area
 * @param dataGeoms geometry pre-passed through {@link #flatFeatureList(Geometry)}
 * @return list of geometry from {@code data} intersecting with {@code envelope}.
 */
private static List<Geometry> flatIntersection(Geometry envelope, List<Geometry> dataGeoms) {
  final List<Geometry> intersectedGeoms = new ArrayList<>(dataGeoms.size());
  Geometry nextIntersected;
  for(Geometry nextGeom : dataGeoms) {
    try {
      // AABB intersection culling
      if(envelope.getEnvelopeInternal().intersects(nextGeom.getEnvelopeInternal())) {
        nextIntersected = envelope.intersection(nextGeom);
        if(!nextIntersected.isEmpty()) {
          nextIntersected.setUserData(nextGeom.getUserData());
          intersectedGeoms.add(nextIntersected);
        }
      }
    } catch (TopologyException e) {
      //LoggerFactory.getLogger(JtsAdapter.class).error(e.getMessage(), e);
    }
  }
  return intersectedGeoms;
}

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

STRtree createIndex() {
  STRtree edgeIndex = new STRtree();
  for (Vertex v : graph.getVertices()) {
    for (Edge e : v.getOutgoing()) {
      if (e instanceof StreetEdge) {
        Envelope envelope;
        Geometry geometry = e.getGeometry();
        envelope = geometry.getEnvelopeInternal();
        edgeIndex.insert(envelope, e);
      }
    }
  }
  log.debug("Created index");
  return edgeIndex;
}

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

/**
 * The function is run periodically by the update manager.
 * The extending class should provide the getNote method. It is not implemented here
 * as the requirements for different updaters can be vastly different dependent on the data source.
 */
@Override
protected void runPolling() throws IOException{
  LOG.info("Run WFS polling updater with hashcode: {}", this.hashCode());
  notesForEdge = HashMultimap.create();
  uniqueMatchers = new HashMap<>();
  FeatureIterator<SimpleFeature> features = featureSource.getFeatures(query).features();
  while ( features.hasNext()){
    SimpleFeature feature = features.next();
    if (feature.getDefaultGeometry() == null) continue;
    Alert alert = getNote(feature);
    if (alert == null) continue;
    Geometry geom = (Geometry) feature.getDefaultGeometry();
    Geometry searchArea = geom.buffer(SEARCH_RADIUS_DEG);
    Collection<Edge> edges = graph.streetIndex.getEdgesForEnvelope(searchArea.getEnvelopeInternal());
    for(Edge edge: edges){
      if (edge instanceof StreetEdge && !searchArea.disjoint(edge.getGeometry())) {
        addNote(edge, alert, NOTE_MATCHER);
      }
    }
  }
  updaterManager.execute(new WFSGraphWriter());
}

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

/**
 * Determines whether a Geometry g interacts with 
 * this geometry by testing the geometry envelopes.
 *  
 * @param g a Geometry
 * @return true if the envelopes intersect
 */
protected boolean envelopesIntersect(Geometry g)
{
 if (! baseGeom.getEnvelopeInternal().intersects(g.getEnvelopeInternal()))
  return false;
 return true;
}

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

/**
 * Determines whether the envelope of 
 * this geometry covers the Geometry g.
 * 
 *  
 * @param g a Geometry
 * @return true if g is contained in this envelope
 */
protected boolean envelopeCovers(Geometry g)
{
 if (! baseGeom.getEnvelopeInternal().covers(g.getEnvelopeInternal()))
  return false;
 return true;
}

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

/**
 * Default implementation.
 */
public boolean containsProperly(Geometry g)
{
  // since raw relate is used, provide some optimizations
  
 // short-circuit test
 if (! baseGeom.getEnvelopeInternal().contains(g.getEnvelopeInternal()))
  return false;
  
 // otherwise, compute using relate mask
 return baseGeom.relate(g, "T**FF*FF*");
}

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

/**
 * Gets a hash code for the Geometry.
 * 
 * @return an integer value suitable for use as a hashcode
 */
public int hashCode()
{
 return getEnvelopeInternal().hashCode();
}

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

/**
 * Finds all {@link PreparedGeometry}s which might 
 * interact with a query {@link Geometry}.
 * 
 * @param g the geometry to query by
 * @return a list of candidate PreparedGeometrys
 */
public List query(Geometry g)
{
  return index.query(g.getEnvelopeInternal());
}

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

/**
 * Inserts a collection of Geometrys into the index.
 * 
 * @param geoms a collection of Geometrys to insert
 */
public void insert(Collection geoms)
{
  for (Iterator i = geoms.iterator(); i.hasNext(); ) {
    Geometry geom = (Geometry) i.next();
    index.insert(geom.getEnvelopeInternal(), PreparedGeometryFactory.prepare(geom));
  }
}

代码示例来源: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

private static double OLDprecisionScaleFactor(Geometry g,
  double distance,
 int maxPrecisionDigits)
{
 Envelope env = g.getEnvelopeInternal();
 double envSize = Math.max(env.getHeight(), env.getWidth());
 double expandByDistance = distance > 0.0 ? distance : 0.0;
 double bufEnvSize = envSize + 2 * expandByDistance;
 // the smallest power of 10 greater than the buffer envelope
 int bufEnvLog10 = (int) (Math.log(bufEnvSize) / Math.log(10) + 1.0);
 int minUnitLog10 = bufEnvLog10 - maxPrecisionDigits;
 // scale factor is inverse of min Unit size, so flip sign of exponent
 double scaleFactor = Math.pow(10.0, -minUnitLog10);
 return scaleFactor;
}

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

public static double computeSizeBasedSnapTolerance(Geometry g)
{
 Envelope env = g.getEnvelopeInternal();
 double minDimension = Math.min(env.getHeight(), env.getWidth());
 double snapTol = minDimension * SNAP_PRECISION_FACTOR;
 return snapTol;
}

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

/**
 * Sets a polygonal mask.
 * 
 * @param mask
 * @throws IllegalArgumentException if the mask is not polygonal
 */
public void setExtent(Geometry mask)
{
  if (! (mask instanceof Polygonal))
    throw new IllegalArgumentException("Only polygonal extents are supported");
  this.maskPoly = mask;
  setExtent(mask.getEnvelopeInternal());
  extentLocator = new IndexedPointInAreaLocator(mask);
}

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

protected Envelope computeEnvelopeInternal() {
 Envelope envelope = new Envelope();
 for (int i = 0; i < geometries.length; i++) {
  envelope.expandToInclude(geometries[i].getEnvelopeInternal());
 }
 return envelope;
}

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

public double measure(Geometry g1, Geometry g2)
{        
  double distance = DiscreteHausdorffDistance.distance(g1, g2, DENSIFY_FRACTION);
  
  Envelope env = new Envelope(g1.getEnvelopeInternal());
  env.expandToInclude(g2.getEnvelopeInternal());
  double envSize = diagonalSize(env);
  // normalize so that more similarity produces a measure closer to 1
  double measure = 1 - distance / envSize;
  
  //System.out.println("Hausdorff distance = " + distance + ", measure = " + measure);
  return measure;
}

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

public boolean contains(Geometry geom)
{
 // the test geometry must be wholly contained in the rectangle envelope
 if (! rectEnv.contains(geom.getEnvelopeInternal()))
  return false;
 
 /**
  * Check that geom is not contained entirely in the rectangle boundary.
  * According to the somewhat odd spec of the SFS, if this
  * is the case the geometry is NOT contained.
  */
 if (isContainedInBoundary(geom))
  return false;
 return true;
}

代码示例来源: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

/**
 * Finds a reasonable point at which to label a Geometry.
 * @param geometry the geometry to analyze
 */
public void addPolygon(Geometry geometry) {
  LineString bisector = horizontalBisector(geometry);
  Geometry intersections = bisector.intersection(geometry);
  Geometry widestIntersection = widestGeometry(intersections);
  double width = widestIntersection.getEnvelopeInternal().getWidth();
  if (interiorPoint == null || width > maxWidth) {
   interiorPoint = centre(widestIntersection.getEnvelopeInternal());
   maxWidth = width;
  }
}

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

protected LineString horizontalBisector(Geometry geometry) {
 Envelope envelope = geometry.getEnvelopeInternal();
 // Assert: for areas, minx <> maxx
 double avgY = avg(envelope.getMinY(), envelope.getMaxY());
 return factory.createLineString(new Coordinate[] {
     new Coordinate(envelope.getMinX(), avgY),
     new Coordinate(envelope.getMaxX(), avgY)
   });
}

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

private Geometry widestGeometry(GeometryCollection gc) {
 if (gc.isEmpty()) {
   return gc;
 }
 Geometry widestGeometry = gc.getGeometryN(0);
 for (int i = 1; i < gc.getNumGeometries(); i++) { //Start at 1
   if (gc.getGeometryN(i).getEnvelopeInternal().getWidth() >
     widestGeometry.getEnvelopeInternal().getWidth()) {
     widestGeometry = gc.getGeometryN(i);
   }
 }
 return widestGeometry;
}

相关文章