~ubuntu-branches/debian/sid/gdal/sid

« back to all changes in this revision

Viewing changes to ogr/ogrpoint.cpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-05-07 15:04:42 UTC
  • mfrom: (5.5.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120507150442-2eks97loeh6rq005
Tags: 1.9.0-1
* Ready for sid, starting transition.
* All symfiles updated to latest builds.
* Added dh_numpy call in debian/rules to depend on numpy ABI.
* Policy bumped to 3.9.3, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
 * $Id: ogrpoint.cpp 16853 2009-04-26 12:22:10Z rouault $
 
2
 * $Id: ogrpoint.cpp 22448 2011-05-28 18:49:54Z rouault $
3
3
 *
4
4
 * Project:  OpenGIS Simple Features Reference Implementation
5
5
 * Purpose:  The Point geometry class.
30
30
#include "ogr_geometry.h"
31
31
#include "ogr_p.h"
32
32
 
33
 
CPL_CVSID("$Id: ogrpoint.cpp 16853 2009-04-26 12:22:10Z rouault $");
 
33
CPL_CVSID("$Id: ogrpoint.cpp 22448 2011-05-28 18:49:54Z rouault $");
34
34
 
35
35
/************************************************************************/
36
36
/*                              OGRPoint()                              */
244
244
 
245
245
    if( bIs3D )
246
246
    {
 
247
        if ( nSize < 29 && nSize != -1 )
 
248
            return OGRERR_NOT_ENOUGH_DATA;
 
249
 
247
250
        memcpy( &z, pabyData + 5 + 16, 8 );
248
251
        if( OGR_SWAP( eByteOrder ) )
249
252
        {
337
340
/*      Check for EMPTY ... but treat like a point at 0,0.              */
338
341
/* -------------------------------------------------------------------- */
339
342
    const char *pszPreScan;
 
343
    int bHasZ = FALSE, bHasM = FALSE;
340
344
 
341
345
    pszPreScan = OGRWktReadToken( pszInput, szToken );
342
346
    if( EQUAL(szToken,"EMPTY") )
343
347
    {
344
 
        *ppszInput = (char *) pszInput;
 
348
        *ppszInput = (char *) pszPreScan;
345
349
        empty();
346
350
        return OGRERR_NONE;
347
351
    }
348
352
 
349
 
    if( !EQUAL(szToken,"(") )
350
 
        return OGRERR_CORRUPT_DATA;
 
353
/* -------------------------------------------------------------------- */
 
354
/*      Check for Z, M or ZM. Will ignore the Measure                   */
 
355
/* -------------------------------------------------------------------- */
 
356
    else if( EQUAL(szToken,"Z") )
 
357
    {
 
358
        bHasZ = TRUE;
 
359
    }
 
360
    else if( EQUAL(szToken,"M") )
 
361
    {
 
362
        bHasM = TRUE;
 
363
    }
 
364
    else if( EQUAL(szToken,"ZM") )
 
365
    {
 
366
        bHasZ = TRUE;
 
367
        bHasM = TRUE;
 
368
    }
351
369
 
352
 
    pszPreScan = OGRWktReadToken( pszPreScan, szToken );
353
 
    if( EQUAL(szToken,"EMPTY") )
 
370
    if (bHasZ || bHasM)
354
371
    {
355
 
        pszInput = OGRWktReadToken( pszPreScan, szToken );
356
 
        
357
 
        if( !EQUAL(szToken,")") )
358
 
            return OGRERR_CORRUPT_DATA;
359
 
        else
 
372
        pszInput = pszPreScan;
 
373
        pszPreScan = OGRWktReadToken( pszInput, szToken );
 
374
        if( EQUAL(szToken,"EMPTY") )
360
375
        {
361
 
            *ppszInput = (char *) pszInput;
 
376
            *ppszInput = (char *) pszPreScan;
362
377
            empty();
 
378
            /* FIXME?: In theory we should store the dimension and M presence */
 
379
            /* if we want to allow round-trip with ExportToWKT v1.2 */
363
380
            return OGRERR_NONE;
364
381
        }
365
382
    }
366
383
 
 
384
    if( !EQUAL(szToken,"(") )
 
385
        return OGRERR_CORRUPT_DATA;
 
386
 
 
387
    if ( !bHasZ && !bHasM )
 
388
    {
 
389
        /* Test for old-style POINT(EMPTY) */
 
390
        pszPreScan = OGRWktReadToken( pszPreScan, szToken );
 
391
        if( EQUAL(szToken,"EMPTY") )
 
392
        {
 
393
            pszInput = OGRWktReadToken( pszPreScan, szToken );
 
394
 
 
395
            if( !EQUAL(szToken,")") )
 
396
                return OGRERR_CORRUPT_DATA;
 
397
            else
 
398
            {
 
399
                *ppszInput = (char *) pszInput;
 
400
                empty();
 
401
                return OGRERR_NONE;
 
402
            }
 
403
        }
 
404
    }
 
405
 
367
406
/* -------------------------------------------------------------------- */
368
407
/*      Read the point list which should consist of exactly one point.  */
369
408
/* -------------------------------------------------------------------- */
374
413
    pszInput = OGRWktReadPoints( pszInput, &poPoints, &padfZ,
375
414
                                 &nMaxPoint, &nPoints );
376
415
    if( pszInput == NULL || nPoints != 1 )
 
416
    {
 
417
        CPLFree( poPoints );
 
418
        CPLFree( padfZ );
377
419
        return OGRERR_CORRUPT_DATA;
 
420
    }
378
421
 
379
422
    x = poPoints[0].x;
380
423
    y = poPoints[0].y;
383
426
 
384
427
    if( padfZ != NULL )
385
428
    {
386
 
        z = padfZ[0];                                           
 
429
        /* If there's a 3rd value, and it is not a POINT M, */
 
430
        /* then assume it is the Z */
 
431
        if ((!(bHasM && !bHasZ)))
 
432
        {
 
433
            z = padfZ[0];
 
434
            nCoordDimension = 3;
 
435
        }
 
436
        else
 
437
            nCoordDimension = 2;
 
438
        CPLFree( padfZ );
 
439
    }
 
440
    else if ( bHasZ )
 
441
    {
 
442
        /* In theory we should have a z coordinate for POINT Z */
 
443
        /* oh well, let be tolerant */
387
444
        nCoordDimension = 3;
388
 
        CPLFree( padfZ );
389
445
    }
390
446
    else
391
447
        nCoordDimension = 2;
431
487
    psEnvelope->MinY = psEnvelope->MaxY = getY();
432
488
}
433
489
 
 
490
/************************************************************************/
 
491
/*                            getEnvelope()                             */
 
492
/************************************************************************/
 
493
 
 
494
void OGRPoint::getEnvelope( OGREnvelope3D * psEnvelope ) const
 
495
 
 
496
{
 
497
    psEnvelope->MinX = psEnvelope->MaxX = getX();
 
498
    psEnvelope->MinY = psEnvelope->MaxY = getY();
 
499
    psEnvelope->MinZ = psEnvelope->MaxZ = getZ();
 
500
}
434
501
 
435
502
 
436
503
/**
542
609
{
543
610
    return nCoordDimension == 0;
544
611
}
 
612
 
 
613
/************************************************************************/
 
614
/*                               swapXY()                               */
 
615
/************************************************************************/
 
616
 
 
617
void OGRPoint::swapXY()
 
618
{
 
619
    double dfTemp = x;
 
620
    x = y;
 
621
    y = dfTemp;
 
622
}