Sunday, July 24, 2011

Single-line batch geocoding with ArcGIS Server 10 geocode services

ArcGIS Server 10 rolled out support for single-line geocoding via Web services, which made it easier to provide a simple, search-engine experience when locating an address. While support for single-line geocoding was included with the REST and SOAP APIs, there remained some differences in functionality. For example, REST does not currently provide an operation that supports batching multiple address inputs in a single request. SOAP supports batching via the GeocodeAddresses operation, but it appears to only support multi-line addresses. In fact, batching multiple single-line address inputs is possible through a "hidden" feature. Simply associate the single-line text with the first address input field. For example, in the North American geocode service hosted by ArcGIS Online, the first address input field is named "Address". The GeocodeAddresses operation needs an address table and address input field mapping. The address input field mapping merely references the first address input field, in this example "Address". The address table includes a field that maps to "Address", and the field values contain the single-line address input text. Here's an example in .NET that uses the precompiled ArcGIS SOAP library available with the ArcGIS SOAP SDK:

GeocodeServerProxy geocodeservice = new GeocodeServerProxy();

geocodeservice.Url =

    "http://tasks.arcgisonline.com/ArcGIS/services/Locators/TA_Address_NA_10/GeocodeServer";

 

// Address input field mapping

PropertySetProperty[] propArray = {

    new PropertySetProperty(){

            Key = "Address",

            Value = "Address"

    }

};

 

PropertySet geocodePropSet = new PropertySet()

{

    PropertyArray = propArray

};           

 

// Address input fields

Field[] fieldarray = {          

    new Field()

    {

        Name = "OID",

        Type = esriFieldType.esriFieldTypeOID,

        Length = 10

    },

    new Field()

    {

        Name = "Address",

        Type = esriFieldType.esriFieldTypeString,

        Length = 100

    }

};

 

// Address inputs

int i = 0;

Record[] addressInputs = {

    new Record(){

        Values = new object[] {i++, "6525 N 15th Avenue Phoenix AZ"}

    },new Record(){

        Values = new object[] {i++, "14756 N 27th ave Seattle"}

    },new Record(){

        Values = new object[] {i++, "455 Orange Show Ln, San Bernardino, CA"}

    },new Record(){

        Values = new object[] {i++, "1514 Redwing Dr, Evansville"}

    }

};

 

RecordSet addressTable = new RecordSet()

{

        Fields = new Fields() { FieldArray = fieldarray },

        Records = addressInputs

};

 

RecordSet results = geocodeservice.GeocodeAddresses(addressTable, geocodePropSet, null);

 

Note that the suggested batch size of this service is 10, which will limit the number of inputs you can include in one request. And of course you'll want to peruse the terms of use. Links to information on the ArcGIS Server 10 geocode services hosted by ArcGIS Online are available below:

North American Address Locator
United States Street Locator

Sunday, April 10, 2011

Get current user info in a Server Object Extension

Server Object Extensions (SOEs) give developers the ability to utilize the extensive geoanalytical capabilities of ArcObjects within an ArcGIS Server service. They also provide a framework that enables access to custom functionality in a service through the standard Web service protocols SOAP and REST. Enabling Web access to an SOE is well documented in the ArcObjects SDK.

ArcGIS Server Web services can also be secured using token or Web server authentication methods. Since SOEs are can be enabled on a specific service, authentication rules configured on a service apply to all of its extensions, including custom SOEs. This poses the question: if an SOE is enabled on a secured Web service, can the authenticated user be retrieved within the SOE? Yes, in ArcGIS Server 10 this is possible.

Use the C# code provided below as an example. Basically, within your SOE code get the current server environment and cast to IServerEnvironment2 to gain access to UserInfo. If authentication is enabled for ArcGIS Server Web services, each request to a service will be associated with an authenticated user. UserInfo will contain the user name and roles within which that user is present for the current request. Note, when Web server authentication is based on Windows users and groups, the user name is in the format domain\user.



Unfortunately, REST SOE's hosted on ArcGIS Server for .NET require ArcGIS Server 10 service pack 2 for this to function. ArcGIS Server 10 service pack 2 will be available for download on the ArcGIS Resource Center soon.