GeoServer-使用REST API添加层(使用PHP)

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

我正在使用GeoServer(v2.5.2)和GeoWebcache进行项目。我希望能够上传图像来创建Coverage Store及其关联的图层。我正在使用带有cURL的PHP​​与REST API通信。

使用此代码上传和创建coverage存储区:

$curl = curl_init($service_url."workspaces/".htmlentities($workspace)."/coveragestores");
        $data = '<coverageStore>
                        <name>'.htmlentities($name).'</name>
                        <type>'.htmlentities($type).'</type>
                        <enabled>true</enabled>
                        <connectionParameters>
                          <entry key="url">file:'.$file.'</entry>
                          <entry key="namespace">'.htmlentities($workspace, ENT_COMPAT).'</entry>
                        </connectionParameters>
                  </coverageStore>';
        curl_setopt($curl, CURLOPT_POST, True);
        curl_setopt($curl, CURLOPT_HTTPHEADER,array("Content-type: application/xml, Content-Length: ".strlen($data)));
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_USERPWD, $auth);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        $buffer = curl_exec($curl);

现在我要创建一个新层。我正在使用与上面相同的代码(仅更改URL和XML参数)。

我找到的最好的“文档”是这个:http://docs.geoserver.org/2.5.x/en/user/geowebcache/rest/layers.html试图使用GeoWebCache和GeoServer版本,都返回了404错误代码。

所以我再次尝试使用此文档:http://docs.geoserver.org/2.5.x/en/user/rest/api/layers.html但是它没有说期望的POST参数是什么。我唯一得到的是500错误代码。

我在做什么错?非常感谢。

php rest curl geoserver
2个回答
2
投票

发现我的错误:我试图添加一个图层,但是我需要添加一个coverage,该图层是使用它自动创建的。

如果可以帮助某人,这就是我所做的事情:

        $data = '<coverage>
                    <name>'.htmlentities($name).'</name>
                    <title>'.htmlentities($name).'</title>
                    <nativeCRS>'.htmlentities('
                        GEOGCS["WGS 84", 
                        DATUM["World Geodetic System 1984", 
                          SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]], 
                          AUTHORITY["EPSG","6326"]],
                        PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], 
                        UNIT["degree", 0.017453292519943295], 
                        AXIS["Geodetic longitude", EAST], 
                        AXIS["Geodetic latitude", NORTH], 
                        AUTHORITY["EPSG","4326"]]
                        ').'
                    </nativeCRS>
                    <supportedFormats>
                         <string>GEOTIFF</string>
                         <string>PNG</string>
                         <string>JPEG</string>
                         <string>TIFF</string>
                    </supportedFormats>
                    <requestSRS>
                        <string>EPSG:4326</string>
                    </requestSRS>
                    <responseSRS>
                        <string>EPSG:4326</string>
                    </responseSRS>
                    <srs>EPSG:4326</srs>
                </coverage>';

$curl = curl_init($service_url."workspaces/".htmlentities($workspace)."/coveragestores/".htmlentities($name)."/coverages");
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER,array("Content-Type: application/xml","Content-Length: ".strlen($data)));
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_USERPWD, $auth);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_exec($curl);

0
投票

请尝试使用带有python的GeoServer API向GeoServer的tif文件中添加图层并向其中添加样式,有帮助吗?

© www.soinside.com 2019 - 2024. All rights reserved.