create-list-of-US-place-names
Table of Contents¶
Library for working with shapefiles is pyshp (Python Shapefile Library) https://github.com/GeospatialPython/pyshp
In [1]:
import shapefile
import datetime
Data for the placenames comes from the USGS Cities and Towns dataset. Downloaded from https://nationalmap.gov/small_scale/atlasftp.html?openChapters=chpref#chpref on January 3, 2017.
In [2]:
sf = shapefile.Reader("/Users/jeriwieringa/Dissertation/drafts/data/external-data/citiesx020_nt00007/citiesx020.shp")
In [3]:
sf.fields
Out[3]:
In [4]:
records = sf.records()
In [5]:
len(records)
Out[5]:
In [6]:
records[:3]
Out[6]:
In [7]:
placenames = []
for each in records:
placenames.append(each[2])
In [8]:
len(placenames)
Out[8]:
In [9]:
placenames[:10]
Out[9]:
In [10]:
with open("/Users/jeriwieringa/Dissertation/drafts/data/word-lists/{}-place-names.txt".format(str(datetime.date.today())), "w") as outfile:
for name in placenames:
if len(name.split()) > 1:
words = name.split()
for word in words:
outfile.write("{}\n".format(word.lower()))
else:
outfile.write("{}\n".format(name.lower()))
In [11]:
# %load shared_elements/system_info.py
import IPython
print (IPython.sys_info())
!pip freeze
In [ ]: