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

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

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

Geometry.union介绍

[英]Computes the union of all the elements of this geometry.

This method supports GeometryCollections (which the other overlay operations currently do not).

The result obeys the following contract:

  • Unioning a set of LineStrings has the effect of fully noding and dissolving the linework.
  • Unioning a set of Polygons always returns a Polygonal geometry (unlike #union(Geometry), which may return geometries of lower dimension if a topology collapse occurred).
    [中]计算此几何图形的所有元素的并集。
    此方法支持GeometryCollection(其他覆盖操作当前不支持)。
    结果符合以下合同:
    *合并一组线串具有完全点头和溶解线条的效果。
    *合并一组多边形始终会返回多边形几何体(与#union(geometry)不同,如果发生拓扑崩溃,则#union(geometry)可能会返回低维几何体)。

代码示例

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

  1. public static Geometry union(Geometry arg0, Geometry arg1) {
  2. if (arg0 == null || arg1 == null) return null;
  3. Geometry _this = arg0;
  4. return _this.union(arg1);
  5. }

代码示例来源:origin: locationtech/spatial4j

  1. private static Geometry unionGeometryCollection(Geometry geom) {
  2. if (geom instanceof GeometryCollection) {
  3. return geom.union();
  4. }
  5. return geom;
  6. }

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

  1. public Geometry union() {
  2. return geometry.union();
  3. }

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

  1. public Geometry union(Geometry other) {
  2. return geometry.union(other);
  3. }

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

  1. /**
  2. * Returns true if the geometry covers the entire world
  3. *
  4. * @param geometry
  5. * @return
  6. */
  7. private boolean isWorld(Literal geometry) {
  8. if (geometry != null) {
  9. Geometry g = geometry.evaluate(null, Geometry.class);
  10. if (g != null) {
  11. return JTS.toGeometry(WORLD).equalsTopo(g.union());
  12. }
  13. }
  14. return false;
  15. }

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

  1. @DescribeProcess(
  2. title = "Union",
  3. description =
  4. "Returns a geometry representing all points contained in any of the geometries in a geometry collection."
  5. )
  6. @DescribeResult(description = "Union of input geometries")
  7. public static Geometry union(
  8. @DescribeParameter(name = "geom", description = "Input geometries (minimum 2)", min = 2)
  9. Geometry... geoms) {
  10. Geometry result = null;
  11. for (Geometry g : geoms) {
  12. if (result == null) {
  13. result = g;
  14. } else {
  15. result = result.union(g);
  16. }
  17. }
  18. return result;
  19. }

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

  1. @DescribeProcess(title = "Split Polygon", description = "Splits a polygon by a linestring")
  2. @DescribeResult(description = "The collection of split polygons")
  3. public static Geometry splitPolygon(
  4. @DescribeParameter(name = "polygon", description = "Polygon to split") Geometry polygon,
  5. @DescribeParameter(name = "line", description = "Linestring to split by")
  6. LineString line) {
  7. Geometry nodedLinework = polygon.getBoundary().union(line);
  8. Geometry polys = polygonize(nodedLinework);
  9. // Only keep polygons which are inside the input
  10. List<Polygon> output = new ArrayList<Polygon>();
  11. for (int i = 0; i < polys.getNumGeometries(); i++) {
  12. Polygon candpoly = (Polygon) polys.getGeometryN(i);
  13. // use interior point to test for inclusion in parent
  14. if (polygon.contains(candpoly.getInteriorPoint())) {
  15. output.add(candpoly);
  16. }
  17. }
  18. return polygon.getFactory()
  19. .createGeometryCollection(GeometryFactory.toGeometryArray(output));
  20. }

代码示例来源:origin: org.n52.sensorweb.sos/hibernate-common

  1. private Geometry mergeGeometries(Geometry geom, List<Object> list) {
  2. for (Object extent : list) {
  3. if (extent != null) {
  4. if (geom == null) {
  5. geom = (Geometry) extent;
  6. } else {
  7. geom.union((Geometry) extent);
  8. }
  9. }
  10. }
  11. return geom;
  12. }

代码示例来源:origin: locationtech/jts

  1. private Geometry repeatedUnion(List geoms)
  2. {
  3. Geometry union = null;
  4. for (Iterator i = geoms.iterator(); i.hasNext(); ) {
  5. Geometry g = (Geometry) i.next();
  6. if (union == null)
  7. union = g.copy();
  8. else
  9. union = union.union(g);
  10. }
  11. return union;
  12. }

代码示例来源:origin: locationtech/jts

  1. public static Geometry bufferByComponents(Geometry g, double distance)
  2. {
  3. return componentBuffers(g, distance).union();
  4. }

代码示例来源:origin: locationtech/jts

  1. (new FailureChecker() { void operation() {
  2. b.union(a);
  3. } }).check(IllegalArgumentException.class);
  4. }

代码示例来源:origin: locationtech/jts

  1. (new FailureChecker() { void operation() {
  2. a.union(b);
  3. } }).check(IllegalArgumentException.class);

代码示例来源:origin: org.opengeo/geodb

  1. @Override
  2. protected void add(Geometry geometry) {
  3. if (result == null) {
  4. result = geometry;
  5. } else {
  6. if (geometry != null) {
  7. result = result.union(geometry.getEnvelope());
  8. }
  9. }
  10. }

代码示例来源:origin: locationtech/jts

  1. public static Geometry logoLines(Geometry g)
  2. {
  3. return create_J(g)
  4. .union(create_T(g))
  5. .union(create_S(g));
  6. }

代码示例来源:origin: locationtech/jts

  1. public static Geometry unionUsingGeometryCollection(Geometry a, Geometry b)
  2. {
  3. Geometry gc = a.getFactory().createGeometryCollection(
  4. new Geometry[] { a, b});
  5. return gc.union();
  6. }

代码示例来源:origin: locationtech/jts

  1. /**
  2. * Computes the set-theoretic union of two {@link Geometry}s, using enhanced precision.
  3. * @param geom0 the first Geometry
  4. * @param geom1 the second Geometry
  5. * @return the Geometry representing the set-theoretic union of the input Geometries.
  6. */
  7. public Geometry union(Geometry geom0, Geometry geom1)
  8. {
  9. Geometry[] geom = removeCommonBits(geom0, geom1);
  10. return computeResultPrecision(geom[0].union(geom[1]));
  11. }

代码示例来源:origin: locationtech/jts

  1. public static Geometry invokeGeometryOverlayMethod(int opCode, Geometry g0, Geometry g1)
  2. {
  3. switch (opCode) {
  4. case OverlayOp.INTERSECTION: return g0.intersection(g1);
  5. case OverlayOp.UNION: return g0.union(g1);
  6. case OverlayOp.DIFFERENCE: return g0.difference(g1);
  7. case OverlayOp.SYMDIFFERENCE: return g0.symDifference(g1);
  8. }
  9. throw new IllegalArgumentException("Unknown overlay op code");
  10. }

代码示例来源:origin: locationtech/jts

  1. public double measure(Geometry g1, Geometry g2)
  2. {
  3. double areaInt = g1.intersection(g2).getArea();
  4. double areaUnion = g1.union(g2).getArea();
  5. return areaInt / areaUnion;
  6. }

代码示例来源:origin: locationtech/jts

  1. public void testNoding() throws Exception {
  2. Geometry a = reader.read("LINESTRING(0 0, 100 100)");
  3. Geometry b = reader.read("LINESTRING(0 100, 100 0)");
  4. List lineStrings = Arrays.asList(new Object[] {a, b});
  5. Geometry nodedLineStrings = (LineString) lineStrings.get(0);
  6. for (int i = 1; i < lineStrings.size(); i++) {
  7. nodedLineStrings = nodedLineStrings.union((LineString)lineStrings.get(i));
  8. }
  9. assertEquals("MULTILINESTRING ((0 0, 50 50), (50 50, 100 100), (0 100, 50 50), (50 50, 100 0))", nodedLineStrings.toString());
  10. }

代码示例来源:origin: locationtech/jts

  1. private Geometry dissolveLines(Geometry lines) {
  2. Geometry dissolved = lines.union();
  3. LineMerger merger = new LineMerger();
  4. merger.add(dissolved);
  5. Collection mergedColl = merger.getMergedLineStrings();
  6. Geometry merged = lines.getFactory().buildGeometry(mergedColl);
  7. return merged;
  8. }

相关文章