30 #define _CRT_SECURE_NO_DEPRECATE
49 : mProvider( provider )
54 , mLabelLayer( toLabel )
55 , mDisplayAll( displayAll )
56 , mCentroidInside( false )
57 , mFitInPolygon( false )
58 , mArrangement( arrangement )
59 , mArrangementFlags( 0 )
60 , mMode( LabelPerFeature )
61 , mMergeLines( false )
62 , mUpsidedownLabels( Upright )
66 if ( defaultPriority < 0.0001 )
68 else if ( defaultPriority > 1.0 )
92 if ( priority >= 1.0 )
94 else if ( priority <= 0.0001 )
120 bool addedFeature =
false;
122 double geom_size = -1, biggest_size = -1;
127 if ( simpleGeometries == NULL )
135 while ( simpleGeometries->
size() > 0 )
137 const GEOSGeometry* geom = simpleGeometries->
takeFirst();
140 if ( GEOSisValid_r( geosctxt, geom ) != 1 )
146 int type = GEOSGeomTypeId_r( geosctxt, geom );
148 if ( type != GEOS_POINT && type != GEOS_LINESTRING && type != GEOS_POLYGON )
157 if (( type == GEOS_LINESTRING && fpart->
nbPoints < 2 ) ||
158 ( type == GEOS_POLYGON && fpart->
nbPoints < 3 ) )
173 if ( type == GEOS_LINESTRING )
174 GEOSLength_r( geosctxt, geom, &geom_size );
175 else if ( type == GEOS_POLYGON )
176 GEOSArea_r( geosctxt, geom, &geom_size );
178 if ( geom_size > biggest_size )
180 biggest_size = geom_size;
182 biggest_part = fpart;
196 delete simpleGeometries;
227 rtree->Insert( bmin, bmax, fpart );
252 while ( p != otherParts->
constEnd() )
287 double bmin[2], bmax[2];
289 rtree->Remove( bmin, bmax, partCheck );
298 rtree->Remove( bmin, bmax, otherPart );
300 rtree->Insert( bmin, bmax, otherPart );
327 const GEOSGeometry* geom = fpart->
geos();
329 if ( chopInterval != 0. && GEOSGeomTypeId_r( geosctxt, geom ) == GEOS_LINESTRING )
332 double bmin[2], bmax[2];
334 rtree->Remove( bmin, bmax, fpart );
336 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosctxt, geom );
340 GEOSCoordSeq_getSize_r( geosctxt, cs, &n );
343 std::vector<Point> points( n );
344 for (
unsigned int i = 0; i < n; ++i )
346 GEOSCoordSeq_getX_r( geosctxt, cs, i, &points[i].x );
347 GEOSCoordSeq_getY_r( geosctxt, cs, i, &points[i].y );
351 std::vector<double> len( n, 0 );
352 for (
unsigned int i = 1; i < n; ++i )
354 double dx = points[i].x - points[i - 1].x;
355 double dy = points[i].y - points[i - 1].y;
356 len[i] = len[i - 1] + std::sqrt( dx * dx + dy * dy );
360 unsigned int cur = 0;
362 std::vector<Point> part;
365 lambda += chopInterval;
366 for ( ; cur < n && lambda > len[cur]; ++cur )
368 part.push_back( points[cur] );
374 double c = ( lambda - len[cur - 1] ) / ( len[cur] - len[cur - 1] );
376 p.
x = points[cur - 1].x + c * ( points[cur].x - points[cur - 1].x );
377 p.
y = points[cur - 1].y + c * ( points[cur].y - points[cur - 1].y );
379 GEOSCoordSequence* cooSeq = GEOSCoordSeq_create_r( geosctxt, part.size(), 2 );
380 for ( std::size_t i = 0; i < part.size(); ++i )
382 GEOSCoordSeq_setX_r( geosctxt, cooSeq, i, part[i].x );
383 GEOSCoordSeq_setY_r( geosctxt, cooSeq, i, part[i].y );
386 GEOSGeometry* newgeom = GEOSGeom_createLineString_r( geosctxt, cooSeq );
388 newFeatureParts.
append( newfpart );
390 rtree->Insert( bmin, bmax, newfpart );
395 part.push_back( points[n - 1] );
396 GEOSCoordSequence* cooSeq = GEOSCoordSeq_create_r( geosctxt, part.size(), 2 );
397 for ( std::size_t i = 0; i < part.size(); ++i )
399 GEOSCoordSeq_setX_r( geosctxt, cooSeq, i, part[i].x );
400 GEOSCoordSeq_setY_r( geosctxt, cooSeq, i, part[i].y );
403 GEOSGeometry* newgeom = GEOSGeom_createLineString_r( geosctxt, cooSeq );
405 newFeatureParts.
append( newfpart );
407 rtree->Insert( bmin, bmax, newfpart );
412 newFeatureParts.
append( fpart );
int reorderPolygon(int nbPoints, double *x, double *y)
iterator insert(const Key &key, const T &value)
const GEOSGeometry * geos() const
Returns the point set's GEOS geometry.
QgsLabelFeature * feature()
Returns the parent feature.
QLinkedList< FeaturePart * > mFeatureParts
List of feature parts.
QStringList mConnectedTexts
Layer(QgsAbstractLabelProvider *provider, const QString &name, Arrangement arrangement, double defaultPriority, bool active, bool toLabel, Pal *pal, bool displayAll=false)
Create a new layer.
static FeaturePart * _findConnectedPart(FeaturePart *partCheck, QLinkedList< FeaturePart * > *otherParts)
QHash< QgsFeatureId, QgsLabelFeature * > mHashtable
Lookup table of label features (owned by the label feature provider that created them) ...
void setPriority(double priority)
Sets the layer's priority.
double priority() const
Returns the layer's priority, between 0 and 1.
GEOSGeometry * geometry() const
Get access to the associated geometry.
QSizeF size() const
Size of the label (in map units)
bool hasFixedPosition() const
Whether the label should use a fixed position instead of being automatically placed.
bool mergeWithFeaturePart(FeaturePart *other)
Merge other (connected) part with this one and save the result in this part (other is unchanged)...
QLinkedList< const GEOSGeometry * > * unmulti(const GEOSGeometry *the_geom)
void setLayer(pal::Layer *layer)
Assign PAL layer to the label feature. Should be only used internally in PAL.
bool isConnected(FeaturePart *p2)
Check whether this part is connected with some other part.
GEOSContextHandle_t geosContext()
Get GEOS context handle to be used in all GEOS library calls with reentrant API.
Main class to handle feature.
The QgsAbstractLabelProvider class is an interface class.
Thrown when a geometry type is not like expected.
void getBoundingBox(double min[2], double max[2]) const
const_iterator constBegin() const
void joinConnectedFeatures()
Join connected features with the same label text.
const_iterator constEnd() const
QHash< QString, QLinkedList< FeaturePart * > * > mConnectedHashtable
Arrangement
The way to arrange labels against spatial entities.
The QgsLabelFeature class describes a feature that should be used within the labeling engine...
void chopFeaturesAtRepeatDistance()
Chop layer features at the repeat distance.
bool registerFeature(QgsLabelFeature *label)
Register a feature in the layer.
void addFeaturePart(FeaturePart *fpart, const QString &labelText=QString())
Add newly created feature part into r tree and to the list.
RTree< FeaturePart *, double, 2, double, 8, 4 > * rtree
bool contains(const Key &key) const
QString labelText() const
Text of the label.
void append(const T &value)
QgsFeatureId id() const
Identifier of the label (unique within the parent label provider)