1

I am trying to select a point from a point layer that intersect a polyline layers firstpoint and using arcpy. I am getting an error "ExecuteError: ERROR 000622: Failed to execute (Select Layer By Location). Parameters are not valid. ERROR 000623: Invalid value type for parameter select_features."

import arcpy
def main():
 arcpy.env.workspace = r'D:\My Documents\SR91_FeasibilityStudy\GISData\SR-91.gdb'
 arcpy.MakeFeatureLayer_management('Build2035', 'plLayer') #polyline Layer
 arcpy.MakeFeatureLayer_management('Build2035_pts_CollectEvents', 'ptLayer') #point Layer
 with arcpy.da.SearchCursor('plLayer',("Shape@","OID@")) as cursor:
 for row in cursor:
 arcpy.SelectLayerByLocation_management('ptLayer','intersect',row[0].firstPoint)
 result = arcpy.GetCount_management('ptLayer')
 print result
asked Jan 26, 2016 at 21:48
1
  • You can save the first point of each Polyline using "Feature Vertices To Points", enter START as the 3rd parameter. Then intersect the two Point layers. Commented Jan 26, 2016 at 22:51

1 Answer 1

2

If you want to perform a selection for each row, as your script indicates, you need to convert your point object to a geometry object. Here's a very messy line of code that will do so:

arcpy.SelectLayerByLocation_management('ptLayer','intersect',arcpy.Geometry ("point", row[0].firstPoint, arcpy.Describe ('Build2035').spatialReference))

If you want to perform a single selection based off of all first points, create a new feature class and export your first points to it using a cursor (or if you have an advanced license, use Feature Vertices To Points as described by klewis in the comments).

Something like this (untested):

import arcpy
def main():
 arcpy.env.workspace = r'D:\My Documents\SR91_FeasibilityStudy\GISData\SR-91.gdb'
 arcpy.MakeFeatureLayer_management('Build2035_pts_CollectEvents', 'ptLayer') #point Layer
 #Create empty point feature class for first points
 outPath = arcpy.env.workspace
 arcpy.CreateFeatureclass_management (outPath, "FirstPoints", "POINT", spatial_reference = 'Build2035')
 #add firstpoints to feature class
 with arcpy.da.SearchCursor ('Build2035', "SHAPE@") as sCurs:
 with arcpy.da.InsertCursor ("FirstPoints", "SHAPE@") as iCurs:
 for geom, in sCurs:
 row = (geom.firstPoint,)
 iCurs.insertRow (row)
 #select points by first points feature class
 arcpy.SelectLayerByLocation_management('ptLayer','intersect', "FirstPoints")
 result = arcpy.GetCount_management('ptLayer').getOutput (0)
 print result
answered Jan 26, 2016 at 23:14
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.