com.esri.core.geometry.Geometry Java Examples

The following examples show how to use com.esri.core.geometry.Geometry. 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 6 votes vote down vote up
private static void writePoint(DynamicSliceOutput output, OGCGeometry geometry)
{
    Geometry esriGeometry = geometry.getEsriGeometry();
    verify(esriGeometry instanceof Point, "geometry is expected to be an instance of Point");
    Point point = (Point) esriGeometry;
    verify(!point.hasAttribute(VertexDescription.Semantics.Z) &&
                    !point.hasAttribute(VertexDescription.Semantics.M) &&
                    !point.hasAttribute(VertexDescription.Semantics.ID),
            "Only 2D points with no ID nor M attribute are supported");
    output.appendByte(GeometrySerializationType.POINT.code());
    if (!point.isEmpty()) {
        output.appendDouble(point.getX());
        output.appendDouble(point.getY());
    }
    else {
        output.appendDouble(NaN);
        output.appendDouble(NaN);
    }
}
 
Example #2
Source File: TestStAsShape.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testPointAsShape() {
	ST_Point point = new ST_Point();
	final double longitude = 12.224;
	final double latitude = 51.829;
	BytesWritable pointAsWritable = point.evaluate(new DoubleWritable(longitude), new DoubleWritable(latitude));
	assertNotNull("The point writable must not be null!", pointAsWritable);
	
	ST_AsShape asShape = new ST_AsShape();
	BytesWritable shapeAsWritable = asShape.evaluate(pointAsWritable);
	assertNotNull("The shape writable must not be null!", pointAsWritable);
	
	byte[] esriShapeBuffer = shapeAsWritable.getBytes();
	Geometry esriGeometry = GeometryEngine.geometryFromEsriShape(esriShapeBuffer, Type.Point);
	assertNotNull("The geometry must not be null!", esriGeometry);
	assertTrue("Geometry type point expected!", esriGeometry instanceof Point);
	
	Point esriPoint = (Point) esriGeometry;
	assertEquals("Longitude is different!", longitude, esriPoint.getX(), Epsilon);
	assertEquals("Latitude is different!", latitude, esriPoint.getY(), Epsilon);
}
 
Example #3
Source File: LocalGeofence.java    From arcgis-runtime-demos-android with Apache License 2.0 6 votes vote down vote up
public static void setFence(Polygon newFence, SpatialReference fenceSpatialReference) {

    // Keep the original geometries.
    mFenceSr = fenceSpatialReference;
    mFence = newFence;

    // Work with the fence in WGS84, as that's what the location updates will be in.
    // Note that transformations could be used here to increase accuracy.
    if ( mFenceSr.getID() != mWgs84Sr.getID() ) {
      Geometry densified = GeometryEngine.geodesicDensifyGeometry(mFence,
          mFenceSr, 20, null);
      mFenceWgs84 = (Polygon)GeometryEngine.project(densified, mFenceSr, mWgs84Sr);
    }
    else {
      mFenceWgs84 = mFence;
    }
  }
 
Example #4
Source File: LocalGeofence.java    From arcgis-runtime-demos-android with Apache License 2.0 6 votes vote down vote up
public static void setFence(Polygon newFence, SpatialReference fenceSpatialReference) {

    // Keep the original geometries.
    mFenceSr = fenceSpatialReference;
    mFence = newFence;

    // Work with the fence in WGS84, as that's what the location updates will be in.
    // Note that transformations could be used here to increase accuracy.
    if ( mFenceSr.getID() != mWgs84Sr.getID() ) {
      Geometry densified = GeometryEngine.geodesicDensifyGeometry(mFence,
          mFenceSr, 20, null);
      mFenceWgs84 = (Polygon)GeometryEngine.project(densified, mFenceSr, mWgs84Sr);
    }
    else {
      mFenceWgs84 = mFence;
    }
  }
 
