C#+MapServer相关代码
//放大的代码: private void MapZoomIn(NameValueCollection queryString)
{
mapObj map = Session["MapServer_MAP"] as mapObj;
PointF pointFLeftBottom = new PointF(float.Parse(queryString["Left"]), float.Parse(queryString["Bottom"]));
PointF pointFRightTop = new PointF(float.Parse(queryString["Right"]), float.Parse(queryString["Top"]));
rectObj rect = map.extent;
rectObj rbox = new rectObj(pointFLeftBottom.X,pointFLeftBottom.Y,pointFRightTop.X,pointFRightTop.Y,);
map.zoomRectangle(rbox, map.width, map.height, rect, null);
Session.Remove("MapServer_MAP");
Session["MapServer_MAP"] = map; } //缩小的代码:
private void MapZoomOut(NameValueCollection queryString)
{
mapObj map = Session["MapServer_MAP"] as mapObj;
PointF pointFLeftBottom = new PointF(float.Parse(queryString["Left"]), float.Parse(queryString["Bottom"]));
PointF pointFRightTop = new PointF(float.Parse(queryString["Right"]), float.Parse(queryString["Top"]));
PointF pointFCenter = new PointF((pointFLeftBottom.X + pointFRightTop.X) / , (pointFLeftBottom.Y + pointFRightTop.Y) / );
double ratio = 0.0;
double ratioX = (pointFRightTop.X - pointFLeftBottom.X) * 1.0 / map.width;
double ratioY = (pointFLeftBottom.Y - pointFRightTop.Y) * 1.0 / map.height;
if (ratioX > ratioY)
{
ratio = ratioX;
}
else
{
ratio = ratioY;
}
map.zoomPoint(-((int)( / ratio)), new pointObj(pointFCenter.X, pointFCenter.Y, , ), map.width, map.height, map.extent, null);
rectObj rectExtent = map.extent;
double mapNewCenterX=(pointFCenter.X - 0.0) / map.width * (rectExtent.maxx - rectExtent.minx) + rectExtent.minx;
double mapNewCenterY=(pointFCenter.Y - 0.0) / map.height * (rectExtent.maxy - rectExtent.miny) + rectExtent.miny; double minx = mapNewCenterX - (rectExtent.maxx - rectExtent.minx) / ratio / ;
double maxx = mapNewCenterX + (rectExtent.maxx - rectExtent.minx) / ratio / ;
double miny = mapNewCenterY - (rectExtent.maxy - rectExtent.miny) / ratio / ;
double maxy = mapNewCenterY + (rectExtent.maxy - rectExtent.miny) / ratio / ;
rectObj rectNewExtent = new rectObj(minx, miny, maxx, maxy, );
Session.Remove("MapServer_MAP");
Session["MapServer_MAP"] = map;
} //平移的代码: private void MapPan(NameValueCollection queryString)
{
mapObj map = Session["MapServer_MAP"] as mapObj;
PointF pointFFirst = new PointF(float.Parse(queryString["FirstX"]), float.Parse(queryString["FirstY"]));
PointF pointFSecond = new PointF(float.Parse(queryString["SecondX"]), float.Parse(queryString["SecondY"]));
System.Drawing.PointF pointFCenter = new PointF(map.width / - (pointFSecond.X - pointFFirst.X), map.height / - (pointFSecond.Y - pointFFirst.Y));
map.zoomPoint(, new pointObj(pointFCenter.X, pointFCenter.Y, , ), map.width, map.height, map.extent, null);
Session.Remove("MapServer_MAP");
Session["MapServer_MAP"] = map;
} //全图显示的代码:
private void MapFullExtent(NameValueCollection queryString)
{
mapObj map = Session["MapServer_MAP"] as mapObj;
rectObj rectOriginalExtent = Session["MapServer_OriginalExtent"] as rectObj;
map.extent = rectOriginalExtent;
Session.Remove("MapServer_MAP");
Session["MapServer_MAP"] = map;
} //属性查询的代码:
private void MapAttributeQuery(NameValueCollection queryString, out string responseXML)
{
mapObj map = Session["MapServer_MAP"] as mapObj;
layerObj layer = null;
string layerName = queryString["LayerName"];
string value = queryString["Value"];
layer = map.getLayerByName(layerName);
String attributeQueryString = "((\"[NAME]\" == '" + value + "') AND (\"[SHAPE_Area]\" > " + "'10'" + "))";
Console.WriteLine("queryString="+queryString);
String path = Server.MapPath("");
Console.WriteLine("path: " + path);
layer.status = ;
layer.queryByAttributes(map, "NAME", attributeQueryString, );
layer.open();
resultCacheObj resultCache = layer.getResults();
int numresults=resultCache.numresults;
string imagePath = GenerateMap();
StringBuilder resultsXML = new StringBuilder("");
resultsXML.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
resultsXML.Append("<map>");
resultsXML.Append("<mapInfo>");
resultsXML.Append("<mapPath>");
resultsXML.Append("<![CDATA[");
resultsXML.Append(imagePath);
resultsXML.Append("]]>");
resultsXML.Append("</mapPath>");
resultsXML.Append("</mapInfo>");
for(int j=; j<numresults; j++)
{
resultCacheMemberObj resultCacheMember=resultCache.getResult(j);
resultCacheMember = layer.getResult(j);
layer.open();
shapeObj shapeResult = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_POLYGON);
layer.getShape(shapeResult, resultCacheMember.tileindex,resultCacheMember.shapeindex);
layer.open(); resultsXML.Append("<feature>");
resultsXML.Append("<objectID>");
resultsXML.Append("<![CDATA[");
resultsXML.Append(shapeResult.getValue());
resultsXML.Append("]]>");
resultsXML.Append("</objectID>"); resultsXML.Append("<name>");
resultsXML.Append("<![CDATA[");
resultsXML.Append(shapeResult.getValue());
resultsXML.Append("]]>");
resultsXML.Append("</name>"); resultsXML.Append("<area>");
resultsXML.Append("<![CDATA[");
resultsXML.Append(shapeResult.getValue());
resultsXML.Append("]]>");
resultsXML.Append("</area>");
resultsXML.Append("</feature>");
}
layer.close();
resultsXML.Append("</map>");
Session.Remove("MapServer_MAP");
Session["MapServer_MAP"] = map;
responseXML = resultsXML.ToString();
} //空间查询的代码: private void MapSpatialQuery(NameValueCollection queryString, out string responseXML)
{
mapObj map = Session["MapServer_MAP"] as mapObj;
layerObj layer = null;
for (int i = ; i < map.numlayers; i++)
{
layer = map.getLayer(i);
layer.opacity = ;
System.Diagnostics.Debug.WriteLine("LayerName= " + layer.name + " FeatureCount= " + layer.maxfeatures);
layer.status = (int)mapscript.MS_ON; } string layerName = queryString["LayerName"];
string value = queryString["Value"];
layer = map.getLayerByName(layerName);
PointF pointFLeftBottom = new PointF(float.Parse(queryString["Left"]), float.Parse(queryString["Bottom"]));
PointF pointFRightTop = new PointF(float.Parse(queryString["Right"]), float.Parse(queryString["Top"]));
pointObj pointMapLeftBottom = Pixel2Point(map, pointFLeftBottom.X, pointFLeftBottom.Y);
pointObj pointMapRightTop = Pixel2Point(map, pointFRightTop.X, pointFRightTop.Y);
rectObj rectSpatialQuery = new rectObj(pointMapLeftBottom.x, pointMapLeftBottom.y, pointMapRightTop.x, pointMapRightTop.y, ); layer.status = (int)mapscript.MS_ON;
layer.queryByRect(map, rectSpatialQuery); layer.open();
resultCacheObj resultCache = layer.getResults();
int numresults = resultCache.numresults;
string imagePath = GenerateMap();
StringBuilder resultsXML = new StringBuilder("");
resultsXML.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
resultsXML.Append("<map>");
resultsXML.Append("<mapInfo>");
resultsXML.Append("<mapPath>");
resultsXML.Append("<![CDATA[");
resultsXML.Append(imagePath);
resultsXML.Append("]]>");
resultsXML.Append("</mapPath>");
resultsXML.Append("</mapInfo>");
for (int j = ; j < numresults; j++)
{
resultCacheMemberObj resultCacheMember = resultCache.getResult(j);
resultCacheMember = layer.getResult(j);
layer.open();
shapeObj shapeResult = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_POLYGON);
layer.getShape(shapeResult, resultCacheMember.tileindex, resultCacheMember.shapeindex);
layer.open(); resultsXML.Append("<feature>");
resultsXML.Append("<objectID>");
resultsXML.Append("<![CDATA[");
resultsXML.Append(shapeResult.getValue());
resultsXML.Append("]]>");
resultsXML.Append("</objectID>"); resultsXML.Append("<name>");
resultsXML.Append("<![CDATA[");
resultsXML.Append(shapeResult.getValue());
resultsXML.Append("]]>");
resultsXML.Append("</name>"); resultsXML.Append("<area>");
resultsXML.Append("<![CDATA[");
resultsXML.Append(shapeResult.getValue());
resultsXML.Append("]]>");
resultsXML.Append("</area>");
resultsXML.Append("</feature>");
}
layer.close();
resultsXML.Append("</map>");
Session.Remove("MapServer_MAP");
Session["MapServer_MAP"] = map;
responseXML = resultsXML.ToString();
System.Diagnostics.Debug.WriteLine(responseXML);
}
C#+MapServer相关代码的更多相关文章
- [ARM] Cortex-M Startup.s启动文件相关代码解释
1. 定义一个段名为CSTACK, 这里: NOROOT表示如何定义的段没有被关联,那么同意会被优化掉,如果不想被优化掉就使用ROOT. 后面的括号里数字表示如下: (1):这个段是2的1次方即2字节 ...
- Kafka Producer相关代码分析【转】
来源:https://www.zybuluo.com/jewes/note/63925 @jewes 2015-01-17 20:36 字数 1967 阅读 1093 Kafka Producer相关 ...
- 命令行方式使用abator.jar生成ibatis相关代码和sql语句xml文件
最近接手一个老项目,使用的是数据库是sql server 2008,框架是springmvc + spring + ibatis,老项目是使用abator插件生成的相关代码,现在需要增加新功能,要添加 ...
- myBatis自动生成相关代码文件配置(Maven)
pom.xml文件添加配置 <build> <finalName>generator</finalName> <plugins> <!-- mav ...
- 临时2级页表的初始化过程 head_32.S 相关代码解释
page_pde_offset = (__PAGE_OFFSET >> 20); /* __PAGE_OFFSET是0xc0000000,page_pde_offset = 3072 = ...
- 使用Mybatis Generator自动生成Mybatis相关代码
本文将简要介绍怎样利用Mybatis Generator自动生成Mybatis的相关代码: 一.构建一个环境: 1. 首先创建一个表: CREATE TABLE pet (name VARCHAR(2 ...
- K:树、二叉树与森林之间的转换及其相关代码实现
相关介绍: 二叉树是树的一种特殊形态,在二叉树中一个节点至多有左.右两个子节点,而在树中一个节点可以包含任意数目的子节点,对于森林,其是多棵树所组成的一个整体,树与树之间彼此相互独立,互不干扰,但其 ...
- js 横屏 竖屏 相关代码 与知识点
<!DOCTYPE html> <html> <head> <title></title> </head> <body&g ...
- 转:关于Latent Dirichlet Allocation及Hierarchical LDA模型的必读文章和相关代码
关于Latent Dirichlet Allocation及Hierarchical LDA模型的必读文章和相关代码 转: http://andyliuxs.iteye.com/blog/105174 ...
随机推荐
- ios实现fastlane自动化打包
终于抽出时间来学习自动化打包了,app在测试阶段一天总会经历好几次的打包,每次打包真是身心疲惫,刚打完的包说不定就被测试妹子反应还要微调什么地方,我就真的有气没法出,打一次包怎么也得浪费十几分钟,还不 ...
- js delete删除对象属性,delete删除不了变量及原型链中的变量
js delete删除对象属性,delete删除不了变量及原型链中的变量 一.delete删除对象属性 function fun(){ this.name = 'gg'; } var obj = ne ...
- (转)权威支持: 选择正确的 WebSphere 诊断工具
权威支持: 选择正确的 WebSphere 诊断工具 原文:https://www.ibm.com/developerworks/cn/websphere/techjournal/0807_supau ...
- Android六大基本布局
一.基本理论Android六大基本布局分别是:线性布局LinearLayout.表格布局TableLayout.相对布局RelativeLayout.层布局FrameLayout.绝对布局Absolu ...
- OkHttp3实现Cookies管理及持久化
转发自:http://www.codeceo.com/article/okhttp3-cookies-manage.html OKHttp3正式版刚发布了没几天,正好重构之前的代码,于是第一时间入坑了 ...
- tomcat 日志详解
1 tomcat 日志详解 1.1 tomcat 日志配置文件 tomcat 对应日志的配置文件:tomcat目录下的/conf/logging.properties. tomcat 的日志等级有 ...
- ABP实战--修改语言配置XML至Json
从ABP官网下载的Zero的多语言配置默认是使用XML文件的,实际使用中XML是没有Json简洁明了的,所以我们将其修改为Json格式. 修改MyLocalizationConfigurer.cs文件 ...
- DHCP协议原理及其实现流程
DHCP(Dynamic Host Configuration Protocol):动态主机配置协议 在常见的小型网络中(例如家庭网络和学生宿舍网),网络管理员都是采用手工分配IP地址的方法,而到了中 ...
- 【Xmail】使用Xmail搭建局域网邮件服务器
下载地址: http://www.xmailserver.org/xmail-1.27.win32bin.zip,当前最新版本 1.27. 解压文件:xmail-1.27.win32bin.zip ...
- golang基础--func函数
函数function Go函数不支持 嵌套, 重载和默认参数 支持以下特性: 无须声明原型,不定长度长度变参,多返回值,命名返回值参数,匿名函数,闭包 定义函数使用关键字func,且左侧大括号不能另起 ...