BrainDump
  Home arrow BrainDump arrow Page 2 - Working with Data with the MapPoint Web Se...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

Working with Data with the MapPoint Web Service Find APIs
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-02-14

    Table of Contents:
  • Working with Data with the MapPoint Web Service Find APIs
  • Querying for Geographic Extent for a Data Source
  • Working with Find Methods
  • Finding more default matches

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Working with Data with the MapPoint Web Service Find APIs - Querying for Geographic Extent for a Data Source


    (Page 2 of 4 )

    Now that you know how the country/region information is organized in MapPoint Web Service, let’s look at how to get a list of countries supported by different data sources.

    The geographic extent of the countries supported by a particular data source is defined using theEntityExtentfield of theDataSourceobject. TheDataSource.EntityExtentfield is an array of integers that represent the corresponding country entity IDs. The following code snippet shows how to get the geographic extent of the data sourceMapPoint.NA:

      //Create Common Service SOAP Class instance
      CommonServiceSoap commonsoap = new CommonServiceSoap();
      //Assign credentials
      . . .

      //Get Data Source Info for MapPoint.NA
      DataSource[] datasources =
              commonsoap.GetDataSourceInfo(new string[] {"MapPoint.NA"});
      //Get entity extent
      int[] extents = datasources[0].
    EntityExtent;

    The geographic extent is expressed using the country/region entity IDs discussed in the previous section. To get the name of the country that each entity ID corresponds to, call the CommonServiceSoap.GetCountryRegionInfo method.

    Programmatically Mapping a Country/Region to a Data Source

    So far, I have shown how to get supported countries given a MapPoint Web Service data source. A common application scenario would be the other way around: choosing an appropriate data source for a given country. To programmatically map a country/region to a data source, you need to identify the task for which you need the data source, deciding whether you want a data source to find a place, find an address, calculate a route, or render a map. You can use the DataSourceCapabilityenumeration discussed in Chapter 5. Once you have theDataSourceCapabilityfigured out, you can get an appropriate MapPoint Web Service data source name using the following code:

      private string[] GetDataSources(string countryRegionName,
                DataSourceCapability capability)
      {
         if(countryRegionName == null || countryRegionName.Length <= 0)
           throw new Exception(
             "Invalid country/region name; country/region
                 name cannot be null or empty.");

      ArrayList datasourceList = new ArrayList();

      //Now loop through the list of data sources and
     
    //see what data source fits the purpose
     
    foreach(DataSource datasource in datasources)
     
    {
        
    if(((int)datasource.Capability & (int)capability) != 0)
        
    {
           
    //OK, this data source has the capability, but does it support the
           
    //entity extent (the country that we need a data source for?)
           
    int[] entityextent = datasource.EntityExtent;
            //Now loop through each entity extent and compare the input name
            foreach(int entityid in entityextent)
           
    {
             
    //Now look up using the entity id to see if the input
             
    //country/region name matches any entity extent
             
    //in this case I'm country region information
             
    //cached in a Hastable
             
    if(this.countryRegionsTable[entityid] as string
                    
    == countryRegionName.Trim())
               {
                
    //Found a match for both requirements
                
    //Return the name
                  
    datasourceList.Add(datasource.Name);
                  break;
               }
             }
          }
        }
        if(datasourceList.Count <= 0)
          throw new Exception(
             "No data source found to match your needs for this country.");

        //Return a sorted list
       
    datasourceList.Sort();

        return datasourceList.ToArray(typeof(String)) as string[];
      }

    The previous function returns an array of suitable MapPoint Web Service data source names. ThecountryRegionsTableis aHashtable containing cached country/region information indexed on the entity IDs. Thealgorithmused in this function is pretty simple: first, find a data source with matching capability, and then get the geographic extent for that data source and see whether there is a match with the input country/region name. You can also find the code for this function, along with other functionalities discussed in this section, in the Chapter 6 solutions on the companion material.

    With this introduction to find methods, entity types, and data source relationships, let’s look at how to perform various spatial queries using Find Service.

    More BrainDump Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Programming MapPoint in .NET," published...
     

    Buy this book now. This article is excerpted from chapter six of the book Programming MapPoint in .NET, written by Chandu Thota (O'Reilly; ISBN: 0596009062). Check it out today at your favorite bookstore. Buy this book now.

    BRAINDUMP ARTICLES

    - Introduction to Office Live Workspace
    - Using MS Excel for One-way Analysis of Varia...
    - Comparing Data Sets Using Statistical Analys...
    - Import Blogger Posts into WordPress Using Wi...
    - Download WordPress from an FTP Server and Ru...
    - Install and Run WordPress in XAMPP Local Host
    - What Windows 7 Brings to the Table
    - Virtualization and Sandbox Detection
    - Advanced Firebug Techniques in Windows XP Ho...
    - Editing CSS with Firebug in Windows XP Home
    - Using Firebug in Windows XP Home
    - Migrating to Exchange Server 2007
    - Using System Restore on a Non-Bootable PC
    - Finding Logged on Users and More Scripting S...
    - Developing Macro Commands in MS Excel





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek