Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 shape file. How can I do this using arcpy?

share|improve this question

2 Answers 2

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

share|improve this answer

.

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...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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