python读取tilemapresource.xml的BoundingBox属性值
from xml.dom.minidom import parsedef read_from_xml(file_path):# 读取文件dom = parse(file_path)# 获取文档元素对象data = dom.documentElement# 获取BoundingBox属性列表dict = data.getElementsByTagName('BoundingBox')[0].attr
·
from xml.dom.minidom import parse
def read_from_xml(file_path):
# 读取文件
dom = parse(file_path)
# 获取文档元素对象
data = dom.documentElement
# 获取BoundingBox属性列表
dict = data.getElementsByTagName('BoundingBox')[0].attributes._attrs
dc = {}
dc['minx'] = dict['minx'].nodeValue
dc['miny'] = dict['miny'].nodeValue
dc['maxx'] = dict['maxx'].nodeValue
dc['maxy'] = dict['maxy'].nodeValue
print(dc)
if __name__ == '__main__':
file_path = 'tilemapresource.xml' # 改下路径
read_from_xml(file_path)
<?xml version="1.0" encoding="utf-8"?>
<TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0">
<Title>hy.tif</Title>
<Abstract></Abstract>
<SRS>EPSG:3857</SRS>
<BoundingBox minx="100.37384033203003" miny="36.73888412439393" maxx="101.35162353515501" maxy="37.65338320128725"/>
<Origin x="100.37384033203003" y="36.73888412439393"/>
<TileFormat width="256" height="256" mime-type="image/png" extension="png"/>
<TileSets profile="mercator">
<TileSet href="2" units-per-pixel="39135.75847500000236" order="2"/>
<TileSet href="3" units-per-pixel="19567.87923750000118" order="3"/>
<TileSet href="4" units-per-pixel="9783.93961875000059" order="4"/>
<TileSet href="5" units-per-pixel="4891.96980937500030" order="5"/>
<TileSet href="6" units-per-pixel="2445.98490468750015" order="6"/>
<TileSet href="7" units-per-pixel="1222.99245234375007" order="7"/>
<TileSet href="8" units-per-pixel="611.49622617187504" order="8"/>
<TileSet href="9" units-per-pixel="305.74811308593752" order="9"/>
<TileSet href="10" units-per-pixel="152.87405654296876" order="10"/>
<TileSet href="11" units-per-pixel="76.43702827148438" order="11"/>
<TileSet href="12" units-per-pixel="38.21851413574219" order="12"/>
<TileSet href="13" units-per-pixel="19.10925706787109" order="13"/>
<TileSet href="14" units-per-pixel="9.55462853393555" order="14"/>
<TileSet href="15" units-per-pixel="4.77731426696777" order="15"/>
<TileSet href="16" units-per-pixel="2.38865713348389" order="16"/>
<TileSet href="17" units-per-pixel="1.19432856674194" order="17"/>
</TileSets>
</TileMap>
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)