OGC Web Map Service标准的实现原理与方法(1)
来源:互联网 发布:猜数游戏编程 编辑:程序博客网 时间:2024/06/01 23:53
基于OGC WMS规范实现的WebGIS系统是目前已经使用的非常广泛的应用。这里主要从原理和Web Service实现过程两个层次说明:
(1)实现原理,以下是基于WMS的B-S交互过程
(2)请求字符串的配置,根据标准,客户端请求的URL可以为以下形式
http//localhost:8080/wms.ashx?SERVICE=WMS&REQUEST=GetMap&Layers=layers&STYLES=styles&FORMAT=format&CRS=coordinate-system&BBOX=boungdingbox&WIDTH=width&HEIGHT=height
(3)Web Service实现:其中GetMap是Web Map Service的核心,他被封装为一个Web Service,以下给出一个ASP.NET实现该Web Service的过程
第一步:建立ASP.NET Web服务
第二步:声明一个Web Service方法,该方法的输入参数为(2)中描述的请求字符串,输出参数为请求的地图的图像字节流,如下
[WebMethod]
public void GetMap(string UserRequest,ref byte[] bytesmap)
第三步:定义这个方法,这里定义一个Map2类,该类通过SharpMap开源类库读取和渲染矢量数据为地图;然后再GetMap这个Web服务方法中新建Map2类对象,并解析请求字符串,返回地图图像的字节流。
public void GetMap(string UserRequest,ref byte[] bytesmap)
{
Map2 map = new Map2();
//以下参数在客户端的请求字符串中均包含
string VERSION = "";//服务版本
string REQUEST = "";//操作名称
string[] LAYERS = new string[1];//图层列表
string[] STYLES = new string[1];//图层风格
string CRS = ""; //空间参考系统
double[] BBOX ={ 0.0 }; //地图的外接矩形
string FORMAT = ""; //输出地图图象的格式
int WIDTH = 0, HEIGHT = 0;//地图高,宽
//以下参数是服务器端默认的,客户端并不包含之
Color BGCOLOR = Color.White; //背景色
//解析字符串开始
System.Drawing.Imaging.ImageCodecInfo imageEncoder;//
bool haveREQUEST=false;
Collection<string> SplitUserRequest = new Collection<string>(); //利用string类Collection存储参数值对
string[] temp = UserRequest.Split(new char[] { '&' });
for (int i = 0; i < temp.Length; i++)
{
SplitUserRequest.Add(temp[i]);
}
//查找用户输入的Request中是否包含REQUEST参数,如果包含,将其赋给REQUEST,如果不包含,抛出异常
foreach (string splitstring in SplitUserRequest)
{
string splitstringLower = splitstring.ToLower();
//Request中的参数名称大小写不敏感,因此在涉及到参数名称时,使用splitstringLower,涉及到参数值时,使用splitstring
int exist = splitstringLower.IndexOf("request");//检查是否存在request参数
if (exist >= 0)
{
string[] requestvalue = splitstring.Split(new char[] { '=' });
haveREQUEST = true;
REQUEST = requestvalue[1];
break;
}
}
if (!haveREQUEST)
{
//抛出异常
//return "Required parameter REQUEST not specified";
WmsException.ThrowWmsException("Required parameter REQUEST not specified");
return;
}
//检查是否缺少必要参数
if (REQUEST == "GetMap")
{
//VERSION
int versionexist = UserRequest.ToLower().IndexOf("version");
if (versionexist < 0)
{
//抛出异常"Required parameter VERSION not specified"
WmsException.ThrowWmsException("Required parameter VERSION not specified");
return;
}
else
{
foreach (string splitstring in SplitUserRequest)
{
string splitstringLower = splitstring.ToLower();
//Request中的参数名称大小写不敏感,因此在涉及到参数名称时,使用splitstringLower,涉及到参数值时,使用splitstring
int exist = splitstringLower.IndexOf("version");//版本参数
if (exist >= 0)
{
string[] versionvalue = splitstring.Split(new char[] { '=' });
VERSION = versionvalue[1];
break;
}
}
if (VERSION != "1.3.0")
{
//抛出异常"Only version 1.3.0 supported"
WmsException.ThrowWmsException("Only version 1.3.0 supported");
return;
}
}
//LAYERS
int layersexist = UserRequest.ToLower().IndexOf("layers");
if (layersexist < 0)
{
//抛出异常"Required parameter LAYERS not specified"
WmsException.ThrowWmsException("Required parameter LAYERS not specified");
return;
}
else
{
foreach (string splitstring in SplitUserRequest)
{
string splitstringLower = splitstring.ToLower();
//Request中的参数名称大小写不敏感,因此在涉及到参数名称时,使用splitstringLower,涉及到参数值时,使用splitstring
int exist = splitstringLower.IndexOf("layers");
if (exist >= 0)
{
string[] layerspara = splitstring.Split(new char[] { '=' });
string[] layersvalue = layerspara[1].Split(new char[] { ',' });
LAYERS = new string[layersvalue.Length];
for (int i = 0; i < LAYERS.Length; i++)
{
LAYERS[i] = layersvalue[i];
}
break;
}
}
}
//STYLES
int stylesexist = UserRequest.ToLower().IndexOf("styles");
if (stylesexist < 0)
{
//抛出异常"Required parameter STYLES not specified"
WmsException.ThrowWmsException("Required parameter STYLES not specified"); return;
}
else
{
foreach (string splitstring in SplitUserRequest)
{
string splitstringLower = splitstring.ToLower();
//Request中的参数名称大小写不敏感,因此在涉及到参数名称时,使用splitstringLower,涉及到参数值时,使用splitstring
int exist = splitstringLower.IndexOf("styles");
if (exist >= 0)
{
string[] stylespara = splitstring.Split(new char[] { '=' });
string[] stylesvalue = stylespara[1].Split(new char[] { ',' });
STYLES = new string[stylesvalue.Length];
for (int i = 0; i < STYLES.Length; i++)
{
STYLES[i] = stylesvalue[i];
}
break;
}
}
}
//CRS
int crsexist = UserRequest.ToLower().IndexOf("crs");
if (crsexist < 0)
{
//抛出异常"Required parameter CRS not specified"
WmsException.ThrowWmsException("Required parameter CRS not specified");
return;
}
else
{
foreach (string splitstring in SplitUserRequest)
{
string splitstringLower = splitstring.ToLower();
//Request中的参数名称大小写不敏感,因此在涉及到参数名称时,使用splitstringLower,涉及到参数值时,使用splitstring
int exist = splitstringLower.IndexOf("crs");
if (exist >= 0)
{
string[] crsvalue = splitstring.Split(new char[] { '=' });
CRS = crsvalue[1];
break;
}
}
}
//BBOX
int bboxexist = UserRequest.ToLower().IndexOf("bbox");
if (bboxexist < 0)
{
//抛出异常"Required parameter BBOX not specified"
WmsException.ThrowWmsException("Required parameter BBOX not specified");
return;
}
else
{
foreach (string splitstring in SplitUserRequest)
{
string splitstringLower = splitstring.ToLower();
//Request中的参数名称大小写不敏感,因此在涉及到参数名称时,使用splitstringLower,涉及到参数值时,使用splitstring
int exist = splitstringLower.IndexOf("bbox");
if (exist >= 0)
{
string[] bboxpara = splitstring.Split(new char[] { '=' });
string[] bboxvalue = bboxpara[1].Split(new char[] { ',' });
BBOX = new double[bboxvalue.Length];
for (int i = 0; i < BBOX.Length; i++)
{
BBOX[i] = Convert.ToDouble(bboxvalue[i]);
}
break;
}
}
if (BBOX.Length != 4)
{
//抛出异常"Invalid parameter BBOX"
WmsException.ThrowWmsException("Invalid parameter BBOX");
return;
}
else
if (BBOX[2] < BBOX[0] || BBOX[3] < BBOX[1])
{
//抛出异常"Invalid parameter BBOX"
WmsException.ThrowWmsException("Invalid parameter BBOX");
return;
}
}
//WIDTH
int widthexist = UserRequest.ToLower().IndexOf("width");
if (widthexist < 0)
{
//抛出异常"Required parameter WIDTH not specified"
WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidDimensionValue, "Required parameter WIDTH not specified"); return;
}
else
{
foreach (string splitstring in SplitUserRequest)
{
string splitstringLower = splitstring.ToLower();
//Request中的参数名称大小写不敏感,因此在涉及到参数名称时,使用splitstringLower,涉及到参数值时,使用splitstring
int exist = splitstringLower.IndexOf("width");
if (exist >= 0)
{
string[] widthvalue = splitstring.Split(new char[] { '=' });
WIDTH = Convert.ToInt32(widthvalue[1]);
break;
}
}
}
//HEIGHT
int heightexist = UserRequest.ToLower().IndexOf("height");
if (heightexist < 0)
{
//抛出异常"Required parameter HEIGHT not specified"
WmsException.ThrowWmsException(WmsException.WmsExceptionCode.InvalidDimensionValue, "Required parameter HEIGHT not specified"); return;
}
else
{
foreach (string splitstring in SplitUserRequest)
{
string splitstringLower = splitstring.ToLower();
//Request中的参数名称大小写不敏感,因此在涉及到参数名称时,使用splitstringLower,涉及到参数值时,使用splitstring
int exist = splitstringLower.IndexOf("height");
if (exist >= 0)
{
string[] heightvalue = splitstring.Split(new char[] { '=' });
HEIGHT = Convert.ToInt32(heightvalue[1]);
break;
}
}
}
//FORMAT
int formatexist = UserRequest.ToLower().IndexOf("format");
if (formatexist < 0)
{
//抛出异常"Required parameter FORMAT not specified"
WmsException.ThrowWmsException("Required parameter FORMAT not specified");
return;
}
else
{
foreach (string splitstring in SplitUserRequest)
{
string splitstringLower = splitstring.ToLower();
//Request中的参数名称大小写不敏感,因此在涉及到参数名称时,使用splitstringLower,涉及到参数值时,使用splitstring
int exist = splitstringLower.IndexOf("format");
if (exist >= 0)
{
string[] formatvalue = splitstring.Split(new char[] { '=' });
FORMAT = formatvalue[1];
break;
}
}
imageEncoder = GetEncoderInfo(FORMAT);
if (imageEncoder == null)
{
//抛出异常"Invalid MimeType specified in FORMAT parameter"
WmsException.ThrowWmsException("Invalid MimeType specified in FORMAT parameter");
return;
}
}
//BGCOLOR
int bgcolorexist = UserRequest.ToLower().IndexOf("bgcolor");
if(bgcolorexist>=0)
{
foreach (string splitstring in SplitUserRequest)
{
string splitstringLower = splitstring.ToLower();
//Request中的参数名称大小写不敏感,因此在涉及到参数名称时,使用splitstringLower,涉及到参数值时,使用splitstring
int exist = splitstringLower.IndexOf("bgcolor");
if (exist >= 0)
{
string[] bgcolorvalue = splitstring.Split(new char[] { '=' });
try
{
BGCOLOR = System.Drawing.ColorTranslator.FromHtml(bgcolorvalue[1]);
}
catch
{
WmsException.ThrowWmsException("Invalid parameter BGCOLOR"); return;
}
break;
}
}
}
//图层信息初始化,对map进行初始化,代码从略
//...
//...
//地图对象初始化
map.BGcolor = BGCOLOR;
map.MapWidth = WIDTH;
map.MapHeight = HEIGHT;
map.BoundingBox = new BBox((float)BBOX[0], (float)BBOX[1], (float)BBOX[2], (float)BBOX[3]);
map.ReadData(Server.MapPath("App_Data"));
System.Drawing.Image img = map.rendermap();
System.IO.MemoryStream MS = new System.IO.MemoryStream();
img.Save(MS, imageEncoder, null);
img.Dispose();
byte[] buffer = MS.ToArray();
bytesmap = buffer;
}
}
(4)实现后可测试之,以下是对应的SOAP的XML描述
(5)客户端解析返回的bytesmap图像字节流,显示地图。
此为(1),欢迎继续关注!!!
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Geoleung/archive/2009/01/05/3714703.aspx
- OGC Web Map Service标准的实现原理与方法(1)
- OGC Web Map Service标准的实现原理与方法(1)
- OGC Web Map Service标准的规范说明
- OGC Web Map Service标准的规范说明
- OGC Web Map Service标准的规范说明
- OGC标准介绍 1
- Skyline加载OGC标准服务WMTS的方法
- web service实现原理与异步调用
- web service实现原理与异步调用
- Web Service 中重载的实现方法
- 开发web service的接口实现方法
- Web Service 的工作原理
- Web Service 的工作原理
- Web Service 的工作原理
- Web Service 的工作原理
- Web Service 的工作原理
- Web Service 的工作原理
- Web Service 的工作原理
- 关于identity
- PHP 业务错误处理
- rrew
- OGC Web Map Service标准的规范说明
- The questions for seeking a job in UK.
- OGC Web Map Service标准的实现原理与方法(1)
- 第二十章 多任务和多线程
- 关于网上支付文档
- jsp中输出一张表内容
- c#.net无边框窗口的拖动!
- FLASH调用XML数据简明教程
- 如何使用kxml解析WAP
- fgets判断文件尾
- 迷茫