geometry-api-java icon indicating copy to clipboard operation
geometry-api-java copied to clipboard

esrijson to geojson Exception

Open handsomeCLF opened this issue 1 year ago • 1 comments

I have an esrijson and when converting it to geojson, I found that the geometry returned by createGeometryByGeoJson is empty. Is there any other way to convert it to geojson? I can successfully convert using https://github.com/Esri/arcgis-to-geojson-utils arcgisToGeoJSON method.

The code example is as follows:

public String EsriJsonToGeoJson(String esri_json){
    Geometry geometry = createGeometryByJson(esri_json);
    return getGeoJson(geometry);
}

private Geometry createGeometryByGeoJson(String geojson) {
    return GeometryEngine.geoJsonToGeometry(geojson, WktExportFlags.wktExportDefaults, Geometry.Type.Unknown).getGeometry();
}

private String getGeoJson(Geometry geometry) {
    return GeometryEngine.geometryToGeoJson(geometry);
}

The data example is as follows: GeoJson.json

EsriJson.json

handsomeCLF avatar May 13 '24 10:05 handsomeCLF

GeometryEngine accepts JSON strings that only have the geometry (with an optional spatial reference), not the other properties. Your JSON string should start with {"rings": and end with the closing brace }

alocke avatar May 14 '24 17:05 alocke