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

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

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

Geometry.intersection介绍

[英]Computes a Geometry representing the point-set which is common to both this Geometry and the other Geometry.

The intersection of two geometries of different dimension produces a result geometry of dimension less than or equal to the minimum dimension of the input geometries. The result geometry may be a heterogenous GeometryCollection. If the result is empty, it is an atomic geometry with the dimension of the lowest input dimension.

Intersection of GeometryCollections is supported only for homogeneous collection types.

Non-empty heterogeneous GeometryCollection arguments are not supported.
[中]计算表示此Geometryother几何体共用的点集的Geometry
两个不同尺寸的几何图形的交点生成的结果几何图形的尺寸小于或等于输入几何图形的最小尺寸。结果几何体可能是非均质几何体集合。如果结果为空,则它是具有最低输入维度维度的原子几何体。
只有同构集合类型才支持GeometryCollection的交集。
不支持非空的异构GeometryCollection参数。

代码示例

代码示例来源: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: com.vividsolutions/jts

public Geometry map(Geometry g) {
  return g.intersection(g2);
 }
});

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

for (NamedArea area : areas) {
  Geometry polygon = area.getPolygon();
  Geometry intersection = polygon.intersection(line);
  if (intersection.getLength() > 0.000001) {
    intersects.add(area);

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

public void intersection(String wktA, String wktB, PrecisionModel pm)
  throws ParseException
{
 System.out.println("Running example using Precision Model = " + pm);
 GeometryFactory fact = new GeometryFactory(pm);
 WKTReader wktRdr = new WKTReader(fact);
 Geometry A = wktRdr.read(wktA);
 Geometry B = wktRdr.read(wktB);
 Geometry C = A.intersection(B);
 System.out.println("A intersection B = " + C);
}

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

public static void main(String[] args)
   throws Exception
 {
  // read a geometry from a WKT string (using the default geometry factory)
  Geometry g1 = new WKTReader().read("LINESTRING (0 0, 10 10, 20 20)");
  System.out.println("Geometry 1: " + g1);

  // create a geometry by specifying the coordinates directly
  Coordinate[] coordinates = new Coordinate[]{new Coordinate(0, 0),
   new Coordinate(10, 10), new Coordinate(20, 20)};
  // use the default factory, which gives full double-precision
  Geometry g2 = new GeometryFactory().createLineString(coordinates);
  System.out.println("Geometry 2: " + g2);

  // compute the intersection of the two geometries
  Geometry g3 = g1.intersection(g2);
  System.out.println("G1 intersection G2: " + g3);
 }
}

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

/**
 * Computes the set-theoretic intersection of two {@link Geometry}s, using enhanced precision.
 * @param geom0 the first Geometry
 * @param geom1 the second Geometry
 * @return the Geometry representing the set-theoretic intersection of the input Geometries.
 */
public Geometry intersection(Geometry geom0, Geometry geom1)
{
 Geometry[] geom = removeCommonBits(geom0, geom1);
 return computeResultPrecision(geom[0].intersection(geom[1]));
}

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

public void run()
 throws ParseException
{
 GeometryFactory fact = new GeometryFactory();
 WKTReader wktRdr = new WKTReader(fact);
 String wktA = "POLYGON((40 100, 40 20, 120 20, 120 100, 40 100))";
 String wktB = "LINESTRING(20 80, 80 60, 100 140)";
 Geometry A = wktRdr.read(wktA);
 Geometry B = wktRdr.read(wktB);
 Geometry C = A.intersection(B);
 System.out.println("A = " + A);
 System.out.println("B = " + B);
 System.out.println("A intersection B = " + C);
 System.out.println("A relate C = " + A.relate(B));
}

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

public double measure(Geometry g1, Geometry g2)
{        
  double areaInt = g1.intersection(g2).getArea();
  double areaUnion = g1.union(g2).getArea();
  return areaInt / areaUnion;
}

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

void run()
  throws Exception
{
 String wkt1, wkt2;
 // two geometries which cause robustness problems
 wkt1 = "POLYGON ((708653.498611049 2402311.54647056, 708708.895756966 2402203.47250014, 708280.326454234 2402089.6337791, 708247.896591321 2402252.48269854, 708367.379593851 2402324.00761653, 708248.882609455 2402253.07294874, 708249.523621829 2402244.3124463, 708261.854734465 2402182.39086576, 708262.818392579 2402183.35452387, 708653.498611049 2402311.54647056))";
 wkt2 = "POLYGON ((708258.754920656 2402197.91172757, 708257.029447455 2402206.56901508, 708652.961095455 2402312.65463437, 708657.068786251 2402304.6356364, 708258.754920656 2402197.91172757))";
 Geometry g1 = reader.read(wkt1);
 Geometry g2 = reader.read(wkt2);
 System.out.println("This call to intersection will throw a topology exception due to robustness problems:");
 try {
  Geometry result = g1.intersection(g2);
 }
 catch (TopologyException ex) {
  ex.printStackTrace();
 }
 System.out.println("Using EnhancedPrecisionOp allows the intersection to be performed with no errors:");
 Geometry result = EnhancedPrecisionOp.intersection(g1, g2);
 System.out.println(result);
}

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

Geometry result = geom0.intersection(geom1);
return result;

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

System.out.println("Internal rep for g2: " + ((Polygon) g2).getExteriorRing().getCoordinateSequence());
Geometry gInt = g1.intersection(g2);

代码示例来源:origin: org.orbisgis/h2gis

/**
   * @param a Geometry instance.
   * @param b Geometry instance
   * @return the intersection between two geometries
   */
  public static Geometry intersection(Geometry a,Geometry b) {
    if(a==null || b==null) {
      return null;
    }
    return a.intersection(b);
  }
}

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

