Adding GeoJSON to Leaflet

6367
6
07-26-2016 06:52 PM
PatrickMcKinney1
Occasional Contributor III

Here's a demo of 2 ways to add GeoJSON to a Leaflet web map: http://codepen.io/pmckinney/pen/mELyNY

 

I know there is also the Leaflet-AJAX plugin.

 

And if you're interested in converting a shapefile or feature class to GeoJSON, check out the City of Philadelphia's ArcToolbox.

 

Does anyone know why the output of the ArcGIS Desktop JSON conversion tool does not work in Leaflet?  I've always wondered what was going on with this.

6 Replies
JohnGravois
Frequent Contributor

output from ArcMap's 'Features to JSON' tool won't work because its not GeoJSON, its Esri's own Geoservices JSON.

http://desktop.arcgis.com/en/arcmap/10.3/tools/conversion-toolbox/features-to-json.htm

in ArcGIS Pro, we've added an optional parameter to the tool for generating GeoJSON

http://pro.arcgis.com/en/pro-app/tool-reference/conversion/features-to-json.htm

ArcGIS REST API - Feature JSON documentation

http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Feature_object/02r3000000n8000000/

GeoJSON and Esri JSON side by side

example of geojson · GitHub

example of geoservices json · GitHub 

0 Kudos
PaulBrown
New Contributor

When I export geojson in wgs84 or not using this tool. It is not usable in Leaflet. 

The coordinates are not in a format usable by Leaflet.  How do I get them to the correct format?

Example:

{
"type" : "FeatureCollection",
"crs" : {
"type" : "name",
"properties" : {
"name" : "EPSG:4326"
}
},
"features" : [
{
"type" : "Feature",
"id" : 1,
"geometry" : {
"type" : "Polygon",
"coordinates" : [
[
[
-10915535.083699999,
3895736.6819000021
],
[
-10915557.3475,
3895736.6819000021

0 Kudos
JohnGravois
Frequent Contributor

WGS84 coordinates are always:

180 > X > -180 (longitude)

90 > Y > -90 (latitude).

Your feature collection looks to be mislabeled Web Mercator northings and eastings.

0 Kudos
PaulBrown
New Contributor

That is how Pro created the GEO JSON.  Even though it says it is supposed to be WGS84, it is Web Mercator.  Ended up projecting the feature class to WGS84 and then telling it to use the original SR.  I think this might be a bug or something in Pro.

0 Kudos
PatrickMcKinney1
Occasional Contributor III

Paul Brown‌, while I can't speak to what's going on with ArcGIS Pro, you could check out the Arc Open Tool to convert shapefiles/feature classes to GeoJSON using ArcGIS Desktop (ArcMap/Catalog).  Maybe you can use this tool while you await resolution with the ArcGIS Pro stuff?

0 Kudos
JohnGravois
Frequent Contributor

I reproed the error you're reporting in ArcGIS Pro 2.2.2 and forwarded on the report to the appropriate team. Sorry for the inconvenience.

  1. Create a wkid:3857 feature class and add a few points to it.
  2. Open the ‘Features to JSON’ tool. Check the ‘Output to GeoJSON’ and ‘Project to WGS_1984’.
  3. Inspect the output file in a text editor. The CRS is labeled as “EPSG:4326” but the coordinates are still northings and eastings.
0 Kudos