Using OpenStreetMap data with Python 使用Python的OpenStrutEMAP数据

上传人:L** 文档编号:55023249 上传时间:2018-09-23 格式:PDF 页数:65 大小:934.94KB
返回 下载 相关 举报
Using OpenStreetMap data with Python 使用Python的OpenStrutEMAP数据_第1页
第1页 / 共65页
Using OpenStreetMap data with Python 使用Python的OpenStrutEMAP数据_第2页
第2页 / 共65页
Using OpenStreetMap data with Python 使用Python的OpenStrutEMAP数据_第3页
第3页 / 共65页
Using OpenStreetMap data with Python 使用Python的OpenStrutEMAP数据_第4页
第4页 / 共65页
Using OpenStreetMap data with Python 使用Python的OpenStrutEMAP数据_第5页
第5页 / 共65页
点击查看更多>>
资源描述

《Using OpenStreetMap data with Python 使用Python的OpenStrutEMAP数据》由会员分享,可在线阅读,更多相关《Using OpenStreetMap data with Python 使用Python的OpenStrutEMAP数据(65页珍藏版)》请在金锄头文库上搜索。

1、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 extensivelyAnd

2、rii 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 respon

3、se 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 freeAndri

4、i 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 for

5、mats 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

6、 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 Op

7、enStreetMap 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

8、/ 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:

9、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 2

10、2, 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 shape

11、ly.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 _

12、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 ()U

13、sing 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, 201

14、119 / 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 OpenStreetMa

15、p 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 (

16、)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

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 学术论文 > 毕业论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号