Example #5
Source File: GeoJsonParser.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
private List<Feature> parseFeatures(ArrayNode jsonFeatures) {
  List<Feature> features = new LinkedList<Feature>();
  for (JsonNode jsonFeature : jsonFeatures) {
    String type = jsonFeature.path(FIELD_TYPE).getTextValue();
    if (!FIELD_FEATURE.equals(type)) {
      continue;
    }
    Geometry g = parseGeometry(jsonFeature.path(FIELD_GEOMETRY));
    if (outSR != null && outSR.getID() != 4326) {
      g = GeometryEngine.project(g, inSR, outSR);
    }
    Map<String, Object> attributes = parseProperties(jsonFeature.path(FIELD_PROPERTIES));
    Feature f = new Graphic(g, symbol, attributes);
    features.add(f);
  } 
  return features; 
}
 
Example #6
Source File: AttributeTypeBuilderTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests {@link AttributeTypeBuilder#roles()}.
 */
@Test
@DependsOnMethod("testOtherCharacteristics")
public void testRoles() {
    final AttributeTypeBuilder<Geometry> builder = new FeatureTypeBuilder().addAttribute(Geometry.class);
    final Set<AttributeRole> roles = builder.roles();
    assertTrue("isEmpty", roles.isEmpty());

    assertTrue("add(DEFAULT_GEOMETRY)", builder.addRole(AttributeRole.DEFAULT_GEOMETRY));
    assertSetEquals(Collections.singleton(AttributeRole.DEFAULT_GEOMETRY), roles);
    assertFalse("add(DEFAULT_GEOMETRY)", builder.addRole(AttributeRole.DEFAULT_GEOMETRY));

    assertTrue("add(IDENTIFIER_COMPONENT)", roles.add(AttributeRole.IDENTIFIER_COMPONENT));
    assertSetEquals(Arrays.asList(AttributeRole.DEFAULT_GEOMETRY, AttributeRole.IDENTIFIER_COMPONENT), roles);
    assertFalse("add(IDENTIFIER_COMPONENT)", roles.add(AttributeRole.IDENTIFIER_COMPONENT));

    assertTrue("remove(DEFAULT_GEOMETRY)", roles.remove(AttributeRole.DEFAULT_GEOMETRY));
    assertSetEquals(Collections.singleton(AttributeRole.IDENTIFIER_COMPONENT), roles);
    assertFalse("remove(DEFAULT_GEOMETRY)", roles.remove(AttributeRole.DEFAULT_GEOMETRY));

    assertTrue("remove(IDENTIFIER_COMPONENT)", roles.remove(AttributeRole.IDENTIFIER_COMPONENT));
    assertTrue("isEmpty", roles.isEmpty());
    assertFalse("remove(IDENTIFIER_COMPONENT)", roles.remove(AttributeRole.IDENTIFIER_COMPONENT));
}
 
Example #7
Source File: GeometryUtility.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
private static String _parseGeometryType(Geometry.Type t)
{
	String type = null;
	if(t == Geometry.Type.Point)
	{
		type = "esriGeometryPoint";
	}
	else if (t==Geometry.Type.Polyline)
	{
		type = "esriGeometryPolyline";
	}
	else if (t==Geometry.Type.Polygon)
	{
		type = "esriGeometryPolygon";
	}
	else if (t==Geometry.Type.MultiPoint)
	{
		type = "esriGeometryMultiPoint";
	}
	return type;
}
 
Example #8
Source File: GeometryUtility.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
private static String _parseGeometryType(Geometry.Type t)
{
	String type = null;
	if(t == Geometry.Type.Point)
	{
		type = "esriGeometryPoint";
	}
	else if (t==Geometry.Type.Polyline)
	{
		type = "esriGeometryPolyline";
	}
	else if (t==Geometry.Type.Polygon)
	{
		type = "esriGeometryPolygon";
	}
	else if (t==Geometry.Type.MultiPoint)
	{
		type = "esriGeometryMultiPoint";
	}
	return type;
}
 
Example #9
Source File: BufferProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
private com.esri.ges.spatial.Geometry constructBuffer(double x, double y, double radius, String units, int wkidin, int wkidbuffer, int wkidout) throws GeometryException
{
	Point center = new Point();
	center.setX(x);
	center.setY(y);
	SpatialReference srIn = SpatialReference.create(wkidin);
	SpatialReference srBuffer = SpatialReference.create(wkidbuffer);
	SpatialReference srOut = SpatialReference.create(wkidout);
	UnitConverter uc = new UnitConverter();
	String c_name = uc.findConnonicalName(units);
	int unitout = uc.findWkid(c_name);
	Unit  u = new LinearUnit(unitout);
	Point centerProj = (Point) GeometryEngine.project(center, srIn, srBuffer);
	Geometry buffer = GeometryEngine.buffer(centerProj, srBuffer, radius, u);
	Geometry bufferout = GeometryEngine.project(buffer, srBuffer, srOut);
	String json = GeometryEngine.geometryToJson(srOut, bufferout);
	return spatial.fromJson(json);
	
}
 
Example #10
Source File: GeoFunctions.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Returns the OGC type of a geometry. */
private static Type type(Geometry g) {
  switch (g.getType()) {
  case Point:
    return Type.POINT;
  case Polyline:
    return Type.LINESTRING;
  case Polygon:
    return Type.POLYGON;
  case MultiPoint:
    return Type.MULTIPOINT;
  case Envelope:
    return Type.POLYGON;
  case Line:
    return Type.LINESTRING;
  case Unknown:
    return Type.Geometry;
  default:
    throw new AssertionError(g);
  }
}
 
Example #11
Source File: ST_AsShape.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
public BytesWritable evaluate(BytesWritable geomref) {
	if (geomref == null || geomref.getLength() == 0){
		LogUtils.Log_ArgumentsNull(LOG);
		return null;
	}

	OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geomref);
	if (ogcGeometry == null){
		LogUtils.Log_ArgumentsNull(LOG);
		return null;
	}

	try {
		// Get Esri shape representation
		Geometry esriGeometry = ogcGeometry.getEsriGeometry();
		byte[] esriShape = GeometryEngine.geometryToEsriShape(esriGeometry);
		return new BytesWritable(esriShape);
	} catch (Exception e){
		LOG.error(e.getMessage());
		return null;
	}
}
 
