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

The following examples show how to use com.esri.core.geometry.MultiPoint#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: AgsBroker.java    From geoportal-server-harvester with Apache License 2.0 6 votes vote down vote up
/**
 * Normalizes extent.
 *
 * @param extent
 * @throws IOException
 * @throws URISyntaxException
 */
private void normalizeExtent(ExtentInfo extent, int wkid) throws IOException, URISyntaxException {
  if (extent != null && extent.isValid()) {
    if (extent.spatialReference != null && extent.spatialReference.wkid != null && extent.spatialReference.wkid != 4326) {
      MultiPoint mp = new MultiPoint();
      mp.add(extent.xmin, extent.ymin);
      mp.add(extent.xmax, extent.ymax);

      mp = gs.project(mp, extent.spatialReference.wkid.intValue(), wkid);

      if (mp.getPointCount() == 2) {
        extent.xmin = mp.getPoint(0).getX();
        extent.ymin = mp.getPoint(0).getY();
        extent.xmax = mp.getPoint(1).getX();
        extent.ymax = mp.getPoint(1).getY();
        extent.spatialReference.wkid = (long) wkid;
      }
    }
  }
}
 
Example 2
Source File: ST_MultiPoint.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
public BytesWritable evaluate(DoubleWritable ... xyPairs) throws UDFArgumentLengthException{

		if (xyPairs == null || xyPairs.length == 0 ||  xyPairs.length%2 != 0) {
			LogUtils.Log_VariableArgumentLengthXY(LOG);
			return null;
		}

		try {
			MultiPoint mPoint = new MultiPoint();

			for (int i=0;i<xyPairs.length;i+=2){
				mPoint.add(xyPairs[i].get(), xyPairs[i+1].get());
			}

			return GeometryUtils.geometryToEsriShapeBytesWritable(OGCGeometry.createFromEsriGeometry(mPoint, null, true));
		} catch (Exception e) {
		    LogUtils.Log_InternalError(LOG, "ST_MultiPoint: " + e);
		    return null;
		}
	}
 
Example 3
Source File: GeoFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
@SqlNullable
@Description("Returns a multi-point geometry formed from input points")
@ScalarFunction("ST_MultiPoint")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stMultiPoint(@SqlType("array(" + GEOMETRY_TYPE_NAME + ")") Block input)
{
    MultiPoint multipoint = new MultiPoint();
    for (int i = 0; i < input.getPositionCount(); i++) {
        if (input.isNull(i)) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_MultiPoint: null at index %s", i + 1));
        }

        Slice slice = GEOMETRY.getSlice(input, i);
        OGCGeometry geometry = deserialize(slice);
        if (!(geometry instanceof OGCPoint)) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_MultiPoint: geometry is not a point: %s at index %s", geometry.geometryType(), i + 1));
        }
        OGCPoint point = (OGCPoint) geometry;
        if (point.isEmpty()) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_MultiPoint: empty point at index %s", i + 1));
        }

        multipoint.add(point.X(), point.Y());
    }
    if (multipoint.getPointCount() == 0) {
        return null;
    }
    return serialize(createFromEsriGeometry(multipoint, null, true));
}
 
Example 4
Source File: PdfUtils.java    From geoportal-server-harvester with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a bounding box for the given set of points
 * 
 * @param points array of points in the form {@code [lat1, lon1, lat2, lon2, ...]}
 * 
 * @returns a bounding box string in the form "latMin lonMin, latMax lonMax"
 */
private static final String generateBbox(float [] points) {
    MultiPoint mp = new MultiPoint();

    for (int i = 0; i < points.length; i += 2) {
        mp.add(points[i+1], points[i]);
    }

    return generateBbox(mp);
}
 
Example 5
Source File: GeoJsonParser.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a multipoint
 * Example:
 * [ [100.0, 0.0], [101.0, 1.0] ].
 * @param parser
 * @return a multipoint.
 * @throws Exception
 */
private MultiPoint parseMultiPointCoordinates(JsonNode node) {
  MultiPoint p = new MultiPoint();
  ArrayNode jsonPoints = (ArrayNode) node;
  for (JsonNode jsonPoint : jsonPoints) {
    Point point = parsePointCoordinates(jsonPoint);
    p.add(point);
  }
  return p;
}
 
Example 6
Source File: OGCMultiPoint.java    From geometry-api-java with Apache License 2.0 4 votes vote down vote up
public OGCMultiPoint(Point startPoint, SpatialReference sr) {
	multiPoint = new MultiPoint();
	multiPoint.add((Point) startPoint);
	esriSR = sr;
}
 
Example 7
Source File: OGCMultiPoint.java    From geometry-api-java with Apache License 2.0 4 votes vote down vote up
public OGCMultiPoint(OGCPoint startPoint, OGCPoint endPoint) {
	multiPoint = new MultiPoint();
	multiPoint.add((Point) startPoint.getEsriGeometry());
	multiPoint.add((Point) endPoint.getEsriGeometry());
	esriSR = startPoint.esriSR;
}
 
Example 8
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);
}