QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsvectortilematrixset.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectortilematrixset.cpp
3  --------------------------------------
4  Date : March 2022
5  Copyright : (C) 2022 by Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsvectortilematrixset.h"
17 #include "qgstiles.h"
18 #include "qgsvectortileutils.h"
19 #include "qgsarcgisrestutils.h"
20 #include "qgslogger.h"
21 
23 {
26  return res;
27 }
28 
29 bool QgsVectorTileMatrixSet::fromEsriJson( const QVariantMap &json )
30 {
32 
33  const QVariantMap tileInfo = json.value( QStringLiteral( "tileInfo" ) ).toMap();
34 
35  const QVariantMap origin = tileInfo.value( QStringLiteral( "origin" ) ).toMap();
36  const double originX = origin.value( QStringLiteral( "x" ) ).toDouble();
37  const double originY = origin.value( QStringLiteral( "y" ) ).toDouble();
38 
39  const int rows = tileInfo.value( QStringLiteral( "rows" ), QStringLiteral( "512" ) ).toInt();
40  const int cols = tileInfo.value( QStringLiteral( "cols" ), QStringLiteral( "512" ) ).toInt();
41  if ( rows != cols )
42  {
43  QgsDebugMsg( QStringLiteral( "row/col size mismatch: %1 vs %2 - tile misalignment may occur" ).arg( rows ).arg( cols ) );
44  }
45 
46  const QgsCoordinateReferenceSystem crs = QgsArcGisRestUtils::convertSpatialReference( tileInfo.value( QStringLiteral( "spatialReference" ) ).toMap() );
47 
48  const QVariantList lodList = tileInfo.value( QStringLiteral( "lods" ) ).toList();
49  bool foundLevel0 = false;
50  double z0Dimension = 0;
51 
52  for ( const QVariant &lod : lodList )
53  {
54  const QVariantMap lodMap = lod.toMap();
55  const int level = lodMap.value( QStringLiteral( "level" ) ).toInt();
56  if ( level == 0 )
57  {
58  z0Dimension = lodMap.value( QStringLiteral( "resolution" ) ).toDouble() * rows;
59  foundLevel0 = true;
60  break;
61  }
62  }
63 
64  if ( !foundLevel0 )
65  return false;
66 
67  for ( const QVariant &lod : lodList )
68  {
69  const QVariantMap lodMap = lod.toMap();
70  const int level = lodMap.value( QStringLiteral( "level" ) ).toInt();
71 
72  // TODO -- we shouldn't be using z0Dimension here, but rather the actual dimension and properties of
73  // this exact LOD
75  level,
76  crs,
77  QgsPointXY( originX, originY ),
78  z0Dimension );
79  tm.setScale( lodMap.value( QStringLiteral( "scale" ) ).toDouble() );
80  addMatrix( tm );
81  }
82  return true;
83 }
QgsVectorTileMatrixSet
Encapsulates properties of a vector tile matrix set, including tile origins and scaling information.
Definition: qgsvectortilematrixset.h:31
qgsvectortilematrixset.h
QgsArcGisRestUtils::convertSpatialReference
static QgsCoordinateReferenceSystem convertSpatialReference(const QVariantMap &spatialReferenceMap)
Converts a spatial reference JSON definition to a QgsCoordinateReferenceSystem value.
Definition: qgsarcgisrestutils.cpp:403
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsVectorTileMatrixSet::fromEsriJson
bool fromEsriJson(const QVariantMap &json)
Initializes the tile structure settings from an ESRI REST VectorTileService json map.
Definition: qgsvectortilematrixset.cpp:29
QgsTileMatrixSet::maximumZoom
int maximumZoom() const
Returns the maximum zoom level for tiles present in the set.
Definition: qgstiles.cpp:169
QgsTileMatrix
Defines a matrix of tiles for a single zoom level: it is defined by its size (width *.
Definition: qgstiles.h:107
Qgis::ScaleToTileZoomLevelMethod::Esri
@ Esri
No scale doubling, always rounds down when matching to available tile levels.
QgsTileMatrixSet::addMatrix
void addMatrix(const QgsTileMatrix &matrix)
Adds a matrix to the set.
Definition: qgstiles.cpp:153
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsTileMatrix::setScale
void setScale(double scale)
Sets the scale denominator of the tile matrix.
Definition: qgstiles.h:178
qgsarcgisrestutils.h
qgstiles.h
QgsTileMatrixSet::crs
QgsCoordinateReferenceSystem crs() const
Returns the coordinate reference system associated with the tiles.
Definition: qgstiles.cpp:195
QgsVectorTileMatrixSet::fromWebMercator
static QgsVectorTileMatrixSet fromWebMercator(int minimumZoom=0, int maximumZoom=14)
Returns a vector tile structure corresponding to the standard web mercator/GoogleCRS84Quad setup.
Definition: qgsvectortilematrixset.cpp:22
QgsTileMatrixSet::setScaleToTileZoomMethod
void setScaleToTileZoomMethod(Qgis::ScaleToTileZoomLevelMethod method)
Sets the scale to tile zoom method.
Definition: qgstiles.h:337
QgsTileMatrixSet::minimumZoom
int minimumZoom() const
Returns the minimum zoom level for tiles present in the set.
Definition: qgstiles.cpp:158
QgsTileMatrix::fromCustomDef
static QgsTileMatrix fromCustomDef(int zoomLevel, const QgsCoordinateReferenceSystem &crs, const QgsPointXY &z0TopLeftPoint, double z0Dimension, int z0MatrixWidth=1, int z0MatrixHeight=1)
Returns a tile matrix for a specific CRS, top left point, zoom level 0 dimension in CRS units.
Definition: qgstiles.cpp:31
qgslogger.h
qgsvectortileutils.h
QgsTileMatrixSet::addGoogleCrs84QuadTiles
void addGoogleCrs84QuadTiles(int minimumZoom=0, int maximumZoom=14)
Adds tile matrices corresponding to the standard web mercator/GoogleCRS84Quad setup.
Definition: qgstiles.cpp:137