Problem with Intersect_analysis

2791
12
01-09-2013 09:21 AM
DuaneDubey
New Contributor
Hello,

I have a script that is to geocode addresses from a database, intersect the results with three boundary files and do a tabletotable conversion on the results.  Below is the intersect statement I am using.

arcpy.Intersect_analysis([geocode_results, boundary1_shp, boundary2_shp, boundary3_shp], qResults, "ALL", "", "INPUT")


The statement is failing on qResults (e.g. creating the output of the intersect).  It seams that no matter what I put there (file path or variable name), the compiler is appending ".shp.shp" to the file name which causes an invalid file error. 

ERROR 000210: Cannot create output \\mydrive\ArcGIS\Default.gdb\qResults.shp.shp
ERROR 000354: The name contains invalid characters
Failed to execute (Intersect).

Any help, would be greatly appreciated.

Thanks,
Dan
Tags (2)
0 Kudos
12 Replies
MathewCoyle
Frequent Contributor
What is the value of your qResults variable? What version of ArcGIS are you using and service pack?
0 Kudos
DuaneDubey
New Contributor
We are using ArcGIS 10 SP 4

What should the value of the output variable be?  I've tried to assign it a .shp file or to simply give it a name and let the compiler figure it out.  Neither have worked.  My understanding is that when the intersect is complete, the result set is saved to a file and I am defining what to call it so that I can use it later.  Is that correct?
0 Kudos
MathewCoyle
Frequent Contributor
We are using ArcGIS 10 SP 4

What should the value of the output variable be?  I've tried to assign it a .shp file or to simply give it a name and let the compiler figure it out.  Neither have worked.  My understanding is that when the intersect is complete, the result set is saved to a file and I am defining what to call it so that I can use it later.  Is that correct?


Since you are outputting to a geodatabase, which I am assuming is your env.workspace, you should just give it a name. Nothing else should be required.

qResults = 'output_featureclass'
0 Kudos
DuaneDubey
New Contributor
Thank you for the reply. I tried setting the value of the output to 'output_featureclass' and I got the same error.

ERROR 000210: Cannot create output \\MyDrive\ArcGIS\Default.gdb\output_featureclass.shp.shp
ERROR 000354: The name contains invalid characters
Failed to execute (Intersect).

Here is the full code:


# Import arcpy module
import arcpy
from arcpy import env

