31 vector_tile::Tile_Feature *
feature =
nullptr;
41 ,
tileDX( tileExtent.width() )
42 ,
tileDY( tileExtent.height() )
48 feature->add_geometry( 1 | ( count << 3 ) );
52 feature->add_geometry( 2 | ( count << 3 ) );
56 feature->add_geometry( 7 | ( 1 << 3 ) );
66 const qint32 vx = pt.x() -
cursor.x();
67 const qint32 vy = pt.y() -
cursor.y();
71 feature->add_geometry( ( ( quint32 )vx << 1 ) ^ ( ( quint32 )( -( qint32 )( ( quint32 )vx >> 31 ) ) ) );
72 feature->add_geometry( ( ( quint32 )vy << 1 ) ^ ( ( quint32 )( -( qint32 )( ( quint32 )vy >> 31 ) ) ) );
88 const double *xData = lineString->
xData();
89 const double *yData = lineString->
yData();
95 QVector<QPoint> tilePoints;
96 QPoint last( -9999, -9999 );
97 tilePoints.reserve( count );
98 for (
int i = 0; i < count; ++i )
107 count = tilePoints.count();
112 geomWriter.
addPoint( tilePoints[0] );
116 for (
int i = count - 1; i >= 1; --i )
117 geomWriter.
addPoint( tilePoints[i] );
121 for (
int i = 1; i < count; ++i )
122 geomWriter.
addPoint( tilePoints[i] );
155 mTileExtent = tileMatrix.
tileExtent( mTileID );
156 mCrs = tileMatrix.
crs();
179 QgsDebugError(
"Failed to reproject tile extent to the layer" );
183 if ( layerName.isEmpty() )
184 layerName = layer->
name();
187 const double bufferRatio =
static_cast<double>( mBuffer ) / mResolution;
189 tileExtent.
grow( bufferRatio * mTileExtent.width() );
190 layerTileExtent.
grow( bufferRatio * std::max( layerTileExtent.
width(), layerTileExtent.
height() ) );
194 if ( !filterExpression.isEmpty() )
204 vector_tile::Tile_Layer *tileLayer = tile.add_layers();
205 tileLayer->set_name( layerName.toUtf8().constData() );
206 tileLayer->set_version( 2 );
207 tileLayer->set_extent(
static_cast<::google::protobuf::uint32
>( mResolution ) );
210 for (
int i = 0; i < fields.
count(); ++i )
212 tileLayer->add_keys( fields[i].name().toUtf8().constData() );
229 QgsDebugError(
"Failed to reproject geometry " + QString::number( f.
id() ) );
245 addFeature( tileLayer, f );
249 mKnownValues.
clear();
252void QgsVectorTileMVTEncoder::addFeature( vector_tile::Tile_Layer *tileLayer,
const QgsFeature &f )
256 const double onePixel = mTileExtent.
width() / mResolution;
260 if ( g.
length() < onePixel )
265 if ( g.
area() < onePixel * onePixel )
269 vector_tile::Tile_Feature *feature = tileLayer->add_features();
271 feature->set_id(
static_cast<quint64
>( f.
id() ) );
278 for (
int i = 0; i < attrs.count(); ++i )
280 const QVariant v = attrs.at( i );
285 if ( mKnownValues.contains( v ) )
287 valueIndex = mKnownValues[v];
291 vector_tile::Tile_Value *value = tileLayer->add_values();
292 valueIndex = tileLayer->values_size() - 1;
293 mKnownValues[v] = valueIndex;
295 switch ( v.userType() )
297 case QMetaType::Type::Double:
298 value->set_double_value( v.toDouble() );
301 case QMetaType::Type::Float:
302 value->set_float_value( v.toFloat() );
305 case QMetaType::Type::Int:
306 case QMetaType::Type::Long:
307 case QMetaType::Type::LongLong:
308 value->set_int_value( v.toLongLong() );
311 case QMetaType::Type::UInt:
312 case QMetaType::Type::ULong:
313 case QMetaType::Type::ULongLong:
314 value->set_uint_value( v.toULongLong() );
317 case QMetaType::Type::Bool:
318 value->set_bool_value( v.toBool() );
322 value->set_string_value( v.toString().toUtf8().toStdString() );
328 feature->add_tags(
static_cast<quint32
>( i ) );
329 feature->add_tags(
static_cast<quint32
>( valueIndex ) );
336 vector_tile::Tile_GeomType mvtGeomType = vector_tile::Tile_GeomType_UNKNOWN;
338 mvtGeomType = vector_tile::Tile_GeomType_POINT;
340 mvtGeomType = vector_tile::Tile_GeomType_LINESTRING;
342 mvtGeomType = vector_tile::Tile_GeomType_POLYGON;
343 feature->set_type( mvtGeomType );
350 MVTGeometryWriter geomWriter( feature, mResolution, mTileExtent );
352 const QgsAbstractGeometry *geom = g.
constGet();
357 const QgsPoint *pt =
static_cast<const QgsPoint *
>( geom );
371 encodePolygon(
static_cast<const QgsPolygon *
>( geom ), geomWriter );
377 const QgsMultiPoint *mpt =
static_cast<const QgsMultiPoint *
>( geom );
389 encodeLineString( mls->
lineStringN( i ),
true,
false, geomWriter );
399 encodePolygon( mp->
polygonN( i ), geomWriter );
412 return QByteArray::fromStdString( tile.SerializeAsString() );
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
@ MultiPolygon
MultiPolygon.
@ MultiLineString
MultiLineString.
@ Reverse
Reverse/inverse transform (from destination to source).
virtual QgsAbstractGeometry * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
Custom exception class for Coordinate Reference System related exceptions.
int numInteriorRings() const
Returns the number of interior rings contained with the curve polygon.
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
Wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
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.
bool isCanceled() const
Tells whether the operation has been canceled already.
Container of fields for a vector layer.
void clear()
Removes all fields.
int numGeometries() const
Returns the number of geometries within the collection.
A geometry is the spatial representation of a feature.
QgsGeometry clipped(const QgsRectangle &rectangle)
Clips the geometry using the specified rectangle.
double length() const
Returns the planar, 2-dimensional length of geometry.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
double area() const
Returns the planar, 2-dimensional area of the geometry.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
Qgis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.).
Line string geometry type, with support for z-dimension and m-values.
const double * yData() const
Returns a const pointer to the y vertex data.
const double * xData() const
Returns a const pointer to the x vertex data.
int numPoints() const override
Returns the number of points in the curve.
QgsCoordinateReferenceSystem crs
QgsLineString * lineStringN(int index)
Returns the line string with the specified index.
QgsPoint * pointN(int index)
Returns the point with the specified index.
QgsPolygon * polygonN(int index)
Returns the polygon with the specified index.
Point geometry type, with support for z-dimension and m-values.
A rectangle specified with double values.
bool intersects(const QgsRectangle &rect) const
Returns true when rectangle intersects with other rectangle.
void grow(double delta)
Grows the rectangle in place by the specified amount.
Defines a matrix of tiles for a single zoom level: it is defined by its size (width *.
QgsRectangle tileExtent(QgsTileXYZ id) const
Returns extent of the given tile in this matrix.
static QgsTileMatrix fromWebMercator(int zoomLevel)
Returns a tile matrix for the usual web mercator.
QgsCoordinateReferenceSystem crs() const
Returns the crs of the tile matrix.
Stores coordinates of a tile in a tile matrix set.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Represents a vector layer which manages a vector based dataset.
QgsRectangle extent() const final
Returns the extent of the layer.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const final
Queries the layer for features specified in request.
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.
QByteArray encode() const
Encodes MVT using data stored previously with addLayer() calls.
QgsVectorTileMVTEncoder(QgsTileXYZ tileID)
Creates MVT encoder for the given tile coordinates for Web Mercator.
static bool isExteriorRing(const QgsLineString *lineString)
Returns whether this linear ring forms an exterior ring according to MVT spec (depending on the orien...
static Q_INVOKABLE bool isCurvedType(Qgis::WkbType type)
Returns true if the WKB type is a curved type or can contain curved geometries.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
T qgsgeometry_cast(QgsAbstractGeometry *geom)
#define QgsDebugError(str)
Helper class for writing of geometry commands.
vector_tile::Tile_Feature * feature
void addPoint(const QgsPoint &pt)
void addMoveTo(int count)
QPoint mapToTileCoordinates(double x, double y) const
MVTGeometryWriter(vector_tile::Tile_Feature *f, int res, const QgsRectangle &tileExtent)
void addLineTo(int count)
void addPoint(const QPoint &pt)