//放大的代码:
private void MapZoomIn(NameValueCollection queryString)
{
SharpMap.Map map = Session["map"] as SharpMap.Map;
PointF pointFLeftBottom = new PointF(float.Parse(queryString["Left"]), float.Parse(queryString["Bottom"]));
PointF pointFRightTop = new PointF(float.Parse(queryString["Right"]), float.Parse(queryString["Top"])); SharpMap.Geometries.BoundingBox zoomToBoundingBox = new SharpMap.Geometries.BoundingBox(map.ImageToWorld(pointFLeftBottom), map.ImageToWorld(pointFRightTop));
map.ZoomToBox(zoomToBoundingBox);
Session.Remove("map");
Session["map"] = map;
} //缩小的代码:
private void MapZoomOut(NameValueCollection queryString)
{
SharpMap.Map map = Session["map"] as SharpMap.Map;
PointF pointFLeftBottom = new PointF(float.Parse(queryString["Left"]), float.Parse(queryString["Bottom"]));
PointF pointFRightTop = new PointF(float.Parse(queryString["Right"]), float.Parse(queryString["Top"]));
SharpMap.Geometries.BoundingBox boundingBox = new SharpMap.Geometries.BoundingBox(map.ImageToWorld(pointFLeftBottom), map.ImageToWorld(pointFRightTop));
SharpMap.Geometries.Point mapCenterPoint = boundingBox.GetCentroid(); double ratio = 0.0;
double ratioX=boundingBox.Width / map.Envelope.Width;
double ratioY=boundingBox.Height / map.Envelope.Height;
if (ratioX > ratioY)
{
ratio = ratioX;
}
else
{
ratio = ratioY;
}
double semiWidth = map.Envelope.Width / ratio / ;
double semiHeight = map.Envelope.Height / ratio / ;
SharpMap.Geometries.BoundingBox zoomToBoundingBox = new SharpMap.Geometries.BoundingBox(mapCenterPoint.X - semiWidth, mapCenterPoint.Y - semiHeight, mapCenterPoint.X + semiWidth, mapCenterPoint.Y + semiHeight); map.ZoomToBox(zoomToBoundingBox);
Session.Remove("map");
Session["map"] = map; } //平移的代码:
private void MapPan(NameValueCollection queryString)
{
SharpMap.Map map = Session["map"] as SharpMap.Map;
PointF pointFFirst = new PointF(float.Parse(queryString["FirstX"]), float.Parse(queryString["FirstY"]));
PointF pointFSecond = new PointF(float.Parse(queryString["SecondX"]), float.Parse(queryString["SecondY"])); SharpMap.Geometries.Point firstPoint = map.ImageToWorld(pointFFirst);
SharpMap.Geometries.Point secondPoint = map.ImageToWorld(pointFSecond);
SharpMap.Geometries.Point mapCenterPoint = map.Center; SharpMap.Geometries.Point mapNewCenterPoint = new SharpMap.Geometries.Point(mapCenterPoint.X + firstPoint.X - secondPoint.X, mapCenterPoint.Y + firstPoint.Y - secondPoint.Y);
map.Center = mapNewCenterPoint; Session.Remove("map");
Session["map"] = map;
} //全图显示的代码:
private void MapFullExtent(NameValueCollection queryString)
{
SharpMap.Map map = Session["map"] as SharpMap.Map;
map.ZoomToExtents();
Session.Remove("map");
Session["map"] = map;
} //空间查询的代码:
private void MapQuery(NameValueCollection queryString)
{
SharpMap.Map map = Session["map"] as SharpMap.Map;
PointF pointFLeftBottom = new PointF(float.Parse(queryString["Left"]), float.Parse(queryString["Bottom"]));
PointF pointFRightTop = new PointF(float.Parse(queryString["Right"]), float.Parse(queryString["Top"]));
SharpMap.Geometries.BoundingBox boundingBox = new SharpMap.Geometries.BoundingBox(map.ImageToWorld(pointFLeftBottom), map.ImageToWorld(pointFRightTop));
SharpMap.Data.FeatureDataSet featureDataSet = new SharpMap.Data.FeatureDataSet(); ILayer pLayer = map.GetLayerByName(queryString["LayerName"]);
SharpMap.Layers.VectorLayer vectorLayer = pLayer as SharpMap.Layers.VectorLayer;
vectorLayer.DataSource.ExecuteIntersectionQuery(boundingBox, featureDataSet);
if (featureDataSet.Tables.Count > ) //得到了结果
{
//增加点击选择的对象到selection图层
//这样就新增了一个图层,因此渲染该副地图则显示选中对象
SharpMap.Layers.VectorLayer layerSelected = new SharpMap.Layers.VectorLayer("Selection");
layerSelected.DataSource = new SharpMap.Data.Providers.GeometryProvider(featureDataSet.Tables[]);
layerSelected.Style.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Yellow);
map.Layers.Add(layerSelected);
}
Session.Remove("map");
Session["map"] = map;
} //长度测量的代码:
private void MapMeasurePolyline(NameValueCollection queryString, out string responseXML)
{
SharpMap.Map map = Session["map"] as SharpMap.Map;
string pointsCoordinate = queryString["PointsCoordinate"];
string[] pointCoordinatePair = pointsCoordinate.Split(',');
SharpMap.Geometries.LineString lineStringMeasure = new SharpMap.Geometries.LineString(); for (int i = ; i < pointCoordinatePair.Length / ; i++)
{
PointF pointF=new PointF(Convert.ToSingle(pointCoordinatePair[i*]),Convert.ToSingle(pointCoordinatePair[i*+]));
SharpMap.Geometries.Point point = map.ImageToWorld(pointF);
lineStringMeasure.Vertices.Add(point);
} StringBuilder resultsXML = new StringBuilder("");
resultsXML.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
resultsXML.Append("<map>");
resultsXML.Append("<measure>"); resultsXML.Append("<长度>");
resultsXML.Append("<![CDATA[");
resultsXML.Append(lineStringMeasure.Length.ToString());
resultsXML.Append("]]>");
resultsXML.Append("</长度>"); resultsXML.Append("</measure>");
resultsXML.Append("</map>");
responseXML = resultsXML.ToString();
}

