资源预览内容
第1页 / 共65页
第2页 / 共65页
第3页 / 共65页
第4页 / 共65页
第5页 / 共65页
第6页 / 共65页
第7页 / 共65页
第8页 / 共65页
第9页 / 共65页
第10页 / 共65页
亲,该文档总共65页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
Using OpenStreetMap data with PythonAndrii V. MishkovskyiJune 22, 2011Andrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 20111 / 1Who is this dude anyway?I love Python I love OpenStreetMap I do map rendering at CloudMade using Python CloudMade uses OpenStreetMap data extensivelyAndrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 20112 / 1ObjectivesUnderstand OpenStreetMap data structure How to parse it Get a feel of how basic GIS services workAndrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 20113 / 1OpenStreetMapFounded in 2004 as a response to Ordnance Survey pricing scheme 400k registered users 16k active mappers Supported by Microsoft, MapQuest (AOL), Yahoo! Crowd-sourcing at its bestAndrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 20114 / 1Why OSM?Fairly easy Good quality Growing community Absolutely freeAndrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 20115 / 1Andrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 20116 / 1Andrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 20117 / 1Storage typeXML (.osm) Protocol buffers (.pbf, in beta status)Other formats through 3rd parties (Esri shapefile, Garmin GPX, etc.)Andrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 20118 / 1The dataEach object has geometry, tags and changeset information Tags are simply a list of key/value pairsGeometry definition differs for different types Changeset is not interesting when simply using the data (as opposed to editing)Andrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 20119 / 1Data typesNode Geometric point or point of interest Way Collection of points Relation Collections of objects of any typeAndrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 201110 / 1NodesAndrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 201111 / 1WaysAndrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 201112 / 1Relations.Andrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 201113 / 1Andrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 201114 / 1Andrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 201115 / 1Major points when parsing OSMExpect faulty data Parse iteratively Cache extensively Order of elements is not guaranteed But its generally: nodes, ways, relations Ids are unique to datatype, not to the whole data setAndrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 201116 / 1Parsing dataUsing SAX Doing simple reprojection Create geometries using ShapelyAndrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 201117 / 1Parsing dataProjectionimport pyprojprojection = pyproj.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)Andrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 201118 / 1Parsing dataNodesfrom shapely.geometry import Pointclass Node(object):def _init_(self, id, lonlat , tags): self.id = id self.geometry = Point(projection(*lonlat) self.tags = tagsAndrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 201119 / 1Parsing dataNodesclass SimpleHandler(sax.handler.ContentHandler):def _init_(self): sax.handler.ContentHandler._init_(self) self.id = None self.geometry = None self.nodes = def startElement(self, name, attrs): if name = node: self.id = attrsid self.tags = self.geometry = map( float, (attrslon, attrslat) elif name = tag: self.tagsattrsk = attrsvAndrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 201119 / 1Parsing dataNodesdef endElement(self, name): if name = node: self.nodesself.id = Node(self.id, self.geometry , self.tags) self.id = None self.geometry = None self.tags = NoneAndrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 201119 / 1Parsing dataWaysfrom shapely.geometry import LineStringnodes = . # dict of nodes, keyed by their idsclass Way(object):def _init_(self, id, refs, tags): self.id = id self.geometry = LineString( (nodesref.x, nodesref.y) for ref in refs) self.tags = tagsAndrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 201120 / 1Parsing dataWaysclass SimpleHandler(sax.handler.ContentHandler):def _init_(self): . self.ways = def startElement(self, name, attrs): if name = way: self.id = attrsid self.tags = self.geometry = elif name = nd: self.geometry.append(attrsref)Andrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 201120 / 1Parsing dataWaysdef reset(self): self.id = None self.geometry = None self.tags = Nonedef endElement(self, name): if name = way: self.wayself.id = Way(self.id, self.geometry , self.tags) self.reset()Andrii V. Mishkovskyi ()Using OpenStreetMap data with PythonJune 22, 201120 / 1Parsing dataRelationsfrom shapely.geometry import MultiPolygon , Mult
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号