com.vividsolutions.jts.operation.union.UnaryUnionOp.union()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(141)

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

UnaryUnionOp.union介绍

[英]Gets the union of the input geometries. If no input geometries were provided but a GeometryFactory was provided, an empty GeometryCollection is returned. Otherwise, the return value is null.
[中]获取输入几何图形的并集。如果未提供输入几何图形,但提供了GeometryFactory,则返回空的GeometryCollection。否则,返回值为[$0$]。

代码示例

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

/**
 * Computes the union of all the elements of this geometry. 
 * <p>
 * <code>union()</code> supports
 * {@link GeometryCollection}s 
 * (which the other overlay operations currently do not).
 * <p>
 * The result obeys the following contract:
 * <ul>
 * <li>Unioning a set of {@link LineString}s has the effect of fully noding
 * and dissolving the linework.
 * <li>Unioning a set of {@link Polygon}s will always 
 * return a {@link Polygonal} geometry (unlike {@link #union(Geometry)},
 * which may return geometrys of lower dimension if a topology collapse occurred.
 * </ul>
 * 
 * @return the union geometry
* @throws TopologyException if a robustness error occurs
 * 
 * @see UnaryUnionOp
 */
public Geometry union() {
  return UnaryUnionOp.union(this);
}

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

public static Geometry union(Geometry geom)
{
  UnaryUnionOp op = new UnaryUnionOp(geom);
  return op.union();
}

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

public static Geometry union(Collection geoms)
{
  UnaryUnionOp op = new UnaryUnionOp(geoms);
  return op.union();
}

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

public static Geometry union(Collection geoms, GeometryFactory geomFact)
{
  UnaryUnionOp op = new UnaryUnionOp(geoms, geomFact);
  return op.union();
}

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

/**
   * @param geomList Geometry list
   * @return union of all Geometries in geomList
   */
  public static Geometry union(Geometry geomList) {
    return UnaryUnionOp.union(geomList);
  }
}

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

/**
   * @param geomList Geometry list
   * @return union of all Geometries in geomList
   */
  public static Geometry union(Geometry geomList) {
    return UnaryUnionOp.union(geomList);
  }
}

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

/**
   * @param geomList Geometry list
   * @return union of all Geometries in geomList
   */
  public static Geometry union(Geometry geomList) {
    return UnaryUnionOp.union(geomList);
  }
}

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

/**
 * Computes the union of all the elements of this geometry. 
 * <p>
 * This method supports
 * {@link GeometryCollection}s 
 * (which the other overlay operations currently do not).
 * <p>
 * The result obeys the following contract:
 * <ul>
 * <li>Unioning a set of {@link LineString}s has the effect of fully noding
 * and dissolving the linework.
 * <li>Unioning a set of {@link Polygon}s always 
 * returns a {@link Polygonal} geometry (unlike {@link #union(Geometry)},
 * which may return geometries of lower dimension if a topology collapse occurred).
 * </ul>
 * 
 * @return the union geometry
 * @throws TopologyException if a robustness error occurs
 * 
 * @see UnaryUnionOp
 */
public Geometry union() {
  return UnaryUnionOp.union(this);
}

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

/**
 * Constructs a unary union operation for a {@link Geometry}
 * (which may be a {@link GeometryCollection}).
 * 
 * @param geom a geometry to union
 * @return the union of the elements of the geometry
 * or an empty GEOMETRYCOLLECTION
 */
public static Geometry union(Geometry geom)
{
  UnaryUnionOp op = new UnaryUnionOp(geom);
  return op.union();
}

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

/**
 * Computes the geometric union of a {@link Collection} 
 * of {@link Geometry}s.
 * 
 * @param geoms a collection of geometries
 * @return the union of the geometries, 
 * or <code>null</code> if the input is empty
 */
public static Geometry union(Collection geoms)
{
  UnaryUnionOp op = new UnaryUnionOp(geoms);
  return op.union();
}

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

/**
 * Computes the geometric union of a {@link Collection} 
 * of {@link Geometry}s.
 * 
 * If no input geometries were provided but a {@link GeometryFactory} was provided, 
 * an empty {@link GeometryCollection} is returned.
 *
 * @param geoms a collection of geometries
 * @param geomFact the geometry factory to use if the collection is empty
 * @return the union of the geometries,
 * or an empty GEOMETRYCOLLECTION
 */
public static Geometry union(Collection geoms, GeometryFactory geomFact)
{
  UnaryUnionOp op = new UnaryUnionOp(geoms, geomFact);
  return op.union();
}

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

