Select to view content in your preferred language

Looking to code a feature service export to a shapefile. Preferably in .NET. Any idea?

1360
6
Jump to solution
10-05-2017 02:01 PM
TheKenerson
Occasional Contributor

Looking to code a feature service export to a shapefile. Preferably in .NET. Any idea?

0 Kudos
1 Solution

Accepted Solutions
KellyGerrow
Esri Frequent Contributor

Try looking into making direct calls to the Rest API from your application. Shapefile is an output format in both tools:

Create Replica:

ArcGIS REST API 

Export Item:

ArcGIS REST API 

Authentication details: ArcGIS REST API 

-Kelly

View solution in original post

6 Replies
XanderBakker
Esri Esteemed Contributor

Here is a good example of how you would do this with Python: Download ArcGIS Online Feature Service or ArcGIS Server Feature/Map Service 

Or this standard tool shipped with ArcGIS: Geoprocessing service example: Clip And Ship—ArcMap | ArcGIS Desktop 

Any additional info on why you prefer .NET? Or why this might be required? What will be the "client implementation"?

TheKenerson
Occasional Contributor

Thank you. This does the trick. It exports the data from a feature service to a locally stored shapefile.

I prefer .NET because I am writing in in a desktop application that uses C# and I was looking to be consistent. To give you a little bit more information:

The program I am working on uses a PGDB and it has a method to export the PGDB Feature Class to a shapefile for field editing in ArcPad. I am looking to enhance the product by writing a shapefile export for use in AGOL. 

So far, I was able to:

1)export the PGDB feature class to a hosted feature service in AGOL using ArcREST and JSON.

2)Write the AGOL application Data Editor in JavaScript. 

3) Iand used .NET interfaces to read and import the data from a locally stored shapefile back to the PGDB Feature Class.

This all works great. However, I am missing a step between #2 and #3 above. I don't know how to export my data from a hosted feature service to a shapefile that is stored locally on my PC. This option does not seem to be present in ArcREST, but maybe i'm just missing it. I the started looking at ArcObjects for.NET and I don't see an interface that states it can perform a feature service to shapefile conversion/export.

I would think this operation would be straightforward as any user, with the proper credentials, can simply login to their AGOL account and export a feature service to a shapefile and then store it locally. I would just like to code this so my users don't have to do this every time they want to import their data.

Any ideas where one may want to look. 

0 Kudos
KellyGerrow
Esri Frequent Contributor

Try looking into making direct calls to the Rest API from your application. Shapefile is an output format in both tools:

Create Replica:

ArcGIS REST API 

Export Item:

ArcGIS REST API 

Authentication details: ArcGIS REST API 

-Kelly

TheKenerson
Occasional Contributor

Thank you. I ended up using ArcREST Create Replica. Hs an example for anyone else who may be looking for an example.

string format = "f=json";
            string replicaName = "replicaName=whatevername";
            string layers = "layers=0";
            string geometryType = "geometryType=esriGeometryPoint";
            string returnAttachmentsDatabyURL = "returnAttachmentsDatabyURL=false";
            string dataFormat = "dataFormat=shapefile";
            string targetType = "targetType=client";
            string attachmentsSyncDirection = "attachmentsSyncDirection=none";
            string syncModel = "syncModel=none";
            string reqString = FeatureServiceURL + "/createReplica?" + replicaName + "&" +
            layers + "&" + geometryType + "&" + returnAttachmentsDatabyURL + "&" + attachmentsSyncDirection + "&" + dataFormat + "&" + targetType + "&" + syncModel + "&" + format;
Another hint: if you use format type json, its simple to get to url of the shapefile. Once you have that you can easily code to save it locally and extract it.
0 Kudos
TheKenerson
Occasional Contributor

Thank you Kelly, I was looking in the authentication details as I will need to generate a token so I can create my replica. The referrer parameter suggests that I will need a base url for the web app. Is this the case? If so, do you know if I need to register my application? Any help/suggestions/examples would be great if you have time.

0 Kudos
KellyGerrow
Esri Frequent Contributor

Hi,

You can use Arcgis.com as your referrer if you are making direct rest calls. If you have a web app url, submit the web app url.

-Kelly