QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
32 vector_tile::Tile_Feature *
feature =
nullptr;
49 feature->add_geometry( 1 | ( count << 3 ) );
53 feature->add_geometry( 2 | ( count << 3 ) );
57 feature->add_geometry( 7 | ( 1 << 3 ) );
67 const qint32 vx = pt.x() -
cursor.x();
68 const qint32 vy = pt.y() -
cursor.y();
72 feature->add_geometry( ( ( quint32 )vx << 1 ) ^ ( ( quint32 )( -( qint32 )( ( quint32 )vx >> 31 ) ) ) );
73 feature->add_geometry( ( ( quint32 )vy << 1 ) ^ ( ( quint32 )( -( qint32 )( ( quint32 )vy >> 31 ) ) ) );
89 const double *xData = lineString->
xData();
90 const double *yData = lineString->
yData();
96 QVector<QPoint> tilePoints;
97 QPoint last( -9999, -9999 );
98 tilePoints.reserve( count );
99 for (
int i = 0; i < count; ++i )
108 count = tilePoints.count();
111 geomWriter.
addPoint( tilePoints[0] );
115 for (
int i = count - 1; i >= 1; --i )
116 geomWriter.
addPoint( tilePoints[i] );
120 for (
int i = 1; i < count; ++i )
121 geomWriter.
addPoint( tilePoints[i] );
154 mTileExtent = tileMatrix.
tileExtent( mTileID );
155 mCrs = tileMatrix.
crs();
170 layerTileExtent = extentTransform.
transformBoundingBox( layerTileExtent, Qgis::TransformDirection::Reverse );
178 QgsDebugMsg(
"Failed to reproject tile extent to the layer" );
182 if ( layerName.isEmpty() )
183 layerName = layer->
name();
186 const double bufferRatio =
static_cast<double>( mBuffer ) / mResolution;
188 tileExtent.
grow( bufferRatio * mTileExtent.
width() );
189 layerTileExtent.
grow( bufferRatio * std::max( layerTileExtent.
width(), layerTileExtent.
height() ) );
193 if ( !filterExpression.isEmpty() )
203 vector_tile::Tile_Layer *tileLayer = tile.add_layers();
204 tileLayer->set_name( layerName.toUtf8() );
205 tileLayer->set_version( 2 );
206 tileLayer->set_extent(
static_cast<::google::protobuf::uint32
>( mResolution ) );
209 for (
int i = 0; i < fields.
count(); ++i )
211 tileLayer->add_keys( fields[i].name().toUtf8() );
228 QgsDebugMsg(
"Failed to reproject geometry " + QString::number( f.
id() ) );
237 addFeature( tileLayer, f );
241 mKnownValues.clear();
244 void QgsVectorTileMVTEncoder::addFeature( vector_tile::Tile_Layer *tileLayer,
const QgsFeature &f )
248 const double onePixel = mTileExtent.
width() / mResolution;
252 if ( g.
length() < onePixel )
257 if ( g.
area() < onePixel * onePixel )
261 vector_tile::Tile_Feature *feature = tileLayer->add_features();
263 feature->set_id(
static_cast<quint64
>( f.
id() ) );
270 for (
int i = 0; i < attrs.count(); ++i )
272 const QVariant v = attrs.at( i );
273 if ( !v.isValid() || v.isNull() )
277 if ( mKnownValues.contains( v ) )
279 valueIndex = mKnownValues[v];
283 vector_tile::Tile_Value *value = tileLayer->add_values();
284 valueIndex = tileLayer->values_size() - 1;
285 mKnownValues[v] = valueIndex;
287 if ( v.type() == QVariant::Double )
288 value->set_double_value( v.toDouble() );
289 else if ( v.type() == QVariant::Int )
290 value->set_int_value( v.toInt() );
291 else if ( v.type() == QVariant::Bool )
292 value->set_bool_value( v.toBool() );
294 value->set_string_value( v.toString().toUtf8().toStdString() );
297 feature->add_tags(
static_cast<quint32
>( i ) );
298 feature->add_tags(
static_cast<quint32
>( valueIndex ) );
305 vector_tile::Tile_GeomType mvtGeomType = vector_tile::Tile_GeomType_UNKNOWN;
307 mvtGeomType = vector_tile::Tile_GeomType_POINT;
309 mvtGeomType = vector_tile::Tile_GeomType_LINESTRING;
311 mvtGeomType = vector_tile::Tile_GeomType_POLYGON;
312 feature->set_type( mvtGeomType );
334 encodeLineString( qgsgeometry_cast<const QgsLineString *>( geom ),
true,
false, geomWriter );
340 encodePolygon(
static_cast<const QgsPolygon *
>( geom ), geomWriter );
358 encodeLineString( mls->
lineStringN( i ),
true,
false, geomWriter );
365 const QgsMultiPolygon *mp = qgsgeometry_cast<const QgsMultiPolygon *>( geom );
368 encodePolygon( mp->
polygonN( i ), geomWriter );
381 return QByteArray::fromStdString( tile.SerializeAsString() );
bool intersects(const QgsRectangle &rect) const SIP_HOLDGIL
Returns true when rectangle intersects with other rectangle.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
QgsCoordinateReferenceSystem crs
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
QPoint mapToTileCoordinates(double x, double y)
Stores coordinates of a tile in a tile matrix set. Tile matrix is identified by the zoomLevel(),...
Point geometry type, with support for z-dimension and m-values.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
QgsVectorTileMVTEncoder(QgsTileXYZ tileID)
Creates MVT encoder for the given tile coordinates for Web Mercator.
const QgsCurve * exteriorRing() const SIP_HOLDGIL
Returns the curve polygon's exterior ring.
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
QgsRectangle tileExtent(QgsTileXYZ id) const
Returns extent of the given tile in this matrix.
int count() const
Returns number of items.
Container of fields for a vector layer.
QByteArray encode() const
Encodes MVT using data stored previously with addLayer() calls.
Multi line string geometry collection.
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
const double * yData() const
Returns a const pointer to the y vertex data.
void addMoveTo(int count)
void addPoint(const QgsPoint &pt)
void addLayer(QgsVectorLayer *layer, QgsFeedback *feedback=nullptr, QString filterExpression=QString(), QString layerName=QString())
Fetches data from vector layer for the given tile, does reprojection and clipping.
static bool isExteriorRing(const QgsLineString *lineString)
Returns whether this linear ring forms an exterior ring according to MVT spec (depending on the orien...
Line string geometry type, with support for z-dimension and m-values.
A rectangle specified with double values.
const double * xData() const
Returns a const pointer to the x vertex data.
QgsCoordinateReferenceSystem crs() const
Returns the crs of the tile matrix.
int numGeometries() const SIP_HOLDGIL
Returns the number of geometries within the collection.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
int numInteriorRings() const SIP_HOLDGIL
Returns the number of interior rings contained with the curve polygon.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
This class wraps a request for features to a vector layer (or directly its vector data provider).
Defines a matrix of tiles for a single zoom level: it is defined by its size (width *.
Custom exception class for Coordinate Reference System related exceptions.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
double length() const
Returns the planar, 2-dimensional length of geometry.
Multi polygon geometry collection.
QgsGeometry clipped(const QgsRectangle &rectangle)
Clips the geometry using the specified rectangle.
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Helper class for writing of geometry commands.
const QgsCurve * interiorRing(int i) const SIP_HOLDGIL
Retrieves an interior ring from the curve polygon.
int zoomLevel() const
Returns tile's zoom level (Z)
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Multi point geometry collection.
vector_tile::Tile_Feature * feature
Abstract base class for all geometries.
virtual QgsAbstractGeometry * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
QgsRectangle extent() const FINAL
Returns the extent of the layer.
QgsPoint * pointN(int index)
Returns the point with the specified index.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
static bool isCurvedType(Type type) SIP_HOLDGIL
Returns true if the WKB type is a curved type or can contain curved geometries.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
bool nextFeature(QgsFeature &f)
A geometry is the spatial representation of a feature.
Represents a vector layer which manages a vector based data sets.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
QgsLineString * lineStringN(int index)
Returns the line string with the specified index.
static QgsTileMatrix fromWebMercator(int zoomLevel)
Returns a tile matrix for the usual web mercator.
void addLineTo(int count)
A vector of attributes. Mostly equal to QVector<QVariant>.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void grow(double delta)
Grows the rectangle in place by the specified amount.
MVTGeometryWriter(vector_tile::Tile_Feature *f, int res, const QgsRectangle &tileExtent)
int numPoints() const override SIP_HOLDGIL
Returns the number of points in the curve.
QgsWkbTypes::GeometryType type
Wrapper for iterator of features from vector data provider or vector layer.
double area() const
Returns the planar, 2-dimensional area of the geometry.
QgsPolygon * polygonN(int index)
Returns the polygon with the specified index.
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)