Example #12
Source File: OGCGeometry.java    From geometry-api-java with Apache License 2.0 6 votes vote down vote up
/**
 * OGC equals. Performs topological comparison with tolerance.
 * This is different from equals(Object), that uses exact comparison.
 */
public boolean Equals(OGCGeometry another) {
	if (this == another)
		return !isEmpty();
	
	if (another == null)
		return false;
	
	if (another.geometryType() == OGCConcreteGeometryCollection.TYPE) {
		return another.Equals(this);
	}
	
	com.esri.core.geometry.Geometry geom1 = getEsriGeometry();
	com.esri.core.geometry.Geometry geom2 = another.getEsriGeometry();
	return com.esri.core.geometry.GeometryEngine.equals(geom1, geom2,
			getEsriSpatialReference());
}
 
Example #13
Source File: BufferProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
@Override
public GeoEvent process(GeoEvent ge) throws Exception {
	// Operation phase...
	if (radius == null) {
		radius = (Double) ge.getField(bufferEventFld);
		if (radius == null) {
			Exception e = new Exception("Radius is not defined in geoevent");
			throw (e);
		}
	}
	MapGeometry mapGeo = ge.getGeometry();
	Point eventGeo = (Point) mapGeo.getGeometry();
	double x = eventGeo.getX();
	double y = eventGeo.getY();
	int inwkid = mapGeo.getSpatialReference().getID();
	//int inwkid = eventGeo.getSpatialReference().getWkid();
	Geometry buffer = constructBuffer(x, y, radius,
			units, inwkid, bufferwkid, outwkid);
	
	SpatialReference srOut = SpatialReference.create(outwkid);
	MapGeometry outMapGeo = new MapGeometry(buffer, srOut);
	ge.setGeometry(outMapGeo);
	return ge;
}
 
Example #14
Source File: GeometryUtility.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
private static String _parseGeometryType(Geometry.Type t)
{
	String type = null;
	if(t == Geometry.Type.Point)
	{
		type = "esriGeometryPoint";
	}
	else if (t==Geometry.Type.Polyline)
	{
		type = "esriGeometryPolyline";
	}
	else if (t==Geometry.Type.Polygon)
	{
		type = "esriGeometryPolygon";
	}
	else if (t==Geometry.Type.MultiPoint)
	{
		type = "esriGeometryMultiPoint";
	}
	return type;
}
 
