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

Header:#include <UnigineDataset.h>

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

#include <UnigineDataset.h>
#include <UnigineLog.h>
#include <UnigineEngine.h>
#include <UnigineImage.h>
#include <UnigineInterface.h>

int AppWorldLogic::init() {
	
	// create a new dataset
	DatasetPtr dataset = Dataset::create();
	// load raster data
	dataset->load("unigine_project/maps/geo.tif");
	// declare images into which raster data obtained from the loaded dataset will be saved
	Vector<ImagePtr> raster_data;
	// print data on each raster band of the dataset
	for (int i = 0; i < dataset->getRasterCount(); i++) {
		Log::message("Band:  %d\n", i);
		Log::message("Type:  %s\n", dataset->getRasterTypeName(i));
		Log::message("Color: %s\n", dataset->getRasterColorName(i));

		ImagePtr image = Image::create();
		// 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: %d\n", i);
			continue;
		}
		// add the obtained raster data to the array
		raster_data.append(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("%4dx%-4d: %f / %f\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.cpp

#include <UnigineDataset.h>
#include <UnigineLog.h>
#include <UnigineEngine.h>
#include <UnigineInterface.h>

using namespace Unigine; 

int AppWorldLogic::init() {
	// create a new dataset
	DatasetPtr 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:  %d\n", i);
		Log::message("Name:   %s\n", dataset->getVectorName(i));
		Log::message("Fields: %d\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
				const char *field_name = dataset->getVectorFieldName(i, j);
				// get the associated value
				Variable field_value = dataset->getVectorFieldValue(i, j);
				// print the obtained values
				Log::message("\t%s: %s\n", field_name, field_value.getTypeInfo().get());
			}
		}
	}
	
	return 1;
}

Dataset Class

Members


static DatasetPtr create()

Constructor. Creates a new dataset.

const char * getCreationData()

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

Return value

Dataset format data types.

const char * getCreationOption()

Returns options specified for the format of the dataset.

Return value

Dataset format options.

const char * getDescription()

Returns the description of the format of the dataset.

Return value

Dataset format description.

int isOwner()

Returns the owner flag. If the pointer is the owner, on its deletion the dataset also will be deleted. Use grab() and release() functions to change ownership

Return value

Owner flag.

const char * 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.

const char * 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, const Ptr<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.
  • const Ptr<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(const Ptr<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

  • const Ptr<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.

Ptr<DatasetRasterPosResolver> getRasterPosResolver()

Returns a current DatasetRasterPosResolver.

Return value

DatasetRasterPosResolver smart pointer.

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.

const char * 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.

const char * 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, const char * 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.
  • const char * 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, const 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.
  • const char * name - Field definition name.

Return value

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

const char * 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.

const char * 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, const Math::dvec3 & min_val, const Math::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.
  • const Math::dvec3 & min_val - Start coordinates of the bounding box.
  • const Math::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.

Math::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.

Vector< Math::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(Math::dvec3 & min_val, Math::dvec3 & max_val)

Arguments

  • Math::dvec3 & min_val
  • Math::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.

void grab()

Grabs the dataset (sets the owner flag to 1). The dataset should not be handled by the engine after this function is called.

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(const char * name)

Loads the given dataset.

Arguments

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

Return value

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

void release()

Releases the dataset (sets the owner flag to 0). The dataset should be handled by the engine after this function is called.

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.
Last update: 2018-04-26
Build: ()