the-villages-import/qgis-functions.py

259 lines
6.7 KiB
Python
Raw Normal View History

2024-07-10 06:54:00 +00:00
import qgis.core
import qgis.gui
import re
2022-09-01 18:52:22 +00:00
2024-07-10 06:54:00 +00:00
#
# This will keep street names like SR 574A as SR 574A however
# will lowercase other number-digit suffixes with <2 or >4 numbers
# or >1 suffix-letters, like 12th Street or 243rd Ave.
#
2022-09-01 18:52:22 +00:00
@qgsfunction(args='auto', group='Custom', referenced_columns=[])
2024-07-10 06:54:00 +00:00
def getstreetfromaddress(value1, feature, parent):
parts = value1.split()
2024-07-10 06:54:00 +00:00
parts.pop(0) # Ignore the first bit (i.e. "123" in "123 N MAIN ST")
parts = map(formatstreetname, parts)
return " ".join(parts)
@qgsfunction(args='auto', group='Custom', referenced_columns=[])
2024-07-10 06:54:00 +00:00
def formatstreet(value1, feature, parent):
2022-09-01 18:52:22 +00:00
parts = value1.split()
2024-07-10 06:54:00 +00:00
# Handle the special case of a street name starting with "ST"
# which is almost always "Saint __" and not "Street __"
if parts[0].upper() == "ST":
parts[0] = "Saint"
if parts[0].upper() == "ROYAL" and parts[1].upper() == "ST":
parts[0] = "Royal"
parts[1] = "Saint"
# And "CR" as a first part (County Road) vs last part (Circle)
if parts[0].upper() == "CR":
parts[0] = "County Road"
if parts[0].upper() == "SR":
parts[0] = "State Route"
2022-09-01 18:52:22 +00:00
parts = map(formatstreetname, parts)
return " ".join(parts)
2024-07-10 06:54:00 +00:00
@qgsfunction(args='auto', group='Custom', referenced_columns=[])
def formatname(value1, feature, parent):
parts = value1.split()
parts = map(formatstreetname, parts)
return " ".join(parts)
@qgsfunction(args='auto', group='Custom', referenced_columns=[])
def gethighwaytype(value1, feature, parent):
match value1:
case "ALLEY":
return "alley"
case "LOCAL":
return "residential"
case "MAJOR":
return "trunk"
case "MEDIAN CUT":
return "primary_link"
case "OTHER":
return "unclassified"
case "PRIMARY":
return "primary"
case "PRIVATE":
return "service"
case "RAMP":
return "trunk_link"
case "SECONDARY":
return "secondary"
case "TURN LANE":
return "primary_link"
case "VEHICULAR TRAIL":
return "track"
# Internal function
2022-09-01 18:52:22 +00:00
def formatstreetname(name):
2024-07-10 06:54:00 +00:00
nameUp = name.upper()
# Acronyms
if nameUp == "SR":
return "SR" # State Route
if nameUp == "NFS":
return "NFS" # National Forest Service?
if nameUp == "US":
return "US"
2022-09-01 18:52:22 +00:00
# Directions
2024-07-10 06:54:00 +00:00
if nameUp == "N":
2022-09-01 18:52:22 +00:00
return "North"
2024-07-10 06:54:00 +00:00
if nameUp == "NE":
2022-09-01 18:52:22 +00:00
return "Northeast"
2024-07-10 06:54:00 +00:00
if nameUp == "E":
2022-09-01 18:52:22 +00:00
return "East"
2024-07-10 06:54:00 +00:00
if nameUp == "SE":
2022-09-01 18:52:22 +00:00
return "Southeast"
2024-07-10 06:54:00 +00:00
if nameUp == "S":
2022-09-01 18:52:22 +00:00
return "South"
2024-07-10 06:54:00 +00:00
if nameUp == "SW":
2022-09-01 18:52:22 +00:00
return "Southwest"
2024-07-10 06:54:00 +00:00
if nameUp == "W":
2022-09-01 18:52:22 +00:00
return "West"
2024-07-10 06:54:00 +00:00
if nameUp == "NW":
2022-09-01 18:52:22 +00:00
return "Northwest"
2024-07-10 06:54:00 +00:00
# Names
if nameUp == "MACLEAY":
return "MacLeay"
if nameUp == "MCCLAINE":
return "McClaine"
if nameUp == "MCAHREN":
return "McAhren"
if nameUp == "MCCAMMON":
return "McCammon"
if nameUp == "MCCLELLAN":
return "McClellan"
if nameUp == "MCCOY":
return "McCoy"
if nameUp == "MCDONALD":
return "McDonald"
if nameUp == "MCGEE":
return "McGee"
if nameUp == "MCGILCHRIST":
return "McGilchrist"
if nameUp == "MCINTOSH":
return "McIntosh"
if nameUp == "MCKAY":
return "McKay"
if nameUp == "MCKEE":
return "McKee"
if nameUp == "MCKENZIE":
return "McKenzie"
if nameUp == "MCKILLOP":
return "McKillop"
if nameUp == "MCKINLEY":
return "McKinley"
if nameUp == "MCKNIGHT":
return "McKnight"
if nameUp == "MCLAUGHLIN":
return "McLaughlin"
if nameUp == "MCLEOD":
return "McLeod"
if nameUp == "MCMASTER":
return "McMaster"
if nameUp == "MCNARY":
return "McNary"
if nameUp == "MCNAUGHT":
return "McNaught"
if nameUp == "O'BRIEN":
return "O'Brien"
if nameUp == "O'CONNOR":
return "O'Connor"
if nameUp == "O'NEIL":
return "O'Neil"
if nameUp == "O'TOOLE":
return "O'Toole"
2022-09-01 18:52:22 +00:00
# Suffixes
2024-07-10 06:54:00 +00:00
if nameUp == "ALY":
return "Alley"
if nameUp == "AV":
return "Avenue"
if nameUp == "AVE":
2022-09-01 18:52:22 +00:00
return "Avenue"
2024-07-10 06:54:00 +00:00
if nameUp == "BAY":
return "Bay"
if nameUp == "BLF":
return "Bluff"
if nameUp == "BLVD":
return "Boulevard"
if nameUp == "BV":
2022-09-01 18:52:22 +00:00
return "Boulevard"
2024-07-10 06:54:00 +00:00
if nameUp == "BND":
2022-09-01 18:52:22 +00:00
return "Bend"
2024-07-10 06:54:00 +00:00
if nameUp == "CIR":
2022-09-01 18:52:22 +00:00
return "Circle"
2024-07-10 06:54:00 +00:00
if nameUp == "CR":
return "Circle"
if nameUp == "CRK":
return "Creek"
if nameUp == "CRST":
return "Crest"
if nameUp == "CT":
2022-09-01 18:52:22 +00:00
return "Court"
2024-07-10 06:54:00 +00:00
if nameUp == "CURV":
return "Curve"
if nameUp == "CV":
return "Curve"
if nameUp == "DR":
2022-09-01 18:52:22 +00:00
return "Drive"
2024-07-10 06:54:00 +00:00
if nameUp == "FLDS":
2022-09-01 18:52:22 +00:00
return "Fields"
2024-07-10 06:54:00 +00:00
if nameUp == "GLN":
return "Glenn"
if nameUp == "GRV":
2022-09-01 18:52:22 +00:00
return "Grove"
2024-07-10 06:54:00 +00:00
if nameUp == "HL":
return "Hill"
if nameUp == "HOLW":
2022-09-01 18:52:22 +00:00
return "Hollow"
2024-07-10 06:54:00 +00:00
if nameUp == "HTS":
return "Heights"
if nameUp == "HW":
return "Highway"
if nameUp == "HWY":
return "Highway"
if nameUp == "HY":
2022-09-01 18:52:22 +00:00
return "Highway"
2024-07-10 06:54:00 +00:00
if nameUp == "LN":
2022-09-01 18:52:22 +00:00
return "Lane"
2024-07-10 06:54:00 +00:00
if nameUp == "LNDG":
return "Landing"
if nameUp == "LOOP":
2022-09-01 18:52:22 +00:00
return "Loop"
2024-07-10 06:54:00 +00:00
if nameUp == "LP":
return "Loop"
if nameUp == "MNR":
return "Manor"
if nameUp == "MT":
return "Mount"
if nameUp == "MTN":
return "Mountain"
if nameUp == "PARK":
return "Park"
if nameUp == "PASS":
return "Pass"
if nameUp == "PATH":
2022-09-01 18:52:22 +00:00
return "Path"
2024-07-10 06:54:00 +00:00
if nameUp == "PKWY":
return "Parkway"
if nameUp == "PL":
2022-09-01 18:52:22 +00:00
return "Place"
2024-07-10 06:54:00 +00:00
if nameUp == "PLZ":
return "Plaza"
if nameUp == "PS":
return "Pass"
if nameUp == "PT":
return "Point"
if nameUp == "RD":
2022-09-01 18:52:22 +00:00
return "Road"
2024-07-10 06:54:00 +00:00
if nameUp == "RDG":
return "Ridge"
2024-07-10 06:54:00 +00:00
if nameUp == "RUN":
2022-09-01 18:52:22 +00:00
return "Run"
2024-07-10 06:54:00 +00:00
if nameUp == "SHRS":
return "Shores"
if nameUp == "SQ":
return "Square"
if nameUp == "ST":
2022-09-01 18:52:22 +00:00
return "Street"
2024-07-10 06:54:00 +00:00
if nameUp == "TER":
2022-09-01 18:52:22 +00:00
return "Terrace"
2024-07-10 06:54:00 +00:00
if nameUp == "TR":
return "Trail"
if nameUp == "TRL":
2022-09-01 18:52:22 +00:00
return "Trail"
2024-07-10 06:54:00 +00:00
if nameUp == "VW":
2022-09-01 18:52:22 +00:00
return "View"
2024-07-10 06:54:00 +00:00
if nameUp == "WALK":
return "Walk"
if nameUp == "WAY":
return "Way"
if nameUp == "WY":
2022-09-01 18:52:22 +00:00
return "Way"
2024-07-10 06:54:00 +00:00
if nameUp == "XING":
2022-09-01 18:52:22 +00:00
return "Crossing"
2024-07-10 06:54:00 +00:00
if re.match('^[0-9]{2,4}[A-Za-z]$', name) != None:
return name
return name #.capitalize()