Example #15
Source File: GeoFunctions.java    From Quicksql with MIT License 5 votes vote down vote up
/** Computes the union of the geometries in {@code geomCollection}. */
@SemiStrict public static Geom ST_Union(Geom geomCollection) {
  SpatialReference sr = geomCollection.sr();
  final Geometry g =
      GeometryEngine.union(new Geometry[] {geomCollection.g()}, sr);
  return bind(g, sr);
}
 
Example #16
Source File: MainActivity.java    From arcgis-runtime-demos-android with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a geojson string to com.esri.core.geometry.Point.
 *
 * @param jsonPoint geoJson string representation of a Point
 * @return com.esri.core.geometry.Point
 * @throws Exception
 */
static Point createPointFromGeoJson(String jsonPoint) throws Exception {

    MapGeometry mapGeom = OperatorImportFromGeoJson.local().execute(GeoJsonImportFlags.geoJsonImportDefaults,
            Geometry.Type.Point,
            jsonPoint,
            null);

    return (Point) mapGeom.getGeometry();
}
 
Example #17
Source File: QueryReportProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private Geometry generateGeoFromMap(Map<String, Object> objGeo)
{
	Geometry geo = null;
	if(objGeo.containsKey("rings"))
	{
		ArrayList<ArrayList<ArrayList<String>>> rings= (ArrayList<ArrayList<ArrayList<String>>>)objGeo.get("rings");
		geo = generatePolygon(rings);
	}
	else if(objGeo.containsKey("paths"))
	{
		ArrayList<ArrayList<ArrayList<String>>> paths= (ArrayList<ArrayList<ArrayList<String>>>)objGeo.get("paths");
		geo = generatePolyLine(paths);
	}
	else if(objGeo.containsKey("points"))
	{
		
	}
	else
	{
		Double x = Double.valueOf(objGeo.get("x").toString());
		Double y = Double.valueOf(objGeo.get("y").toString());
		if(objGeo.size() > 2)
		{
			Double z = Double.valueOf(objGeo.get("z").toString());
			geo = generate3DPoint(x,y,z);
		}
		else
		{
			geo = generatePoint(x,y);
		}
	}
	return geo;
}
 
Example #18
Source File: VisibilityProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private String ConstructJsonMaskFromGeoEvent(GeoEvent ge) throws IOException
{
	com.esri.ges.spatial.Geometry eventgeo = ge.getGeometry();
	String json = eventgeo.toJson();
	JsonFactory jf = new JsonFactory();
	JsonParser jp = jf.createJsonParser(json);
	MapGeometry mgeo = GeometryEngine.jsonToGeometry(jp);
	Geometry geo = mgeo.getGeometry();
	Geometry maskGeo = GeometryEngine.project(geo, srIn, srBuffer);
	return GeometryEngine.geometryToJson(srBuffer, maskGeo);
}
 
Example #19
Source File: RangeFanProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private Geometry constructRangeFan(double x, double y, double range,
		String unit, double bearing, double traversal)
		throws GeometryException {
	Polygon fan = new Polygon();
	Point center = new Point();
	center.setX(x);
	center.setY(y);
	// SpatialReference srIn = SpatialReference.create(wkidin);
	// SpatialReference srBuffer = SpatialReference.create(wkidbuffer);
	// SpatialReference srOut = SpatialReference.create(wkidout);
	Point centerProj = (Point) GeometryEngine.project(center, srIn,
			srBuffer);

	double centerX = centerProj.getX();
	double centerY = centerProj.getY();
	bearing = GeometryUtility.Geo2Arithmetic(bearing);
	double leftAngle = bearing - (traversal / 2);
	double rightAngle = bearing + (traversal / 2);
	int count = (int) Math.round(Math.abs(leftAngle - rightAngle));
	fan.startPath(centerProj);
	UnitConverter uc = new UnitConverter();
	range = uc.Convert(range, unit, srBuffer);
	for (int i = 0; i < count; ++i) {
		double d = Math.toRadians(leftAngle + i);
		double arcX = centerX + (range * Math.cos(d));
		double arcY = centerY + (range * Math.sin(d));
		Point arcPt = new Point(arcX, arcY);
		// arcPt = (Point) GeometryEngine.project(arcPt, srBuffer, srOut);
		fan.lineTo(arcPt);
	}
	fan.closeAllPaths();
	return fan;
}
 