private static Geometry clipGeometryCollection(Geometry geom, Envelope clipEnv)
  {
    Geometry clipPoly = geom.getFactory().toGeometry(clipEnv);
    List clipped = new ArrayList();
    for (int i = 0; i < geom.getNumGeometries(); i++) {
      Geometry g = geom.getGeometryN(i);
      Geometry result = null;
      // don't clip unless necessary
      if (clipEnv.contains(g.getEnvelopeInternal()))
          result = g;
      else if (clipEnv.intersects(g.getEnvelopeInternal())) {
        result = clipPoly.intersection(g);
        // keep vertex key info
        result.setUserData(g.getUserData());
      }

      if (result != null && ! result.isEmpty()) {
        clipped.add(result);
      }
    }
    return geom.getFactory().createGeometryCollection(GeometryFactory.toGeometryArray(clipped));
  }
}

代码示例来源:origin: matsim-org/matsim

static Collection<Geometry> cutPolygonsByBoundary(Collection<Polygon> polygons, Polygon boundingPolygon) {
    Collection<Geometry> cutPolygons = new LinkedList<>();
    for (Polygon polygon : polygons) {
      // Need to determine convex hull of geometry to prevent it from staying self-intersecting
      Geometry hull = polygon.convexHull();
      Geometry intersection = hull.intersection(boundingPolygon);
      cutPolygons.add(intersection);
    }
    return cutPolygons;
  }
}

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

public void intersection(String wktA, String wktB, PrecisionModel pm)
  throws ParseException
{
 System.out.println("Running example using Precision Model = " + pm);
 GeometryFactory fact = new GeometryFactory(pm);
 WKTReader wktRdr = new WKTReader(fact);
 Geometry A = wktRdr.read(wktA);
 Geometry B = wktRdr.read(wktB);
 Geometry C = A.intersection(B);
 System.out.println("A intersection B = " + C);
}

代码示例来源:origin: org.geotools/gt-coverage

/**
 * Helper method for {@link #intersection(Geometry, Geometry) intersection(Geometry, Geometry)}
 */
private static List<Geometry> intersection(GeometryCollection gc, Geometry g) {
  List<Geometry> ret = new ArrayList<Geometry>();
  final int size=gc.getNumGeometries();
  for (int i = 0; i < size; i++) {
    Geometry g1 = (Geometry)gc.getGeometryN(i);
    collect(g1.intersection(g), ret);
  }
  return ret;
}

代码示例来源:origin: Stratio/cassandra-lucene-index

/**
 * Returns the intersection of the specified shapes.
 *
 * @return the intersection
 */
@Override
public JtsGeometry apply() {
  Geometry result = shapes.get(0).apply().getGeom();
  for (int i = 1; i < shapes.size(); i++) {
    result = result.intersection(shapes.get(i).apply().getGeom());
  }
  return CONTEXT.makeShape(result);
}

代码示例来源:origin: BaseXdb/basex

@Override
 public Item item(final QueryContext qc, final InputInfo ii) throws QueryException {
  return toElement(checkGeo(0, qc).intersection(checkGeo(1, qc)), qc);
 }
}

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

public double measure(Geometry g1, Geometry g2)
{        
  double areaInt = g1.intersection(g2).getArea();
  double areaUnion = g1.union(g2).getArea();
  return areaInt / areaUnion;
}

代码示例来源:origin: org.teiid/teiid-engine

public static GeometryType intersection(GeometryType geom1, GeometryType geom2) throws FunctionExecutionException {
  Geometry g1 = getGeometry(geom1);
  Geometry g2 = getGeometry(geom2);
  return getGeometryType(g1.intersection(g2), geom1.getSrid());
}

相关文章