Permalink
Browse files

Change the translations to a submodule

  • Loading branch information...
pnorman committed Apr 26, 2012
1 parent b750431 commit d4c83b977080b9291a7be763f6277078097bdb5e
Showing with 4 additions and 239 deletions.
  1. +3 −0 .gitmodules
  2. +1 −0 translations
  3. +0 −124 translations/langleyroad.py
  4. +0 −115 translations/uvmtrans.py
View
@@ -0,0 +1,3 @@
+[submodule "translations"]
+ path = translations
+ url = git://github.com/pnorman/ogr2osm-translations.git
Submodule translations added at 2e42fb
View
@@ -1,124 +0,0 @@
-'''
-A translation function for Township of Langley Roads_shp.shp roads data.
-
-The shapefiles are availble under the PDDL as "Roads" from the Township of Langley
-at http://www.tol.ca/ServicesContact/OpenData/OpenDataCatalogue.aspx
-
-The following fields are dropped from the source shapefile:
-
-Field Definition Reason
-ALTROADNAM Alternate name? Always blank
-ALTSTNMID Alternate name ID? Always blank
-FROMLEFTPR From left property number Belongs on different ways
-FROMLEFTTH From left theoretical Not mappable
-FROMRIGHTP From right property number Belongs on different ways
-FROMRIGHTH From right theoretical Not mappable
-OBJECTID Internal feature number Automatically generated
-OWNER Owner of road Does not add to classification beyond ROADTYPE
-PROJECTNUM Project number Always blank
-ROADCLASS Road class # Text version of ROADTYPE
-SHAPE_LEN Length of feature Automatically generated
-STNAMEID Unique ID for street name. Not mappable
-TOLEFTPROP To left property number Belongs on different ways
-TOLEFTTHEO To left theoretical Not mappable
-TORIGHTPRO To left property number Belongs on different ways
-TORIGHTTHE To left theoretical Not mappable
-YEARADDED Year added to GIS database Not mappable
-
-The following fields are used:
-
-Field Used for Reason
-ROADNAME name=ROADNAME Name of the road
-ROADTYPE highway=* Type of the road
-STREETID tol:streetid Unique ID for the road segment
-
-Internal mappings:
-OWNER=Provincial <==> ROADTYPE=Highway Ramp|Ministry of Transportation
-OWNER=Regional ==> ROADTYPE=Major Road Network
-
-OSM Mappings
-Source value OSM value Shortcomings
-ROADTYPE=Arterial highway=secondary
-ROADTYPE=Collector highway=tertiary
-ROADTYPE=Local highway=residential May need to be changed to highway=unclassified for some roads
-ROADTYPE=Lane highway=service Source data does not indicate if service=alley
-ROADTYPE=Gravel highway=residential surface=gravel
-ROADTYPE=Ministry of Transportation highway=primary|motorway Huristics used to differentiate between highways. Double-check these
-ROADTYPE=Major Road Network highway=secondary Does not identify Highway 1A as primary
-ROADTYPE=Highway Ramp highway=motorway_link
-'''
-
-def translateName(rawname):
- '''
- A general purpose name expander.
- '''
- suffixlookup = {
- 'Ave':'Avenue',
- 'Rd':'Road',
- 'St':'Street',
- 'Pl':'Place',
- 'Cres':'Crescent',
- 'Blvd':'Boulevard',
- 'Dr':'Drive',
- 'Lane':'Lane',
- 'Crt':'Court',
- 'Gr':'Grove',
- 'Cl':'Close',
- 'Rwy':'Railway',
- 'Div':'Diversion',
- 'Hwy':'Highway',
- 'Hwy':'Highway',
- 'Conn': 'Connector',
- 'E':'East',
- 'S':'South',
- 'N':'North',
- 'W':'West'}
-
- newName = ''
- for partName in rawname.split():
- newName = newName + ' ' + suffixlookup.get(partName,partName)
-
- return newName.strip()
-
-
-def filterTags(attrs):
- if not attrs:
- return
- tags = {}
-
- if 'ROADNAME' in attrs:
- translated = translateName(attrs['ROADNAME'].title())
- if translated != '(Lane)' and translated != '(Ramp)':
- tags['name'] = translated
-
- if 'STREETID' in attrs:
- tags['tol:streetid'] = attrs['STREETID'].strip()
-
- if 'ROADTYPE' in attrs:
- if attrs['ROADTYPE'].strip() == 'Major Road Network':
- tags['highway'] = 'secondary'
- elif attrs['ROADTYPE'].strip() == 'Arterial':
- tags['highway'] = 'secondary'
- elif attrs['ROADTYPE'].strip() == 'Collector':
- tags['highway'] = 'tertiary'
- elif attrs['ROADTYPE'].strip() == 'Local':
- tags['highway'] = 'residential'
- elif attrs['ROADTYPE'].strip() == 'Lane':
- tags['highway'] = 'service'
- elif attrs['ROADTYPE'].strip() == 'Gravel':
- tags['highway'] = 'residential'
- tags['surface'] = 'gravel'
- elif attrs['ROADTYPE'].strip() == 'Ministry of Transportation':
- if translated and (translated == '#1 Highway' or translated == 'Golden Ears Bridge'):
- tags['highway'] = 'motorway'
- else:
- tags['highway'] = 'primary'
- elif attrs['ROADTYPE'].strip() == 'Highway Ramp':
- tags['highway'] = 'motorway_link'
- else:
- tags['highway'] = 'road'
- tags['tol:roadtype'] = attrs['ROADTYPE'].strip()
-
- tags['source'] = 'Township of Langley GIS Data'
-
- return tags
View
@@ -1,115 +0,0 @@
-from osgeo import ogr
-import re
-import urllib
-import json
-
-uvmfeatures = []
-
-def filterLayer(layer):
- if layer is None:
- return None
- print layer.GetName()
- return layer
-
-def filterFeature(ogrfeature, fieldNames, reproject):
- if ogrfeature is None:
- return
- layer = ogrfeature.GetFieldAsString("Layer")
- if (layer == "VA-BLDG-UVM" or
- layer == "VA-BLDG-NON UVM"):
- return ogrfeature
- elif (layer == "VA-BLDG-ATTRIBUTES" and len(ogrfeature.GetFieldAsString("Text")) == 4):
- # Ignore CFC Soccer Stands - has no building outline
- if ogrfeature.GetFieldAsString("Text") == "0979":
- return
- return ogrfeature
- else:
- return
-
-def filterFeaturePost(feature, ogrfeature, ogrgeometry):
- if feature is None and ogrfeature is None and ogrgeometry is None:
- return
- global uvmfeatures
- uvmfeatures.append((feature, ogrfeature, ogrgeometry))
-
-def filterTags(tags):
- if tags is None:
- return
- newtags = {}
- for (key, value) in tags.items():
- if (key == "Layer" or
- (key == "Text" and value != "")):
- newtags[key] = value
- if (key == "Layer" and value != "VA-UVM-BLDG-CODE"):
- newtags["building"] = "yes"
- return newtags
-
-
-def preOutputTransform(geometries, features):
- if geometries is None and features is None:
- return
- global uvmfeatures
- buildingcodes = [(feature, ogrfeature, ogrgeometry) for (feature, ogrfeature, ogrgeometry) in uvmfeatures if ogrfeature.GetFieldAsString("Layer") == "VA-BLDG-ATTRIBUTES"]
- buildings = [x for x in uvmfeatures if x not in buildingcodes]
- # Match each code to the closest building, setting the building's feature's
- # name
- for (codef, codeogrf, codeogrg) in buildingcodes:
- dist = float("inf")
- chosenfeature = (None, None, None)
- for (bldgf, bldgogrf, bldgogrg) in buildings:
- newdist = codeogrg.Distance(bldgogrg)
- if newdist < dist:
- dist = newdist
- chosenfeature = (bldgf, bldgogrf, bldgogrg)
- (bldgf, bldgogrf, bldgogrg) = chosenfeature
- buildingid = codeogrf.GetFieldAsString("Text")
- if bldgf.tags.has_key("uvm:buildingid") and bldgf.tags["uvm:buildingid"] != buildingid:
- print "WARNING: buildingid overlap detected! " + bldgf.tags["uvm:buildingid"] + " " + buildingid
- bldgf.tags["uvm:buildingid"] = buildingid
- page = urllib.urlopen("http://www-dev.uvm.edu/~aguertin/webteam/map/famis/getbldgname.php?BLDG="+buildingid)
- name = page.read()
- page.close
- bldgf.tags["name"] = name
-
- # Remove the building code nodes
- for feature in [f for f in features if f.tags["Layer"] == "VA-BLDG-ATTRIBUTES"]:
- print "Removing a text node: " + feature.tags["Text"]
- features.remove(feature)
- feature.geometry.removeparent(feature)
-
- # Remove buildings that were not given a buildingid
- for feature in [f for f in features if "uvm:buildingid" not in f.tags]:
- features.remove(feature)
- try:
- geometries.remove(feature.geometry)
- try:
- for point in set(feature.geometry.points):
- try:
- point.removeparent(feature.geometry)
- except:
- print "What went wrong here???"
- except:
- print "Failed -- geometry.points does not exist -- not a way"
- except:
- print "Failed -- two building features with same geometry??"
-
- uvmjson(geometries, features)
-
-def uvmjson(geometries, features):
- print "IN UVMJSON"
- buildings = [building for building in features if "uvm:buildingid" in building.tags]
- outbuildings = []
- for building in buildings:
- outbuilding = {}
- outbuilding["id"] = building.tags["uvm:buildingid"]
- outbuilding["geometry"] = []
- if str(type(building.geometry)) != "<class '__main__.Way'>":
- print "WARNING: building not way, being ignored!"
- print str(type(building.geometry))
- else:
- for point in building.geometry.points:
- outbuilding["geometry"].append({"x": point.x, "y": point.y})
- outbuildings.append(outbuilding)
- f = open('/tmp/uvmbuildings.json', 'w')
- f.write(json.dumps(outbuildings, indent=4))
- f.close()

0 comments on commit d4c83b9

Please sign in to comment.