This page has been translated automatically.
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
FAQ
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
CIGI Client Plugin
Rendering-Related Classes
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Unigine.Dataset Class

The Dataset class is used for processing raster and vector data with binding to geo-coordinates. The class uses GDAL API to retrieve data from files.

The class allows for loading such rare raster formats as .dem, .tiff (with information on binding to geo-coordinates), .ecw and vector formats .osm, .shp.

Notice
The .ecw format will be loaded only if you install the ECW plugin and accept the ECW EULA.

For raster data, geo-coordinates can be obtained per-pixel in the (latitude, longitude) format. Pixel values can be of different formats (R8, R16, R32F for single-channel data; RGB8, RGB16, RGB32F, RGBA8, RGBA16, RGBA32F for multi-channel data).

The following example shows how raster data can be accessed by using methods of the Dataset class:

Source code (C#)
// AppWorldLogic.cs

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{
		public override int init()
		{
			// create a new dataset
	        Dataset dataset = new Dataset();
	        // load raster data
	        dataset.load("unigine_project/maps/geo.tif");
	        // declare images into which raster data obtained from the loaded dataset will be saved
            Image[] raster_data = new Image[dataset.getRasterCount()];
	        // print data on each raster band of the dataset
	        for (int i = 0; i < dataset.getRasterCount(); i++) {
		        Log.message("Band:  {0}\n", i);
                Log.message("Type:  {0}\n", dataset.getRasterTypeName(i));
                Log.message("Color: {0}\n", dataset.getRasterColorName(i));

		        Image image = new Image();
		        // create an image of the size and format of the current raster band
		        image.create2D(dataset.getRasterSizeX(), dataset.getRasterSizeY(), Image.FORMAT_R8);
		        // read the region of the current raster band into the created image
		        if (dataset.getRasterImage(i, image) == 0) {
                    Log.error("Can't import raster band, layer: {0}\n", i);
			        continue;
		        }
		        // add the obtained raster data to the array
		        raster_data[i] = image;
	        }

	        for (int y = 0; y < dataset.getRasterSizeY(); y += dataset.getRasterSizeY() - 1) {
		        for (int x = 0; x < dataset.getRasterSizeX(); x += dataset.getRasterSizeX() - 1) {
			        double latitude = dataset.getLatitude(x, y);
			        double longitude = dataset.getLongitude(x, y);
                    Log.message("{0}x{1}: {2} / {3}\n", x, y, latitude, longitude);
		        }
	        }
			
			return 1;
		}
	}
}

For vector data, the number of primitives, their points and properties can be obtained. You can also triangulate a primitive and save it to a dynamic mesh (see the samples_2/geodetics/dataset_00 sample).

Vector Dataset

A vector dataset is a set of layers, each of which contains meta-information (field definitions) and data (features).

Field definitions is a set of names that can be associated with the application logic. For example, the name "height" allows assuming that the feature will contain information on heights, so you can make geometry three-dimensional in your application.

Features contain geometry and field values that are associated with field definitions. If a layer of vector dataset contains several features, they will be read from the source successively. The memory contains only the currently read feature that is processed.

Geometry can be simple (a point, line, polygon) and complex (a set of points, lines or polygons). In the Dataset class, working with geometry is similar to working with Unigine mesh: you can get the number of "surfaces" (geometries) and points of one of such "surfaces" (geometries). For the simple geometry, there is a single "surface". For the complex one, there are several "surfaces".

The following example shows how vector data can be accessed by using methods of the Dataset class:

Source code (C#)
// AppWorldLogic.cs

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{
		public override int init()
		{
			// create a new dataset
			Dataset dataset = Dataset.create();
			// load vector data
			dataset.load("unigine_project/maps/antarctica.shp");
			// print information on the dataset layers
			for (int i = 0; i < dataset.getVectorCount(); i++) {
				Log.message("Layer:  {0}\n", i);
				Log.message("Name:   {0}\n", dataset.getVectorName(i));
				Log.message("Fields: {0}\n", dataset.getVectorFieldCount(i));
				Log.message("Features:\n");
				// print field definitions and its associated values for each feature of the dataset layer
				// starting from the first feature
				dataset.vectorFeatureReadReset(i);
				// obtain the current feature
				while (dataset.vectorFeatureReadNext(i)) {
					// for each field definition of the current feature
					for (int j = 0; j < dataset.getVectorFieldCount(i); j++) {
						// get the name
						string field_name = dataset.getVectorFieldName(i, j);
						// get the associated value
						Variable field_value = dataset.getVectorFieldValue(i, j);
						// print the obtained values
						Log.message("\t{0}: {1}\n", field_name, field_value.getTypeInfo().get());
					}
				}
			}
			
			return 1;
		}
	}
}

Dataset Class

Members


static Dataset()

Constructor. Creates a new dataset.

string getCreationData()

Returns a list of space separated data types supported by the format of the dataset.

Return value

Dataset format data types.

string getCreationOption()

Returns options specified for the format of the dataset.

Return value

Dataset format options.

