bu不多说,上代码

using System.Windows;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Tasks;
using ESRI.ArcGIS.Client.Local;
using System;
using System.Windows.Input;
using ESRI.ArcGIS.Client.Geometry;
using ESRI.ArcGIS.Client.Symbols;
using System.Collections.Generic; namespace ArcGISWpfApplication2
{ public partial class MainWindow : Window
{
GeometryService gMeasureLength,gMeasureArea;
Draw drawMeasure;
public MainWindow()
{
// License setting and ArcGIS Runtime initialization is done in Application.xaml.cs. InitializeComponent();
GraphicsLayer gLayer = new GraphicsLayer();
gLayer.ID = "MyGraphicsLayerMeasure";
Map.Layers.Add(gLayer);
//Map.Layers.Insert(0, gLayer);//这样不行,arcgis runtime加载图层与arcgis mapinfo方式相反,索引大的在上面
LocalGeometryServiceInit();
} void LocalGeometryServiceInit()
{
LocalGeometryService.GetServiceAsync(localGeometryService =>
{
gMeasureLength = new GeometryService();
gMeasureLength.Url = localGeometryService.UrlGeometryService;
gMeasureLength.LengthsCompleted += gMeasureLength_LengthsCompleted;
gMeasureLength.Failed += gMeasureLength_Failed;
}); LocalGeometryService.GetServiceAsync(localGeometryService =>
{
gMeasureArea = new GeometryService();
gMeasureArea.Url = localGeometryService.UrlGeometryService;
gMeasureArea.AreasAndLengthsCompleted += gMeasureArea_AreasAndLengthsCompleted;
gMeasureArea.Failed += gMeasureLength_Failed;
});
} void gMeasureArea_AreasAndLengthsCompleted(object sender, AreasAndLengthsEventArgs e)
{
double _Lengths = e.Results.Lengths[];
double _Area = e.Results.Areas[];
MessageBox.Show(String.Format("多边形周长为{0},面积为{1}",Math.Round(_Lengths,),Math.Round(_Area,)));
} void gMeasureLength_Failed(object sender, TaskFailedEventArgs e)
{
MessageBox.Show("测量失败");
} void gMeasureLength_LengthsCompleted(object sender, LengthsEventArgs e)
{
MessageBox.Show(String.Format("折线的长度:{0} 公里", Math.Round(e.Results[], )));
Map.Cursor = Cursors.Hand;
} private void MeasureLine(object sender, RoutedEventArgs e)
{
GraphicsLayer _GraphicsLayer = Map.Layers["MyGraphicsLayerMeasure"] as GraphicsLayer;
_GraphicsLayer.ClearGraphics();
drawMeasure = new Draw(Map)
{
DrawMode = DrawMode.Polyline,
IsEnabled = true,
//LineSymbol = Root.Resources["SelectLineSymbol"] as LineSymbol
}; drawMeasure.DrawBegin +=drawMeasure_DrawBegin;
drawMeasure.DrawComplete +=drawMeasure_DrawDistanceComplete;
} void drawMeasure_DrawDistanceComplete(object sender, DrawEventArgs e)
{
Polyline _Polyline = e.Geometry as Polyline;
_Polyline.SpatialReference = Map.SpatialReference;
Graphic _Graphic = new Graphic()
{
Symbol = Resources["CompleteLineSymbol"] as Symbol,//不自定义的话默认的是透明的,不然测量完看不到线
Geometry = _Polyline
}; GraphicsLayer _GraphicsLayer = Map.Layers["MyGraphicsLayerMeasure"] as GraphicsLayer;
_GraphicsLayer.Graphics.Add(_Graphic); //开始计算长度
gMeasureLength.LengthsAsync(_GraphicsLayer.Graphics, LinearUnit.Kilometer, CalculationType.Geodesic, null);
drawMeasure.DrawMode = DrawMode.None; } void drawMeasure_DrawBegin(object sender, EventArgs e)
{
Map.Cursor=Cursors.Arrow;
}
//MeasureAreaLength
private void MeasureAreaLength(object sender, RoutedEventArgs e)
{
GraphicsLayer _GraphicsLayer = Map.Layers["MyGraphicsLayerMeasure"] as GraphicsLayer;
_GraphicsLayer.ClearGraphics();
drawMeasure = new Draw(Map)
{
DrawMode = DrawMode.Polygon,
IsEnabled = true,
//LineSymbol = Root.Resources["SelectLineSymbol"] as LineSymbol
}; drawMeasure.DrawBegin += drawMeasure_DrawBegin;
drawMeasure.DrawComplete += drawMeasure_DrawAreaLengthComplete;
} private void drawMeasure_DrawAreaLengthComplete(object sender, DrawEventArgs e)
{
Polygon _Polygon = e.Geometry as Polygon;
_Polygon.SpatialReference = Map.SpatialReference;
Graphic _Graphic = new Graphic() {
Symbol = Resources["CompletePolygonSymbol"] as Symbol,
Geometry = _Polygon
};
GraphicsLayer _GraphicsLayer = Map.Layers["MyGraphicsLayerMeasure"] as GraphicsLayer;
_GraphicsLayer.Graphics.Add(_Graphic);
List<Graphic> _GraphicList = new List<Graphic>();
_GraphicList.Add(_Graphic);
gMeasureArea.AreasAndLengthsAsync(_GraphicList,AreaUnit.SquareKilometers);
} }
}
<Window x:Class="ArcGISWpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<esri:SimpleLineSymbol x:Key="CompleteLineSymbol" Color="Green" Width="4" />
<esri:SimpleFillSymbol x:Key="CompletePolygonSymbol" Fill="Green" BorderBrush="LightBlue" BorderThickness="1" />
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Border Background="#ccc">
<StackPanel Orientation="Horizontal">
<Button Height="30" Width="100" Click="MeasureLine">测距</Button>
<Button Height="30" Width="100" Click="MeasureAreaLength">测面积</Button>
</StackPanel>
</Border>
<esri:Map x:Name="Map" Grid.Row="1" Background="White" Cursor="Hand" Extent="-20014711, 15, 1656956, 12175318">
<esri:ArcGISTiledMapServiceLayer ID="BaseLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
<!--<esri:GpsLayer x:Name="MyGpsLayer" />-->
</esri:Map>
</Grid>
</Window>

