Java Code Examples for com.esri.core.geometry.Polygon#addEnvelope()

The following examples show how to use com.esri.core.geometry.Polygon#addEnvelope() . 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: 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 2
Source File: OGCConcreteGeometryCollection.java    From geometry-api-java with Apache License 2.0 5 votes vote down vote up
@Override
public OGCGeometry envelope() {
	GeometryCursor gc = getEsriGeometryCursor();
	Envelope env = new Envelope();
	for (Geometry g = gc.next(); g != null; g = gc.next()) {
		Envelope e = new Envelope();
		g.queryEnvelope(e);
		env.merge(e);
	}

	Polygon polygon = new Polygon();
	polygon.addEnvelope(env, false);
	return new OGCPolygon(polygon, esriSR);
}
 
Example 3
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();
}