Converting Parcels to Address Points With a Python Script

a wooden fence

I feel that I have grown in leaps and bounds this year with my Python and ArcPy coding skills.  A big part of this has been the various projects I’ve taken on helping the Pennsylvania South Central Task Force’s (SCTF) GIS Workgroup with its regional data sharing.  I’ve also been learning a lot about ArcPy in a summer side-gig developing a Python for ArcGIS workforce course for Harrisburg Area Community College (HACC).

In this post, I want to share a work-around script I developed for a SCTF member county.  The script converts their parcel dataset into a pseudo-address points dataset.  Previously, the SCTF used the Feature to Point geoprocessing tool to accomplish this task.  This tool requires the ArcGIS Desktop Advanced license, and the organization had down-graded the license level.  As I have learned a great deal about the ArcPy Data Access module in developing the HACC course, I had an idea that cursors could be used to convert the parcels (polygon geometry) to the address points (point geometry).

Below is a diagram and sample code for the script.  I think this is a nice work-around to the license-level limitations the SCTF has.

graphic representing python script workflow for converting parcels to points layer

# allow data to be overwritten each time script is run
arcpy.env.overwriteOutput = True

# Copy data for features in parcels layer to a list element
# list to contain data for each record
featuresList = []

# parcels layer
parcels = r'C:\Geodata\LandBase.gdb\Parcels'
# fields from parcels to access in search cursor
# SHAPE@TRUECENTROID provides us the centroid coordinates
parcelFields = ['SHAPE@TRUECENTROID','PIN','SITEADDR','SITECTY','SITEZIP','MUNI']

# create search cursor to loop over records in parcels layer
# and add data to featuresList
with arcpy.da.SearchCursor(parcels,parcelFields) as cursor:
   # row represents a record in the dataset
   for row in cursor:
      # append data from each record to a list item in featuresList
      featuresList.append([row[0],row[1],row[2],row[3],row[4],row[5]])
   # end for
# end with

# create empty feature class container for address points
# output geodatabase
geodatabase = r'S:\Region\RegionData.gdb'
# create spatial reference object to define coordinate system for layer
# use WKID (well-known ID)
sr = arcpy.SpatialReference(2272)

# create feature class
arcpy.CreateFeatureclass_management(geodatabase,'AddressPoints','POINT',spatial_reference=sr)

# variable to store newly created address points
addressPoints = r'S:\Region\RegionData.gdb\AddressPoints'

# loop through list of fields from parcels layer and add fields to address points layer
for field in parcelFields:
   # skip over item from centroid coordinates
   if field == 'SHAPE@TRUECENTROID':
      continue
   else:
      arcpy.AddField_management(addressPoints,field,'TEXT')
   # end if/else
# end for

# create insert cursor to loop over featuresList and add records for Address Points layer
# addPtsFields = ['SHAPE@XY','PIN','SITEADDR','SITECTY','SITEZIP','MUNI']

# open insert cursor
# because structure/order of fields from parcels cursor matches the address
# points, we can simply pass in the list item from featuresList into the layer
# cursor
with arcpy.da.InsertCursor(addressPoints,addPtsFields) as cursor:
   for record in featuresList:
      cursor.insertRow(record)
   # end for
# end with

# delete cursor
del cursor
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s