Java Code Examples for com.esri.core.geometry.Geometry#isEmpty()

The following examples show how to use com.esri.core.geometry.Geometry#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OGCConcreteGeometryCollection.java    From geometry-api-java with Apache License 2.0 6 votes vote down vote up
private GeometryCursor removeOverlapsHelper_(List<Geometry> geoms) {
	List<Geometry> result = new ArrayList<Geometry>();
	for (int i = 0; i < geoms.size(); ++i) {
		Geometry current = geoms.get(i);
		if (current.isEmpty())
			continue;
		
		for (int j = i + 1; j < geoms.size(); ++j) {
			Geometry subG = geoms.get(j);
			current = OperatorDifference.local().execute(current, subG, esriSR, null);
			if (current.isEmpty())
				break;
		}
		
		if (current.isEmpty())
			continue;
		
		result.add(current);
	}
	
	return new SimpleGeometryCursor(result);
}
 
Example 2
Source File: GeometrySerde.java    From presto with Apache License 2.0 5 votes vote down vote up
private static OGCGeometry createFromEsriGeometry(Geometry geometry, boolean multiType)
{
    Geometry.Type type = geometry.getType();
    switch (type) {
        case Polygon: {
            if (!multiType && ((Polygon) geometry).getExteriorRingCount() <= 1) {
                return new OGCPolygon((Polygon) geometry, null);
            }
            return new OGCMultiPolygon((Polygon) geometry, null);
        }
        case Polyline: {
            if (!multiType && ((Polyline) geometry).getPathCount() <= 1) {
                return new OGCLineString((Polyline) geometry, 0, null);
            }
            return new OGCMultiLineString((Polyline) geometry, null);
        }
        case MultiPoint: {
            if (!multiType && ((MultiPoint) geometry).getPointCount() <= 1) {
                if (geometry.isEmpty()) {
                    return new OGCPoint(new Point(), null);
                }
                return new OGCPoint(((MultiPoint) geometry).getPoint(0), null);
            }
            return new OGCMultiPoint((MultiPoint) geometry, null);
        }
        case Point: {
            if (!multiType) {
                return new OGCPoint((Point) geometry, null);
            }
            return new OGCMultiPoint((Point) geometry, null);
        }
        case Envelope: {
            Polygon polygon = new Polygon();
            polygon.addEnvelope((Envelope) geometry, false);
            return new OGCPolygon(polygon, null);
        }
        default:
            throw new IllegalArgumentException("Unexpected geometry type: " + type);
    }
}
 
Example 3
Source File: OGCConcreteGeometryCollection.java    From geometry-api-java with Apache License 2.0 5 votes vote down vote up
@Override
public OGCGeometry difference(OGCGeometry another) {
	if (isEmpty() || another.isEmpty()) {
		return this;
	}

	List<Geometry> geometries = toList(prepare_for_ops_(toGeometryCollection(this)));
	List<Geometry> otherGeometries = toList(prepare_for_ops_(toGeometryCollection(another)));

	List<OGCGeometry> result = new ArrayList<OGCGeometry>();
	for (Geometry geometry : geometries) {
		for (Geometry otherGeometry : otherGeometries) {
			if (geometry.getDimension() > otherGeometry.getDimension()) {
				continue; //subtracting lower dimension has no effect.
			}

			geometry = OperatorDifference.local().execute(geometry, otherGeometry, esriSR, null);
			if (geometry.isEmpty()) {
				break;
			}
		}

		if (!geometry.isEmpty()) {
			result.add(OGCGeometry.createFromEsriGeometry(geometry, esriSR));
		}
	}

	if (result.size() == 1) {
		return result.get(0).reduceFromMulti();
	}
	
	return new OGCConcreteGeometryCollection(result, esriSR).flattenAndRemoveOverlaps();
}
 
Example 4
Source File: OGCConcreteGeometryCollection.java    From geometry-api-java with Apache License 2.0 4 votes vote down vote up
@Override
public OGCGeometry convexHull() {
	GeometryCursor cursor = OperatorConvexHull.local().execute(
			getEsriGeometryCursor(), false, null);
	MultiPoint mp = new MultiPoint();
	Polygon polygon = new Polygon();
	VertexDescription vd = null;
	for (Geometry geom = cursor.next(); geom != null; geom = cursor.next()) {
		vd = geom.getDescription();
		if (geom.isEmpty())
			continue;

		if (geom.getType() == Geometry.Type.Polygon) {
			polygon.add((MultiPath) geom, false);
		}
		else if (geom.getType() == Geometry.Type.Polyline) {
			mp.add((MultiVertexGeometry) geom, 0, -1);
		}
		else if (geom.getType() == Geometry.Type.Point) {
			mp.add((Point) geom);
		}
		else {
			throw new GeometryException("internal error");
		}
	}

	Geometry resultGeom = null;
	if (!mp.isEmpty()) {
		resultGeom = OperatorConvexHull.local().execute(mp, null);
	}

	if (!polygon.isEmpty()) {
		if (resultGeom != null && !resultGeom.isEmpty()) {
			Geometry[] geoms = { resultGeom, polygon };
			resultGeom = OperatorConvexHull.local().execute(
					new SimpleGeometryCursor(geoms), true, null).next();
		}
		else {
			resultGeom = OperatorConvexHull.local().execute(polygon, null);
		}
	}

	if (resultGeom == null) {
		Point pt = new Point();
		if (vd != null)
			pt.assignVertexDescription(vd);

		return new OGCPoint(pt, getEsriSpatialReference());
	}

	return OGCGeometry.createFromEsriGeometry(resultGeom, getEsriSpatialReference(), false);
}
 
Example 5
Source File: OGCGeometry.java    From geometry-api-java with Apache License 2.0 4 votes vote down vote up
public static OGCGeometry createFromEsriGeometry(Geometry geom,
		SpatialReference sr, boolean multiType) {
	if (geom == null)
		return null;
	Geometry.Type t = geom.getType();
	if (t == Geometry.Type.Polygon) {
		if (!multiType && ((Polygon) geom).getExteriorRingCount() == 1)
			return new OGCPolygon((Polygon) geom, sr);
		else
			return new OGCMultiPolygon((Polygon) geom, sr);
	}
	if (t == Geometry.Type.Polyline) {
		if (!multiType && ((Polyline) geom).getPathCount() == 1)
			return new OGCLineString((Polyline) geom, 0, sr);
		else
			return new OGCMultiLineString((Polyline) geom, sr);
	}
	if (t == Geometry.Type.MultiPoint) {
		if (!multiType && ((MultiPoint) geom).getPointCount() <= 1) {
			if (geom.isEmpty())
				return new OGCPoint(new Point(), sr);
			else
				return new OGCPoint(((MultiPoint) geom).getPoint(0), sr);
		} else
			return new OGCMultiPoint((MultiPoint) geom, sr);
	}
	if (t == Geometry.Type.Point) {
		if (!multiType) {
			return new OGCPoint((Point) geom, sr);
		} else {
			return new OGCMultiPoint((Point) geom, sr);
		}
	}
	if (t == Geometry.Type.Envelope) {
		Polygon p = new Polygon();
		p.addEnvelope((Envelope) geom, false);
		return createFromEsriGeometry(p, sr, multiType);
	}

	throw new UnsupportedOperationException();
}