try:
   env.workspace = "\\\\MyDrive\\ArcGIS\\Default.gdb"

   if arcpy.Exists(dbo_View1):
       arcpy.Delete_management(dbo_View1)
   if arcpy.Exists(dbo_GeocodeAddresses3):
       arcpy.Delete_management(dbo_GeocodeAddresses3)

   # Local variables:
   dbo_CDM_ARCCHANCERY = "Database Connections\\Chancery.odc\\dbo.CDM_ARCCHANCERY"
   NewAASD_Streets = "\\\\MyDrive\Transportation\\ArcGIS ver 10\\Locators\\NewAASD_Streets"
   elembound_shp = "\\\\MyDrive\Transportation\\ArcGIS ver 10\\Boundaries\\elembound.shp"
   highbound_shp = "\\\\MyDrive\Transportation\\ArcGIS ver 10\\Boundaries\\highbound.shp"
   middlebound_shp = "\\\\MyDrive\Transportation\\ArcGIS ver 10\\Boundaries\\middlebound.shp"
   arc__VERSION_dbo_DEFAULT_ = "Database Servers\\MyServer_ARC.gds\\arc (VERSION:dbo.DEFAULT)"
   dbo_View1 = "dbo_View1"
   dbo_GeocodeAddresses3 = "\\\\MyDrive\\ArcGIS\\Default.gdb\\dbo_GeocodeAddresses3.shp"
   dbo_GeocodeAddresses3_Inters = 'output_featureclass'

   # Process: Make Table View
   arcpy.MakeTableView_management(dbo_CDM_ARCCHANCERY, dbo_View1, "", "", "Id Id VISIBLE NONE;StudentId StudentId VISIBLE NONE;'Last Name' 'Last Name' VISIBLE NONE;'First Name' 'First Name' VISIBLE NONE;'Middle Name' 'Middle Name' VISIBLE NONE;School School VISIBLE NONE;'School #' 'School #' VISIBLE NONE;'Street Number' 'Street Number' VISIBLE NONE;'Street Direction' 'Street Direction' VISIBLE NONE;Street Street VISIBLE NONE;'Street Type' 'Street Type' VISIBLE NONE;Apt Apt VISIBLE NONE;City City VISIBLE NONE;State State VISIBLE NONE;ZIP ZIP VISIBLE NONE;'Full Address' 'Full Address' VISIBLE NONE;DOB DOB VISIBLE NONE;Gender Gender VISIBLE NONE;Grade Grade VISIBLE NONE;Ethnicity Ethnicity VISIBLE NONE;LunchStatus LunchStatus VISIBLE NONE;PrivateSchool PrivateSchool VISIBLE NONE")
    
   # Process: Geocode Addresses
   arcpy.GeocodeAddresses_geocoding(dbo_View1, NewAASD_Streets, "Street 'Full Address' VISIBLE NONE;ZIP ZIP VISIBLE NONE", dbo_GeocodeAddresses3, "STATIC")
  
   # Process: Intersect
   arcpy.Intersect_analysis([dbo_GeocodeAddresses3, elembound_shp, highbound_shp, middlebound_shp], dbo_GeocodeAddresses3_Inters, "ALL", "", "INPUT")

   # Process: Table to Table
   arcpy.TableToTable_conversion(#Removed because of length#)

   # Cleanup temporary tables
   if arcpy.Exists(dbo_View1):
       arcpy.Delete_management(dbo_View1)
   if arcpy.Exists(dbo_GeocodeAddresses3):
       arcpy.Delete_management(dbo_GeocodeAddresses3)

except Exception, e:
    #If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "Line %i" % tb.tb_lineno
    print e.message
0 Kudos
curtvprice
MVP Esteemed Contributor
I think the root of your problems may be this line:
dbo_GeocodeAddresses3 = "\\\\MyDrive\\ArcGIS\\Default.gdb\\dbo_GeocodeAddresses3.shp"


You can't have a shapefile inside a geodatabase; this may be messing up your parameter validation and adding .shp to the output feature class name.

Just a tip, try "raw" strings to make it easier to copy and paste paths into code.
arcpy.env.workspace = r"\\MyDrive\ArcGIS\Default.gdb"
0 Kudos
DuaneDubey
New Contributor
I removed the .shp from the GeocodeAddresses3 variable and got the below error:

dbo_GeocodeAddresses3 = r"\\MyDrive\ArcGIS\Default.gdb\dbo_GeocodeAddresses3" 


Line 39
Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset \\MyDrive\ArcGIS\Default.gdb\dbo_GeocodeAddresses3 #;'\\MyDrive\Transportation\ArcGIS ver 10\Boundaries\elembound.shp' #;'\\MyDrive\Transportation\ArcGIS ver 10\Boundaries\highbound.shp' #;'\\MyDrive\Transportation\ArcGIS ver 10\Boundaries\middlebound.shp' # does not exist or is not supported
Failed to execute (Intersect).

How should I be handling the output from the GeocodeAddresses process?
0 Kudos
curtvprice
MVP Esteemed Contributor
My advice is to do this process interactively and look at the results window.

"Copy As Python Snippet" is your friend!
0 Kudos
DuaneDubey
New Contributor
I will try doing that however, we used the interface initially.  It worked once and failed when we tried to run it again as a job.
0 Kudos
DuaneDubey
New Contributor
OK, now I am working on my model.

I'm using:

1.  Geocode addresses to connect to a SQL Server table and geocode against a locator file.
2. Intersect to combine the results of #1 with three boundary files.
3. Table to Table to output the results of #2 to SQL Server Express which is installed on the GIS Server.

Question is related to #3.  The OLE DB connection to SQL appears to be read only.  How can I create a connection to SQL Server Express that can be written to?  Is there a way to create an ADO connection?

Thanks,

Dan
0 Kudos