Industrial Data Science
in C# and .NET:
Simple. Fast. Reliable.
 
 

ILNumerics - Technical Computing

Modern High Performance Tools for Technical

Computing and Visualization in Industry and Science

This article describes pre-release functionality, available from version 4.13.

Shapefile reader

The ShapefileReader converts shapefiles to cell arrays. A shapefile is a data format for geographic information system software. It usually consists of three files:

  • shape format (.shp)
  • shape index format (.shx)
  • attribute format (.dbf)

The shape format is also referred to as the main file since it contains the geometry data for each record. The index file specifies the position and length of each record in the main file while the corresponding attributes are stored in the attribute file.  

Using ShapefileReader

To read and convert shapefiles, the ShapefileReader.constructor must be provided with the absolute or relative path of

  • the main file (.shp) and
  • the index file (.shx).

As a result, you can not only look into the geometry data that your shapefile consists of but you can also get information on the number of records and the shape type.

Cell format

To understand the structure of the cell array, it is essential to know that each record contains information on at least one closed polygon. This information includes the positions as well as the index of the first point of each polygon, since the polygons of one record are listed one after another.

 

The resulting cell reflects this format: Three rows always correspond to one record. While the first row contains an array of incides, the second row contains an array of positions. The third row specifies the limits of the record. However, the very first row of the cell array contains an integer that specifies the shape type.

 

The following image shall clarify the structure.

 

Limitations

Currently, it is only possible to provide shapefiles that contain the shape type polygon. Furthermore, you must make sure that the main file and index file belong to the same shapefile. This is usually indicated by the same name. Otherwise it is very likely that an error will occur. Also, note that not the complete information a shapefile contains is extracted. Instead, the minimum necessary data is stored inside the cell.

Application

Now that the geometry data is available in the form of arrays, the data can easily be manipulated. Here, you can read more on cell manipulation.

But there is also the class RegionPlot() that exactly expects the resulting cell array format to visualize its content.

 

Read more: