@@ -229,7 +229,7 @@ namespace pal
229
229
230
230
bool Layer::registerFeature ( const char *geom_id, PalGeometry *userGeom, double label_x, double label_y, const char * labelText,
231
231
double labelPosX, double labelPosY, bool fixedPos, double angle, bool fixedAngle,
232
- int xQuadOffset, int yQuadOffset, double xOffset, double yOffset, bool alwaysShow, double repeatDistance )
232
+ int xQuadOffset, int yQuadOffset, double xOffset, double yOffset, bool alwaysShow )
233
233
{
234
234
if ( !geom_id || label_x < 0 || label_y < 0 )
235
235
return false ;
@@ -285,86 +285,6 @@ namespace pal
285
285
throw InternalException::UnknownGeometry ();
286
286
}
287
287
288
- // if multiple labels are requested for lines, split the line in pieces of desired distance
289
- if ( repeatDistance > 0 )
290
- {
291
- int nSimpleGeometries = simpleGeometries->size ();
292
- for ( int i = 0 ; i < nSimpleGeometries; ++i )
293
- {
294
- const GEOSGeometry* geom = simpleGeometries->pop_front ();
295
- if ( GEOSGeomTypeId ( geom ) == GEOS_LINESTRING )
296
- {
297
- const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq ( geom );
298
-
299
- // get number of points
300
- unsigned int n;
301
- GEOSCoordSeq_getSize ( cs, &n );
302
-
303
- // Read points
304
- std::vector<Point> points ( n );
305
- for ( unsigned int i = 0 ; i < n; ++i )
306
- {
307
- GEOSCoordSeq_getX ( cs, i, &points[i].x );
308
- GEOSCoordSeq_getY ( cs, i, &points[i].y );
309
- }
310
-
311
- // Cumulative length vector
312
- std::vector<double > len ( n, 0 );
313
- for ( unsigned int i = 1 ; i < n; ++i )
314
- {
315
- double dx = points[i].x - points[i - 1 ].x ;
316
- double dy = points[i].y - points[i - 1 ].y ;
317
- len[i] = len[i - 1 ] + std::sqrt ( dx * dx + dy * dy );
318
- }
319
-
320
- // Walk along line
321
- unsigned int cur = 0 ;
322
- double lambda = 0 ;
323
- std::vector<Point> part;
324
- for ( ;; )
325
- {
326
- lambda += repeatDistance;
327
- for ( ; cur < n && lambda > len[cur]; ++cur )
328
- {
329
- part.push_back ( points[cur] );
330
- }
331
- if ( cur >= n )
332
- {
333
- break ;
334
- }
335
- double c = ( lambda - len[cur - 1 ] ) / ( len[cur] - len[cur - 1 ] );
336
- Point p;
337
- p.x = points[cur - 1 ].x + c * ( points[cur].x - points[cur - 1 ].x );
338
- p.y = points[cur - 1 ].y + c * ( points[cur].y - points[cur - 1 ].y );
339
- part.push_back ( p );
340
- GEOSCoordSequence* cooSeq = GEOSCoordSeq_create ( part.size (), 2 );
341
- for ( std::size_t i = 0 ; i < part.size (); ++i )
342
- {
343
- GEOSCoordSeq_setX ( cooSeq, i, part[i].x );
344
- GEOSCoordSeq_setY ( cooSeq, i, part[i].y );
345
- }
346
-
347
- simpleGeometries->push_back ( GEOSGeom_createLineString ( cooSeq ) );
348
- part.clear ();
349
- part.push_back ( p );
350
- }
351
- // Create final part
352
- part.push_back ( points[n - 1 ] );
353
- GEOSCoordSequence* cooSeq = GEOSCoordSeq_create ( part.size (), 2 );
354
- for ( std::size_t i = 0 ; i < part.size (); ++i )
355
- {
356
- GEOSCoordSeq_setX ( cooSeq, i, part[i].x );
357
- GEOSCoordSeq_setY ( cooSeq, i, part[i].y );
358
- }
359
- simpleGeometries->push_back ( GEOSGeom_createLineString ( cooSeq ) );
360
- }
361
- else
362
- {
363
- simpleGeometries->push_back ( geom );
364
- }
365
- }
366
- }
367
-
368
288
while ( simpleGeometries->size () > 0 )
369
289
{
370
290
const GEOSGeometry* geom = simpleGeometries->pop_front ();
@@ -401,7 +321,7 @@ namespace pal
401
321
continue ;
402
322
}
403
323
404
- if ( mode == LabelPerFeature && repeatDistance == 0.0 && ( type == GEOS_POLYGON || type == GEOS_LINESTRING ) )
324
+ if ( mode == LabelPerFeature && ( type == GEOS_POLYGON || type == GEOS_LINESTRING ) )
405
325
{
406
326
if ( type == GEOS_LINESTRING )
407
327
GEOSLength ( geom, &geom_size );
@@ -430,7 +350,7 @@ namespace pal
430
350
modMutex->unlock ();
431
351
432
352
// if using only biggest parts...
433
- if ((( mode == LabelPerFeature && repeatDistance == 0.0 ) || f->fixedPosition () ) && biggest_part != NULL )
353
+ if (( mode == LabelPerFeature || f->fixedPosition () ) && biggest_part != NULL )
434
354
{
435
355
addFeaturePart ( biggest_part, labelText );
436
356
first_feat = false ;
@@ -569,6 +489,102 @@ namespace pal
569
489
connectedTexts = NULL ;
570
490
}
571
491
492
+ void Layer::chopFeatures ( double chopInterval )
493
+ {
494
+ LinkedList<FeaturePart*> * newFeatureParts = new LinkedList<FeaturePart*>( ptrFeaturePartCompare );
495
+ while ( FeaturePart* fpart = featureParts->pop_front () )
496
+ {
497
+ const GEOSGeometry* geom = fpart->getGeometry ();
498
+ if ( GEOSGeomTypeId ( geom ) == GEOS_LINESTRING )
499
+ {
500
+
501
+ double bmin[2 ], bmax[2 ];
502
+ fpart->getBoundingBox ( bmin, bmax );
503
+ rtree->Remove ( bmin, bmax, fpart );
504
+
505
+ const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq ( geom );
506
+
507
+ // get number of points
508
+ unsigned int n;
509
+ GEOSCoordSeq_getSize ( cs, &n );
510
+
511
+ // Read points
512
+ std::vector<Point> points ( n );
513
+ for ( unsigned int i = 0 ; i < n; ++i )
514
+ {
515
+ GEOSCoordSeq_getX ( cs, i, &points[i].x );
516
+ GEOSCoordSeq_getY ( cs, i, &points[i].y );
517
+ }
518
+
519
+ // Cumulative length vector
520
+ std::vector<double > len ( n, 0 );
521
+ for ( unsigned int i = 1 ; i < n; ++i )
522
+ {
523
+ double dx = points[i].x - points[i - 1 ].x ;
524
+ double dy = points[i].y - points[i - 1 ].y ;
525
+ len[i] = len[i - 1 ] + std::sqrt ( dx * dx + dy * dy );
526
+ }
527
+
528
+ // Walk along line
529
+ unsigned int cur = 0 ;
530
+ double lambda = 0 ;
531
+ std::vector<Point> part;
532
+ for ( ;; )
533
+ {
534
+ lambda += chopInterval;
535
+ for ( ; cur < n && lambda > len[cur]; ++cur )
536
+ {
537
+ part.push_back ( points[cur] );
538
+ }
539
+ if ( cur >= n )
540
+ {
541
+ break ;
542
+ }
543
+ double c = ( lambda - len[cur - 1 ] ) / ( len[cur] - len[cur - 1 ] );
544
+ Point p;
545
+ p.x = points[cur - 1 ].x + c * ( points[cur].x - points[cur - 1 ].x );
546
+ p.y = points[cur - 1 ].y + c * ( points[cur].y - points[cur - 1 ].y );
547
+ part.push_back ( p );
548
+ GEOSCoordSequence* cooSeq = GEOSCoordSeq_create ( part.size (), 2 );
549
+ for ( std::size_t i = 0 ; i < part.size (); ++i )
550
+ {
551
+ GEOSCoordSeq_setX ( cooSeq, i, part[i].x );
552
+ GEOSCoordSeq_setY ( cooSeq, i, part[i].y );
553
+ }
554
+
555
+ GEOSGeometry* newgeom = GEOSGeom_createLineString ( cooSeq );
556
+ FeaturePart* newfpart = new FeaturePart ( fpart->getFeature (), newgeom );
557
+ newFeatureParts->push_back ( newfpart );
558
+ newfpart->getBoundingBox ( bmin, bmax );
559
+ rtree->Insert ( bmin, bmax, newfpart );
560
+ part.clear ();
561
+ part.push_back ( p );
562
+ }
563
+ // Create final part
564
+ part.push_back ( points[n - 1 ] );
565
+ GEOSCoordSequence* cooSeq = GEOSCoordSeq_create ( part.size (), 2 );
566
+ for ( std::size_t i = 0 ; i < part.size (); ++i )
567
+ {
568
+ GEOSCoordSeq_setX ( cooSeq, i, part[i].x );
569
+ GEOSCoordSeq_setY ( cooSeq, i, part[i].y );
570
+ }
571
+
572
+ GEOSGeometry* newgeom = GEOSGeom_createLineString ( cooSeq );
573
+ FeaturePart* newfpart = new FeaturePart ( fpart->getFeature (), newgeom );
574
+ newFeatureParts->push_back ( newfpart );
575
+ newfpart->getBoundingBox ( bmin, bmax );
576
+ rtree->Insert ( bmin, bmax, newfpart );
577
+ }
578
+ else
579
+ {
580
+ newFeatureParts->push_back ( fpart );
581
+ }
582
+ }
583
+
584
+ delete featureParts;
585
+ featureParts = newFeatureParts;
586
+ }
587
+
572
588
573
589
574
590
} // end namespace
0 commit comments