2

I have a *.shp file which contains only polyline features. How can I iterate over all the point features. Given ESRI Polyline example only uses already defined points to make polylines. But I want to iterate over all the polylines found on a shapefile.

How can I do this using ArcPy?

3

This is directly from the ESRI Help File: Accessing Data using Cursors

This example shows a simple cursor operation. It prints out name and value of each string field for each row in a feature class.

import arcpy

fc = "D:/st_johns/roads.shp"

# Create a search cursor 
#
rows = arcpy.SearchCursor(fc) 

# Create a list of string fields
fields = arcpy.ListFields(fc, "", "String")

for row in rows:
    for field in fields:
        if field.type != "Geometry":
            print "%s: Value = %s" % (field.name, row.getValue(field.name))

When you reach the line:

for row in rows:

You have a cursor that will iterate through the rows that represent the features in the shapefile. I encourage you to search through the ESRI Help files for Accessing Geographic Data with Python. Describing Data is the first section.

This example allows you to directly access the geometry of each feature and returns the length.

import arcpy

fc = "D:/st_johns/roads.shp"

# Create a search cursor 
#
rows = arcpy.SearchCursor(fc) 

length = 0

shapeName = arcpy.Describe(fc).shapeFieldName

for row in rows:
  feat = row.getValue(shapeName)
  length += feat.length

# Print the total length of all roads
#
print length

The previous example was from the help file on Working with geometry in python

| improve this answer | |
0

.

beside @Get Spatial solution, you should check out Iterate Feature Selection (ModelBuilder) here.

Summary

Iterates over features in a feature class.

iterate

i hope it helps you...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.