Example #20
Source File: ParticleGraphicsEllipseApp.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
private void addEllipses(int numberOfEllipses) {
  SimpleMarkerSymbol[] symbols = {symbol4, symbol3, symbol2, symbol1};
  // some values that works well
  int majorAxisLength = 4612483;
  int minorAxisLength = 1843676;

  centerPoint = new Point(500000-5000000, 500000 + 3000000);
  centerGraphicsLayer.addGraphic(new Graphic(centerPoint, null));

  for (int i = 0; i < numberOfEllipses; i++) {
    Point center = new Point(random.nextInt(500000)-5000000, random.nextInt(500000) + 3000000);
    int majorAxisDirection = random.nextInt(60);
    LinearUnit unit = new LinearUnit(LinearUnit.Code.METER);

    Geometry ellipse = GeometryEngine.geodesicEllipse(center, map.getSpatialReference(), majorAxisLength, minorAxisLength,
        majorAxisDirection, pointCount, unit, Geometry.Type.MULTIPOINT);

    if (ellipse instanceof MultiPoint) {
      SimpleMarkerSymbol symbol = symbols[i%4];
      MultiPoint mp = (MultiPoint) ellipse;
      Ellipse currentEllipse = new Ellipse(mp); 
      ellipses.add(currentEllipse);
      int j = 0;
      while (j < mp.getPointCount()) {
        if (j%8==0) {
          Point point = mp.getPoint(j);
          int id = ellipseGraphicsLayer.addGraphic(new Graphic(point, symbol));
          currentEllipse.addPoint(id, j);
        }
        j++;
      }
    }
  }
}
 
Example #21
Source File: GeometryOnlineApp.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
@Override
public void onMouseClicked(MouseEvent event) {
  graphicsLayer.removeAll();

  // add buffer as a graphic
  Point mapPoint = map.toMapPoint(event.getX(), event.getY());
  Geometry buffer = GeometryEngine.buffer(
      mapPoint, map.getSpatialReference(), 200000, map.getSpatialReference().getUnit());
  graphicsLayer.addGraphic(new Graphic(buffer, new SimpleFillSymbol(new Color(100, 0, 0, 80))));

  // get states at the buffered area
  QueryTask queryTask = new QueryTask(featureLayer.getUrl());
  QueryParameters queryParams = new QueryParameters();
  queryParams.setInSpatialReference(map.getSpatialReference());
  queryParams.setOutSpatialReference(map.getSpatialReference());
  queryParams.setGeometry(buffer);
  queryParams.setReturnGeometry(true);
  queryParams.setOutFields(new String[] {"STATE_NAME"});

  queryTask.executeAsync(queryParams, new CallbackListener<FeatureResult>() {

    @Override
    public void onError(Throwable arg0) {
      // deal with any exception
    }

    @Override
    public void onCallback(FeatureResult result) {
      for (Object objFeature : result) {
        Feature feature = (Feature) objFeature;
        graphicsLayer.addGraphic(new Graphic(feature.getGeometry(), stateSymbol));
      }
    }
  });
}
 
Example #22
Source File: BufferProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
@Override
public GeoEvent process(GeoEvent ge) throws Exception {
	String radiusSource = properties.get("radiusSource").getValue().toString();
	double radius;
	if(radiusSource.equals("Constant"))
	{
		radius = (Double)properties.get("radius").getValue();
	}
	else
	{
		String eventfld = properties.get("radiusEvent").getValue().toString();
		String[] arr = eventfld.split(":");
		radius = (Double)ge.getField(arr[1]);
	}
	
	
	String units = properties.get("units").getValue().toString();
	int inwkid = (Integer) properties.get("wkidin").getValue();
	int outwkid = (Integer) properties.get("wkidout").getValue();
	int bufferwkid = (Integer) properties.get("wkidbuffer").getValue();
	com.esri.ges.spatial.Point eventGeo = (com.esri.ges.spatial.Point) ge.getGeometry();
	double x = eventGeo.getX();
	double y = eventGeo.getY();
	com.esri.ges.spatial.Geometry buffer = constructBuffer(x,y,radius,units,inwkid,bufferwkid,outwkid);
	ge.setGeometry(buffer);
	return ge;
}
 
