Select by Location Toolbox - Python script automation used to work and now shows ERROR 000210

4909
3
Jump to solution
03-10-2015 09:33 AM
SusanZwillinger
Occasional Contributor

I have used the attached toolbox/script in the past to automate Select by Location. In this case, I have points that I want to assign to polygons. The script allows you to enter the polygon layer and an ID field as well as the item to be selected (points layer).  It places the polygons into memory and iterates through each polygon, selecting the points that intersect the polygon and writing the ID field to a table of those records and exporting the output shapefile of the points with the polygon ID assignment.  After it iterates through all of the polygons, it merges the output shapefiles into a single shapefile called Final_Merge.shp.

(Note, some people may wonder why I'm not using a spatial join for this operation.  The reason is that the "point in polygon" method skips any points that are on the boundary line.  Yes, you could use the "closest" option of the spatial join, but I find that to take a long time to calculate the distances when you have large files.  In addition, I like the flexibility and control of the select by location options to control just what gets selected and assigned.)

I've used the script for other layer combinations, not just points and polygons.  I edit the script before running the toolbox to change which Select by Location method works best for the situation --e.g. INTERSECT versus WITHIN_A_DISTANCE, by using the # to comment out the intersect line and "uncommenting" the line that has the selection option that I want.

The script used to work great.  With very large processes, it sometimes ran out of memory after about 500 shapefiles and I would simply re-run the script with the records that were remaining.

I ran this once this morning as a test--and it worked perfectly.  However, when I tried to run it again, it always gives me a "ERROR 000210: Cannot create output".  I tried rebooting, creating a new MXD, using a different ID, using different output folders, and nothing has worked.

The main reason for my using the script now is that I wanted to try to change the input and output types to file geodatabase feature classes instead of shapefiles, but all of my attempts to make that change have failed and until I can get the original script to run consistently with shapefiles, I don't want to try to make further changes.

I am not a Python programmer and the original code was written by someone else.  Can anyone help get this working again?  I think this tool could help a LOT of people.  I have attached a zip file with the toolbox file and the Python script.

Message was edited by: Susan Zwillinger I uploaded the revised toolbox and script that is working consistently for me when using shapefiles.

Message was edited by: Susan Zwillinger Removed the option that deleted the output folder when the script failed in case someone chose an output folder that contained other data that should not be deleted.

Message was edited by: Susan Zwillinger I got it working again. This time it is more consistent. I removed some of the output messages in the script. It will accept either a shapefile or a feature class as an input, but it still only outputs shapefiles. One note about the different inputs--if you use a file geodatabase as an input, depending on whether or not you used the default XY tolerance value when you created the file geodatabase or whether you specified this in the geoprocessing-->environment settings, you can get very different "select by location" results compared to the same data in a shapefile format.

0 Kudos
1 Solution

Accepted Solutions
SusanZwillinger
Occasional Contributor

I fixed the script but I'm not exactly sure why it decided to work consistently again.

View solution in original post

0 Kudos
3 Replies
SusanZwillinger
Occasional Contributor

I fixed the script.  I added the bold items and it fixed ERROR 00210.  The first thing that I tried was to add the overwrite option (I already had that specified in my geoprocessing-->options, but I thought it couldn't hurt to include this).  That change alone did not solve the problem.  However, the class LicenseError(Exception): pass lines did the trick.  I have no idea why that worked.  Now, can anyone tell me how to get this to work with file geodatabase feature class as input and output?

# Import system modules

class LicenseError(Exception):

    pass

import string

import os

import sys

import arcview

import arcpy

from arcpy import env

import traceback

try:

    # Create the Geoprocessor object

    arcpy.env.overwriteOutput = True

    arcpy.AddMessage("Starting script...")

    print arcpy.GetMessages()

0 Kudos
SusanZwillinger
Occasional Contributor

Well, I thought that was a fix, but as soon as I tried to see what would happen if I used feature classes as input, it gave me an error and now I can't get it to work again.  The problem seems to be related to the fact that when I got this to run successfully, the input window would show the "Add" button for the Output Folder.  Now, it only shows me the "Save" option and that always returns the error.

0 Kudos
SusanZwillinger
Occasional Contributor

I fixed the script but I'm not exactly sure why it decided to work consistently again.

0 Kudos