private Collection<Geometry> unionAdjacentPolygons(Collection<Geometry> list) {
  UnaryUnionOp op = new UnaryUnionOp(list);
  Geometry result = op.union();
  if (result.getNumGeometries() < list.size()) {
    list.clear();
    for (int i = 0; i < result.getNumGeometries(); i++) {
      list.add(result.getGeometryN(i));
    }
  }
  return list;
}

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

private Collection<Geometry> unionAdjacentPolygons(Collection<Geometry> list) {
  UnaryUnionOp op = new UnaryUnionOp(list);
  Geometry result = op.union();
  if (result.getNumGeometries() < list.size()) {
    list.clear();
    for (int i = 0; i < result.getNumGeometries(); i++) {
      list.add(result.getGeometryN(i));
    }
  }
  return list;
}

代码示例来源:origin: conveyal/r5

/**
 * Create a geometry in FIXED POINT DEGREES containing all the points on all edges created or removed by the
 * scenario that produced this StreetLayer, buffered by radiusMeters. This is a MultiPolygon or GeometryCollection.
 * When there are no created or removed edges, returns an empty geometry rather than null, because we test whether
 * transit stops are contained within the resulting geometry.
 */
public Geometry scenarioEdgesBoundingGeometry(int radiusMeters) {
  List<Polygon> geoms = new ArrayList<>();
  Edge edge = edgeStore.getCursor();
  edgeStore.forEachTemporarilyAddedOrDeletedEdge(e -> {
    edge.seek(e);
    Envelope envelope = edge.getEnvelope();
    GeometryUtils.expandEnvelopeFixed(envelope, radiusMeters);
    geoms.add((Polygon)GeometryUtils.geometryFactory.toGeometry(envelope));
  });
  // We can't just make a multipolygon as the component polygons may not be disjoint. Unions are pretty quick though.
  // The UnaryUnionOp gets its geometryFactory from the geometries it's operating on.
  // We need to supply one in case the list is empty, so it can return an empty geometry instead of null.
  Geometry result = new UnaryUnionOp(geoms, GeometryUtils.geometryFactory).union();
  // logFixedPointGeometry("Unioned buffered streets", result);
  return result;
}

代码示例来源:origin: com.conveyal/r5

/**
 * Create a geometry in FIXED POINT DEGREES containing all the points on all edges created or removed by the
 * scenario that produced this StreetLayer, buffered by radiusMeters. This is a MultiPolygon or GeometryCollection.
 * When there are no created or removed edges, returns an empty geometry rather than null, because we test whether
 * transit stops are contained within the resulting geometry.
 */
public Geometry scenarioEdgesBoundingGeometry(int radiusMeters) {
  List<Polygon> geoms = new ArrayList<>();
  Edge edge = edgeStore.getCursor();
  edgeStore.forEachTemporarilyAddedOrDeletedEdge(e -> {
    edge.seek(e);
    Envelope envelope = edge.getEnvelope();
    GeometryUtils.expandEnvelopeFixed(envelope, radiusMeters);
    geoms.add((Polygon)GeometryUtils.geometryFactory.toGeometry(envelope));
  });
  // We can't just make a multipolygon as the component polygons may not be disjoint. Unions are pretty quick though.
  // The UnaryUnionOp gets its geometryFactory from the geometries it's operating on.
  // We need to supply one in case the list is empty, so it can return an empty geometry instead of null.
  Geometry result = new UnaryUnionOp(geoms, GeometryUtils.geometryFactory).union();
  // logFixedPointGeometry("Unioned buffered streets", result);
  return result;
}

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

/**
 * Splits a Polygon with a LineString.
 *
 * @param polygon
 * @param lineString
 * @return
 */
public static Collection<Polygon> splitPolygonizer(Polygon polygon, LineString lineString) {
  Set<LineString> segments = GeometryConvert.toSegmentsLineString(polygon.getExteriorRing());
  segments.add(lineString);
  int holes = polygon.getNumInteriorRing();
  for (int i = 0; i < holes; i++) {
    segments.addAll(GeometryConvert.toSegmentsLineString(polygon.getInteriorRingN(i)));
  }
  // Perform union of all extracted LineStrings (the edge-noding process)  
  UnaryUnionOp uOp = new UnaryUnionOp(segments);
  Geometry union = uOp.union();
  // Create polygons from unioned LineStrings  
  Polygonizer polygonizer = new Polygonizer();
  polygonizer.add(union);
  Collection<Polygon> polygons = polygonizer.getPolygons();
  if (polygons.size() > 1) {
    return polygons;
  }
  return null;
}

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

/**
 * Splits a Polygon with a LineString.
 *
 * @param polygon
 * @param lineString
 * @return
 */
