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 ...
随机推荐
- (转)Linux Shell系列教程之(十四) Shell Select教程
本文属于<Linux Shell 系列教程>文章系列,该系列共包括以下 18 部分: Linux Shell系列教程之(一)Shell简介 Linux Shell系列教程之(二)第一个Sh ...
- EF基础知识小记七(拆分实体到多个表以及拆分表到多个实体)
一.拆分实体到多个表 1.在日常开发中,会经常碰到一些老系统,当客户提出一些新的需求,这些需求需要在原来的表的基础上加一些字段,大多数人会选择通过给原表添加字段的方式来完成这些需求,方法,虽然可行,但 ...
- Windows下如何正确下载并安装可视化的Redis数据库管理工具(redis-desktop-manager)(图文详解)
不多说,直接上干货! Redis Desktop Manager是一个可视化的Redis数据库管理工具,使用非常简单. 官网下载:https://redisdesktop.com/down ...
- excel将内容粘贴到筛选后的可见单元格
默认情况下,筛选后excel表格进行复制粘贴,会贴到隐藏的表格. 可以添加两个辅助列来完成操作:1.在筛选前在表格右边添加"辅助1"列,在第二行输入1,按Ctrl+鼠标左键往下拉到 ...
- Python中文分词 jieba
三种分词模式与一个参数 以下代码主要来自于jieba的github,你可以在github下载该源码 import jieba seg_list = jieba.cut("我来到北京清华大学& ...
- YAOLEI
http://www.cnblogs.com/skyblue/p/3356933.html
- Linux内存信息查看——free命令
free 命令可以显示系统已用和空闲的内存情况.包括物理内存.交互区内存(swap)和内核缓冲区内存(buffer).共享内存将被忽略.在Linux系统监控的工具中,free命令是最经常使用的命令之一 ...
- TCP三次握手/四次挥手
TCP 三次握手 TCP 连接是通过三次握手进行初始化的.三次握手的目的是同步连接双方的序列号和确认号并交换 TCP 窗口大小信息.以下步骤概述了通常情况下客户端计算机联系服务器计算机的过程: 1. ...
- in运算符
//in运算符(用来判断一个属性是否在对象里面)var obj={"username":"hh"};console.log("username&quo ...
- c#基础学习(0701)之一些简单的方法练习
一个简单的求数组最大值的方法 //可变参数 int max=GetMaxNumbers(101,30) static int GetMaxNumbers(params int[] pms) { ]; ...