problem with intersect

178
5
Jump to solution
06-27-2019 04:49 AM
JohannesBierer
Regular Contributor

Hello,

This code leads to a error message:

Object: Error in executing tool

Any ideas why? Might be something in line 17?

# -*- coding: cp1252 -*-
import arcpy

InFc = r"R:\Karto\Bierer2019\Kaltenbronn_DGM\shapes\Geodaten.gdb\data\graeben_breitlhohloh_Prioritaer"
field = "OBJECTID"
InContour = r"R:\Karto\Bierer2019\Kaltenbronn_DGM\shapes\Geodaten.gdb\data\Hohlohbreitl_Contour_50cm"

try:
with arcpy.da.SearchCursor(InFc, field) as cursor:
for row in cursor:
print(row)

scl = "OBJECTID = {}".format(row[0])
print scl
inFcLayer = arcpy.MakeFeatureLayer_management(InFc, "lyr_{}".format(row[0]), scl)

inFeatures = """ ["{}", "{}"] """.format(inFcLayer, InContour)
print inFeatures

outFeature = r"R:\Karto\Bierer2019\Kaltenbronn_DGM\shapes\Zwischendaten.gdb\data\a_{}".format(row[0])

arcpy.Intersect_analysis(inFeatures, outFeature, "ALL", "", "POINT")

del cursor

except Exception:
e = sys.exc_info()[1]
print(e.args[0])
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Esteemed Contributor
x = r"R:\Karto\Bierer2019\Kaltenbronn_DGM\shapes\Zwischendaten.gdb\data\a"

arcpy.Intersect_analysis(inFeatures, x, join_attributes="ALL", output_type="POINT")

Try overt assignment of the 'optional' parameters, so you can skip the 2nd last one.

barring that... make a gdb in c:\temp and direct the output there to see if there is something wrong with the full path or the ... .gdb\data portion of it

View solution in original post

0 Kudos
5 Replies
DanPatterson_Retired
MVP Esteemed Contributor
a = 'first'
b = 'second'

c = ' ["{}", "{}"] '.format(a, b) # ---- option 1
c
' ["first", "second"] '‍‍‍‍‍‍

c = " ['{}', '{}'] ".format(a, b) # ---- option 2
c
" ['first', 'second'] "‍‍‍‍‍‍‍‍‍‍‍

You syntax checked, but the two options to derive single vs double quotes can be simplified to.

But you might have problems depending on whether row[0] returns single or double quotes

r"R:\Karto\Bierer2019\Kaltenbronn_DGM\shapes\Zwischendaten.gdb\data\a_{}".format('field')

'R:\\Karto\\Bierer2019\\Kaltenbronn_DGM\\shapes\\Zwischendaten.gdb\\data\\a_field'

r'R:\Karto\Bierer2019\Kaltenbronn_DGM\shapes\Zwischendaten.gdb\data\a_{}'.format("field")
'R:\\Karto\\Bierer2019\\Kaltenbronn_DGM\\shapes\\Zwischendaten.gdb\\data\\a_field'

r"R:\Karto\Bierer2019\Kaltenbronn_DGM\shapes\Zwischendaten.gdb\data\a_{}.format("field")

.... doesn't complete

Get rid of the try-except stuff to test to see if a syntax error will be returned

JohannesBierer
Regular Contributor

Without try except I get the following message?

Traceback (most recent call last):
  line 22, in <module>
    arcpy.Intersect_analysis(inFeatures, outFeature, "ALL", "", "POINT")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\analysis.py", line 289, in Intersect
    raise e
RuntimeError: Object: Error in executing tool

0 Kudos
JohannesBierer
Regular Contributor

For:

outFeature = r"R:\Karto\Bierer2019\Kaltenbronn_DGM\shapes\Zwischendaten.gdb\data\a"
        
arcpy.Intersect_analysis(inFeatures, outFeature1, "ALL", "", "POINT")

It is the same error message
0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor
x = r"R:\Karto\Bierer2019\Kaltenbronn_DGM\shapes\Zwischendaten.gdb\data\a"

arcpy.Intersect_analysis(inFeatures, x, join_attributes="ALL", output_type="POINT")

Try overt assignment of the 'optional' parameters, so you can skip the 2nd last one.

barring that... make a gdb in c:\temp and direct the output there to see if there is something wrong with the full path or the ... .gdb\data portion of it

View solution in original post

0 Kudos
JohannesBierer
Regular Contributor

If I write it like this it worked

arcpy.Intersect_analysis([outFG, outFC], outFeature, join_attributes="ALL", output_type="POINT")

0 Kudos