How to copy all records from a Map/Feature Service

2468
5
12-16-2016 10:33 AM
PatrickMcKinney1
Occasional Contributor III

I have heard that there is a way to copy all records from a map/feature service to a geodatabase feature class, even if the max record count set for the service is less than the total records in the dataset.

Does anyone know how to do this? Or could anyone help point me in the right direction?

Thanks,

Patrick

0 Kudos
5 Replies
FrankPrice
New Contributor III
PatrickMcKinney1
Occasional Contributor III

Thanks for the link to the tool.

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

fnprice‌,

Thank you for sharing. The above tool by Jake Skinner‌ looks very promising.

Another (traditional) alternative. If you have a license of ArcGIS Desktop and the feature service has EXPORT option enabled, you could just add the service to ArcMap/ArcCatalog/ArcGIS Pro and Export Data to a geodatabase Feature Class. 



Think Location
PatrickMcKinney1
Occasional Contributor III

Thanks for the tip!

0 Kudos
BlakeTerhune
MVP Regular Contributor

Here are some resources I found helpful

ArcGIS REST API 

Quick Tips: Consuming Feature Services with Geoprocessing | ArcGIS Blog 

Here's the code I put together to do a simple data download. Note, this was tested with 10.2.2, which does not support resultOffset and resultRecordCount request parameters for pagination so you will be limited to 1000 records at a time.

import arcpy
import urllib

def main():
    svc_lyr_url = "http://somedomain.com/arcgis/rest/services/MapServiceName/MapServer/0"
    where_clause = "objectid<100"  ## Required
    field_names = ""  ## Optional "FIELD1,FIELD2,FIELD3"

    # Test availability of service
    try:
        svc_lyr_response = urllib.urlopen(svc_lyr_url)
        print svc_lyr_response
        if svc_lyr_response.getcode() == 200:  ## The request has succeeded
            # Build and format query url
            query_url = "{}/query?where={}&outFields={}&returnGeometry=true&f=json".format(
                svc_lyr_url,
                where_clause,
                field_names,
            )
            try:
                query_response = urllib.urlopen(query_url)
                print query_response
                if query_response.getcode() == 200:  ## The request has succeeded
                    print "http code {} from {}".format(svc_lyr_response.getcode(), query_response.geturl())
                    # Load JSON data from query and copy to feature class
                    fs = arcpy.FeatureSet()
                    fs.load(query_url)
                    arcpy.env.overwriteOutput = True  ## Optional
                    arcpy.CopyFeatures_management(fs, r"C:\temp\TEMP.gdb\SampleDownload")
                    print arcpy.GetMessages()
                else:
                    response_msg = "http code {} from {}".format(
                        query_response.getcode(),
                        query_response.geturl()
                    )
                    raise Exception(response_msg)
            finally:
                query_response.close()

        else:
            response_msg = "http code {} from {}".format(
                svc_lyr_response.getcode(),
                svc_lyr_response.geturl()
            )
            raise Exception(response_msg)
    finally:
        svc_lyr_response.close()


if __name__ == '__main__':
    main()‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos