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 some polyline feature objects in python. Now I want to get all the points of polylines.

For example, if a polyline has start point [0,0] end point [5,5]. Result: [1,1];[2,2];[3,3];[4,4];[5,5].

I want to find all the integer points on that line including end points. For straight line this is dead simple, but if polyline has Beizer Curve, Circular Arc, Elliptic Arc geometry types, then how can I do it?

EDIT:

I can only use those tools which are available in all versions of ArcGIS foe example ArcView

share|improve this question
2  
In general you won't often get nice 'integer' points. It works in your example, but not often in real life. Usually, you just get locations for vertices, so in your case you would get [0,0] and [5,5]. The 'intermediate' points can be 'assumed.' Not sure how to do this in python, but several tools will allow you to create a point file of vertices from a line. –  Darren Cope May 29 '12 at 11:57
add comment

4 Answers 4

As Darren Cope has suggested, converting your layer to a point vertices may be done using the Feature Vertices to Points tool.

Here is the python code snippedt:

# import system modules 
import arcpy
from arcpy import env

# Set environment settings
env.workspace = "C:/data"

# Set local variables
inFeatures = "majorrds.shp"
outFeatureClass = "c:/output/output.gdb/majorrds_midpt"

# Execute FeatureVerticesToPoints
arcpy.FeatureVerticesToPoints_management(inFeatures, outFeatureClass, "MID")
share|improve this answer
add comment

As I understood you need to increase number of vertices for your polyline features. And also to transform all "Beizer Curve, Circular Arc, Elliptic Arc" segments into several line segments.

For this task in ArcGIS you can use Densify (Editing) tool in ArcToolbox.

Then you can convert your polylines' vertices to point features as suggested Darren Cope and artwork21.

If you prefer to do it in ArcMap take a look at Creating new points along a line help topic.

share|improve this answer
add comment

The following should work on polylines and polygons:

import arcpy

infc = r"D:\Projects\GDBs\slowbutter.gdb\fc"

desc = arcpy.Describe(infc)
shapefieldname = desc.ShapeFieldName

rows = arcpy.SearchCursor(infc)
for row in rows:
    # Create the geometry object
    feat = row.getValue(shapefieldname)
    print "Feature %i: " % row.getValue(desc.OIDFieldName)
    partnum = 0
    # Step through each part of the feature
    for part in feat:
        print "Part %i: " % partnum
        part_list = []
        for pnt in feat.getPart(partnum):
            if pnt:
                # Add to list
                part_list.append([pnt.X, pnt.Y])
            else:
                # If pnt is None, this represents an interior ring
                print "Interior Ring:"
        partnum += 1  
        print part_list

For some UK road data, I get this; a nested list of X,Y pairs for each vertex that makes up the polyline:

Feature 7: 
Part 0: 
[[-0.48053999999996222, 51.482510000000048], [-0.48032999999992398, 
51.482609000000082], [-0.48026999999996178, 51.48273800000004], 
[-0.48043999999993048, 51.482891000000052], [-0.48065999999994347, 51.482948000000079],
[-0.48123999999995704, 51.483009000000038]]
share|improve this answer
    
I've seen this on ESRI page. But if you look carefully in their description this code only returns the end points, not the points between them –  user May 29 '12 at 17:08
1  
@crucifiedsoul - Yes, this is a variation of that ESRI sample, but it gives the X,Y pair of all the points, not just the end points. That's what you want, correct? –  Chad Cooper May 29 '12 at 17:56
    
I don't get it. The only thing is changing you are replacing print pnt.X, pnt.Y with part_list.append([pnt.X, pnt.Y]). And you are printing this at the end of the loop. How can your code get all the points of a line but ESRIs code doesn't? –  user May 30 '12 at 2:58
add comment

I know this is old but I was looking for the same as I don't have ArcInfo for the FeatureVerticesToPoints tools. After using Search cursor solution above I went forward to simplify the code and found that using NumPy Arrays in the Data Access Module a simple and very quick script could be produced. I'm using this as a script tool.

Note: The key is the explode_to_points parameter in arcpy.da.FeatureClassToNumPyArray

Hope this helps other. Cheers Paul

Here is link to ArcGIS Repository Location: Feature Class to Points

# Feature Class to Points
# 
# Paul Smith (2012) paul@neoncs.com.au

# Imports
import arcpy
import numpy

#Inputs from user parameters
InFc  = arcpy.GetParameterAsText(0) # input feature class
OutFc = arcpy.GetParameterAsText(1) # output feature class

# Spatial reference of input feature class
SR = arcpy.Describe(InFc).spatialReference

# Create NumPy array from input feature class
array = arcpy.da.FeatureClassToNumPyArray(InFc,["SHAPE@XY"], spatial_reference=SR, explode_to_points=True)

# Check array and Exit if no features found
if array.size == 0:
    arcpy.AddError(InFc + " has no features.")

# Create a new points feature class
else:
    arcpy.da.NumPyArrayToFeatureClass(array, OutFc, ['SHAPE@XY'], SR)
share|improve this answer
    
Welcome to GIS.se Paul :) +1 for a well rounded and better than average first contribution, with code to boot. Thanks! Some editing tips: select text, inline or a block, and then ctrl-k to apply code formatting (same for bold and italic). By convention we tend to avoid chatty bits like "hi", "thanks", "cheers". Those are implied as being always present, and help reinforce the idea this place is different from the usual forums and email. Welcome aboard. –  matt wilkie Nov 14 '12 at 5:47
    
You need to put a placeholder for the where_clause on this line of the code array = arcpy.da.FeatureClassToNumPyArray(InFc,["SHAPE@XY"], "", spatial_reference=SR, explode_to_points=True) –  TForward May 23 at 20:50
add comment

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.