# Create a shapefile from geometry

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?

-
I added the polygon-creation tag to help you find related threads. A search turns up some promising ones, especially the Python code found at gis.stackexchange.com/questions/21443/…. Would that perhaps answer your question? –  whuber Feb 8 '13 at 20:47

## 1 Answer

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? –  user1898629 Feb 11 '13 at 15:30
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. –  Jason Scheirer Feb 11 '13 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? –  user1898629 Feb 11 '13 at 16:54
Yes. CreateFeatureclass will let you enable M or Z and adding other values will require additional columns with AddField calls. –  Jason Scheirer Feb 11 '13 at 16:57
oh ok. Righteous. Thanks for all your help. –  user1898629 Feb 11 '13 at 17:01