我的应用程序从客户端和服务器端读取shapefile并将其显示在地图上。我从客户端加载shapefile没有问题。用户首先从浏览器加载文件,然后将File对象传递到后端。
public ActionResult ShpRead()
{
try
{
string resultTest = "";
// Get all files from Request object
HttpFileCollectionBase files = Request.Files;
HttpPostedFileBase file = files[0];
string fname;
Stream FileStream = file.InputStream;
BinaryReader br = new BinaryReader(FileStream);
br.ReadBytes(24);
int FileLength = br.ReadInt32();
int FileVersion = br.ReadInt32();
int ShapeType = br.ReadInt32();
double xmin = br.ReadDouble();
double ymin = br.ReadDouble();
double xmax = br.ReadDouble();
double ymax = br.ReadDouble();
double width = xmax - xmin;
double height = ymax - ymin;
br.ReadBytes(32);
//more code for handling each shape type
}
从服务器端,前端首先从Azure存储中检索shapefile,然后使用AJAX将shapefile传递到后端。然后,使用Stream和BinaryReader类,该程序将读取shapefile二进制文件,并根据以下格式(https://en.wikipedia.org/wiki/Shapefile)提取信息。
但是,读取shapefile二进制文件总是会产生此错误。
System.IO.EndOfStreamException: Unable to read beyond the end of the stream.
这使我认为从两侧加载的shapefile不同,或者客户端和服务器端均不能使用ShpRead()方法。
如果我将从服务器检索到的shapefile作为二进制字符串传递给后端,那么解析该字符串并提取信息的一种好方法是什么?