Select to view content in your preferred language

Create Map Service for AGOL using JSON

3278
6
09-11-2015 09:36 AM
ChrisHolmes
Frequent Contributor

Hello everyone,

I have a .json file which I would like to be able to import into ArcMap to then publish as a map service to AGOL. The format of the json file when I receive it is like this:

[{"geometry":{"x":-5561.656,"y":5659411.683,"spatialReference":{"wkid":3776}},"attributes":{"EXTERNALNUM":"FILE1","STATUS":"OPEN","FILECLERK":"JANE DOE","RPID":1111111}},{"geometry":{"x":-4480.512000000001,"y":5671280.649,"spatialReference":{"wkid":3776}},"attributes":{"EXTERNALNUM":"FILE2","STATUS":"HOLD","FILECLERK":"BOB BROWN","RPID":2222222}}}]

Is this possible given the way the file is formatted? It doesn't seem to be formatted in a manner to work with the JSON toolset in ArcMap: ArcGIS Help (10.2, 10.2.1, and 10.2.2)

Any suggestions appreciated,

Chris

Tags (2)
0 Kudos
6 Replies
ChrisHolmes
Frequent Contributor

Nothing? Anyone? I'm hoping I don't have to write something to reformat the json file. Do I need to see if the service that provides the file to me can format it differently?

0 Kudos
JeffJacobson
Frequent Contributor

Is your ultimate goal to display the data on a map in a web application using ArcGIS for JavaScript? This is what I would do...

  1. Put your JSON in the same directory on the web server as the rest of your web application.
  2. In your JavaScript code, use dojo/text to import the JSON file as a text string.
  3. Use JSON.parse to convert the JSON text into an array of Feature objects. The "reviver" function parameter should do the following:
    1. Check to see if the current value is an object with properties named "geometry" and "attributes".
    2. Create a Graphic using the Graphic(json) constructor.
    3. Test to see if your geometry can be projected to Web Mercator using webMercatorUtils.
    4. If the test returns true, use the webMercatorUtils.project function to project the Graphic's geometry. If false, (meaning your spatial reference isn't supported by webMercatorUtils) use proj4js to do the projection. (Once you've determined which method you need to use, you can remove the test code and go directly to the projection code.)
    5. The reviver function should return the projected graphic.
  4. Create a new FeatureLayer object. Use your array of features from the previous step to create an object for the featureCollectionObject parameter.
0 Kudos
ChrisHolmes
Frequent Contributor

Yes, the goal is to display the data on a map. Thanks for your input Jeff.

0 Kudos
ChrisHolmes
Frequent Contributor

Hey Jeff, follow up question. What if I only want to get the data into ArcMap?

Thanks

0 Kudos
JeffJacobson
Frequent Contributor

Since this forum is for the ArcGIS API for JavaScript, it's likely that no one here will know the answer. Try posting in Geoprocessing.

0 Kudos
ChrisHolmes
Frequent Contributor

Yes, I did have that thought. Thanks Jeff

0 Kudos