Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

esriJSON feature arrays not captured by parse() in arcgis.js #104

Closed
abenrob opened this issue Jun 22, 2013 · 8 comments
Closed

esriJSON feature arrays not captured by parse() in arcgis.js #104

abenrob opened this issue Jun 22, 2013 · 8 comments
Labels

Comments

@abenrob
Copy link

abenrob commented Jun 22, 2013

Is this intentional?
When I point to an AGS JSON rest endpoint and try to parse to geoJSON, the object matches no cases and the geoJSON object remains empty.
If I limit to one feature (e.g. arcgis.features[0]) the conversion succeeds.

@patrickarlt
Copy link
Contributor

@abenrob There is an explict reason we don't support this but do support converting single features. When you parse a feature into GeoJSON like

var geojson = Terraformer.ArcGIS.parse(arcgis.features[0]);

Does not produce valid GeoJSON because geojson.id is undefined. Valid GeoJSON Features must have a id property. Since converting an array of ArcGIS features to an array of GeoJSON Features would result in alot of invalud GeoJSON you should do this in a loop like this...

var FeatureCollection = {
  type: "FeatureCollection",
  features: []
}

for (var i = 0; i < arcgis.features.length; i++) {
  var feature = Terraformer.ArcGIS.parse(arcgis.features[i]);
  feature.id = i;
  FeatureCollection.features.push(feature)
};

If we allow passing an array we also open our selves up to bugs where mixed arrays of geometries and features are passed (which cant exist in GeoJSON) and would require us to sort them out into FeatureCollections or GeometryCollections.

@abenrob
Copy link
Author

abenrob commented Jun 24, 2013

Thanks for the clarification.

@patrickarlt
Copy link
Contributor

@abenrob fleshed out the explanation a little hit "Comment" to soon.

@jhobz
Copy link

jhobz commented Jul 11, 2013

I believe you have a typo in your explanation. The following line:

FeatureCollection.features.push(geojson)

should probably read

FeatureCollection.features.push(feature)

right?

@patrickarlt
Copy link
Contributor

@jeffreyhobson Thanks, corrected it.

@jgravois
Copy link
Collaborator

hello from 2018!

in @esri/arcgis-to-geojson-utils we ultimately landed support for converting arrays of Esri JSON features into a GeoJSON FeatureCollection and auto-incrementing ids.

its also worth noting:

  • RFC 7946 the id requirement was downgraded from a MUST to a SHOULD
  • the Geoservices spec doesn't emit arrays of features with dissimilar geometries.

@hoogw
Copy link

hoogw commented Apr 4, 2018

@jgravois

can you show me example, how to do it?


in @esri/arcgis-to-geojson-utils we ultimately landed support for converting arrays of Esri JSON features into a GeoJSON FeatureCollection and auto-incrementing ids.

@jgravois
Copy link
Collaborator

jgravois commented Apr 4, 2018

@hoogw no need to respost the same question in three different places. i've answered you in Esri/arcgis-to-geojson-utils#30 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants