Terraformer

# ArcGIS JSON Parser

This plugin handles 2 way conversion between GeoJSON and the ArcGIS Geometry format used by Esri.

## Link Using the ArcGIS JSON Parser Back to Top

The ArcGIS parser can be used client-side in a browser and server-side via Node.js.

    //parse an ArcGIS Geometry to GeoJSON
    var geojsonPoint = Terraformer.ArcGIS.parse({
      x:"-122.6764",
      y:"45.5165",
      spatialReference: {
        wkid: 4326
      }
    });

    // convert a GeoJSON object into an ArcGIS geometry
    var arcgisPoint = Terraformer.ArcGIS.convert(point)

### Link Using in the Browser Back to Top

In the browser, the core Terraformer library is required.

    <script src="terraformer.min.js"></script>
    <script src="terraformer-arcgis-parser.min.js"></script>
    <script>
      //Terraformer and Terraformer.ArcGIS will be defined.
    </script>

You can also use Bower to install the components if you like or download them and host them yourself.

    $ bower install terraformer-arcgis-parser

### Link Using in Node.js Back to Top

Just install the package from NPM with `$ npm install terraformer-arcgis-parser` Then include it in your application

    var ArcGIS = require('terraformer-arcgis-parser');

    // Start using the parse and convert methods!

### Link Methods Back to Top

#### Link ArcGIS.parse(json, options) Back to Top

`Terraformer.ArcGIS.prase(json, options)` - Converts a GeoJSON or a Terraformer.Primitive into the ArdGIS JSON format.

Option | Type | Default | Description
--- | --- | --- | ---
`sr` | `Number` | `4236` | This is used to set the value of `spatialReference.wkid` on the output. By default this will use 4326.
`idAttribute` | `String` | `"OBJECTID"` | When converting GeoJSON Features the `id` key of your feature will be set on the `OBJECTID` field in your output. If you want to assign your id to a different key you should set this to the string of the key your wish to assign the `id` to.

##### Notes

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.

##### Example

    //parse an ArcGIS Geometry to GeoJSON
    var point = Terraformer.ArcGIS.parse({
      x:"-122.6764",
      y:"45.5165",
      spatialReference: {
        wkid: 4326
      }
    });

#### Link ArcGIS.convert(geojson, options) Back to Top

`Terraformer.ArcGIS.convert(geoJSON, options)` will convert GeoJSON or a Terraformer Primitive to ArcGIS JSON.

Option | Type | Default | Description
--- | --- | --- | ---
`idAttribute` | `String` | `"OBJECTID" "FID"` | When converting ArcGIS Feature the `attributes` will contain id of the feature. This is usually called `OBJECTID` or `FID`. If your feature does not use the `OBJECTID` or `FID` keys as its id, you should define what the key representing your Features ID is.

##### Notes

If the object is in the Web Mercator spatial reference it will be converted to WGS84.

##### Example

    // take a Terraformer.Primitive or GeoJSON and convert it to ArcGIS JSON object
    var point = ArcGIS.convert({
      "type": "Point",
      "coordinates": [45.5165, -122.6764]
    });