string getDescription()

Returns the description of the format of the dataset.

Return value

Dataset format description.

string getProjection()

Returns a string that defines the projection coordinate system of the image in OpenGIS WKT format.

Return value

String with the projection coordinate system.

int[] getRasterBandHistogramm(int num, double v_min, double v_max, int num_buckets)

Calculates histogram for the specified raster band. Note that the bucket size is: (v_max - v_min) / num_buckets.

Arguments

  • int num - Raster band number.
  • double v_min - Lower bound of the histogram.
  • double v_max - Upper bound of the histogram.
  • int num_buckets - Number of buckets in the histogram.

Return value

Vector to which the calculated histogram will be put.

string getRasterColorName(int num)

Returns the name of color representation for the given raster band of the dataset.

Arguments

  • int num - Raster band number.

Return value

Name of color representation.

int getRasterCount()

Returns the number of raster bands in the dataset.

Return value

Number of raster bands.

int getRasterImage(int num, Image image, int offset_x = 0, int offset_y = 0, int scale = 1)

Writes the region of the raster band with the specified offsets into the given image. The size of the region corresponds to the size of the given image. If the raster band less that the image, the whole raster band will be written.
Notice
Only R8, R16, R32F types of the pixel values of the raster band are supported.

Arguments

  • int num - Raster band number.
  • Image image - Image into which the raster band should be read.
  • int offset_x - Pixel offset to the top left corner of the region of the band to be written. To start from the left, 0 should be specified.
  • int offset_y - Line offset to the top left corner of the region of the band to be written. To start from the top, 0 should be specified.
  • int scale - Scale factor.

Return value

1 if the region has been read successfully; otherwise, 0.

int getRasterImageAllBands(Image image, int offset_x = 0, int offset_y = 0, int scale = 1)

Writes the regions of all the raster band with the specified offsets into the given images. The size of the region corresponds to the size of the given image. If the raster band size less that the image size, the whole raster band will be written. The function processes only 3 or 4 raster bands (an image must be of theRGB format for 3 bands or the RGBA format for 4 bands).
Notice
Only RGB8, RGB16, RGB32F, RGBA8, RGBA16, RGBA32F types of the pixel values of the raster bands are supported. Pixels of all the raster bands must be of the same type.

Arguments

  • Image image - Image into which the raster bands should be read.
  • int offset_x - Pixel offset to the top left corner of the region of the band to be accessed. To start from the left, 0 should be specified.
  • int offset_y - Line offset to the top left corner of the region of the band to be accessed. To start from the top, 0 should be specified.
  • int scale - Scale factor.

Return value

1 if the regions have been read successfully; otherwise, 0.

double getRasterMaximumValue(int num)

Returns the maximum value for the specified raster band of the dataset.

Arguments

  • int num - Raster band number.

Return value

Maximum raster value.

double getRasterMinimumValue(int num)

Returns the minimum value for the specified raster band of the dataset.

Arguments

  • int num - Raster band number.

Return value

Minimum raster value.

double getRasterNoDataValue(int num)

Returns the no data value for the specified raster band of the dataset. The no data value for a band is a special marker value used to mark pixels that are not valid data. Such pixels should generally not be displayed, nor contribute to analysis operations.

Arguments

  • int num - Raster band number.

Return value

No data value.

double getRasterOffset(int num)

Returns the offset value for the specified raster band of the dataset.

Arguments

  • int num - Raster band number.

Return value

Raster offset value.

DatasetRasterPosResolver getRasterPosResolver()

Returns a current DatasetRasterPosResolver.

Return value

DatasetRasterPosResolver.

double getRasterScale(int num)

Returns the scale value for the given raster band of the dataset.

Arguments

  • int num - Raster band number.

Return value

Raster scale.

int getRasterSizeX()

Returns the width of raster bands of the dataset.

Return value

Raster width in pixels.

int getRasterSizeY()

Returns the height of raster bands of the dataset.

Return value

Raster height in pixels.

string getRasterTypeName(int num)

Returns the name for the data type of the specified raster band of the dataset.

Arguments

  • int num - Raster band number.

Return value

Name of the data type.

string getRasterUnitType(int num)

Returns the name of the units of the raster band values.

Arguments

  • int num - Raster band number.

Return value

Name of the units.

int setVectorAttributeFilter(int num, string filter)

This method sets the attribute query string to be used when fetching features via the vectorFeatureReadNext() method. Only features for which the query evaluates as true will be returned.

The query string should be in the format of an SQL WHERE clause. For instance: "population > 1000000 and population < 5000000", where population is an attribute in the layer. The query format is normally a restricted form of SQL WHERE clause. In some cases (RDBMS backed drivers) the native capabilities of the database may be used to interpret the WHERE clause in which case the capabilities will be broader than those of OGR SQL.

Notice
Note that installing a query string will generally result in resetting the current reading position (vectorFeatureReadReset()).

Arguments

  • int num - Layer index in the vector dataset.
  • string filter - Query in restricted SQL WHERE format, or NULL to clear the current query.