Example #23
Source File: GeoFunctions.java    From Quicksql with MIT License 5 votes vote down vote up
/** Returns whether {@code geom1} intersects {@code geom2}. */
public static boolean ST_Intersects(Geom geom1, Geom geom2)  {
  final Geometry g1 = geom1.g();
  final Geometry g2 = geom2.g();
  final SpatialReference sr = geom1.sr();
  return intersects(g1, g2, sr);
}
 
Example #24
Source File: SpatialQProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private Geometry constructGeometry(MapGeometry geo) throws Exception {
	try {

		Geometry geoIn = geo.getGeometry();
		return GeometryEngine.project(geoIn, srIn, srBuffer);
	} catch (Exception e) {
		LOG.error(e.getMessage());
		LOG.error(e.getStackTrace());
		throw (e);
	}
}
 
Example #25
Source File: ESRI.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * If the given object is an ESRI geometry, returns its centroid. Otherwise returns {@code null}.
 */
@Override
final Object tryGetCentroid(final Object geometry) {
    if (geometry instanceof Geometry) {
        return OperatorCentroid2D.local().execute((Geometry) geometry, null);
    }
    return null;
}
 
Example #26
Source File: OGCGeometry.java    From geometry-api-java with Apache License 2.0 5 votes vote down vote up
public boolean crosses(OGCGeometry another) {
	if (another.geometryType() == OGCConcreteGeometryCollection.TYPE) {
		//TODO
		throw new UnsupportedOperationException();
	}
	
	com.esri.core.geometry.Geometry geom1 = getEsriGeometry();
	com.esri.core.geometry.Geometry geom2 = another.getEsriGeometry();
	return com.esri.core.geometry.GeometryEngine.crosses(geom1, geom2,
			getEsriSpatialReference());
}
 
Example #27
Source File: GeoFunctions.java    From Quicksql with MIT License 5 votes vote down vote up
protected static Geom bind(Geometry geometry, int srid) {
  if (geometry == null) {
    return null;
  }
  if (srid == NO_SRID) {
    return new SimpleGeom(geometry);
  }
  return bind(geometry, SpatialReference.create(srid));
}
 
Example #28
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 #29
Source File: ST_GeomFromShape.java    From spatial-framework-for-hadoop with Apache License 2.0 5 votes vote down vote up
public BytesWritable evaluate(BytesWritable shape, int wkid) throws UDFArgumentException  {
	try {
		Geometry geometry = GeometryEngine.geometryFromEsriShape(shape.getBytes(), Geometry.Type.Unknown);
		switch (geometry.getType())
		{
		case Point:
			return GeometryUtils.geometryToEsriShapeBytesWritable(geometry, wkid, OGCType.ST_POINT);
			
		case MultiPoint:
			return GeometryUtils.geometryToEsriShapeBytesWritable(geometry, wkid, OGCType.ST_MULTIPOINT);
			
		case Line:
			return GeometryUtils.geometryToEsriShapeBytesWritable(geometry, wkid, OGCType.ST_LINESTRING);
			
		case Polyline:
			return GeometryUtils.geometryToEsriShapeBytesWritable(geometry, wkid, OGCType.ST_MULTILINESTRING);
			
		case Envelope:
			return GeometryUtils.geometryToEsriShapeBytesWritable(geometry, wkid, OGCType.ST_POLYGON);
			
		case Polygon:
			return GeometryUtils.geometryToEsriShapeBytesWritable(geometry, wkid, OGCType.ST_MULTIPOLYGON);
			
		default:
			return GeometryUtils.geometryToEsriShapeBytesWritable(geometry, wkid, OGCType.UNKNOWN);
		}
	} catch (Exception e) {
		LogUtils.Log_ExceptionThrown(LOG, "geom-from-shape", e);
		return null;
	}
}
 
Example #30
Source File: GeoJsonParser.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
private List<Geometry> parseGeometries(ArrayNode jsonGeometries) {
  List<Geometry> geometries = new LinkedList<Geometry>();
  for (JsonNode jsonGeometry : jsonGeometries) {
    Geometry g = parseGeometry(jsonGeometry);
    if (outSR != null && outSR.getID() != 4326) {
      g = GeometryEngine.project(g, inSR, outSR);
    }
    geometries.add(g);
  } 
  return geometries; 
}