now arcgis online already support output geojson format through arcgis rest api URL. All you need to do is set f=geojson in the URL.
Below query page, at bottom, format dropdown list has geojson option.http://services.arcgis.com/uCXeTVveQzP4IIcx/ArcGIS/rest/services/Portland_Coffee_Shops/FeatureServer/0/query
Be aware, by default, arcgis online will out allow geojson format until you set it allow other output format(geojson).
here is how to do that:
arcgis online, click the feature layers, click the setting tab
check this box
Export Data Allow others to export to different formats.
save and wait a few minutes,
in the query page, you should see the output format dropdownlist already have geojson option, before, it only has json/html.
here is doc https://geonet.esri.com/groups/geodev/blog/2014/12/11/new-geojson-and-interop-capabilities-for-arcgis-online
===============================================================
arcgis server rest api, feature service,
if you query the layer, with URL like this, .../FeatureServer/query?layerDefs=...
You can not set geojson format, f=pgeojson will be bad request, f=json, because the return stuff is not feature, the layers json was return.
Try this html query page, you can see, no geojson option,
http://services3.arcgis.com/VILr8UqX00eNAkeO/arcgis/rest/services/Parcels/FeatureServer/query
------------------------------------------------
If you want to return geojson (feature), you must use this URL .../FeatureServer/0/query...
/0/ means layerID, if on has only 1 layer, then layerID = 0.....
Try this html query page, you can see, geojson is option, because you are query specific layer with layerID = 0
http://services3.arcgis.com/VILr8UqX00eNAkeO/arcgis/rest/services/Parcels/FeatureServer/0/query
Note: remember to set those 2 parameters: outSR=4326&f=geojson in the URL spatial reference ID, srid = 4326, because web map all use this, f means format, both f=pgeojson and f=geojson works. If you don't set outSR=4326, arcgis server rest api by default will NOT use 4326, instead use something else, only 4326 has unit degree, which is used in most web map. Other format would not work with web maps.
so the working example URL is:
http://services3.arcgis.com/VILr8UqX00eNAkeO/arcgis/rest/services/city_online/FeatureServer/17/query?returnGeometry=true&f=pgeojson&geometryType=esriGeometryEnvelope&geometry={"xmin" : -117.923158, "ymin" : 33.644081, "xmax" : -117.921436, "ymax" : 33.645157,"spatialReference" : {"wkid" : 4326}}
/city_online/ is feature layer
/17/ is layerID
No comments:
Post a Comment