Select to view content in your preferred language

Export data from Map Service

13276
14
10-23-2014 03:35 AM
HaniDraidi
Frequent Contributor

Hi,

Is there a tool (in ArcMap) to extract data from a map or feature service I am accessing?

Clip_715.jpg

Thank you,

Hani

0 Kudos
14 Replies
OLANIYANOLAKUNLE
Frequent Contributor

Hi Jake Skinner, I found your tool very useful and helpful but I still get the error below;

iteration = int(data['OBJECTIDS'][-1])

KeyError: 'OBJECTIDS'

See my code block below as well;

username = "ASDERT"
        password = "@######"
        baseURL = 'http://services5.arcgis.com/b23aIR8OqGRlfJlE/arcgis/rest/services/PropertyEnumerationForm/FeatureSer...'
      

        arcpy.AddMessage('\nGenerating Token\n')
        tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken'
        params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'http://www.arcgis.com'}
        req = urllib2.Request(tokenURL, urllib.urlencode(params))
        response = urllib2.urlopen(req)
        data = json.load(response)
        token = data['token']

        # Return largest objectIds
        params = {'where': '1=1', 'returnIdsOnly': 'true', 'token': token, 'f': 'json'}
        req = urllib2.Request(baseURL, urllib.urlencode(params))
        response = urllib2.urlopen(req)
        data = json.load(response)
        try:
            data['objectIds'].sort()
        except:
            arcpy.AddWarning("\nURL is incorrect.  Or, Service is secure, please enter username and password.\n")
        iteration = int(data['OBJECTIDS'][-1])
        minOID = int(data['OBJECTIDS'][0]) - 1
        OID = data['objectIdsFieldName']

Kindly assist me with this, Thanks

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Hi Olaniyan,

When running the tool on the service, I did not receive any errors.  Ex:

screen1.PNG

screen2.PNG

0 Kudos
OLANIYANOLAKUNLE
Frequent Contributor

Thanks Jake,

I was trying to run the script behind a button, see script below;

import pythonaddins
import os
import datetime
import time
import os, sys
import urllib, urllib2, arcpy, json
import uuid
arcpy.env.overwriteOutput = True
class AGOLClass1(object):
    """Implementation for AGOL_addin.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        username = "TAXXXX"
        password = "#######"
        baseURL = 'http://services5.arcgis.com/b23aIR8OqGRlfJlE/arcgis/rest/services/PropertyEnumerationForm/FeatureSer...'
         
        
        arcpy.AddMessage('\nGenerating Token\n')
        tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken'
        params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'http://www.arcgis.com'}
        req = urllib2.Request(tokenURL, urllib.urlencode(params))
        response = urllib2.urlopen(req)
        data = json.load(response)
        token = data['token']
        # Return largest objectIds
        params = {'where': '1=1', 'returnIdsOnly': 'true', 'token': token, 'f': 'json'}
        req = urllib2.Request(baseURL, urllib.urlencode(params))
        response = urllib2.urlopen(req)
        data = json.load(response)
        try:
            data['objectIds'].sort()
        except:
            arcpy.AddWarning("\nURL is incorrect.  Or, Service is secure, please enter username and password.\n")
        iteration = str(data['objectIds'][-1])
        minOID = str(data['objectIds'][0]) - 1
        OID = data['objectIdsFieldName']

and I get the error below;

>>>

Traceback (most recent call last):

  File "C:\Users\KUNLE\AppData\Local\ESRI\Desktop10.2\AssemblyCache\{322E160C-A3DE-48C9-BEBC-86802FD9C785}\AGOL_addin.py", line 40, in onClick

    iteration = str(data['objectIds'][-1])

KeyError: 'objectIds'

>>>

But the script runs well as a script tool under a toolbox. Kindly assist, thanks.

TanuHoque
Esri Regular Contributor

Thanks Jake Skinner‌ for the python script. This is awesome!

Just an FYI for all - in ArcGIS Pro, you can use geoprocessing tools such as 'Feature Class to Feature Class' to export data from a layer off a map service. And you can download all data not just first 1,000 or whatever is MaxRecordCount is set to (as long as the server is not an older version).

Steps

Esad
by
Emerging Contributor

I am trying to fetch data from a map server that I do not manage and I am receiving the following error:

Proxy server got bad address from remote server (verify the server is running). (status code 504).

0 Kudos