2022-09-01 18:52:22 +00:00
|
|
|
from qgis.core import *
|
|
|
|
from qgis.gui import *
|
2022-09-01 20:12:13 +00:00
|
|
|
import re
|
2022-09-01 18:52:22 +00:00
|
|
|
|
|
|
|
@qgsfunction(args='auto', group='Custom', referenced_columns=[])
|
2022-09-01 20:12:13 +00:00
|
|
|
def getformattedstreetname(value1, feature, parent):
|
|
|
|
parts = value1.split()
|
|
|
|
parts = map(formatstreetname, parts)
|
|
|
|
return " ".join(parts)
|
|
|
|
|
|
|
|
@qgsfunction(args='auto', group='Custom', referenced_columns=[])
|
|
|
|
def getformattedstreetnamefromaddress(value1, feature, parent):
|
2022-09-01 18:52:22 +00:00
|
|
|
parts = value1.split()
|
|
|
|
parts.pop(0) # Ignore the first bit (i.e. "123" in "123 N MAIN ST")
|
|
|
|
parts = map(formatstreetname, parts)
|
|
|
|
return " ".join(parts)
|
|
|
|
|
|
|
|
def formatstreetname(name):
|
2022-09-01 20:12:13 +00:00
|
|
|
# Specific suffixes like "123th" we have lower
|
|
|
|
if re.search("[0-9]+TH", name):
|
|
|
|
return name.capitalize()
|
|
|
|
if re.search("[0-9]+ND", name):
|
|
|
|
return name.capitalize()
|
|
|
|
if re.search("[0-9]+ST", name):
|
|
|
|
return name.capitalize()
|
|
|
|
if re.search("[0-9]+RD", name):
|
|
|
|
return name.capitalize()
|
|
|
|
# Weird names like 123D we keep upper
|
|
|
|
if re.search("[0-9]+[A-Z]+", name):
|
|
|
|
return name
|
2023-12-30 00:28:54 +00:00
|
|
|
# Highway/etc prefixes
|
2022-09-01 20:12:13 +00:00
|
|
|
if name == "US":
|
|
|
|
return "US"
|
|
|
|
if name == "SR":
|
|
|
|
return "SR"
|
|
|
|
if name == "CR":
|
2023-12-30 00:28:54 +00:00
|
|
|
return "County Road"
|
2022-09-01 20:12:13 +00:00
|
|
|
if name == "C":
|
|
|
|
return "C"
|
2022-09-01 18:52:22 +00:00
|
|
|
# Directions
|
|
|
|
if name == "N":
|
|
|
|
return "North"
|
|
|
|
if name == "NE":
|
|
|
|
return "Northeast"
|
|
|
|
if name == "E":
|
|
|
|
return "East"
|
|
|
|
if name == "SE":
|
|
|
|
return "Southeast"
|
|
|
|
if name == "S":
|
|
|
|
return "South"
|
|
|
|
if name == "SW":
|
|
|
|
return "Southwest"
|
|
|
|
if name == "W":
|
|
|
|
return "West"
|
|
|
|
if name == "NW":
|
|
|
|
return "Northwest"
|
|
|
|
# Suffixes
|
|
|
|
if name == "AVE":
|
|
|
|
return "Avenue"
|
|
|
|
if name == "BLVD":
|
|
|
|
return "Boulevard"
|
|
|
|
if name == "BND":
|
|
|
|
return "Bend"
|
|
|
|
if name == "CIR":
|
|
|
|
return "Circle"
|
|
|
|
if name == "CT":
|
|
|
|
return "Court"
|
|
|
|
if name == "DR":
|
|
|
|
return "Drive"
|
|
|
|
if name == "FLDS":
|
|
|
|
return "Fields"
|
|
|
|
if name == "GRV":
|
|
|
|
return "Grove"
|
|
|
|
if name == "HOLW":
|
|
|
|
return "Hollow"
|
|
|
|
if name == "HWY":
|
|
|
|
return "Highway"
|
|
|
|
if name == "LN":
|
|
|
|
return "Lane"
|
|
|
|
if name == "LOOP":
|
|
|
|
return "Loop"
|
|
|
|
if name == "PATH":
|
|
|
|
return "Path"
|
|
|
|
if name == "PL":
|
|
|
|
return "Place"
|
|
|
|
if name == "RD":
|
|
|
|
return "Road"
|
2022-09-02 03:11:16 +00:00
|
|
|
if name == "RDG":
|
|
|
|
return "Ridge"
|
2022-09-01 18:52:22 +00:00
|
|
|
if name == "RUN":
|
|
|
|
return "Run"
|
|
|
|
if name == "ST":
|
|
|
|
return "Street"
|
|
|
|
if name == "TER":
|
|
|
|
return "Terrace"
|
|
|
|
if name == "TRL":
|
|
|
|
return "Trail"
|
|
|
|
if name == "VW":
|
|
|
|
return "View"
|
|
|
|
if name == "WAY":
|
|
|
|
return "Way"
|
|
|
|
if name == "XING":
|
|
|
|
return "Crossing"
|
2022-09-01 20:12:13 +00:00
|
|
|
# Irish names
|
|
|
|
if name == "MCCRAY":
|
|
|
|
return "McCray"
|
|
|
|
if name == "MCKOWN":
|
|
|
|
return "McKown"
|
|
|
|
return name.capitalize()
|