10#ifndef GISRASTERLAYER_H
11#define GISRASTERLAYER_H
19#include <QFutureWatcher>
34class OGRCoordinateTransformation;
35class OGRSpatialReference;
69 Q_CLASSINFO("group:
filePath", "Source")
93 [[nodiscard]] QString
filePath() const;
122 [[nodiscard]] QVector<QPair<QString, QString>>
extendedMetadata() const override;
132 [[nodiscard]] QPair<
double,
double>
bandRange(
int band) const;
140 [[nodiscard]] QVector<
double>
sampleValues(
int band,
int maxSamples = 200000) const;
147 [[nodiscard]] QList<
int>
uniqueValues(
int band,
int cap = 256) const;
166 [[nodiscard]] std::vector<std::unique_ptr<
openswmmvis::ui::ILayerStyleSubject>>
213 [[nodiscard]]
double valueAt(
double mapX,
double mapY,
216 bool *
ok =
nullptr) const;
229 const QSize &viewportSize,
232 void render(QPainter *painter,
234 const QSize &imageSize,
261 double zFactor,
double strength);
290 void openDataset(
const QString &
filePath);
292 void invalidateCache();
298 void maybeBuildOverviews();
303 void buildOverviewsAsync();
316 bool hasNoData =
false;
317 double noDataValue = 0.0;
318 bool hillshadeEnabled =
false;
319 double hillshadeAzimuthDeg = 315.0;
320 double hillshadeAltitudeDeg = 45.0;
321 double hillshadeZFactor = 1.0;
322 double hillshadeStrength = 0.5;
323 std::shared_ptr<const OpenSWMM::Render::IRasterRenderer> renderer;
325 [[nodiscard]] WarpParams snapshotWarpParams()
const;
333 [[nodiscard]] QImage warpToCanvas(GDALDataset *
src,
338 const WarpParams &
params)
const;
349 [[nodiscard]] GDALDataset *buildWindowedSource(
352 int pixelWidth,
int pixelHeight,
int outBands,
bool isRGB,
353 const WarpParams &
params)
const;
362 static constexpr int kTilePx = 256;
365 static constexpr double kMaxAncestorSpanRatio = 64.0;
366 struct TileReq {
int level;
int col;
int row; };
380 [[nodiscard]]
static int levelForResolution(
double mapUnitsPerPixel);
382 [[nodiscard]]
static MapExtent tileExtent(
int level,
int col,
int row);
383 [[nodiscard]]
static QString tileKey(
int level,
int col,
int row);
391 void enqueueSeedTiles();
394 void startNextTiles();
397 void onSlotFinished(
int slotIndex);
406 std::unique_ptr<QFutureWatcher<TileResult>> watcher;
408 GDALDataset *handle =
nullptr;
413 void openHandlePool();
416 void closeHandlePool();
421 void drainTileSlots();
424 void finishSlot(TileSlot &slot);
428 [[nodiscard]] QList<OpenSWMM::Render::PalettedRasterRenderer::Class>
429 readColorTableLocked()
const;
432 int m_renderBand = 1;
433 bool m_isBasemap =
false;
434 double m_noDataValue = std::numeric_limits<double>::quiet_NaN();
435 bool m_hasNoData =
false;
439 mutable QHash<int, QPair<double, double>> m_bandRangeCache;
440 mutable QHash<int, QVector<double>> m_sampleCache;
443 bool m_hillshadeEnabled =
false;
444 double m_hillshadeAzimuthDeg = 315.0;
445 double m_hillshadeAltitudeDeg = 45.0;
446 double m_hillshadeZFactor = 1.0;
447 double m_hillshadeStrength = 0.5;
449 GDALDataset *m_dataset =
nullptr;
455 mutable QMutex m_datasetMutex;
460 mutable OGRCoordinateTransformation *m_probeCT =
nullptr;
461 mutable const OGRSpatialReference *m_probeCTCanvasKey =
nullptr;
462 mutable const OGRSpatialReference *m_probeCTRasterKey =
nullptr;
465 std::atomic<bool> m_datasetReloadPending{
false};
466 bool m_overviewBuildInFlight =
false;
471 QList<TileReq> m_tileQueue;
472 QSet<QString> m_queuedKeys;
473 quint64 m_cacheGeneration = 0;
474 quint64 m_seedGeneration = ~0ULL;
480 int m_maxConcurrentTiles = 1;
481 QThreadPool m_tilePool;
482 std::vector<GDALDataset *> m_poolHandles;
483 QList<GDALDataset *> m_freeHandles;
484 std::vector<TileSlot> m_slots;
494 std::unique_ptr<OpenSWMM::Render::IRasterRenderer> m_rasterRenderer;
A map layer backed by a GDAL raster dataset.
Definition gisrasterlayer.h:61
int renderBand
Definition gisrasterlayer.h:65
void setRenderBand(int band)
Sets the 1-based band index to render on the single-band colour path. Re-reads that band's NoData val...
Definition gisrasterlayer.cpp:313
void setHillshadeEnabled(bool on)
Definition gisrasterlayer.cpp:1285
void openAsync(const QString &filePath)
Asynchronously open filePath. GDALOpenEx + metadata read + ComputeStatistics run on a worker thread; ...
Definition gisrasterlayer.cpp:1234
QList< OpenSWMM::Render::PalettedRasterRenderer::Class > colorTableClasses() const
Band 1's GDAL colour table as paletted classes (value, label = value, RGBA). Tables larger than 32 en...
Definition gisrasterlayer.cpp:458
void fetchCache(const MapExtent &extent, const QSize &viewportSize, const SpatialReferenceSystem *srs) override
Triggers any asynchronous (or synchronous) tile/data fetch needed to populate this layer's internal c...
Definition gisrasterlayer.cpp:597
void populateScene(QGraphicsScene *scene, const MapExtent &canvasExtent, const SpatialReferenceSystem *canvasSRS) override
Creates / updates QGraphicsItems representing this layer in the scene.
Definition gisrasterlayer.cpp:882
void setRasterRenderer(std::unique_ptr< OpenSWMM::Render::IRasterRenderer > r)
Replaces the current raster renderer.
Definition gisrasterlayer.cpp:196
QPair< double, double > bandRange(int band) const
Approximate (min, max) of band from GDAL statistics (PAM-cached when available). (NaN,...
Definition gisrasterlayer.cpp:358
QVector< QPair< QString, QString > > extendedMetadata() const override
Ordered key→value pairs of TYPE-SPECIFIC metadata, rendered by the Metadata tab below the common bloc...
Definition gisrasterlayer.cpp:249
std::vector< std::unique_ptr< openswmmvis::ui::ILayerStyleSubject > > styleSubjects() override
Definition gisrasterlayer.cpp:490
bool isBasemapLayer() const override
Returns true for world-spanning basemap layers (XYZ tile providers, WMS/WMTS services covering the wh...
Definition gisrasterlayer.h:226
double hillshadeStrength() const
Definition gisrasterlayer.h:259
void depopulateScene(QGraphicsScene *scene) override
Removes all QGraphicsItems belonging to this layer from the scene.
Definition gisrasterlayer.cpp:955
int bandCount
Definition gisrasterlayer.h:64
double valueAt(double mapX, double mapY, const SpatialReferenceSystem *canvasSRS, int band=1, bool *ok=nullptr) const
Returns the pixel value at the given geographic coordinate.
Definition gisrasterlayer.cpp:504
double hillshadeZFactor() const
Definition gisrasterlayer.h:258
double hillshadeAltitudeDeg() const
Definition gisrasterlayer.h:257
void setIsBasemap(bool on)
Marks this raster as a basemap (added via Add Basemap ▸ Local File). Also retags the layer type to SW...
Definition gisrasterlayer.cpp:305
void renderBandChanged(int band)
void notifyRasterRendererEdited()
Call after mutating the live renderer in place (through its own setters) so cached tiles are dropped,...
Definition gisrasterlayer.cpp:217
void setHillshadeParams(double azimuthDeg, double altitudeDeg, double zFactor, double strength)
Definition gisrasterlayer.cpp:1294
void noDataValueChanged(double value)
void overviewBuildFinished(bool ok)
The background overview build finished (ok ⇒ pyramids ready and the render will pick them up on the n...
bool isRasterLayer() const override
Returns true for layers that render into a raster buffer (WMS, WMTS, GISRaster) rather than populatin...
Definition gisrasterlayer.h:220
QString filePath
Definition gisrasterlayer.h:63
void filePathChanged(const QString &path)
void overviewBuildStarted(const QString &name)
A background overview (.ovr pyramid) build has started for this raster. name is the display file name...
bool isByteRaster() const
True when band 1 is 8-bit (GDT_Byte) — the only type the RGB composite path renders without saturatin...
Definition gisrasterlayer.cpp:478
double noDataValue
Definition gisrasterlayer.h:66
void openFinished(bool ok)
Emitted on the GUI thread when openAsync() completes.
bool hasNoDataValue() const
Returns true when the dataset has a known no-data value.
Definition gisrasterlayer.cpp:241
bool hasColorTable() const
True when band 1 carries a GDAL colour table (paletted raster).
Definition gisrasterlayer.cpp:449
void render(QPainter *painter, const MapExtent &extent, const QSize &imageSize, const SpatialReferenceSystem *srs) override
Renders this layer's content directly into painter.
Definition gisrasterlayer.cpp:894
void onCanvasCRSChanged(const SpatialReferenceSystem *newCanvasSRS) override
Called when the user changes the canvas CRS so layers can pre-compute any CRS-dependent transform cac...
Definition gisrasterlayer.cpp:968
QVector< double > sampleValues(int band, int maxSamples=200000) const
Decimated, overview-aware value sample of band — at most maxSamples finite, non-NoData values on a re...
Definition gisrasterlayer.cpp:381
double hillshadeAzimuthDeg() const
Definition gisrasterlayer.h:256
bool hillshadeEnabled() const
Definition gisrasterlayer.h:254
void rasterRendererChanged()
Emitted when setRasterRenderer() swaps the renderer pointer or notifyRasterRendererEdited() reports a...
QString sourceDescription() const override
Human-readable source of this layer: a file path, a service URL, or a description for in-memory / der...
Definition gisrasterlayer.cpp:243
QString detectVerticalUnit() const
Heuristically detects the vertical unit of the raster's elevation values from the embedded CRS metada...
Definition gisrasterlayer.cpp:259
QList< int > uniqueValues(int band, int cap=256) const
Distinct integer values observed in sampleValues(band), ascending, truncated to cap entries....
Definition gisrasterlayer.cpp:427
void refreshScene(QGraphicsScene *scene, const MapExtent &canvasExtent, const SpatialReferenceSystem *canvasSRS) override
Smart scene refresh — updates existing items instead of destroying and recreating.
Definition gisrasterlayer.cpp:945
OpenSWMM::Render::IRasterRenderer * rasterRenderer() const
The IRasterRenderer that will drive this layer's warp pass.
Definition gisrasterlayer.cpp:191
An axis-aligned bounding box in the coordinate space of a given CRS.
Definition mapextent.h:26
Abstract interface — every raster layer's paint path goes here.
Definition irasterrenderer.h:66
QString name() const
Returns the user-visible name of this layer.
Definition openswmmvislayer.cpp:62
SpatialReferenceSystem * srs() const
Returns the spatial reference system for this layer, or nullptr if the layer has no known CRS.
Definition openswmmvislayer.cpp:201
MapExtent extent() const
Returns the layer extent in the layer's own CRS.
Definition openswmmvislayer.cpp:252
Top-level project container managing sessions, the SWMM model layer, and persistence paths for one SW...
Definition openswmmvisworkspace.h:42
Definition graphicsitems.h:300
Represents a coordinate reference system backed by a GDAL OGRSpatialReference.
Definition spatialreferencesystem.h:28
Base class owning the tile cache + parent-fallback compositor shared by tile-pyramid layers.
Definition tilepyramidlayer.h:47
RasterColorRamp — gradient mapping from a normalised value in [0,1] to a display QColor.
QGraphicsScene * scene
Definition inletdrawingview.cpp:78
bool ok
Definition inpmeshwriter.cpp:575
QString params
Definition lidlayerdiagram.cpp:96
const char * key
Definition meshcellparams.cpp:24
Definition gisrasterlayer.h:40
Definition contourchain.h:23
Definition aquiferprovider.h:21
VS.6 — categorical (paletted) raster renderer.
int path
Definition pslgminsize.cpp:234
int src
index into the caller's vector; -1 = new
Definition pslgminsize.cpp:152
QVector< int > parent
union-find
Definition pslgminsize.cpp:176
Definition gisrasterlayer.cpp:981
Shared tile-pyramid machinery for tiled raster layers (GISRasterLayer, WMTSLayer): a thread-safe tile...