BrainDump
  Home arrow BrainDump arrow Page 3 - Finding Entities with the MapPoint Web Ser...
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

Finding Entities 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-28

    Table of Contents:
  • Finding Entities with the MapPoint Web Service Find APIs
  • Finding entity by properties
  • Finding Polygons
  • Getting Entities from Latitude/Longitude

  • 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


    Finding Entities with the MapPoint Web Service Find APIs - Finding Polygons


    (Page 3 of 4 )

    With the find methods, you have seen how to find places, addresses, and points around a place or address, but all you have been finding so far are points (latitude and longitude coordinates). You may have a requirement to find polygons in situations with queries such as: “find all polygons that contain a point (latitude/longitude)” or “find all polygons that have spatial relationship with a rectangle.” In order to accomplish such tasks, use the FindServiceSoap.FindPolygon method.

    To learn more about polygons, refer to Appendix B.

    Like any find method in Find Service, theFindPolygonmethod takes theFindPolygonSpecificationobject as an argument and returns a validFindResultsobject. TheFindPolygonSpecificationobject provides a way for you to specify arguments such as data source name and spatial filter. Table 6-8 shows the fields exposed by theFindPolygonSpecificationclass.

    Table 6-8. Fields of the FindPolygonSpecification class

    Field Description
    DataSourceName Name of the data source as a string
    Filter The filter (FindFilterobject) to apply to the results, including the specific entity type, properties, and values that the returned results must match
    Options The search options (FindOptionsobject), which may include the range of results and a flag to identify which objects are desired in the returned results
    SpatialFilter The spatial filter (SpatialFilterobject) to apply to the results

    One interesting field from Table 6-8 is theSpatialFilter field; this field is of typeSpatialFilterclass, and it defines the spatial relationship between polygons, points, and rectangles. TheSpatialFilterclass is an abstract class, and there are two classes that derive this abstract class to define two specific spatial relationships:

    LatLongSpatialFilter

    Defines a spatial filter that returns only polygons that include the point specified by theLatLongobject. This is used in specifying a spatial filter to find polygons that contain a certain point. This class has only one field that takes the target point as aLatLongobject. The following code shows how to specify aLatLongSpatialFilterto find polygons that contain a given set of latitude and longitude coordinates:

      //Create a new instance of LatLongSpatialFilter
      LatLongSpatialFilter filter = new LatLongSpatialFilter();
      //Assign the given latitude and longitude values
      Filter.LatLong = new LatLong();
      Filter.LatLong.Latitude = 47.44;
      Filter.LatLong.Longitude = -122.55;

    LatLongRectangleSpatialFilter

    Defines a spatial filter that returns polygons related to theLatLongRectanglespecified via theBoundingRectanglefield. The relation between the polygons and the rectangle is determined by thePolygonRectangleRelationfield. This field is of typeSpatialRelationenumeration and has two values that are shown in Table 6-10. TheLatLongRectangleSpatialFilterclass is used in defining a spatial filter to find polygons that fall within or touch a rectangle. The following code shows how to define this spatial filter to find all polygons that fall within a rectangle:

      //Define a new instance of LatLongRectanglSpatialFilter
      LatLongRectangleSpatialFilter rectangleFilter =
            new LatLongRectangleSpatialFilter();

      //Define a bounding rectangle with north east and south west
      //corners
      LatLongRectangle boundingRectangle = new LatLongRectangle();
      boundingRectangle.Northeast = new LatLong();
      boundingRectangle.Northeast.Latitude = 47.44;
      boundingRectangle.Northeast.Latitude =
    -122.56;

      boundingRectangle.Southwest = new LatLong();
      boundingRectangle.Southwest.Latitude = 41.44;
      boundingRectangle.Southwest.Latitude =
    -119.56;

      //Now assign bounding rectangle to the filter
      rectangleFilter.BoundingRectangle = boundingRectangle;
      //Define the spatial relationship to be
      //"find polygons inside the rectangle"
      rectangleFilter.PolygonRectangleRelation =
                     SpatialRelation.WithinArea;

    Now that you know how to define spatial filters, let’s look at theFindPolygonmethod in action, using the relations shown in Table 6-9.

    Table 6-9. SpatialRelation enumeration

    Item Description
    WithinArea Returns all polygons contained entirely within the specified rectangle
    TouchesArea Returns all polygons that come into contact with the specified rectangle

    Use theFindPolygonmethod to findPolygonsthat either contain a specified point or are spatially related to a rectangle. Theymethod takes theFindPolygonSpecificationobject as an argument, as shown in the following code:

      //Create an instance of FindServiceSoap and assign
      //Credentials
      FindServiceSoap findService
                       
    = new FindserviceSoap();
      //Assign your credentials
      . . .

      //Create an instance of FindPlygonSpecification
      FindPolygonSpecification findPolySpec
               = new FindPolygonSpecification();

      //Create a new instance of LatLongSpatialFilter
      LatLongSpatialFilter filter = new LatLongSpatialFilter();
      //Assign the given latitude and longitude values
      Filter.LatLong = new LatLong();
      Filter.LatLong.Latitude = 47.44;
      Filter.LatLong.Longitude = -122.55;

      //Assign the spatial filter to the find polygon specification
      findPolySpec.SpatialFilter=filter;

      //Assign your polygon data source
      findPolySpec.DataSourceName="your polygon data source";

      //Define what kind of entities you are looking for
      FindFilter findfilter = new FindFilter();
      findfilter.EntityTypeName = "your entity name";
      findPolySpec.Filter = findfilter;

      //Call Find Polygon
      FindResults findResults = findService.FindPolygon(findPolySpec);
      //Now get the polygon entities
      foreach(FindResult findResult in findResults.Results)
      {
        
    //Get polygons that matched the query
         Console.WriteLine(String.Format(
          "Polygon Entity Matched with ID: {0}",
           findResult.FoundLocation.Entity.ID)
                          );
      }

    Now that you have the entity IDs of polygons that match your spatial filter criteria, you can use that information either to render the polygons (covered more in Chapter 8) or to perform any other processing to suit your business needs.

    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
    Stay green...Green IT