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. 属性检测 In,hasOwnPreperty()和propertyIsEnumerable()

    IN  左侧是属性名:右侧是对象名, 如果 属性是 自有属性 或者继承属性 则返回 TRUE var o={x:1,y:2} "x" in  o    返回 true: hasOw ...

  2. Spring_通过注解配置 Bean(2)

  3. 2017 湘潭邀请赛&JSCPC G&J

    训练的时候对G想了一个假算法..也有很大可能是写错了.. 下来一看别人的G 看起来很奇妙.. 开始把所有的左括号翻成右括号,然后cost*=-1 这样在优先队列中就是最优的 然后for每一段 如果前缀 ...

  4. Permutations,全排列

    问题描述:给定一个数组,数字中数字不重复,求所有全排列. 算法分析:可以用交换递归法,也可以用插入法. 递归法:例如,123,先把1和1交换,然后递归全排列2和3,然后再把1和1换回来.1和2交换,全 ...

  5. JSP web.xml <jsp-config>标签使用详解

    <jsp-config> 包括 <taglib> 和 <jsp-property-group> 两个子元素.其中<taglib> 元素在JSP 1.2  ...

  6. java中HashMap、HashTable、TreeMap的区别总结【表格对比清楚明了】

      底层 有序否 键值对能否为Null 遍历 线程安全 哈希Code Hashmap 数组+链表 无序 都可null iterator 不安全 内部hash方法 Hashtable 数组+链表 无序 ...

  7. freemarker报 java.io.FileNotFoundException:及TemplateLoader使用

    使用过freemarker的肯定其见过如下情况: java.io.FileNotFoundException: Template xxx.ftl not found. 模板找不到.可能你会认为我明明指 ...

  8. smarty语法

    HTML中直接显示数据 <{$data}> foreach循环 <{foreach from=$data item=item key=key}> <li data-ind ...

  9. 【Python】unicode' object is not callable

    在Python中,出现'unicode' object is not callable的错误一般是把字符串当做函数使用了.

  10. Nginx 常用配置模板

    user root root; worker_processes auto; worker_rlimit_nofile 51200; events { use epoll; worker_connec ...