C#+SharpMap的相关代码的更多相关文章

  1. [ARM] Cortex-M Startup.s启动文件相关代码解释

    1. 定义一个段名为CSTACK, 这里: NOROOT表示如何定义的段没有被关联,那么同意会被优化掉,如果不想被优化掉就使用ROOT. 后面的括号里数字表示如下: (1):这个段是2的1次方即2字节 ...

  2. Kafka Producer相关代码分析【转】

    来源:https://www.zybuluo.com/jewes/note/63925 @jewes 2015-01-17 20:36 字数 1967 阅读 1093 Kafka Producer相关 ...

  3. 命令行方式使用abator.jar生成ibatis相关代码和sql语句xml文件

    最近接手一个老项目,使用的是数据库是sql server 2008,框架是springmvc + spring + ibatis,老项目是使用abator插件生成的相关代码,现在需要增加新功能,要添加 ...

  4. myBatis自动生成相关代码文件配置(Maven)

    pom.xml文件添加配置 <build> <finalName>generator</finalName> <plugins> <!-- mav ...

  5. 临时2级页表的初始化过程 head_32.S 相关代码解释

    page_pde_offset = (__PAGE_OFFSET >> 20); /* __PAGE_OFFSET是0xc0000000,page_pde_offset = 3072 = ...

  6. 使用Mybatis Generator自动生成Mybatis相关代码

    本文将简要介绍怎样利用Mybatis Generator自动生成Mybatis的相关代码: 一.构建一个环境: 1. 首先创建一个表: CREATE TABLE pet (name VARCHAR(2 ...

  7. K:树、二叉树与森林之间的转换及其相关代码实现

    相关介绍:  二叉树是树的一种特殊形态,在二叉树中一个节点至多有左.右两个子节点,而在树中一个节点可以包含任意数目的子节点,对于森林,其是多棵树所组成的一个整体,树与树之间彼此相互独立,互不干扰,但其 ...

  8. js 横屏 竖屏 相关代码 与知识点

    <!DOCTYPE html> <html> <head> <title></title> </head> <body&g ...

  9. 转:关于Latent Dirichlet Allocation及Hierarchical LDA模型的必读文章和相关代码

    关于Latent Dirichlet Allocation及Hierarchical LDA模型的必读文章和相关代码 转: http://andyliuxs.iteye.com/blog/105174 ...

随机推荐

  1. 【bzoj3028】 食物 生成函数+隔板法

    题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=3028 这题的推导很妙啊,裸的推母函数的题. 我们首先构造出每种食物的母函数: 汉堡:$ ...

  2. Git&GitHub学习日志

    Git是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的项目版本管理. Git是Linus Torvalds为了帮助管理Linux内核开发而开发的一个开放源码的版本控制软件.作为一个 ...

  3. vs2013 with update2安装记录

    1.安装之后,提示update2无法安装2.按照以下方法进行修复,提示无法安装的项更多了(1项变3项了) http://jingyan.baidu.com/article/6d704a13f34d10 ...

  4. UBUNTU下MONGODB出现PHP Fatal error: Uncaught exception 'MongoConnectionException' with message 和 Authentication failed on database 'admin' with username

    MONGO 远程连接服务器,出现: PHP Fatal error: Uncaught exception Stack trace:# /var/www/data/update_data.php(): ...

  5. Eclipse删除switch workspace下多余的workspace

    第一步:修改org.eclipse.ui.ide.prefs 文件 打开Eclipse目录的\configuration\.settings目录,找到org.eclipse.ui.ide.prefs ...

  6. Android 开发工具类 03_HttpUtils

    Http 请求的工具类: 1.异步的 Get 请求: 2.异步的 Post 请求: 3.Get 请求,获得返回数据: 4.向指定 URL 发送 POST方法的请求. import java.io.Bu ...

  7. mongodb 数据库备份脚本

    写了小shell bash, 用于给mongodb数据进行备份 #!/bin/bash #backup MongoDB #文件目录 #backup MongoDB #!/bin/bash #backu ...

  8. C#循环读取文件流,按行读取

    public Dictionary<string,string> GetSourceDisksElements(String section) { section = "[&qu ...

  9. sql典例分析

    1. 条件过滤 & Having 表结构 #tab_a #tab_b 表关系 tab_a.id = tab_b.relation_id 表数据 需求 查新把tab_a的ID对应的表tab_b的 ...

  10. java内存中的对象

    前记:几天前,在浏览网页时偶然的发现一道以前就看过很多遍的面试题,题目是:“请说出‘equals’和‘==’的区别”,当时我觉得我还是挺懂的,在心里答了一点(比如我们都知道的:‘==’比较两个引用是否 ...