FindNearFeaturesSoapClient\Form1.cs
// Copyright 2012 ESRI // // All rights reserved under the copyright laws of the United States // and applicable international laws, treaties, and conventions. // // You may freely redistribute and use this sample code, with or // without modification, provided you include the original copyright // notice and use restrictions. // // See the use restrictions. // // Copyright 2012 ESRI // // All rights reserved under the copyright laws of the United States // and applicable international laws, treaties, and conventions. // // You may freely redistribute and use this sample code, with or // without modification, provided you include the original copyright // notice and use restrictions. // // See the use restrictions at <your ArcGIS install location>/DeveloperKit10.1/userestrictions.txt. // using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using NetFindNearFeaturesSOAPClient.localhost; namespace NetFindNearFeaturesSOAPClient { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private object GetProperty(PropertySet props, string key) { foreach (PropertySetProperty prop in props.PropertyArray) { if (string.Compare(prop.Key, key, true) == 0) return prop.Value; } return null; } private void GetCenterPointAndDistance(EnvelopeN extent, out PointN center, out double distance) { center = new PointN(); center.SpatialReference = extent.SpatialReference; center.X = extent.XMin + (Math.Abs(extent.XMax - extent.XMin) / 2); center.Y = extent.YMin + (Math.Abs(extent.YMax - extent.YMin) / 2); distance = Math.Abs(extent.XMax - extent.XMin) / 10; } private void button1_Click(object sender, EventArgs e) { try { //create instance of proxy USA_NetFindNearFeaturesSoapSOE nearFeatsService = new USA_NetFindNearFeaturesSoapSOE(); nearFeatsService.Url = "http://localhost:6080/arcgis/services/USA/MapServer/NetFindNearFeaturesSoapSOE"; //getLayerInfos CustomLayerInfo[] layerInfos = nearFeatsService.GetLayerInfos(); foreach (CustomLayerInfo layerInfo in layerInfos) { EnvelopeN extent = (EnvelopeN)layerInfo.Extent; debug( string.Format("Layer {0} has ID: {1} and extent: {2},{3},{4},{5}", layerInfo.Name, layerInfo.ID, extent.XMin, extent.YMin, extent.XMax, extent.YMax)); } //findNearFeatures CustomLayerInfo aLayerInfo = layerInfos[0]; PointN location; double distance; GetCenterPointAndDistance((EnvelopeN)aLayerInfo.Extent, out location, out distance); RecordSet feats = nearFeatsService.FindNearFeatures(aLayerInfo.ID, location, distance); foreach (Record record in feats.Records) { foreach (object o in record.Values) if (o != null) debug(o.ToString() + ", "); debug("\n"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void debug(string info) { richTextBox1.AppendText(info + "\n"); } } }