Version

Triangulating Geographic Data

Purpose

This topic provides information on how triangulation of data points works as well as how it can improve the performance of rendering data in the XamGeographicMap™ control.

Required background

The following table lists the topics required as a prerequisite to understanding this topic.

Topic Purpose

This topic provides information on how to bind shape files with geo-spatial data to the XamGeographicMap control.

This topic provides resources about maps and geo-spatial related material as well as information about shape files. Use these resources to learn about and obtain shape files as well as tools for their editing before starting to bind geo-spatial data to the XamGeographicMap control.

Understanding Triangulation

Introduction

Triangulation is a process of triangulating data points with the same values based on their longitude and latitude locations. Consider the following simplified scenario of triangulating data in a geographic context:

The following is a screenshot of (-130, 30), (-130, 50), (-100, 50), (-100, 30), (-70, 40) geographic locations plotted using the GeographicScatterAreaSeries.

GeographicMap Triangulating Geographic Data 1.png

For the above five points, there are three triangles and their triangle vertex indices are as follows: (0, 1, 2), (0, 2, 3), (2, 3, 4).

The following image shows these triangles and their vertex indices.

GeographicMap Triangulating Geographic Data 2.png

Triangulation Source

In the XamGeographicMap control, the TriangulationSource class represents the data source for creating, loading, and saving triangulation. A complete data structure for TriangulationSource consist of two properties that are listed in the following table:

Property Name Property Type Description

ObservableCollection<TriangulationSourcePointRecord>

Gets or sets a collection of TriangulationSourcePointRecord objects that store points combined with numeric values from which triangulation is created.

ObservableCollection<Triangle>

Gets or sets a collection of Triangle objects that store three indices with each one corresponding to a point in the Points collection.

The TriangulationSourcePointRecord class represents one of the triangle points in triangulation. The following table lists key properties of the TriangulationSourcePointRecord class.

Property Name Property Type Description

Point

Gets or sets a point that represents a two dimensional (2-D) location of one of triangle points.

Value

float

Gets or sets a value associated with a one of triangle points.

The Triangle class represents a record with three integer values or triangle vertex indices. Each integer is an index which corresponds to a point in the Points collection. The following table lists key properties of the Triangle class.

Property Name Property Type Description

V1

integer

Gets or sets an index of the first vertex of a triangle.

V2

integer

Gets or sets an index of the second vertex of a triangle.

V3

integer

Gets or sets an index of the third vertex of a triangle.

Triangulation Files

Triangulation data can also be stored in triangulation files that use the Intermediate Triangular Irregular Network Format (or ITF for short). For more information on this file format and its specifications, please visit this website.

Triangulation Methods

The TriangulationSource class provides methods for creating triangulation, saving and loading triangulation data to and from ITF files.

The following table lists key methods in the TriangulationSource class for working with triangulation data

Method Name Description

A method for creating triangulation of geographic data.

A method for saving triangulation of geographic data to binary ITF file.

A method for loading triangulation of geographic data from binary ITF file.

Note
Note:

A detailed explanation of each of these methods along with some code examples follow at end of this topic.

Pre-Triangulation Process

In the XamGeographicMap control, the following types of geographic series can use pre-triangulated data or perform triangulation of data at runtime if no triangulation source is specified:

Type of Geographic Series Description

This series represents a geographic series that draws a colored surface, in a geographic context, based on a triangulation of longitudinal and latitudinal data with numeric values assigned to each point. Refer to Using Geographic Scatter Area Series topic for more information about this geographic series.

This series represents a geographic series that draws colored contour lines, in a geographic context, based on a triangulation of longitudinal and latitudinal data with numeric values assigned to each point. Refer to Using Geographic Contour Line Series topic for more information about this geographic series.

These types of series provide built-in data triangulation that is automatically performed on items in the ItemsSource if no triangulation is set to the TrianglesSource property. However, computing triangulation can be a very time-consuming process, so the runtime performance will be better when specifying a TriangulationSource for this property, especially when a large number of data items are present. Therefore, you should avoid this computation at run-time by “pre-triangulating” the data and providing the triangulation to a geographic series.

The following table list the main steps of pre-triangulation process:

Triangulation Process Description

Creates triangulation data as a TriangulationSource object from shape files using the ShapefileConverter class.

Saves triangulation data to an ITF file that can be deployed with your application.

Loads triangulation data from an ITF file stores it as a TriangulationSource object.

After completing the pre-triangulation process, a step for binding a geographic series to triangulation data is necessary. Please refer to the following topics for a more detailed explanation. in:

Creating Triangulation from Shape Files

Overview

The TriangulationSource class provides the Create method for creating triangulation of geographic data. This static method creates a TriangulationSource using delegates to get the Points and Triangles to create a triangulation.

Example

The following code demonstrates how to create triangulation from shape files by implementing a handler for ImportCompleted event of the ShapefileConverter class and passing delegates to get Points and Fields collections to the Create method of the TriangulationSource class.

Note
Note:

This code example uses a shape file that contains precipitation data from NOAA website and it assumes that you already know how to add shape files to your project and use it with the ShapefileConverter. Also, stores values associated with geographic data points in “Globvalue” data column of the database (DBF) file, but the name of the data column containing values might be different in your shape file, in which case you will need to update the key passed in the Fields collections of the ShapefileConverter.

In Visual Basic:

Imports Infragistics.Controls.Charts
Imports Infragistics.Controls.Maps
Imports System.ComponentModel

Private WithEvents converter As New ShapefileConverter()

converter.ShapefileSource = New Uri("nws_precip_1day_observed_20110419.shp", System.UriKind.RelativeOrAbsolute)
converter.DatabaseSource = New Uri("nws_precip_1day_observed_20110419.dbf", System.UriKind.RelativeOrAbsolute)

Private Sub OnShapeFileConverterImportCompleted(sender As Object, e As AsyncCompletedEventArgs) Handles converter.ImportCompleted
      Dim triangulationSource As TriangulationSource = TriangulationSource.Create(converter.Count,
                    Function(i) converter(i).Points(0)(0),
                    Function(i) Convert.ToSingle(converter(i).Fields("Globvalue")))
End Sub

In C#:

using Infragistics.Controls.Charts;
using Infragistics.Controls.Maps;
using System.ComponentModel;

var converter = new ShapefileConverter();
converter.ImportCompleted += OnShapeFileConverterImportCompleted;
converter.ShapefileSource= new Uri("nws_precip_1day_observed_20110419.shp", System.UriKind.Relative);
converter.DatabaseSource = new Uri("nws_precip_1day_observed_20110419.dbf", System.UriKind.Relative);

void OnShapeFileConverterImportCompleted(object sender, AsyncCompletedEventArgs e)
{
  TriangulationSource triangulationSource = TriangulationSource.Create(converter.Count,
        (i) => converter[i].Points[0][0],
        (i) => Convert.ToSingle(converter[i].Fields["Globvalue"]));
}

Saving Triangulation to an ITF file

Overview

The TriangulationSource class provides the SaveItf method for saving triangulation of geographic data. This static method saves a triangulation to binary ITF file that you can deploy with your application and use later for loading triangulation data.

Example

The following code demonstrates how to save triangulation data to an ITF file by providing an IsolatedStorageFileStream to the SaveItf method of the TriangulationSource class.

Note
Note:

This code example assumes an approved request for allocating appropriate space for size of the ITF file in isolated storage.

In Visual Basic:

Using iso As IsolatedStorageFile = IsolatedStorageProvider.GetIsolatedStorageFile()
      Dim filePath As String = "TriangulatedFile.itf"
      Using stream = New IsolatedStorageFileStream(filePath, FileMode.Create, iso)
            triangulationSource.SaveItf(stream)
            stream.Close()
      End Using
End Using

In C#:

using (IsolatedStorageFile iso = IsolatedStorageProvider.GetIsolatedStorageFile())
{
    string filePath = "TriangulatedFile.itf";
    using (var stream = new IsolatedStorageFileStream(filePath, FileMode.Create, iso))
    {
        triangulationSource.SaveItf(stream);
        stream.Close();
    }
}

Loading Triangulation from an ITF file

Overview

Similar to saving triangulation method, the TriangulationSource class also provides the LoadItf method for loading triangulation of geographic data. This static method loads a triangulation data from binary ITF file.

Example

The following code demonstrates how to load triangulation from an ITF file by providing an IsolatedStorageFileStream of an ITF file and passing it to the TriangulationSource class’ LoadItf method.

Note
Note:

This code example assumes the ITF file already exists and is accessible in isolated storage.

In Visual Basic:

Dim triangulationSource As TriangulationSource
Using iso As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForAssembly()
      Dim filePath As String = "TriangulatedFile.itf"
      If iso.FileExists(filePath) Then
            Using stream = New IsolatedStorageFileStream(filePath, FileMode.Open, iso)
                  triangulationSource = TriangulationSource.LoadItf(stream)
                  stream.Close()
            End Using
      End If
End Using

In C#:

TriangulationSource triangulationSource;
using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForAssembly();
{
    string filePath = "TriangulatedFile.itf";
    if (iso.FileExists(filePath))
    {
        using (var stream = new IsolatedStorageFileStream(filePath, FileMode.Open, iso))
        {
            triangulationSource = TriangulationSource.LoadItf(stream);
            stream.Close();
        }
    }
}

Using the ItfConverter method is an alternative for loading triangulation data from an ITF file as demonstrated in the following code:

In XAML:

<ig:ItfConverter x:Key="itfConverter"
                 Source="TriangulatedFile.itf" >
</ig:ItfConverter>

In Visual Basic:

Dim itfConverter = New ItfConverter()
itfConverter.Source = New Uri("TriangulatedFile.itf", UriKind.RelativeOrAbsolute)
Dim triangulationSource As TriangulationSource = itfConverter.TriangulationSource

In C#:

var itfConverter = new ItfConverter();
itfConverter.Source = new Uri("TriangulatedFile.itf", UriKind.RelativeOrAbsolute);
TriangulationSource triangulationSource = itfConverter.TriangulationSource;

Related Content

The following topics provide additional information related to this topic.

Topic Purpose

This topic provides information on how to bind shape files with geo-spatial data to the XamGeographicMap control.

This topic provides resources about maps and geo-spatial related material as well as information about shape files. Use these resources to learn about and obtain shape files as well as tools for their editing before starting to bind geo-spatial data to the XamGeographicMap control.

This topic provides information on how to use the GeographicScatterAreaSeries element in the XamGeographicMap control.

This topic provides information on how to use the GeographicContourLineSeries element in the XamGeographicMap control.