Return value

OGRERR_NONE if successfully installed, or an error code if the query expression is incorrect, or some other failure occurs.

int getVectorCount()

Returns the number of layers in the vector dataset.

Return value

Number of layers in the vector dataset.

int getVectorFieldCount(int num)

Returns the number of field definitions in the given layer of the vector dataset.

Arguments

  • int num - Layer index in the vector dataset.

Return value

Number of layer field definitions.

int findVectorField(int num, char[] name)

Finds the field definition of the current feature of the given layer by the given name and returns its index.

Arguments

  • int num - Layer index in the vector dataset.
  • char[] name - Field definition name.

Return value

Field definition index if there is a field definition with the given name; otherwise, -1.

string getVectorFieldName(int num, int field)

Returns the name of the given field definition of the current feature of the given layer.

Arguments

  • int num - Layer index in the vector dataset.
  • int field - Field definition index.

Return value

Field definition name.

int getVectorFieldType(int num, int field)

Returns the type of the given field definition of the current feature of the given layer.

Arguments

  • int num - Layer index in the vector dataset.
  • int field - Field definition index.

Return value

Field type value.

Variable getVectorFieldValue(int num, int field)

Returns the value of the given field definition of the current feature of the given layer.

Arguments

  • int num - Layer index in the vector dataset.
  • int field - Field definition index.

Return value

Field value.

string getVectorName(int num)

Returns the name of the given layer of the vector dataset.

Arguments

  • int num - Layer index in the vector dataset.

Return value

Name of the layer.

void setVectorSpatialFilter(int num, dvec3 min_val, dvec3 max_val)

Sets a bounding box for the data that is obtained via vectorFeatureReadNext(). The vector dataset from the data inside this bounding box only will be passed.

Arguments

  • int num - Layer index in the vector dataset.
  • dvec3 min_val - Start coordinates of the bounding box.
  • dvec3 max_val - End coordinates for the bounding box.

int getVectorSurfaceCount(int num)

Returns the number of surfaces of the current feature in the given Layer.

Arguments

  • int num - Layer index in the vector dataset.

Return value

Number of surfaces.

dvec3 getVectorSurfacePoint(int num, int surface, int point)

Returns coordinates of the surface point in the current feature of the given layer.

Arguments

  • int num - Layer index in vector dataset.
  • int surface - Surface index from which to get point coordinates.
  • int point - Surface point index.

Return value

Surface point coordinates.

int getVectorSurfacePointCount(int num, int surface)

Returns the number of surface points in the current feature of the given layer.

Arguments

  • int num - Layer index in vector dataset.
  • int surface - Surface index from which to get points.

Return value

Number of surface points.

dvec3[] getVectorSurfacePoints(int num, int surface)

Returns coordinates of all of the surface points in the current feature of the given layer.

Arguments

  • int num - Layer index in vector dataset.
  • int surface - Surface index from which to get points.

Return value

Array of surface points coordinates.

int calcVectorBounds(out dvec3 min_val, out dvec3 max_val)

Arguments

  • out dvec3 min_val
  • out dvec3 max_val

void clear()

Clears the dataset.

void clearVectorSpatialFilter(int num)

Clears the coordinates of the bounding box set via setVectorSpatialFilter().

Arguments

  • int num - Layer index in vector dataset.

int hasRasterRGBColorTable(int num)

Returns a value indicating if there is a raster RGB table for a given band.

Arguments

  • int num - Band number.

Return value

1 if there is a raster RGB table for a given band; otherwise, 0.

int load(string name)

Loads the given dataset.

Arguments

  • string name - Dataset name (a path to a file with raster or vector data).

Return value

1 if dataset has been loaded successfully; otherwise, 0.

int vectorFeatureReadNext(int num)

Reads the next available feature from the given layer.
Notice
The setVectorSpatialFilter() allows to set a bounding box for the data that will be obtained. The vector dataset from the data inside this bounding box only will be passed.

Arguments

  • int num - Layer index in vector dataset.

Return value

1 if the feature exists; otherwise, 0.

void vectorFeatureReadReset(int num)

Resets feature reading to start on the first feature.

Arguments

  • int num - Layer index in vector dataset.

int rasterizeIntoMask(int num, string output_path, string[] filters, int width, int height)

Rasterizes the specified vector dataset layer and saves it to the specified output path.

Arguments

  • int num - Layer index in vector dataset.
  • string output_path - Path to which the rasterized vector dataset layer is to be saved.
  • string[] filters -

    Queries in restricted SQL WHERE clause format to be evaluated against the datasource to produce a virtual layer of features to be rasterized. For instance: "population > 1000000 and population < 5000000", where population is an attribute in the layer.

    Each filter is represented by a separate raster band.

    Notice
    The maximum supported number of filters is 4.
  • int width - Output raster mask width, in pixels.
  • int height - Output raster mask height, in pixels.

Return value

1 if the specified vector dataset layer was successfully rasterized; otherwise, 0.
Last update: 2018-08-10
Build: ()