# Create Locator; Using Services as the Data Source

503
4
11-25-2020 08:59 AM
MVP Esteemed Contributor

ArcGIS Pro 2.6

Yesterday I successfully created a multi-role locator using the Create Locator tool. Three of the four data sources are rest-end services.

I would like to automate the task in a python script and things aren't quite working for me and I'm not sure why. The history of the tool is my source for the parameters.  I've used it before but the data sources were feature classes rather than services.  At any rate, here is what I use and the ensuing error:

countryCode = 'USA'
centerlinesPrimary = r'https://path/to/rest/services/Transportation/MapServer/0'
parcelsPrimary = r'https://path/tos/rest/services/Land/MapServer/1'

#parcelsPrimary)

outLocator =  r'M:\HansenSQL\HansenGeocodingTestMultiRole'

"'Parcel.PARCEL_NAME 1.parcel_id';"\
"POI.PLACE_NAME 'owner.AddressGridCoordinatePoints'.Coordinates"

Error:

Failed to execute. Parameters are not valid.
ERROR 002782: Selected Primary Table does not contain geometry.

I don't care for this new code editor as it doesn't list line numbers, but I'll limp through this.

Notice in the field mapping portion it refers to the feature id only; does it need to be fully qualified with the entire url?

can't wait to retire....
4 Replies
MVP Esteemed Contributor

The help page has a sample; I'll see what I need to do to get it to work for me...

can't wait to retire....
MVP Esteemed Contributor

Following the example towards the bottom of the help page mentioned, I am trying to create a single role street address locator with a service as the data source: (sorry for the lame code editing, but I'm at the mercy of the new geonet)

import arcpy

arcpy.env.overwriteOutput = True
arcpy.SetLogHistory(False)

outLocator = r'M:\HansenSQL\HansenGeocoding\TestLocator'
language = 'ENG'
country = 'USA'

inTable = "https://blah/blahlah/rest/services/Transportation/MapServer/0 StreetAddress"

arcpy.geocoding.CreateLocator(country, inTable, fieldMapping, outLocator, language)

However, it errors out with:

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 002782: Selected Primary Table does not contain geometry.
Failed to execute (CreateLocator).

I can think of two things:

I can get to the service via the create locator tool, but perhaps there is a security setting that does not allow me to hit it with python; I don't think that's it because in a console window I can use arcpy.ListFields(inTable) and get a list.

or

Creating a locator with a service as the data source simply does not work in python....

can't wait to retire....
Esri Regular Contributor

Joe,

You need to call

and then using services as data sources should work just fine for CreateLocator using Python. The data sources need to be on the server federated with the Portal you are signing into.

If your data sources are shared with everyone (public) you don’t need to call SignInToPortal() first.

MVP Esteemed Contributor

Turns out the arcpy.SignInToPotal() call isn't needed for me.  The game changer is while the create locator tool is able to exploit a map service as a data source, arcpy cannot; arcpy wants a feature service.

The portal I have access to is behind a firewall and is available 'publicly' to those users logged into the network which I am.  All I had to do is change the urls to the various feature services and I'm good to go.

One of the data sources in my multi-role locator is on our SDE-Egdb, so it's part of inTable variable as shown below in the final code:

import arcpy
arcpy.env.overwriteOutput = True
arcpy.SetLogHistory(False)

outLocator = r'M:\path_to\my_locator'
language = 'ENG'
country = 'USA'

arcpy.geocoding.CreateLocator(country, inTable, fieldMapping, outLocator, language)