Table of Contents

Class RegexStyle

Namespace
ThinkGeo.Core
Assembly
ThinkGeo.Core.dll

This class allows you to draw features differently based on regular expression matching.

public class RegexStyle : Style
Inheritance
RegexStyle
Inherited Members

Remarks

RegexStyle:

The RegexStyle allows you to use complex regular expression matching to determine how your features are drawn. A regular expression is a matching syntax that allows you to match a string based on very complex criteria. For example, let's say you have a layer that has a column in the data that contains school names. Most school names include the type of school they are. For instance, you may have "Lincoln Middle School" or "Bush High School." There are variations to these names though, containing words such as "Elementary" or "Prep." With a regular expression, you can create matching criteria that will allow you to match on many variations of the names. It is especially useful for fuzzy matches where your data is not clearly categorized. Another classic example is for matching or validating email addresses, where matching rules can become complex.

In the RegexStyle, you specify the matching criteria string and also the style you want to use to draw the feature if the criteria matches. It is a simple yet powerful style for dealing with complex rule sets and imprecise data.

Constructors

RegexStyle()

This is a constructor for the class.

public RegexStyle()

Remarks

If you use this constructor, you need to set the various properties manually.

RegexStyle(string, Collection<RegexItem>)

This is a constructor for the class.

public RegexStyle(string columnName, Collection<RegexItem> regexItems)

Parameters

columnName string

This parameter is the columnName you want to use in the style.

regexItems Collection<RegexItem>

This parameter specifies the regexItems in the style.

Remarks

None.

RegexStyle(string, Collection<RegexItem>, RegexMatching)

This is a constructor for the class.

public RegexStyle(string columnName, Collection<RegexItem> regexItems, RegexMatching regexMatching)

Parameters

columnName string

This parameter is the columnName you want to use in the style.

regexItems Collection<RegexItem>

This parameter specifies the regexItems in the style.

regexMatching RegexMatching

This parameter specifies the regexMatching rule for the style.

Remarks

None.

Properties

ColumnName

This property gets and sets the column name whose value will be tested against the regular expression.

public string ColumnName { get; set; }

Property Value

string

This property gets the column name whose value will be tested against the regular expression.

Remarks

This is the column we use for matching.

RegexItems

This property gets the collection of RegexItems. Each item can have its own regular expression to match.

public Collection<RegexItem> RegexItems { get; }

Property Value

Collection<RegexItem>

This property gets the collection of RegexItems.

Remarks

You will want to add RegexItems to this collection. Each item can have its own style and matching string.

RegexMatchingRule

This property gets and sets the regular expression matching rule. The rule determines whether we match the entire string or just any portion of it.

public RegexMatching RegexMatchingRule { get; set; }

Property Value

RegexMatching

This property gets the regular expression matching rule.

Remarks

This is used to determine how much of a string needs to match a regular expression in order to declare it a match for that expression. Sometimes, you only need one part of the string to match in order for the expression to be considered a match; other times you may want the entire string to match.

Methods

DrawCore(IEnumerable<Feature>, GeoCanvas, Collection<SimpleCandidate>, Collection<SimpleCandidate>)

This method draws the features on the view you provided.

protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)

Parameters

features IEnumerable<Feature>

This parameter represents the features you want to draw on the view.

canvas GeoCanvas

This parameter represents the view you want to draw the features on.

labelsInThisLayer Collection<SimpleCandidate>

The labels will be drawn in the current layer only.

labelsInAllLayers Collection<SimpleCandidate>

The labels will be drawn in all layers.

Remarks

This overridden method is called from the concrete public method Draw. In this method, we take the features you passed in and draw them on the view you provided. Each style based on its properties may draw each feature differently.


When overriding this method, consider each feature and its column data values. You can use the full power of the GeoCanvas to do the drawing. If you need column data for a feature, be sure to override the GetRequiredColumnNamesCore and add the columns you need to the collection. In many of the styles, we add properties to allow the user to specify which field they need; then, in the GetRequiredColumnNamesCore, we read that property and add it to the collection.

Exceptions

InvalidOperationException

In the event you attempt to call this method when the GeoCanvas's IsDrawing mode is false, it will throw an InvalidOperationException.

ArgumentNullException

If you pass a null as the view, we will throw an ArgumentNullException.

ArgumentNullException

If you pass a null as the features, we will throw an ArgumentNullException.

ArgumentNullException

If columnName is null, we will throw an ArgumentNullException.

GetRequiredColumnNamesCore()

This method returns the column data for each feature that is required for the style to properly draw.

protected override Collection<string> GetRequiredColumnNamesCore()

Returns

Collection<string>

This method returns a collection of the column names that it needs.

Remarks

This abstract method is called from the concrete public method GetRequiredFieldNames. In this method, we return the column names that are required for the style to draw the feature properly. For example, if you have a style that colors areas blue when a certain column value is over 100, then you need to be sure you include that column name. This will ensure that the column data is returned to you in the feature when it is ready to draw.

In many of the styles, we add properties to allow the user to specify which field they need; then, in the GetRequiredColumnNamesCore, we read that property and add it to the collection.

Exceptions

ArgumentNullException

If columnName is null, we will throw an ArgumentNullException.