我正在尝试将栅格图层的默认样式从栅格更改为我定义的样式。
我已经创建了一个sld文件,并将其放在geoserver的data目录的styles文件夹中。
接下来,我使用geoserver(http://docs.geoserver.org/latest/en/user/rest/examples/curl.html)的文档中给出的以下命令创建了一个XML文件。
curl -u admin:geoserver -XPOST -H 'Content-type: text/xml' -d '<style><name>aspect_style</name><filename>aspect.sld</filename></style>' http://localhost:8080/geoserver/rest/styles然后我已经上传了文件,并使用以下命令将样式应用到图层。
curl -u admin:geoserver -XPUT -H 'Content-type: application/vnd.ogc.sld+xml' -d @aspect.sld http://localhost:8080/geoserver/rest/styles/aspect_raster_style
curl -u admin:geoserver -XPUT -H 'Content-type: text/xml' -d '<layer><defaultStyle><name>aspect_raster_style</name></defaultStyle><enabled>true</enabled></layer>' http://localhost:8080/geoserver/rest/layers/dem:vinnu_aspect_raster它通过CLI工作,当我在geoserver中看到它时,样式就更新了。当我用php做同样的事情时,我无法做到这一点。我得到一个错误,因为“输入源不包含数据”。
我能够创建工作空间,coveragestore,层使用卷曲与php。但我无法更改图层的样式。
我的php代码如下。
$file="F:/Vineendra/Images/abcd_aspect_qgis.tif";
$coverage_name="rast";
$workspace="medford";
// Open log file
$logfh = fopen("GeoserverPHP.log", 'w') or die("can't open log file");
// Initiate cURL session
$service = "http://localhost:8080/geoserver/";
$request = "rest/layers/".$workspace.":".$coverage_name."_raster"; // to add a new workspace
$url = $service . $request;
$ch = curl_init($url);
// Optional settings for debugging
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //option to return string
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, $logfh); // logs curl messages
//Required POST request settings
curl_setopt($ch, CURLOPT_PUT, True);
$passwordStr = "admin:geoserver"; // replace with your username:password
curl_setopt($ch, CURLOPT_USERPWD, $passwordStr);
//POST data
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("Content-type:text/xml"));
$xmlStr = "<layer><defaultStyle><name>aspect_raster_style</name></defaultStyle></layer>";
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlStr);
//POST return code
$successCode = 201;
$buffer = curl_exec($ch); // Execute the curl request
// Check for errors and process results
$info = curl_getinfo($ch);
if ($info['http_code'] != $successCode) {
$msgStr = "# Unsuccessful cURL request to ";
$msgStr .= $url." [". $info['http_code']. "]\n";
fwrite($logfh, $msgStr);
} else {
$msgStr = "# Successful cURL request to ".$url."\n";
fwrite($logfh, $msgStr);
}
fwrite($logfh, $buffer."\n");curl_close($ch);
因为我已经创建并上传了样式,所以我直接尝试使用php更改图层的默认样式。
发布于 2013-12-13 04:25:11
不确定这篇文章是否仍然活跃,但如果有人点击place寻找答案(就像我一样),请确保你在HttpHeader中通知了$xmlString长度:
curl_setopt($ch, CURLOPT_HTTPHEADER,
array(
"Content-type: application/xml",
"Content-Length: ".strlen($xmlStr)
)
);在我的例子中,它解决了问题。
发布于 2014-11-24 11:56:26
不要使用curl_setopt($ch, CURLOPT_PUT, True);
使用curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
https://stackoverflow.com/questions/18312154
复制相似问题