Last active
August 29, 2015 14:09
-
-
Save jenningsanderson/3d4ec63f8077f5db6813 to your computer and use it in GitHub Desktop.
A python script to identify corporate land owners
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, itertools, re | |
#Global Vars: | |
owner_field = 'Owner' | |
file_location = r'/Users/jenningsanderson/Desktop/Tax_Parcels2014.dbf' | |
limit = 10000000 | |
pattern = r".*(LLC|BANK|GROUP|\sLP)+.*" | |
output_file = r'/Users/jenningsanderson/Desktop/companies.shp' | |
######################################### Runtime ################################## | |
try: | |
from osgeo import ogr | |
except: | |
sys.exit('ERROR: cannot find GDAL/OGR modules') | |
print "Importing File: ", file_location | |
db_file = ogr.Open(file_location) | |
lyr = db_file.GetLayer(0) | |
feature_count = lyr.GetFeatureCount() | |
print "Making new export file: ", output_file | |
driver = ogr.GetDriverByName("ESRI Shapefile") | |
data_source = driver.CreateDataSource(output_file) | |
dest_layer = data_source.CreateLayer('layer1', | |
srs = lyr.GetSpatialRef(), | |
geom_type=lyr.GetLayerDefn().GetGeomType()) | |
feature = lyr.GetFeature(0) | |
[dest_layer.CreateField(feature.GetFieldDefnRef(i)) for i in range(feature.GetFieldCount())] | |
print "Number of features: ", feature_count | |
print "Iterating..." | |
error_count = 0 | |
match = 0 | |
prog = re.compile(pattern) | |
for feature in itertools.islice(lyr, limit): #Safe guard | |
try: | |
owner_string = feature.GetField(owner_field) | |
if prog.match(owner_string): | |
match += 1 | |
dest_layer.CreateFeature(feature) | |
except: | |
error_count += 1 | |
print "Successfully Matched: ", match | |
print "Did not have names: ", error_count | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For Windows: osgeo4w