ArcObjects Library Reference  

Form1

About the Find near features SOAP SOE Sample

[C#]

Form1.cs

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 FindNearFeaturesSOAPClient.localhost;

namespace FindNearFeaturesSOAPClient
{
    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_FindNearFeaturesSoapSOE nearFeatsService = new USA_FindNearFeaturesSoapSOE();
                nearFeatsService.Url = "http://localhost/ArcGIS/services/USA/MapServer/FindNearFeaturesSoapSOE";


                //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");
        }
    }
}

[Visual Basic .NET]

Form1.vb

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports FindNearFeaturesSOAPClient_VBNet.localhost

Namespace FindNearFeaturesSOAPClient_VBNet
    Partial Public Class Form1
        Inherits Form
        Public Sub New()
            InitializeComponent()
        End Sub

        Private Function GetProperty(ByVal props As PropertySet, ByVal key As String) As Object
            For Each prop As PropertySetProperty In props.PropertyArray
                If String.Compare(prop.Key, key, True) = 0 Then
                    Return prop.Value
                End If
            Next prop
            Return Nothing
        End Function

        Private Sub GetCenterPointAndDistance(ByVal extent As EnvelopeN, <System.Runtime.InteropServices.Out()> ByRef center As PointN, <System.Runtime.InteropServices.Out()> ByRef distance As Double)
            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
        End Sub

        Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
            Try
                'create instance of proxy
                Dim nearFeatsService As New USA_FindNearFeaturesSoapSOE_VBNet()
                nearFeatsService.Url = "http://localhost/ArcGIS/services/USA/MapServer/FindNearFeaturesSoapSOE_VBNet"


                'getLayerInfos
                Dim layerInfos() As CustomLayerInfo_VBNet = nearFeatsService.GetLayerInfos()

                For Each layerInfo As CustomLayerInfo_VBNet In layerInfos
                    Dim extent As EnvelopeN = CType(layerInfo.Extent, EnvelopeN)

                    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))
                Next layerInfo


                'findNearFeatures
                Dim aLayerInfo As CustomLayerInfo_VBNet = layerInfos(0)

                Dim location As PointN
                Dim distance As Double
                GetCenterPointAndDistance(CType(aLayerInfo.Extent, EnvelopeN), location, distance)

                Dim feats As RecordSet = nearFeatsService.FindNearFeatures(aLayerInfo.ID, location, distance)

                For Each record As Record In feats.Records
                    For Each o As Object In record.Values
                        If o IsNot Nothing Then
                            debug(o.ToString() & ", ")
                        End If
                    Next o
                    debug(Constants.vbLf)
                Next record

            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub

        Private Sub debug(ByVal info As String)
            richTextBox1.AppendText(info & Constants.vbLf)
        End Sub
    End Class
End Namespace