首页 文章

PHP使用XML发布WMS GetMap请求(GeoServer)

提问于
浏览
2

我需要能够将一些XML“发布”到Geoserver WMS GetMap并获取图像 . 我有一些有效的XML,我可以使用Geoserver上的'demo'功能进行测试,它会按预期返回一个图像 .

但是,我似乎无法弄清楚我需要用来在PHP中生成相同的请求和响应的机制 .

我已经尝试过使用cURL(因为我已经成功使用了WFS请求)并且已经玩过fput但我似乎无法破解它 .

有没有人有使用PHP的WMS GetMap'发布'XML请求到GeoServer的工作示例?

非常感谢,史蒂夫

1 回答

  • 2

    Plesae查看下面的代码,了解如何使用curl从geoserver使用xml,php和curl获取项目的示例 .

    <?php
    
      $xml_builder = '
                        <?xml version="1.0" encoding="utf-8"?>
                        <ogc:GetMap xmlns:ogc="http://www.opengis.net/ows"
                            xmlns:gml="http://www.opengis.net/gml"
                            version="1.2.0"
                            service="WMS">
                        <StyledLayerDescriptor version="1.0.0">
                        <NamedLayer>
                         <Name>myNs:roads</Name>
                         <NamedStyle>
                          <Name>simple_roads</Name>
                         </NamedStyle>
                        </NamedLayer>
                        </StyledLayerDescriptor>
                        <Output>
                         <Format>image/png</Format>
                         <Size>
                         <Width>600</Width>
                         <Height>320</Height>
                         </Size>
                        </Output>
                        <Exceptions>application/vnd.ogc.se+xml</Exceptions>
    
    </ogc:GetMap>
                     ';
      // We send XML via CURL using POST with a http header of text/xml.
      $ch = curl_init('http://localhost:8080/GeoServer/wms');
      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_builder);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      $ch_result = curl_exec($ch);
      curl_close($ch);
      // Print CURL result.
      echo $ch_result;
    ?>
    

    显然,您需要更改XML以适应您所追求的层 . 如果从服务器角度来看它不在localhost上,您还需要将curl_init中的URL更改为您的服务器 .

    如果一切正常,那么应该打印很多奇怪的文本,因为它是返回的图像 . 有时您可以在顶部看到PNG文本,因为它是png Headers 的一部分 .

相关问题