嗨,根据此question ,我编写了将Store和ShapeFile添加到Geoserver的方法,这些方法可以正常工作,但是在获取图层预览时说bbox不正确
非法bbox,minX:0.0大于maxX:-1.0
添加shapefile后,当我从geoserver Web界面手动更改时,它的工作正常,但是我想通过编程这是我的代码
public bool UploadShapeFile()
{
var uploads = Path.Combine(_host.WebRootPath, "Upload");
var filePath = Path.Combine(uploads, "states_25.zip");
string result = Path.GetFileNameWithoutExtension(filePath);
String fileUri = filePath;
Console.Write(fileUri);
byte[] localShapeFile = readLocalShapeFile(fileUri);
String sUrl = "http://192.168.1.2:8080/geoserver/rest/workspaces" +
"/sf/datastores/sf3/file.shp";
WebRequest request = WebRequest.Create(sUrl);
request.ContentType = "application/zip";
request.Method = "PUT";
request.Credentials = new NetworkCredential("admin", "geoserver");
Stream requestStream = request.GetRequestStream();
requestStream.Write(localShapeFile, 0, localShapeFile.Length);
requestStream.Close();
WebResponse response = request.GetResponse();
CreatePostGISTableAndFeatureType();
return true;
}
public bool CreatePostGISTableAndFeatureType()
{
string featXml = GetXml();
string fUrl = "http://192.168.1.2:8080/geoserver/rest/workspaces" +
"/sf/datastores/sf3/featuretypes";
WebRequest request = WebRequest.Create(fUrl);
request.Method = "POST";
request.ContentType = "application/xml";
request.Credentials = new NetworkCredential("admin", "geoserver");
byte[] buffer = Encoding.GetEncoding("UTF-8").GetBytes(featXml);
Stream requestStream = request.GetRequestStream();
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Close();
try
{
WebResponse response = request.GetResponse();
}
catch (Exception ee)
{
}
return false;
}
private string GetXml()
{
string fXml = "<featureType>" +
"<name>sepp</name>" +
"<nativeName>sepp</nativeName>" +
"<title>sepp</title>" +
"<srs>EPSG:4326</srs>" +
"<attributes>" +
"<attribute>" +
"<name>the_geom</name>" +
"<binding>com.vividsolutions.jts.geom.Point</binding>" +
"</attribute>" +
"<attribute>" +
"<name>description</name>" +
"<binding>java.lang.String</binding>" +
"</attribute>" +
"<attribute>" +
"<name>timestamp</name>" +
"<binding>java.util.Date</binding>" +
"</attribute>" +
"</attributes>" +
"</featureType>";
return fXml;
}
private byte[] readLocalShapeFile(string filePath)
{
byte[] buffer;
FileStream fStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
try
{
int length = (int)fStream.Length;
buffer = new byte[length];
int count;
int sum = 0;
while ((count = fStream.Read(buffer, sum, length - sum)) > 0)
sum += count;
}
finally
{
fStream.Close();
}
return buffer;
}
非常感谢您的关注
PUT
发送到服务器的XML文件中指定数据集的边界框,或在请求中包含recalculate
选项。有关详细信息,请参见REST Manual:
重新计算数组字符串指定是否重新计算要素类型的任何边界框。必要时会自动重新计算要素类型的某些属性。特别是,当更改投影或投影策略时,将重新计算本机边界框,并在重新计算本机边界框时或在请求中显式提供新的本机边界框时,重新计算纬度/经度边界框。 (在请求中明确包含本机和纬度/经度边界框时,它们不会自动重新计算。)此外,客户端可以通过在其中包含逗号分隔的名称列表来显式请求一组固定的字段进行计算。重新计算参数。空参数“ recalculate =”非常有用,可以避免在处理大型数据集时进行缓慢的重新计算,因为“ recalculate =”可以避免计算任何字段,而不管投影,投影策略等是否发生任何变化。使用nativebbox参数“ recalculate = nativebbox”进行重新计算本机边界框,同时避免重新计算纬度/经度边界框。重新计算参数可以一起使用-批量导入后可以使用‘recalculate = nativebbox,latlonbbox’重新计算本机边界框和纬度/经度边界框。