如何在python中读取具有特定标识符的kml文件?
我正在阅读德国气象局提供的kml文件: 使用以下代码,我无法访问如何在python中读取具有特定标识符的kml文件?,python,xml,xsd,Python,Xml,Xsd,我正在阅读德国气象局提供的kml文件: 使用以下代码,我无法访问dwd:子项: from zipfile import ZipFile from lxml import html from urllib.request import urlretrieve urlretrieve('http://opendata.dwd.de/weather/local_forecasts/mos/MOSMIX_L/single_stations/10641/kml/MOSMIX_L_LATEST_10641
dwd:
子项:
from zipfile import ZipFile
from lxml import html
from urllib.request import urlretrieve
urlretrieve('http://opendata.dwd.de/weather/local_forecasts/mos/MOSMIX_L/single_stations/10641/kml/MOSMIX_L_LATEST_10641.kmz')
kmz = ZipFile("local_data.kmz", 'r')
kml = kmz.open(kmz.filelist[0].filename, 'r').read()
root = parser.fromstring(kml)
使用
root.Document.Placemark.ExtendedData.getchildren()
命令,我可以访问以下列表(长度为114,我在这里剪切):
我想问题是使用了标准的opengis kml模式。如何访问数据
这是文件的头:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<kml:kml xmlns:dwd="https://opendata.dwd.de/weather/lib/pointforecast_dwd_extension_V1_0.xsd" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<kml:Document>
<kml:ExtendedData>
<dwd:ProductDefinition>
<dwd:Issuer>Deutscher Wetterdienst</dwd:Issuer>
<dwd:ProductID>DWD_MOSMIX_1H</dwd:ProductID>
<dwd:GeneratingProcess>DWD MOSMIX hourly, Version 1.0</dwd:GeneratingProcess>
<dwd:IssueTime></dwd:IssueTime>
<dwd:ReferencedModel>
<dwd:Model dwd:name="ICON" dwd:referenceTime="2018-05-17T00:00:00Z"/>
<dwd:Model dwd:name="ECMWF/IFS" dwd:referenceTime="2018-05-17T00:00:00Z"/>
</dwd:ReferencedModel>
<dwd:ForecastTimeSteps>
<dwd:TimeStep>2018-05-17T10:00:00.000Z</dwd:TimeStep>
<dwd:TimeStep>2018-05-17T11:00:00.000Z</dwd:TimeStep>
<dwd:TimeStep>2018-05-17T12:00:00.000Z</dwd:TimeStep>
<dwd:TimeStep>2018-05-17T13:00:00.000Z</dwd:TimeStep>
<dwd:TimeStep>2018-05-17T14:00:00.000Z</dwd:TimeStep>
<dwd:TimeStep>2018-05-17T15:00:00.000Z</dwd:TimeStep>
德国气象局
DWD_MOSMIX_1H
DWD MOSMIX每小时一次,版本1.0
2018-05-17T10:00:00.000Z
2018-05-17T11:00:00.000Z
2018-05-17T12:00:00.000Z
2018-05-17T13:00:00.000Z
2018-05-17T14:00:00.000Z
2018-05-17T15:00:00.000Z
root.Document.Placemark.ExtendedData
没有预测,它有许多预测。您在哪里看到了成功使用的root.Document.Placemark.ExtendedData.Foreast
?这到底意味着什么?如果您想要第一个预测,那么大概root.Document.Placemark.ExtendedData.getchildren()[0]
会这样做。@FiddleStix感谢它能收到一个值列表。您甚至知道如何取消ForecastTimeSteps
?
AttributeError: no such child: {http://www.opengis.net/kml/2.2}Forecast
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<kml:kml xmlns:dwd="https://opendata.dwd.de/weather/lib/pointforecast_dwd_extension_V1_0.xsd" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:xal="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<kml:Document>
<kml:ExtendedData>
<dwd:ProductDefinition>
<dwd:Issuer>Deutscher Wetterdienst</dwd:Issuer>
<dwd:ProductID>DWD_MOSMIX_1H</dwd:ProductID>
<dwd:GeneratingProcess>DWD MOSMIX hourly, Version 1.0</dwd:GeneratingProcess>
<dwd:IssueTime></dwd:IssueTime>
<dwd:ReferencedModel>
<dwd:Model dwd:name="ICON" dwd:referenceTime="2018-05-17T00:00:00Z"/>
<dwd:Model dwd:name="ECMWF/IFS" dwd:referenceTime="2018-05-17T00:00:00Z"/>
</dwd:ReferencedModel>
<dwd:ForecastTimeSteps>
<dwd:TimeStep>2018-05-17T10:00:00.000Z</dwd:TimeStep>
<dwd:TimeStep>2018-05-17T11:00:00.000Z</dwd:TimeStep>
<dwd:TimeStep>2018-05-17T12:00:00.000Z</dwd:TimeStep>
<dwd:TimeStep>2018-05-17T13:00:00.000Z</dwd:TimeStep>
<dwd:TimeStep>2018-05-17T14:00:00.000Z</dwd:TimeStep>
<dwd:TimeStep>2018-05-17T15:00:00.000Z</dwd:TimeStep>