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

The following examples show how to use com.esri.core.geometry.Polygon#add() . 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: GeoFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
private static Polygon getSubPolygon(Polygon polygon, int startIndex, int endIndex)
{
    Polyline boundary = new Polyline();
    boundary.startPath(polygon.getPoint(startIndex));
    for (int i = startIndex + 1; i < endIndex; i++) {
        Point current = polygon.getPoint(i);
        boundary.lineTo(current);
    }

    final Polygon newPolygon = new Polygon();
    newPolygon.add(boundary, false);
    return newPolygon;
}
 
Example 2
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 3
Source File: GeoJsonParser.java    From arcgis-runtime-demo-java with Apache License 2.0 3 votes vote down vote up
/**
 * Parses a polygon string
 * Example:
 * without holes:
 * [
 *   [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
 * ]
 * 
 * with holes:
 * [
 *   [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ],
 *   [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ]
 * ]
 * @param parser
 * @return a polygon
 * @throws Exception
 */
private Polygon parsePolygonCoordinates(JsonNode node) {
  Polygon g = new Polygon();
  ArrayNode jsonPolygons = (ArrayNode) node;
  for (JsonNode jsonPolygon : jsonPolygons) {
    Polygon simplePolygon = parseSimplePolygonCoordinates(jsonPolygon);
    g.add(simplePolygon, false);
  }
  return g;
}
 
Example 4
Source File: GeoJsonParser.java    From arcgis-runtime-demo-java with Apache License 2.0 3 votes vote down vote up
/**
 * Parses a multi polygon string
 * Example:
 *  [
 *   [[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],
 *   [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],
 *    [[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]
 *  ]
 * @param parser
 * @return a polygon
 * @throws Exception
 */ 
private Polygon parseMultiPolygonCoordinates(JsonNode node) {
  Polygon g = new Polygon();
  ArrayNode jsonPolygons = (ArrayNode) node;
  for (JsonNode jsonPolygon : jsonPolygons) {
    Polygon simplePolygon = parsePolygonCoordinates(jsonPolygon);
    g.add(simplePolygon, false);
  }
  return g;
}