QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
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 qint32 vx = pt.x() -
cursor.x();
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] );
168 QgsDebugMsg(
"Failed to reproject tile extent to the layer" );
172 if ( layerName.isEmpty() )
173 layerName = layer->
name();
176 double bufferRatio =
static_cast<double>( mBuffer ) / mResolution;
178 tileExtent.
grow( bufferRatio * mTileExtent.
width() );
179 layerTileExtent.
grow( bufferRatio * std::max( layerTileExtent.
width(), layerTileExtent.
height() ) );
183 if ( !filterExpression.isEmpty() )
193 vector_tile::Tile_Layer *tileLayer = tile.add_layers();
194 tileLayer->set_name( layerName.toUtf8() );
195 tileLayer->set_version( 2 );
196 tileLayer->set_extent(
static_cast<::google::protobuf::uint32
>( mResolution ) );
199 for (
int i = 0; i < fields.
count(); ++i )
201 tileLayer->add_keys( fields[i].name().toUtf8() );
218 QgsDebugMsg(
"Failed to reproject geometry " + QString::number( f.
id() ) );
227 addFeature( tileLayer, f );
231 mKnownValues.clear();
234 void QgsVectorTileMVTEncoder::addFeature( vector_tile::Tile_Layer *tileLayer,
const QgsFeature &f )
238 double onePixel = mTileExtent.
width() / mResolution;
242 if ( g.
length() < onePixel )
247 if ( g.
area() < onePixel * onePixel )
251 vector_tile::Tile_Feature *feature = tileLayer->add_features();
253 feature->set_id(
static_cast<quint64
>( f.
id() ) );
260 for (
int i = 0; i < attrs.count(); ++i )
262 const QVariant v = attrs.at( i );
263 if ( !v.isValid() || v.isNull() )
267 if ( mKnownValues.contains( v ) )
269 valueIndex = mKnownValues[v];
273 vector_tile::Tile_Value *value = tileLayer->add_values();
274 valueIndex = tileLayer->values_size() - 1;
275 mKnownValues[v] = valueIndex;
277 if ( v.type() == QVariant::Double )
278 value->set_double_value( v.toDouble() );
279 else if ( v.type() == QVariant::Int )
280 value->set_int_value( v.toInt() );
281 else if ( v.type() == QVariant::Bool )
282 value->set_bool_value( v.toBool() );
284 value->set_string_value( v.toString().toUtf8().toStdString() );
287 feature->add_tags(
static_cast<quint32
>( i ) );
288 feature->add_tags(
static_cast<quint32
>( valueIndex ) );
295 vector_tile::Tile_GeomType mvtGeomType = vector_tile::Tile_GeomType_UNKNOWN;
297 mvtGeomType = vector_tile::Tile_GeomType_POINT;
299 mvtGeomType = vector_tile::Tile_GeomType_LINESTRING;
301 mvtGeomType = vector_tile::Tile_GeomType_POLYGON;
302 feature->set_type( mvtGeomType );
324 encodeLineString( qgsgeometry_cast<const QgsLineString *>( geom ),
true,
false, geomWriter );
330 encodePolygon(
static_cast<const QgsPolygon *
>( geom ), geomWriter );
348 encodeLineString( qgsgeometry_cast<const QgsLineString *>( mls->
geometryN( i ) ),
true,
false, geomWriter );
355 const QgsMultiPolygon *mp = qgsgeometry_cast<const QgsMultiPolygon *>( geom );
371 return QByteArray::fromStdString( tile.SerializeAsString() );
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
QgsCoordinateReferenceSystem crs
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
QPoint mapToTileCoordinates(double x, double y)
Point geometry type, with support for z-dimension and m-values.
int numGeometries() const
Returns the number of geometries within the collection.
QgsVectorTileMVTEncoder(QgsTileXYZ tileID)
Creates MVT encoder for the given tile coordinates.
int numPoints() const override
Returns the number of points in the curve.
QgsRectangle tileExtent(QgsTileXYZ id) const
Returns extent of the given tile in this matrix.
int count() const
Returns number of items.
QByteArray encode() const
Encodes MVT using data stored previously with addLayer() calls.
Multi line string geometry collection.
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
QgsWkbTypes::Type wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
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.
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
const double * xData() const
Returns a const pointer to the x vertex data.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
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.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Helper class for writing of geometry commands.
int zoomLevel() const
Returns tile's zoom level (Z)
Multi point geometry collection.
vector_tile::Tile_Feature * feature
Abstract base class for all geometries.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
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.
bool isCanceled() const
Tells whether the operation has been canceled already.
bool intersects(const QgsRectangle &rect) const
Returns true when rectangle intersects with other rectangle.
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
int numInteriorRings() const
Returns the number of interior rings contained with the curve polygon.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
bool nextFeature(QgsFeature &f)
double height() const
Returns the height of the rectangle.
void addLineTo(int count)
static bool isCurvedType(Type type)
Returns true if the WKB type is a curved type or can contain curved geometries.
static QgsTileMatrix fromWebMercator(int mZoomLevel)
Returns a tile matrix for the usual web mercator.
void grow(double delta)
Grows the rectangle in place by the specified amount.
MVTGeometryWriter(vector_tile::Tile_Feature *f, int res, const QgsRectangle &tileExtent)
QgsWkbTypes::GeometryType type
double area() const
Returns the planar, 2-dimensional area of the geometry.
double width() const
Returns the width of the rectangle.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
static Type flatType(Type type)
Returns the flat type for a WKB type.