Finding Entities with the MapPoint Web Service Find APIs - Finding entity by properties
(Page 2 of 4 )
Many times, you want to query for entities based on their properties—for example, finding all ATMs in the city of Chicago, or all coffee shops that accept credit cards. In this case, the query is based solely on the entity properties, and you should use the FindServiceSoap.FindByProperty method for this purpose. The FindByProperty method takes a specification object of type FindByPropertySpecification, which takes the queries to find entities using their properties. Table 6-7 shows the fields exposed on theFindByPropertySpecificationobject.
Table 6-7. Fields in the FindByPropertySpecification object
| Field | Description |
| DataSourceName | Name of the data source as a string |
| Filter | The filter (FindFilterobject) to apply to the results; that is, 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 |
The following code shows how to use these expressions to find entities using theFindByPropertymethod:
//Create a find service soap proxy class
FindServiceSoap findService = new FindServiceSoap();
//Assign credentials
. . .
//Create find by property specification
FindByPropertySpecification findbypropspec = new FindByPropertySpecification();
//Define find by property specification
findbypropspec.DataSourceName = "MapPoint.FourthCoffeeSample";
//Assign a filter
findbypropspec.Filter = new FindFilter();
//Specify the entity type that you are looking for
findbypropspec.Filter.EntityTypeName = "FourthCoffeeShops";
//Now define and assign the expression
findbypropspec.Filter.Expression = new FilterExpression();
findbypropspec.Filter.Expression.Text = "PrimaryCity = {0} AND IsWiFiHotSpot";
findbypropspec.Filter.Expression. Parameters = new object[] {"Chicago"};
FindResults foundResults;
foundResults = findService.FindByProperty(findbypropspec);
The resulting expression from this code is"PrimaryCity = 'Chicago' AND IsWiFiHotSpot", which means to return only coffee shops in the city of Chicago that have WiFi Hotspots available. Even though the filter expressions look and behave like SQL expressions, there are limitations that you need to be aware of:
- The expression text should never contain the values that are being compared, but the text must provide the placeholders for all non-Boolean value types. Placeholders are represented by “{nn}” where n is an integer between 0 and 9.
- The comparison operators LIKE and NOT LIKE support only the “Starts with” condition.
- Maximum length of the expression text is limited to 2,000 characters.
- No more than one level of nesting (parenthesis) is allowed.
- A maximum of 10 non-Boolean comparisons and a maximum of 10 sub-clauses are allowed.
- A maximum of 50 total comparisons per expression is allowed.
Next, let’s look at an example expression: you want to find all coffee shops in the city of Chicago that have a seating capacity greater than 20 or that are open 24 hours a day whose names start with the letter C. The expression to pass for theFindByPropertymethod would be:(City={0} AND SeatingCapacity>{1}) OR (StoreType={2} AND Name LIKE {3}) with the arguments Chicago, 20, Open 24 Hours and C.
Now that you know how to use the find service APIs, let’s look at some of the common service methods that are relevant to the finding places, addresses, and entities.
Next: Finding Polygons >>
More BrainDump Articles
More By O'Reilly Media
|
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.
|
|