This plugin handles 2 way conversion between GeoJSON and the ArcGIS Geometry format used by Esri.
This package is part of the Terraformer project.
$ npm install terraformer-arcgis-parser
In the browser, Terraformer is required.
You can use Bower to install the components if you like or download them and host them yourself.
$ bower install terraformer
$ bower install terraformer-arcgis-parser
parse(json)
- parse ArcGIS JSON into a Terraformer.Primitive. If the object is in the Web Mercator spatial reference it will be converted to WGS84. Aliased asfromGeoJSON
.convert(json, spatialReference)
- Convert GeoJSON or a Terraformer.Primitive into ARCGIS JSON. You can also pass a valid ArcGIS spatial reference like{ wkid:102100 }
as the second parameter. By default we assume WGS84 like GeoJSON. Aliased astoGeoJSON
var ArcGIS = require('terraformer-arcgis-parser');
// parse ArcGIS JSON, convert it to a Terraformer.Primitive
var primitive = ArcGIS.parse({
x:"-122.6764",
y:"45.5165",
spatialReference: {
wkid: 4326
}
});
// take a Terraformer.Primitive or GeoJSON and convert it to ArcGIS JSON
var point = ArcGIS.convert({
"type": "Point",
"coordinates": [45.5165, -122.6764]
});
The Terraformer ArcGIS Parser can be used in the browser with some simple includes.
<!-- Load the main Terraformer library -->
<script src="terraformer.min.js" type="text/javascript"></script>
<!-- Load the ArcGIS Parser -->
<script src="terraformer-arcgis-parser.min.js" type="text/javascript"></script>
<!-- Use it! -->
<script>
var primitive = Terraformer.ArcGIS.parse({
x:"-122.6764",
y:"45.5165",
spatialReference: {
wkid: 4326
}
});
// take a Terraformer.Primitive or GeoJSON and convert it to ArcGIS JSON
var point = Terraformer.ArcGIS.convert({
"type": "Point",
"coordinates": [45.5165, -122.6764]
});
</script>
It is important to note that Terraformer DOES NOT attempt to set an ID on the feature is outputs when converting ArcGIS into GeoJSON. You should always set an id after parsing it to GeoJSON. This is because the concept a unique feature id does not exist in the ArcGIS spec.
Terraformer will also handle converting FeatureCollection
and GeometryCollection
objects to arrays of ArcGIS geometries or features. However it will Not do this in reverse as there is no official structure for arrays of features and geometries in ArcGIS and all the output features will not have id
properties. See this issue for more details.
[](Esri Tags: Terraformer GeoJSON ArcGIS) [](Esri Language: JavaScript)