Select to view content in your preferred language

How to create a shapefile from a python list using ArcPy?

3260
12
04-22-2014 07:07 AM
ArielleSimmons
Emerging Contributor
I've been looking for a way to create a shapefile from a python list (in the case below, uniqueList).

Basically, I have been using SearchCursor's to iterate through a shapefile, and I would like to export the result as a shapefile...I tried CopyFeatures...but it didn't even return a blank file (it returned nothing).

import arcpy

def find_overlaps(input_features, output_features):
   uniqueList = []
   for row in arcpy.da.SearchCursor(input_features, ('OBJECTID', 'SHAPE@', 'name')):
      foundMatch = False
      for row2 in uniqueList:
          if row[1].equals(row2[1]):
              foundMatch = True
              break
      if foundMatch == False
          uniqueList.append(row)
   return uniqueList
   ## no work ##
   arcpy.management.CopyFeatures(uniqueList, output_features)
Tags (2)
0 Kudos
12 Replies
MathewCoyle
Honored Contributor
It's for constructing a query that returns no results. It's the quick and dirty way of creating an empty template from an existing feature class.
0 Kudos
ArielleSimmons
Emerging Contributor
It's for constructing a query that returns no results. It's the quick and dirty way of creating an empty template from an existing feature class.


It is sql then....'''{0} < 0'' ... fascinating. If the condition is less then 0 then ...go forward... with the .format command?
0 Kudos
MathewCoyle
Honored Contributor
It is sql then....'''{0} < 0'' ... fascinating. If the condition is less then 0 then ...go forward... with the .format command?


It is just simple string substitution. The format method is just inserting the delimited OID field name. It's broken onto two lines to ease readability.
template_query = '''{0} < 0'''.format(arcpy.AddFieldDelimiters(input_fc, arcpy.Describe(input_fc).OIDFieldName))


https://docs.python.org/2/library/string.html#format-string-syntax
0 Kudos