Please excuse my lingo, I am still learning some aspects of geo spatial and arcpy.

I have a python script that takes a shapefile. The shapefile consists of a polyline. I have traversed the polyline, done some interpolation and retrieved some points. Long story short, I'm trying to generate polygons along the polyline based on intervals of the M values. These polygons have four points (my geometries).

How can I take these geometries, or points, that are in my python script and output them into a shapefile. I know I'll have to pass my points to a function that produces a shapefile, but that is my dilemma. How exaclty do I create the function that creates my shapefile for the geometries?


1 Answer 1


Create a new Polyline object, then use CopyFeatures.

import arcpy
coords = [(1, 2), (3, 4), (5, 6), (7, 8)]
ar = arcpy.Array()
for x, y in coords:
    ar.add(arcpy.Point(x, y))
polyline = arcpy.Polyline(ar)
arcpy.management.CopyFeatures(polyline, r"c:\path\to\my\new.shp")
  • THis seems to work perfectly as far as outputting a shapefile. I wasn't aware that it'd create the projection file, an xml file, etc. If I needed to store other information in regards to the polyline (perhaps the type or something of that sort) can I alter the above code to have this information stored in one of the created files? Feb 11, 2013 at 15:30
  • 1
    If you needed to add additional fields, etc, it'd be a little more complex and involve a call to CreateFeatureclass and as many AddField calls as necessary to get the columns you'd need, and then an InsertCursor to insert the values. Feb 11, 2013 at 16:14
  • The additional fields would be information pertaining to the polygon such as the M value at certain intervals. I'd need to store this value and a few other values in the .dbf file. Using CreateFeatureClass should help me accomplish this, correct? Feb 11, 2013 at 16:54
  • Yes. CreateFeatureclass will let you enable M or Z and adding other values will require additional columns with AddField calls. Feb 11, 2013 at 16:57
  • I'm having some difficulty completing this. The values that I am trying to add to the .dbf file are values that are passed into the function. I shouldn't neccesarily need a cursor for that. And I think AddField is a little overkill for this scenario Feb 11, 2013 at 19:03

Your Answer

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

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