This week we focus on Precisely’s Raster capabilities, with the release of the new Geo Raster SDK version 2.0. This is the first of a two-part series on raster.
Raster is a great format for holding vast amounts of spatial data and for querying and displaying it quickly. The data can represent not just traditional imagery but also numeric and categorical values. Use cases cover all aspects of industry from environmental data such as flood and forest cover, to representing locations of activities, cell phone coverage and more.
There are three main categories of raster data:
|
|
|
Continuous
|
Classified
|
Imagery
|
Each cell represents a continuous numeric value. Has multiple bands.
|
Each cell represents a discrete categorical value.
|
Each cell value represents a multi banded data which can be optical, multispectral, or hyperspectral.
|
e.g.
• Elevation
• Flood depth
• Temperature
• Cell phone coverage
|
e.g.
• Agricultural Land/Cropland and Pasture
• Water/Bays and Estuaries
• Urban or Built-up Land/Residential
|
e.g.
• RGB [128, 215, 112]
• RGB [233, 245, 85]
|
The creation, processing and analysis of raster has been part of MapInfo Pro Advanced for some time now using our innovative raster format called “Multi-Resolution Raster” (MRR). With the Java-based Geo Raster SDK, it is now possible to create and process raster files on a server environment in either Windows or Linux.
In the first part of this series below we walk through creating a raster using the SDK and then showcase our capabilities to open and display the raster in MapInfo Pro and Spectrum Spatial and to create styling using custom breaks.
In the second part next week we will cover some of the analysis functions, using Spatial Analyst to determine raster statistics along a line and within a polygon, and perform the same queries using SQL via the Spatial Feature REST APIs.
1. Create the raster file using the Geo Raster 2.0 SDK.
The raster SDK exposes several APIs for creating and processing MapInfo Raster tables. These are listed here on the Precisely Help Center and include
- Input/Output APIs with operations for
- Metadata of the overall raster information such as extents and cell size
- Analysis to get line and polygon statistics, cross section, and cell value.
- Read/write operations for modify existing raster tables.
- Operation APIs including
- Convert data such as ASCII Grid and other formats to MapInfo Raster
- Rasterize to create MapInfo Raster from vector data.
- Re-projection and clipping of raster.
- Rendering APIs to generate images of the raster.
In this example we will use the Rasterize API which takes a vector polygon file and converts it into a MapInfo Raster.
The polygon file we will use is a TAB file of vector contours for the UK, which has been derived from the OS Terrain 50 elevation data. The use is relevant for many industries such telco, for example, where the organisation will often have their own polygon data representing detailed coverage maps.
The original elevation data is available as line contours or as an ASCII grid format of points representing elevation. The line contour data has over a million records and is 4GB. Contour data does not lend itself for inspection at a location since the gaps between the lines have no data. We therefore took the ASCII grid data and created a polygon vector TAB file from it for demonstration purposes. Whilst the polygon file works fine for inspection, the file the size grows to 11 GB, and we have 47.5 million records. It’s a large file.
The file looks like this in MapInfo Pro, showing Lands’ End in the UK.
As we zoom in you can see the level of detail we have. Each contour traces around a 50m grid value.
We will therefore use the Raster SDK to convert this to MapInfo Raster. The raster SDK is designed to be deployed as a java library that can be developed against using java code.
Below is a code snippet used to rasterize the above polygon file and create a MRR file. We also have a convert operation (not shown here) that can convert ASCII grid direct to MRR.
The rasterize operation is called at line 52. The same can also be achieved in MapInfo Pro Advanced, however the benefit of the SDK is that these capabilities can now be integrated into other solutions and processing can be automated on a fast server environment (either Windows or Linux). The code snippet can be compiled and run at the command line also.
package com.precisely.raster.samples;
import com.mapinfo.midev.raster.mrr.jna.MIR_RasterizeForegroundValueType;
import com.mapinfo.midev.raster.mrr.jna.MIR_RasterizeOperator;
import com.precisely.raster.RasterEngines;
import com.precisely.raster.common.MapInfoUnitCode;
import com.precisely.raster.io.RasterEngine;
import com.precisely.raster.operations.RasterOperations;
public class RasterOp {
public static void main(String[] args) {
try {
//indices of the columns in the vector data to be used for rasterization
short[] vectorFieldIDs = {1};
String filePath = System.getProperty("user.dir") + "/data/";
String inputFilePath= filePath + "VectorFiles/BritishDEM_Polygons.TAB";
String outputFilePath= filePath + "VectorFiles/output_BritishDEM_Polygons.mrr";
RasterEngine rasterEngine = RasterEngines.getRasterEngine();
RasterOperations rasterOperations = rasterEngine.getRasterOperations();
rasterOperations.Rasterize(inputFilePath, outputFilePath, "MI_MRR", false,"",
MapInfoUnitCode.METERS, 50.0f, 50.0f,
MIR_RasterizeForegroundValueType.MIR_Rasterize_Field, 0.0f, MIR_RasterizeOperator.MIR_Rasterize_Average,
true, 0.0f, vectorFieldIDs, null, null);
}
catch(Exception ex)
{
ex.printStackTrace();
}
System.out.println("Unit test for Rasterize operation using vector field value is successful!");
}
}
|
2. Viewing the raster in MapInfo Pro.
After the MRR is created we can open it directly into MapInfo Pro
The MapInfo Raster file has the exact same level of detail as the polygon file but is only 200 MB in size. It is just 1.6% of the polygon file size and loading, querying, and rendering the data is super-fast.
3. Adding the raster to Spectrum Spatial or the Private Spatial APIs.
The same MRR table can also be added to our enterprise spatial product. Many readers will be familiar with Spectrum Spatial and Spatial Manager. The same is now also available as the “Private Spatial APIs” which can be deployed into cloud native (Kubernetes) environments for even better auto-scaling and resilience.
Here is an animated GIF where we create a named table in Spatial Manager by browsing to the MRR table and picking it. As you can see the rendering is fast even when zoomed out.
Next we create a named layer for the named table in Spatial Manager and then switch to our end-user web mapping product, Spatial Analyst. The layer is opened by the user and we can see it loaded along with the legend.
4. Styling the data in Spectrum Spatial or Private Spatial APIs.
One of the capabilities of Spatial Manager, and benefits of having a named layer, is the ability to style the raster.
Layers can contain all kinds of styling and other settings such as zoom dependant rendering. For raster layers admins can choose a wide range of palettes (the same ones that in MapInfo Pro) or can create a custom style.
Below we walk through creating a fully custom style with ranges that represent 200 metres height. We start by creating a new layer for the table as we do not want to remove the one created above, and then choose custom breaks and the ranges we need. The same table can have many layers associated with it, which is useful if your raster has multiple bands, and you want to show all these on the same map in Spatial Analyst.
Next week
Next week we will add the above re-styled layer into Spatial Analyst and show how an end-use can perform some basic analysis on it. Then we will focus on the Spatial REST APIs which lets you query the raster data using traditional SQL.
SQL based query of raster data is one of the more powerful capabilities of our Spatial APIs. It enables many of the above use cases to be automated in business processes that are improved by using raster data analysis and enrichment.
In the meantime, here are some further links about the raster and the SDK
· Background on raster support and MRR. link
· Raster SDK 2.0 release notes link
· Raster SDK 2.0 guide. link
· Raster SDK 2.0 sample project. link
· Raster functions available in the Private Spatial APIs. The same are also available in Spectrum Spatial. link
· Spatial Analyst documentation on raster information. link
· Spatial Manager documentation on raster styling. link
------------------------------
Mustafa Ismail
Precisely
------------------------------