ArcGIS Runtime SDK for WPF之测量距离和面积的更多相关文章

  1. ArcGIS Runtime SDK for WPF已不更新,后续将被ArcGIS Runtime SDK for .NET取代

    ArcGIS Runtime SDK 10.2.5 for WPF is now available! by mbranscomb and Rex Hansen on January 27, 2015 ...

  2. ArcGIS runtime sdk for wpf 授权

    这两天由于runtime sdk for wpf的授权和runtime sdk 其他产品的授权的不一样导致自己混乱不堪. 总结下吧. sdk 简介 当前ArcGIS runtime sdk 包括一系列 ...

  3. ArcGIS Runtime SDK for WPF之SimpleRenderer无法添加、报错“图形符号无法序列化为 JSON”

    ArcGIS Runtime SDK for WPF之SimpleRenderer无法添加.报错“图形符号无法序列化为 JSON” 在上一篇博文中如果在 esri:Map 里面是否设置了的UseAcc ...

  4. ArcGIS Runtime SDK for WPF 初始化

    安装包 管理nuget包 Esri.ArcGISRuntime.WPF 也许还需要 Esri.ArcGISRuntime.Hydrography Esri.ArcGISRuntime.LocalSer ...

  5. ArcGIS Runtime SDK for WPF学习笔记(一)

    本节主要讲解如何安装ArcGIS Runtime SDK,以及移除注释与水印. 附上ArcGIS Runtime SDK for .NET的官方操作手册网址:https://developers.ar ...

  6. Arcgis for Js之GeometryService实现测量距离和面积

    距离和面积的测量时GIS常见的功能,在本节,讲述的是通过GeometryService实现测量面积和距离.先看看实现后的效果:                                  距离 ...

  7. (转)Arcgis for Js之GeometryService实现测量距离和面积

    http://blog.csdn.net/gisshixisheng/article/details/40540601 距离和面积的测量时GIS常见的功能,在本节,讲述的是通过GeometryServ ...

  8. 《ArcGIS Runtime SDK for Android开发笔记》——(3)、ArcGIS Runtime SDK概述

    1.前言 ArcGIS Runtime SDK是一整套用于构建原生及跨平台的地图应用程序的开发包,包括移动设备的Android.iOS.Windows Phone,针对桌面的.Net.Java.OSX ...

  9. Arcgis runtime sdk .net 二次开发

    前段时间研究了下 arcgis runtime sdk .net 二次开发··这里做个笔记 runtime版本为100.6 基于WPF 开发 命名空间引入 xmlns:esri="http: ...

