本文整理汇总了Java中com.vividsolutions.jts.operation.union.UnaryUnionOp.union方法的典型用法代码示例。如果您正苦于以下问题:Java UnaryUnionOp.union方法的具体用法?Java UnaryUnionOp.union怎么用?Java UnaryUnionOp.union使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vividsolutions.jts.operation.union.UnaryUnionOp
的用法示例。
在下文中一共展示了UnaryUnionOp.union方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connect
import com.vividsolutions.jts.operation.union.UnaryUnionOp; //导入方法依赖的package包/类
/**
* Forms create edges between two shapes maintaining convexity.
*
* Does not currently work if the shapes intersect
*
* @param shape1
* @param shape2
* @return
*/
public Geometry connect(
final Geometry shape1,
final Geometry shape2 ) {
try {
if (shape1 instanceof Polygon && shape2 instanceof Polygon && !shape1.intersects(shape2)) return connect(
shape1,
shape2,
getClosestPoints(
shape1,
shape2,
distanceFnForCoordinate));
return UnaryUnionOp.union(Arrays.asList(
shape1,
shape2));
}
catch (Exception ex) {
LOGGER.warn(
"Exception caught in connect method",
ex);
}
return createHullFromGeometry(
shape1,
Arrays.asList(shape2.getCoordinates()),
false);
}
示例2: getResult
import com.vividsolutions.jts.operation.union.UnaryUnionOp; //导入方法依赖的package包/类
/** Uses a JTS Polygonizer to identify all possible polygons from a set
* of input linework, then uses an iterative algorithm to determine which
* of the returned polygons represent holes. The algorithm is:
* 1. Identify the outermost polygons in the returned set (those polygons
* that have at least one unique vertex). These polygons cannot
* be holes.
* 2. Classify as a "hole" any polygon that has a linear intersection with
* a non-hole polygon.
* 3. Classify as "non-hole" any polygon that has a linear intersection
* with a hole polygon.
* 4. Repeat steps 2-3 until all polygons have been classified.
*
* @return A single Geometry representing the union of all non-hole polygons.
*/
public Geometry getResult() {
Collection<Geometry> polys = polygen.getPolygons();
Set<Geometry> exteriorPolys = new HashSet<>(getNonRedundantGeom(polys));
Set<Geometry> unknownPolys = new HashSet<>(polys);
Set<Geometry> interiorPolys = new HashSet<>();
unknownPolys.removeAll(exteriorPolys);
Geometry mainPoly = UnaryUnionOp.union(exteriorPolys);
Geometry holePoly = null;
boolean changed = true;
while (!unknownPolys.isEmpty() && changed) {
interiorPolys.clear();
exteriorPolys.clear();
changed = false;
for (Geometry p : unknownPolys) {
if (p.intersects(mainPoly) && p.intersection(mainPoly).getDimension() > 0) {
changed = true;
interiorPolys.add(p);
} else if (holePoly != null && p.intersects(holePoly) && p.intersection(holePoly).getDimension() > 0) {
changed = true;
exteriorPolys.add(p);
}
}
unknownPolys.removeAll(exteriorPolys);
unknownPolys.removeAll(interiorPolys);
if (!exteriorPolys.isEmpty()) {
exteriorPolys.add(mainPoly);
mainPoly = UnaryUnionOp.union(exteriorPolys);
}
if (!interiorPolys.isEmpty()) {
if (holePoly != null) {
interiorPolys.add(holePoly);
}
holePoly = UnaryUnionOp.union(interiorPolys);
}
}
return mainPoly;
}
示例3: getResult
import com.vividsolutions.jts.operation.union.UnaryUnionOp; //导入方法依赖的package包/类
public Object getResult()
{
return UnaryUnionOp.union(geoms);
}
示例4: cutOnPoles
import com.vividsolutions.jts.operation.union.UnaryUnionOp; //导入方法依赖的package包/类
/**
* Cut given polygon on poles (89 and -89)
*/
private static String cutOnPoles(String polygonWKT) throws Exception
{
JtsSpatialContextFactory noCheckFactory = new JtsSpatialContextFactory();
noCheckFactory.datelineRule = DatelineRule.none;
noCheckFactory.validationRule = ValidationRule.none;
JtsSpatialContext noCheckContext = noCheckFactory.newSpatialContext();
JtsWKTReaderShapeParser noCheckParser =
new JtsWKTReaderShapeParser(noCheckContext, noCheckFactory);
JtsGeometry polygon = (JtsGeometry) noCheckParser.parse(polygonWKT);
JtsGeometry northPole =
(JtsGeometry) noCheckParser.parse("LINESTRING(180 89, 0 89, -180 89)");
JtsGeometry southPole =
(JtsGeometry) noCheckParser.parse("LINESTRING(180 -89, 0 -89, -180 -89)");
LineMerger lm = new LineMerger();
lm.add(polygon.getGeom());
lm.add(northPole.getGeom());
lm.add(southPole.getGeom());
Geometry geometry = UnaryUnionOp.union(lm.getMergedLineStrings());
Polygonizer polygonizer = new Polygonizer();
polygonizer.add(geometry);
List<Polygon> foundPolygons = (List<Polygon>) polygonizer.getPolygons();
List<Polygon> filteredPolygons = new ArrayList<>();
for (Polygon p: foundPolygons)
{
// removing polygons over the poles
if (p.getCentroid().getCoordinate().y < 89 && p.getCentroid().getCoordinate().y > -89)
{
filteredPolygons.add(p);
}
}
Geometry res = null;
if (!filteredPolygons.isEmpty())
{
res = filteredPolygons.get(0);
}
if (filteredPolygons.size() > 1)
{
// Should not happen...
LOGGER.error("A Multipolygon was found, instead of a single polygon. Only the first one is retained.");
}
WKTWriter wkw = new WKTWriter();
return wkw.write(res);
}
示例5: union
import com.vividsolutions.jts.operation.union.UnaryUnionOp; //导入方法依赖的package包/类
/**
* 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);
}
示例6: union
import com.vividsolutions.jts.operation.union.UnaryUnionOp; //导入方法依赖的package包/类
/**
* 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);
}
示例7: union
import com.vividsolutions.jts.operation.union.UnaryUnionOp; //导入方法依赖的package包/类
/**
* 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);
}