Do you work with Feature Services? Do you want to use geoprocessing tools or Python to perform analysis with ArcGIS for Desktop? Here’s a few quick tips for using a hosted feature service from arcgis.com or your own ArcGIS for Server feature service with geoprocessing tools.
Identifying a Feature Service
When connecting to your local ArcGIS Server, you can quickly identify a feature service by the presence of a callout on the map service icon. Note that all the hosted services on ArcGIS.com which can be brought into ArcMap are feature services.
Consuming the Feature Service
Before you can use a feature service with geoprocessing, you need to add it your map. To add, simply drag and drop the feature service onto your table of contents.
With the feature service in your table of contents, you can then use it as an input layer into most geoprocessing tools that accept features.
Notice the auto-generated output name in the Buffer tool dialog above. This name is based on the layer index number by which feature service layers are identified. The name will always be a “c”, followed by the layer index number, followed by the name of the tool to be run. If you’re unsure about the feature service layer index or properties, just pull it up on the Source tab of the Layer Properties as illustrated below.
Max Records
If you’ve already performed some analysis on a hosted feature service from arcgis.com, you may have encountered the following warning:
WARNING 001406: Query operation has exceeded the feature service transfer limit
Only the first 1000 records will be used by the geoprocessing tools. Hosted feature services have their maximum query set to 1000 records. 1000 is also the default maximum with a local ArcGIS for Server. However you have the option to increase this value in your local deployment. To work with a feature service that has more than 1000 records you will have to iterate through the records 1000 (or less) at a time. Remember that geoprocessing tools honor selection sets. You can manually select 1000 records at a time, or you can use a geoprocessing tool like Select Layer by Attribute. Tools like Merge and Append can be used to combine all your features into a single feature class depending on your needs.
Maintaining ObjectIDs
If you’re consuming a feature service that has a lot of active additions and deletions you may have noticed that the ObjectIDs are not sequential. Using the tool Copy Features to make a local copy of the features will condense the IDs in the local dataset to be sequential. If you want to preserve the IDs in your local data, you can use the FeatureSet object within the Python Window. Remember though, the 1000 record limit mentioned above still applies when using this technique.
1
2
3
4
5
|
fset = arcpy.FeatureSet() fset.load( 'Dispatch' ) #Dispatch is the name of the layer in the Table of Contents fset.save(r 'c:\mydata\fgdb.gdb\dispatchLocal' ) |
Feautre Service in standalone scripts
You can also use the arcpy.FeatureSet() approach in your standalone Python scripts with a feature service. The only trick is knowing the feature service URL and the proper query to return features. The following Python code demonstrates the URL you need to build up which will be used in the FeatureSet load. The URL below submits a query for the JSON of the features, which is valid input to the FeatureSet function. A query minimally needs an appropriate ‘where clause’ and output fields. Remember, this query is no different than working with a feature service in ArcMap; you could ask for more records than the query limit of the service allows. The code below also accepts a token if you have a secure service.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
import arcpy # Modify the following variables: # URL to your service, where clause, fields and token if applicable baseURL = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/PoolPermits/FeatureServer/1/query" where = '1=1' fields = 'apn, address, pool_permit' token = '' #The above variables construct the query query = "?where={}&outFields={}&returnGeometry=true&f=json&token={}" . format (where, fields, token) # See http://services1.arcgis.com/help/index.html?fsQuery.html for more info on FS-Query fsURL = baseURL + query fs = arcpy.FeatureSet() fs.load(fsURL) arcpy.CopyFeatures_management(fs, r "c:\local\data.gdb\permits" ) |
Online Analysis Results in ArcMap
The new Online Analytic tools allow you to perform analysis in your webmap. This analysis result gets saved into your arcgis.com account as a hosted feature service. After signing into your account within ArcMap, you can add those feature services from the My Hosted Services node in the bottom of Catalog window into your map. You can now perform analysis on the result from your web analysis within ArcGIS for Desktop–over 900 tools to take your analysis one step further!
Commenting is not enabled for this article.