Permalink
Browse files

multiline_centerline() takes a min_area, ParseOSM.parse() takes a fil…

…e-like stream
  • Loading branch information...
1 parent 16e4541 commit f4beaba9050073b9714e480846295e100e66251e Michal Migurski committed Oct 10, 2011
Showing with 19 additions and 7 deletions.
  1. +7 −2 Skeletron/__init__.py
  2. +10 −3 Skeletron/input.py
  3. +1 −1 osm-slurp.py
  4. +1 −1 osm-to-json.py
View
9 Skeletron/__init__.py
@@ -8,7 +8,7 @@
from .util import simplify_line, densify_line, polygon_rings
-def multiline_centerline(multiline, buffer=20, density=10, min_length=25):
+def multiline_centerline(multiline, buffer=20, density=10, min_length=25, min_area=100):
""" Coalesce a linear street network to a centerline.
Accepts and returns instances of shapely LineString and MultiLineString.
@@ -25,11 +25,16 @@ def multiline_centerline(multiline, buffer=20, density=10, min_length=25):
min_length
Minimum length of centerline portions to skip spurs and forks.
+
+ min_area
+ Minimum area of roads kinks for them to be maintained through
+ generalization by util.simplify_line(), should be approximately
+ min_length squared.
"""
polygon = multiline_polygon(multiline, buffer, density)
skeleton = polygon_skeleton(polygon)
routes = skeleton_routes(skeleton, min_length)
- lines = [simplify_line(route) for route in routes]
+ lines = [simplify_line(route, min_area) for route in routes]
return MultiLineString(lines)
View
13 Skeletron/input.py
@@ -4,7 +4,7 @@
from pyproj import Proj
from networkx import Graph
-merc = Proj('+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over')
+mercator = Proj('+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over')
def name_highway_key(tags):
"""
@@ -37,10 +37,17 @@ def __init__(self):
#self.p.CharacterDataHandler = char_data
def parse(self, input, key_func=name_highway_key):
+ """ Given a file-like stream of OSM XML data, return a dictionary of network graphs.
+
+ Keys are generated from way tags based on the key_func argument.
+
+ Each network graph node will have a "point" attribute with
+ the node's location projected to spherical mercator.
+ """
self.nodes = dict()
self.ways = dict()
self.key = key_func
- self.p.Parse(input)
+ self.p.ParseFile(input)
return self.graph_response()
def graph_response(self):
@@ -80,7 +87,7 @@ def end_element(self, name):
self.end_way()
def add_node(self, id, lat, lon):
- x, y = merc(lon, lat)
+ x, y = mercator(lon, lat)
self.nodes[id] = Point(x, y)
def add_way(self, id):
View
2 osm-slurp.py
@@ -9,7 +9,7 @@
from Skeletron.draw import Canvas
p = ParserOSM()
-g = p.parse(stdin.read())
+g = p.parse(stdin)
print sorted(g.keys())
View
2 osm-to-json.py
@@ -8,7 +8,7 @@
from Skeletron.input import ParserOSM, merc
p = ParserOSM()
-g = p.parse(stdin.read())
+g = p.parse(stdin)
output = dict(type='FeatureCollection', features=[])

0 comments on commit f4beaba

Please sign in to comment.