我正在使用GeoServer(v2.5.2)和GeoWebcache开展项目。我希望能够上传图像以创建coverage商店及其关联的图层。我使用PHP和cURL与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参数)。
最好的&#34;文档&#34;我发现这是一个: 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错误代码。
我做错了什么?非常感谢。
答案 0 :(得分:2)
发现我的错误: 我试图添加一个图层,但我需要添加一个图层,图层会自动创建。
如果它可以帮助某人,我就是这样做的:
$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);