Catalog search methods – Pitney Bowes MapXtreme User Manual
Page 188

Chapter 8: Working with Data
Features and Feature Collections
MapXtreme v7.1
195
Developer Guide
// Using SQL
command.CommandText = "Select Obj From States Where state = ‘NY’;
FeatureGeometry nyGeom = command.ExecuteScalar() as FeatureGeometry;
command.CommandText =
"SELECT * FROM Cities WHERE Obj within @newyork";
command.Parameters.Add("@newyork", nyGeom);
MIDataReader reader = command.ExecuteReader();
// or… to get a FeatureCollection
IFeatureCollection fc = command.ExecuteFeatureCollection();
// Using Features
Feature fNY = catalog.SearchForFeature("States", _
SearchInfoFactory.SearchWhere("state='NY'"));
SearchInfo si = SearchInfoFactory.SearchWithinFeature(fNY, _
ContainsFilter.ContainsType.Centroid);
IDynamicFeatureCollection dfc = _
catalog.Search("Cities", si) as IDynamicFeatureCollection;
Console.Out.WriteLine( _
"There are {0} cities whose centroid is within NewYork." _
dfc.Count);
SQL searches are more fully discussed in
. The following
sections focus on searches using the Catalog and SearchInfo.
Catalog Search Methods
The Catalog has a number of search methods as members. The overloaded Search method can be
used to search on one or more tables. They include different arguments to make each search
unique. For example, the basic Search (Table, SearchInfo) searches the given table and returns a
FeatureCollection. The Search (ITableEnumerator, SearchInfo) method searches on multiple tables
and returns a MultiResultSetFeatureCollection.
The SearchForFeature method returns the first Feature from the results. The SearchReader method
returns an MIDataReader cursor with the results.
Code Sample: SearchForFeature
The following example shows how to use Catalog.SearchForFeature and
Catalog.SearchWithinGeometry. It finds all the cities in the uscty_1k table that are within Florida. It
assumes that tables “usa” and “uscty_1k” are open and that there is one map.
VB example:
Public Shared Sub MapInfo_Data_SearchInfo(ByVal catalog As Catalog)
Dim fFlorida As Feature = _
catalog.SearchForFeature("usa",MapInfo.Data._
SearchInfoFactory.SearchWhere_("State='FL'"))
Dim si As SearchInfo =
MapInfo.Data.SearchInfoFactory.SearchWithinGeomeTry(fFlorida._
Geometry,ContainsType.Centroid)
Dim fc As IResultSetFeatureCollection = _
MapInfo.Engine.Session.Current.Catalog.Search("uscty_1k",si)