XML 响应中的访问层

问题描述 投票:0回答:1

我无法访问对

request.get
的 XML 响应中的特定层。

我正在尝试访问位于

Radar_UK_Composite_Highres
下面的
Contents
的“时间”值。 XML 响应附在帖子末尾。

我尝试通过

layer_elem.find
访问图层,以及手动索引到该位置。
.find
方法没有结果,如果我尝试比
tree[3]
更进一步,索引方法会给出超出范围的错误。看起来就像在
</ows:OperationsMetadata>
之后文件就结束了,就像在
elementtree
方法看来一样。

<?xml version="1.0" encoding="UTF-8"?>
<Capabilities xmlns="http://www.opengis.net/wmts/1.0"
xmlns:ows="http://www.opengis.net/ows/1.1"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd"
version="1.0.0">
<ows:ServiceIdentification>
  <ows:Title>GeoWebCache</ows:Title>
  <ows:Abstract>GeoWebCache is an advanced tile cache for WMS servers.It supports a large variety of protocols and
      formats, including WMS-C, WMTS, KML, Google Maps and Virtual Earth.</ows:Abstract>
  <ows:Keywords>
    <ows:Keyword>WFS</ows:Keyword>
    <ows:Keyword>WMS</ows:Keyword>
    <ows:Keyword>WMTS</ows:Keyword>
    <ows:Keyword>GEOWEBCACHE</ows:Keyword>
  </ows:Keywords>
  <ows:ServiceType>OGC WMTS</ows:ServiceType>
  <ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
  <ows:Fees>NONE</ows:Fees>
  <ows:AccessConstraints>NONE</ows:AccessConstraints>
</ows:ServiceIdentification>
<ows:ServiceProvider>
  <ows:ProviderName>Met Office</ows:ProviderName>
  <ows:ProviderSite xlink:href="http://www.metoffice.gov.uk/" />
  <ows:ServiceContact>
    <ows:ContactInfo>
      <ows:Phone>
      <ows:Voice>+441392885680</ows:Voice>
      <ows:Facsimile>+441392885681</ows:Facsimile>
      </ows:Phone>
      <ows:Address>
      <ows:DeliveryPoint>Fitzroy Road</ows:DeliveryPoint>
      <ows:City>Exeter</ows:City>
      <ows:AdministrativeArea>Devon</ows:AdministrativeArea>
      <ows:PostalCode>EX1 3PB</ows:PostalCode>
      <ows:Country>United Kingdom</ows:Country>
      <ows:ElectronicMailAddress>[email protected]</ows:ElectronicMailAddress>
      </ows:Address>
    </ows:ContactInfo>
  </ows:ServiceContact>
</ows:ServiceProvider>
<ows:OperationsMetadata>
  <ows:Operation name="GetCapabilities">
    <ows:DCP>
      <ows:HTTP>
        <ows:Get xlink:href="http://datapoint.metoffice.gov.uk/public/data/inspire/view/wmts?">
          <ows:Constraint name="GetEncoding">
            <ows:AllowedValues>
              <ows:Value>KVP</ows:Value>
            </ows:AllowedValues>
          </ows:Constraint>
        </ows:Get>
      </ows:HTTP>
    </ows:DCP>
  </ows:Operation>
  <ows:Operation name="GetTile">
    <ows:DCP>
      <ows:HTTP>
        <ows:Get xlink:href="http://datapoint.metoffice.gov.uk/public/data/inspire/view/wmts?">
          <ows:Constraint name="GetEncoding">
            <ows:AllowedValues>
              <ows:Value>KVP</ows:Value>
            </ows:AllowedValues>
          </ows:Constraint>
        </ows:Get>
      </ows:HTTP>
    </ows:DCP>
  </ows:Operation>
  <ows:Operation name="GetFeatureInfo">
    <ows:DCP>
      <ows:HTTP>
        <ows:Get xlink:href="http://datapoint.metoffice.gov.uk/public/data/inspire/view/wmts?">
          <ows:Constraint name="GetEncoding">
            <ows:AllowedValues>
              <ows:Value>KVP</ows:Value>
            </ows:AllowedValues>
          </ows:Constraint>
        </ows:Get>
      </ows:HTTP>
    </ows:DCP>
  </ows:Operation>
</ows:OperationsMetadata>
<Contents>
  <Layer>
    <ows:Title>RADAR_UK_Composite_Highres</ows:Title>
    <ows:WGS84BoundingBox>
      <ows:LowerCorner>-180.0 -90.0</ows:LowerCorner>
      <ows:UpperCorner>180.0 90.0</ows:UpperCorner>
    </ows:WGS84BoundingBox>
    <ows:Identifier>RADAR_UK_Composite_Highres</ows:Identifier>
    <Style>
      <ows:Identifier>Bitmap 1km Blue-Pale blue gradient 0.01 to 32mm/hr</ows:Identifier>
    </Style>
    <Style>
      <ows:Identifier>Bitmap 1km Blue-Pale blue gradient 0.25 to 32mm/hr</ows:Identifier>
    </Style>
    <Style>
      <ows:Identifier>Bitmap Interpolated 1km Blue-Pale blue gradient 0.25 to 32mm/hr</ows:Identifier>
    </Style>
    <Format>image/png</Format>
    <Dimension>      <Identifier>TIME</Identifier>     
    <Default>2023-11-23T14:15:00Z</Default>   
    <Value>2023-11-22T00:00:00Z</Value> 
    </Dimension>    <TileMatrixSetLink>      <TileMatrixSet>EPSG:29903</TileMatrixSet>
    </TileMatrixSetLink>    <TileMatrixSetLink>      <TileMatrixSet>EPSG:4326</TileMatrixSet>
    </TileMatrixSetLink>    <TileMatrixSetLink>      <TileMatrixSet>EPSG:4258</TileMatrixSet>
    </TileMatrixSetLink>    <TileMatrixSetLink>      <TileMatrixSet>EPSG:27700</TileMatrixSet>
    </TileMatrixSetLink>    <TileMatrixSetLink>      <TileMatrixSet>EPSG:2157</TileMatrixSet>
    </TileMatrixSetLink>  </Layer>

XML 数据持续了相当多的时间,但这是我当前想要使用的部分。

python xml elementtree
1个回答
0
投票

由于文档上有默认名称空间,因此在查找元素时需要使用它:

layer = doc.find(".//{http://www.opengis.net/wmts/1.0}Layer")
© www.soinside.com 2019 - 2024. All rights reserved.