Skip to main content

GeoStream

The GeoStream plugin provides an interface for managing and accessing geographic data streams from various sources. It supports chaining multiple GeoStream instances to improve data precision within specific geographic regions and enables advanced features like data caching and proxy configuration. The plugin allows retrieving color values at geographic coordinates.

info

This plugin is used by XYZTile tool to convert and process different geographic datums.

#include <geospatial/geostream/include/TellusimGeoStream.h>

Example

The following example demonstrates how to use the GeoStreamXYZ class to fetch and sample geographic imagery from a remote XYZ tile server.

GeoRectd rect;
rect.min.lon = -117.299;
rect.max.lat = 32.866;
rect.max.lon = rect.min.lon + 0.4;
rect.min.lat = rect.max.lat - 0.4;

// create XYZ stream to access USDA data
GeoStreamXYZ stream(4, 0, "https://gis.apfo.usda.gov/arcgis/rest/services/NAIP/USDA_CONUS_PRIME/ImageServer/tile/{z}/{y}/{x}");

// set local cache directory
if(!stream.open("NAIP/level_{Z}/{y}/{x}")) return false;

// sample image
Image image;
image.create2D(FormatRGBu8n, size);

// sample stream
ImageSampler sampler(image);
for(uint32_t y = 0; y < sampler.getHeight(); y += step) {
async.append(async.run([&](uint32_t y0, uint32_t y1) {
for(uint32_t y = y0; y < y1; y++) {
float64_t lat = (rect.min.lat - rect.max.lat) * y / (sampler.getHeight() - 1) + rect.max.lat;
for(uint32_t x = 0; x < sampler.getWidth(); x++) {
float64_t lon = (rect.max.lon - rect.min.lon) * x / (sampler.getWidth() - 1) + rect.min.lon;
Color color = stream.get(GeoVector2d(lon, lat));
sampler.set2D(x, y, ImageColor(color, sampler.getFormat()));
}
}
}, y, min(y + step, sampler.getHeight())));
}
async.wait();

// save image
image.save("stream_xyz.image");