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. [UML]UML系列——包图Package

    系列文章 [UML]UML系列——用例图Use Case       [UML]UML系列——用例图中的各种关系(include.extend)       [UML]UML系列——类图Class   ...

  2. MVC5与EF6 Code First 第一个入门完整实例教程

    mvc如今火的不行,我今天就来介绍一个MVC5与EF6开发的实际的入门实例,因为EF6默认是Code First的,所以我今天也就用EF6 的Code First来做一个简单的实例,为了让实例显得简单 ...

  3. Cacti安装详细步骤

    原文链接: https://www.centos.bz/2012/01/cacti-install-tutorials/ Cacti-监控MySQL: http://www.cszhi.com/201 ...

  4. UI5_UINavigation传值

    // // AppDelegate.m // UI5_UINavigation传值 // // Created by zhangxueming on 15/7/7. // Copyright (c) ...

  5. 8 Things Every Person Should Do Before 8 A.M.

    https://medium.com/@benjaminhardy/8-things-every-person-should-do-before-8-a-m-cc0233e15c8d 1. Get A ...

  6. Maven详解(五)------ 坐标的概念以及依赖管理

    我们知道maven能帮我们管理jar包,那么它是怎么管理的呢?这篇博客我们来详细介绍. 1.什么是坐标? ①.数学中的坐标 在平面上,使用 X .Y 两个向量可以唯一的定位平面中的任何一个点 在空间中 ...

  7. mysql ssh 端口转发

    某些时候 mysql  只允许 指定的 ip连接 .这时候怎么在本机 连接mysql 的呢? 条件 1 mysql 只有 允许 指定ip连接 2 有连接 指定 ip 服务器的  账密 这时候我们可以通 ...

  8. Memory leak by misusing Autofac

    Recently I’ve found out that we can easily cause a memory leaks in our .net application by improper ...

  9. centos7 minimal connect: Network is unreachable(转)

    新装的centos7,果然是很崭新啊. 装好之后打算看一下局域网的地址,然后就ip addr(centos 7 已经去掉了ifconfig这个命令).并没有显示局域网的ip地址. 然后我尝试ping ...

  10. YTU 2832: 使用指针访问数组元素--程序填空

    2832: 使用指针访问数组元素--程序填空 时间限制: 1 Sec  内存限制: 128 MB 提交: 328  解决: 160 题目描述 输入10个整数值到数组中,使用指针来完成对这10个数组元素 ...