Selection code examples, Selecting features within another feature, Checking a table for selections – Pitney Bowes MapXtreme User Manual

Page 204

Advertising
background image

Chapter 9: Working with Core MapXtreme Classes

Selection Code Examples

MapXtreme v7.1

211

Developer Guide

ISerializable Interface on Selection and Selections Classes

The ISerializable interface is implemented on the Selection and Selections classes. The following
code example demonstrates how to serialize or deserialize a Selections object:

// Create a MemoryStream to serialize into
MemoryStream stream = new MemoryStream();

// Serialize the Selections object
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, Session.Current.Selections);
stream.Position = 0;

// Make changes to the Session's Selections object to make sure the
// deserialization works correctly.
...

// Recreate the Selections object from the stream.
// Note: this replaces the current Session's Selections object with
// the contents of the stream
formatter = new BinaryFormatter();
formatter.Deserialize(stream);

Selection Code Examples

The following are code examples of common selection operations. Additional code examples are
included in many topics of the MapXtreme Developer Reference.

Selecting Features Within Another Feature

A common search technique using MapXtreme is to find features within another feature. You may do
this to find all the customers within a postal code boundary or all the highways that are under
construction in a sector. Follow the example below. The parameter f is a MapInfo.Data.Feature.

VB example:

Dim si As MapInfo.Data.SearchInfo = _
MapInfo.Data.SearchInfoFactory.SearchWithinFeature(f, _

MapInfo.Data.ContainsType.Centroid)

Dim irfc As MapInfo.Data.IResultSetFeatureCollection = _

MapInfo.Engine.Session.Current.Catalog.Search("USCty_8k", si)

MapInfo.Engine.Session.Current.Selections.DefaultSelection.Clear()
MapInfo.Engine.Session.Current.Selections.DefaultSelection.Add(irfc)

irfc.Close()

Checking a Table for Selections

Follow the code example below to learn how to get a count of selections in a table.

Advertising