Skip to content

Commit 29e4aea

Browse files
committed
fix build on ubuntu precise (older geos)
1 parent 0903684 commit 29e4aea

File tree

1 file changed

+48
-36
lines changed

1 file changed

+48
-36
lines changed

src/core/pal/layer.cpp

+48-36
Original file line numberDiff line numberDiff line change
@@ -286,68 +286,80 @@ namespace pal
286286
}
287287

288288
// if multiple labels are requested for lines, split the line in pieces of desired distance
289-
if(repeatDistance > 0) {
289+
if ( repeatDistance > 0 )
290+
{
290291
int nSimpleGeometries = simpleGeometries->size();
291-
for(int i = 0; i < nSimpleGeometries; ++i) {
292+
for ( int i = 0; i < nSimpleGeometries; ++i )
293+
{
292294
const GEOSGeometry* geom = simpleGeometries->pop_front();
293-
if(GEOSGeomTypeId(geom) == GEOS_LINESTRING) {
295+
if ( GEOSGeomTypeId( geom ) == GEOS_LINESTRING )
296+
{
297+
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( geom );
294298

295299
// get number of points
296-
int n = GEOSGeomGetNumPoints(geom);
300+
unsigned int n;
301+
GEOSCoordSeq_getSize( cs, &n );
297302

298303
// Read points
299-
std::vector<Point> points(n);
300-
for(int i = 0; i < n; ++i) {
301-
GEOSGeometry* p = GEOSGeomGetPointN(geom, i);
302-
GEOSGeomGetX(p, &points[i].x);
303-
GEOSGeomGetY(p, &points[i].y);
304-
GEOSGeom_destroy(p);
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 );
305309
}
306310

307311
// Cumulative length vector
308-
std::vector<double> len(n, 0);
309-
for(int i = 1; i < n; ++i) {
312+
std::vector<double> len( n, 0 );
313+
for ( unsigned int i = 1; i < n; ++i )
314+
{
310315
double dx = points[i].x - points[i - 1].x;
311316
double dy = points[i].y - points[i - 1].y;
312-
len[i] = len[i - 1] + std::sqrt(dx * dx + dy * dy);
317+
len[i] = len[i - 1] + std::sqrt( dx * dx + dy * dy );
313318
}
314319

315320
// Walk along line
316-
int cur = 0;
321+
unsigned int cur = 0;
317322
double lambda = 0;
318323
std::vector<Point> part;
319-
while(true) {
324+
for ( ;; )
325+
{
320326
lambda += repeatDistance;
321-
for(; cur < n && lambda > len[cur]; ++cur) {
322-
part.push_back(points[cur]);
327+
for ( ; cur < n && lambda > len[cur]; ++cur )
328+
{
329+
part.push_back( points[cur] );
323330
}
324-
if(cur >= n) {
331+
if ( cur >= n )
332+
{
325333
break;
326334
}
327-
double c = (lambda - len[cur - 1]) / (len[cur] - len[cur - 1]);
335+
double c = ( lambda - len[cur - 1] ) / ( len[cur] - len[cur - 1] );
328336
Point p;
329-
p.x = points[cur - 1].x + c * (points[cur].x - points[cur - 1].x);
330-
p.y = points[cur - 1].y + c * (points[cur].y - points[cur - 1].y);
331-
part.push_back(p);
332-
GEOSCoordSequence* cooSeq = GEOSCoordSeq_create(part.size(), 2);
333-
for(std::size_t i = 0; i < part.size(); ++i) {
334-
GEOSCoordSeq_setX(cooSeq, i, part[i].x);
335-
GEOSCoordSeq_setY(cooSeq, i, part[i].y);
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 );
336345
}
337346

338-
simpleGeometries->push_back(GEOSGeom_createLineString(cooSeq));
347+
simpleGeometries->push_back( GEOSGeom_createLineString( cooSeq ) );
339348
part.clear();
340-
part.push_back(p);
349+
part.push_back( p );
341350
}
342351
// Create final part
343-
part.push_back(points[n - 1]);
344-
GEOSCoordSequence* cooSeq = GEOSCoordSeq_create(part.size(), 2);
345-
for(std::size_t i = 0; i < part.size(); ++i) {
346-
GEOSCoordSeq_setX(cooSeq, i, part[i].x);
347-
GEOSCoordSeq_setY(cooSeq, i, part[i].y);
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 );
348358
}
349-
simpleGeometries->push_back(GEOSGeom_createLineString(cooSeq));
350-
}else{
359+
simpleGeometries->push_back( GEOSGeom_createLineString( cooSeq ) );
360+
}
361+
else
362+
{
351363
simpleGeometries->push_back( geom );
352364
}
353365
}
@@ -418,7 +430,7 @@ namespace pal
418430
modMutex->unlock();
419431

420432
// if using only biggest parts...
421-
if (( (mode == LabelPerFeature && repeatDistance == 0.0) || f->fixedPosition() ) && biggest_part != NULL )
433+
if ((( mode == LabelPerFeature && repeatDistance == 0.0 ) || f->fixedPosition() ) && biggest_part != NULL )
422434
{
423435
addFeaturePart( biggest_part, labelText );
424436
first_feat = false;

0 commit comments

Comments
 (0)