private static Collection<Polygon> splitPolygonizer(Polygon polygon, LineString lineString) throws SQLException {
  LinkedList<LineString> result = new LinkedList<LineString>();
  ST_ToMultiSegments.createSegments(polygon.getExteriorRing(), result);
  result.add(lineString);
  int holes = polygon.getNumInteriorRing();
  for (int i = 0; i < holes; i++) {
    ST_ToMultiSegments.createSegments(polygon.getInteriorRingN(i), result);
  }
  // Perform union of all extracted LineStrings (the edge-noding process)  
  UnaryUnionOp uOp = new UnaryUnionOp(result);
  Geometry union = uOp.union();
  // Create polygons from unioned LineStrings  
  Polygonizer polygonizer = new Polygonizer();
  polygonizer.add(union);
  Collection<Polygon> polygons = polygonizer.getPolygons();
  if (polygons.size() > 1) {
    return polygons;
  }
  return null;
}

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

/**
 * Splits a Polygon with a LineString.
 *
 * @param polygon
 * @param lineString
 * @return
 */
private static Collection<Polygon> splitPolygonizer(Polygon polygon, LineString lineString) throws SQLException {
  LinkedList<LineString> result = new LinkedList<LineString>();
  ST_ToMultiSegments.createSegments(polygon.getExteriorRing(), result);
  result.add(lineString);
  int holes = polygon.getNumInteriorRing();
  for (int i = 0; i < holes; i++) {
    ST_ToMultiSegments.createSegments(polygon.getInteriorRingN(i), result);
  }
  // Perform union of all extracted LineStrings (the edge-noding process)  
  UnaryUnionOp uOp = new UnaryUnionOp(result);
  Geometry union = uOp.union();
  // Create polygons from unioned LineStrings  
  Polygonizer polygonizer = new Polygonizer();
  polygonizer.add(union);
  Collection<Polygon> polygons = polygonizer.getPolygons();
  if (polygons.size() > 1) {
    return polygons;
  }
  return null;
}

代码示例来源:origin: harbby/presto-connectors

/**
 * This "pages" through standard geo boundaries offset by multiples of 360
 * longitudinally that intersect geom, and the intersecting results of a page
 * and the geom are shifted into the standard -180 to +180 and added to a new
 * geometry that is returned.
 */
private static Geometry cutUnwrappedGeomInto360(Geometry geom) {
 Envelope geomEnv = geom.getEnvelopeInternal();
 if (geomEnv.getMinX() >= -180 && geomEnv.getMaxX() <= 180)
  return geom;
 assert geom.isValid() : "geom";
 //TODO opt: support geom's that start at negative pages --
 // ... will avoid need to previously shift in unwrapDateline(geom).
 List<Geometry> geomList = new ArrayList<Geometry>();
 //page 0 is the standard -180 to 180 range
 for (int page = 0; true; page++) {
  double minX = -180 + page * 360;
  if (geomEnv.getMaxX() <= minX)
   break;
  Geometry rect = geom.getFactory().toGeometry(new Envelope(minX, minX + 360, -90, 90));
  assert rect.isValid() : "rect";
  Geometry pageGeom = rect.intersection(geom);//JTS is doing some hard work
  assert pageGeom.isValid() : "pageGeom";
  shiftGeomByX(pageGeom, page * -360);
  geomList.add(pageGeom);
 }
 return UnaryUnionOp.union(geomList);
}

代码示例来源:origin: com.spatial4j/spatial4j

/**
 * This "pages" through standard geo boundaries offset by multiples of 360
 * longitudinally that intersect geom, and the intersecting results of a page
 * and the geom are shifted into the standard -180 to +180 and added to a new
 * geometry that is returned.
 */
private static Geometry cutUnwrappedGeomInto360(Geometry geom) {
 Envelope geomEnv = geom.getEnvelopeInternal();
 if (geomEnv.getMinX() >= -180 && geomEnv.getMaxX() <= 180)
  return geom;
 assert geom.isValid() : "geom";
 //TODO opt: support geom's that start at negative pages --
 // ... will avoid need to previously shift in unwrapDateline(geom).
 List<Geometry> geomList = new ArrayList<Geometry>();
 //page 0 is the standard -180 to 180 range
 for (int page = 0; true; page++) {
  double minX = -180 + page * 360;
  if (geomEnv.getMaxX() <= minX)
   break;
  Geometry rect = geom.getFactory().toGeometry(new Envelope(minX, minX + 360, -90, 90));
  assert rect.isValid() : "rect";
  Geometry pageGeom = rect.intersection(geom);//JTS is doing some hard work
  assert pageGeom.isValid() : "pageGeom";
  shiftGeomByX(pageGeom, page * -360);
  geomList.add(pageGeom);
 }
 return UnaryUnionOp.union(geomList);
}

相关文章