随机推荐

  1. WPF MVVM模式下ComboBox级联效果 选择第一项

    MVVM模式下做的省市区的级联效果.通过改变ComboBox执行命令改变市,区. 解决主要问题就是默认选中第一项 1.首先要定义一个属性,继承自INotifyPropertyChanged接口.我这里 ...

  2. Maven的Mirror和Repository

    今天新公司入职,项目经理让迁出项目,心想maven的阿里镜像源挺快的,干脆在配置了公司私服之后自己配置了阿里的镜像源,没成想项目屡屡报错,找不到项目依赖的公司jar包,后来才发现,同事配置mirror ...

  3. Zabbix 自定义Key

    系统:Linux Centos 7.4 x64.Windos 2008 x64 服务:Zabbix 3.0.16 说明1:自定义Key 主要通过自定义 脚本 或者 命令 来实现自定义监控类型,需要在a ...

  4. Linux系统基本的内存管理知识讲解

    内存是Linux内核所管理的最重要的资源之一.内存管理系统是操作系统中最为重要的部分,因为系统的物理内存总是少于系统所需要的内存数量.虚拟内存就是为了克服这个矛盾而采用的策略.系统的虚拟内存通过在各个 ...

  5. OSTU二值化算法

    介绍 Ostu方法又名最大类间差方法,通过统计整个图像的直方图特性来实现全局阈值T的自动选取,其算法步骤为: 1) 先计算图像的直方图,即将图像所有的像素点按照0~255共256个bin,统计落在每个 ...

  6. Hibernate的一级缓存、二级缓存和查询缓存。

    Hibernate的Session提供了一级缓存的功能,默认总是有效的,当应用程序保存持久化实体.修改持久化实体时,Session并不会立即把这种改变提交到数据库,而是缓存在当前的Session中,除 ...

  7. nginx+tomcat网页动静分离配置

    1.环境描述 nginx server (Proxy):192.168.1.135(作为代理服务器)WEB server1: 192.168.1.138(使用tomcat作为web容器)WEB ser ...

  8. IDEA 修改JSP和后端数据后,页面刷新可以实时更新

    情况:刚开始使用IDEA进行开发时,发现修改JSP页面或者后端数据后,再刷新浏览器页面,发现没有变化,页面无更新. 这样就导致不得不频繁重启tomcat服务器.非常麻烦 解决方法: 步骤1. 先设置t ...

  9. Java值传递还是引用传递?

    回顾: 在程序设计语言中,将参数传递分为按值调用和按引用调用.按值调用:表示方法接收的是调用者提供的值.而按引用调用表示方法接收的是调用者提供的变量地址.一个方法可以修改传递引用所对应的变量值,而不能 ...

  10. php模拟发送GET和POST请求

    php分别模拟发送GET和POST请求,非常实用的额,也可作PHP CURL入门级的理解教材的,示例代码如下: <?php /* ** php分别模拟发送GET与POST请求 ** */ fun ...