Skip to content

Commit

Permalink
move splitting county and state to parse stage
Browse files Browse the repository at this point in the history
  • Loading branch information
mtmail committed Aug 27, 2021
1 parent 3e03dc3 commit 30b3f41
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions lib/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os.path
import json
import re

try:
from osgeo import ogr
Expand Down Expand Up @@ -67,9 +68,12 @@ def get_tags_from_feature(po_feature):
statefp = po_feature.GetField("STATEFP")
countyfp = po_feature.GetField("COUNTYFP")
if (statefp is not None) and (countyfp is not None):
county_name = county_fips_data.get(statefp + '' + countyfp)
if county_name:
tags["tiger:county"] = county_name
county_and_state = county_fips_data.get(statefp + '' + countyfp)
if county_and_state: # e.g. 'Perquimans, NC'

result = re.match('^(.+), ([A-Z][A-Z])', county_and_state)
tags["tiger:county"] = result[1]
tags["tiger:state"] = result[2]

lfromadd = po_feature.GetField("LFROMADD")
if lfromadd is not None:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def test_parse_shp_for_geom_and_tags():
{
'tiger:way_id': 18401089,
'name': 'Hickory Cross Rd',
'tiger:county': 'Perquimans, NC',
'tiger:county': 'Perquimans',
'tiger:state': 'NC',
'tiger:lfromadd': '388',
'tiger:rfromadd': '389',
'tiger:ltoadd': '100',
Expand Down
5 changes: 2 additions & 3 deletions tiger_address_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,8 @@ def addressways(waylist, nodelist, first_id):
zipr = tags.get("tiger:zip_right", '')
zipl = tags.get("tiger:zip_left", '')
name = tags.get("name", '')
result = re.match('^(.+), ([A-Z][A-Z])', tags.get("tiger:county", ",")) # e.g. 'Perquimans, NC'
county = result[1]
state = result[2]
county = tags.get("tiger:county", '')
state = tags.get("tiger:state", '')

# Write the nodes of the offset ways
if right:
Expand Down

0 comments on commit 30b3f41

Please sign in to comment.