GeometryEngine.geometryFromEsriShape. How to load from a file.shp?

1829
1
06-21-2016 10:36 AM
EdgarCanul
New Contributor III

Hello,

I'm trying to use the GeometryEngine.getNearestCoordinate() method but one of its arguments is a Geometry which I suppose it'd be the multi-point or polyline shape file which contains a trajectory I want to evaluate.

So that I'm trying to load this shapefile as a geometry using GeometryEngine.geometryFromEsriShape(). First I load the shape file as follows:

byte[] esriShapeBuffer = null;
  try {
  esriShapeBuffer = Files.readAllBytes(shapeFile.toPath());
  } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  }
  Geometry g = GeometryEngine.geometryFromEsriShape(esriShapeBuffer, Geometry.Type.UNKNOWN);
  Point p = GeometryEngine.getNearestCoordinate(g, mapPoint, false).getCoordinate();

But in line 8 Geometry g results to be null, even though I tried all Geometry Types (although I know my shape file is multi point).

When I reviewed the documentation of geometryFromEsriShape it says: Note: this is not from a shape-file on disk.

So, please, how can I generate a geometry from a shapefile?

Thanks in advance.

1 Reply
EricBader
Occasional Contributor III

Hi Edgar,

In ArcGIS Runtime, you can dynamically add geometries from a shapefile to you map by following the code example here:

Dynamic workspaces shapefile | ArcGIS for Developers

I hope this helps!

0 Kudos