Skip to content

RegexStyle

Namespace: ThinkGeo.Core

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

public class RegexStyle : Style

Inheritance ObjectStyleRegexStyle

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.

Properties

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.

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.

Name

This property gets and set the name of the style.

public string Name { get; set; }

Property Value

String
This property gets the name of the style.

Remarks:

This name is not used by the system; it is only for the developer. However, it can be used if you generate your own legend.

IsActive

This property gets and sets the active status of the style.

public bool IsActive { get; set; }

Property Value

Boolean
This property gets the active status of the style.

Remarks:

If the style is not active then it will not draw.

RequiredColumnNames

This property gets the collection of fields that are required for the style.

public Collection<string> RequiredColumnNames { get; }

Property Value

Collection<String>

        This property gets the collection of fields that are required for the
        style.

Remarks:

This property gets the collection of fields that are required for the style. These are in addition to any other columns you specify in styles that inherit from this one. For example, if you have use a ValueStyle and it requires a column name for the value comparison, then that column does not need to be in this collection. You only use the RequiredColumnNames for columns you need beyond those required by specific inherited styles.

Filters

public Collection<string> Filters { get; }

Property Value

Collection<String>

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.

Methods

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

This method draws the features on the view you provided.

protected 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.

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.

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.

GetRequiredColumnNamesCore()

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

protected Collection<string> GetRequiredColumnNamesCore()

Returns

Collection<String>
This method returns a collection of the column names that it needs.

Exceptions

ArgumentNullException
If columnName is null, we will throw an ArgumentNullException.

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.