~ubuntu-branches/ubuntu/raring/mapserver/raring-security

« back to all changes in this revision

Viewing changes to mapogr.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine, Alan Boudreault, Francesco Paolo Lovergine
  • Date: 2010-03-24 22:13:25 UTC
  • mfrom: (10.2.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100324221325-g9hwfpfqeiq4fz7m
Tags: 5.6.3-1
[ Alan Boudreault ]
* New upstream release, with important bug fixes.
* Fixed some typo in debian/control.

[ Francesco Paolo Lovergine ]
* Policy bumped to 3.8.4 without changes.
* Removed Andreas Putzo among Uploaders: last contribution dated more than
  two years ago.
* Added shapelib to Suggests in mapserver-bin. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**********************************************************************
2
 
 * $Id: mapogr.cpp 9356 2009-09-29 21:34:13Z assefa $
 
2
 * $Id: mapogr.cpp 9709 2010-01-18 18:55:29Z aboudreault $
3
3
 *
4
4
 * Project:  MapServer
5
5
 * Purpose:  OGR Link
40
40
#  include "ogr_srs_api.h"
41
41
#endif
42
42
 
43
 
MS_CVSID("$Id: mapogr.cpp 9356 2009-09-29 21:34:13Z assefa $")
 
43
MS_CVSID("$Id: mapogr.cpp 9709 2010-01-18 18:55:29Z aboudreault $")
44
44
 
45
45
#if defined(GDAL_VERSION_NUM) && (GDAL_VERSION_NUM < 1400)
46
46
#  define ACQUIRE_OLD_OGR_LOCK   msAcquireLock( TLOCK_OGR )
75
75
  struct ms_ogr_file_info_t *poCurTile; /* exists on tile index, -> tiles */
76
76
  rectObj     rect;                     /* set by WhichShapes */
77
77
 
 
78
  int         last_record_index_read;
 
79
 
78
80
} msOGRFileInfo;
79
81
 
80
82
static int msOGRLayerIsOpen(layerObj *layer);
1485
1487
  psInfo->poCurTile = NULL;
1486
1488
  psInfo->rect.minx = psInfo->rect.maxx = 0;
1487
1489
  psInfo->rect.miny = psInfo->rect.maxy = 0;
 
1490
  psInfo->last_record_index_read = -1;
1488
1491
 
1489
1492
  return psInfo;
1490
1493
}
1629
1632
 * Reset current feature pointer
1630
1633
 * ------------------------------------------------------------------ */
1631
1634
  OGR_L_ResetReading( psInfo->hLayer );
 
1635
  psInfo->last_record_index_read = -1;
1632
1636
 
1633
1637
  RELEASE_OGR_LOCK;
1634
1638
 
1741
1745
 
1742
1746
      if( (hFeature = OGR_L_GetNextFeature( psInfo->hLayer )) == NULL )
1743
1747
      {
 
1748
          psInfo->last_record_index_read = -1;
1744
1749
          if( CPLGetLastErrorType() == CE_Failure )
1745
1750
          {
1746
1751
              msSetError(MS_OGRERR, "%s", "msOGRFileNextShape()",
1757
1762
          }
1758
1763
      }
1759
1764
 
 
1765
      psInfo->last_record_index_read++;
 
1766
 
1760
1767
      if(layer->numitems > 0) 
1761
1768
      {
1762
1769
          shape->values = msOGRGetValues(layer, hFeature);
1804
1811
      shape->type = MS_SHAPE_NULL;
1805
1812
  }
1806
1813
 
1807
 
  shape->index = OGR_F_GetFID( hFeature );
 
1814
  shape->index = psInfo->last_record_index_read;
1808
1815
  shape->tileindex = psInfo->nTileId;
1809
1816
 
1810
1817
  if (layer->debug >= MS_DEBUGLEVEL_VVV)
1830
1837
 **********************************************************************/
1831
1838
static int 
1832
1839
msOGRFileGetShape(layerObj *layer, shapeObj *shape, long record,
1833
 
                  msOGRFileInfo *psInfo )
 
1840
                  msOGRFileInfo *psInfo, int record_is_fid )
1834
1841
{
1835
1842
  OGRFeatureH hFeature;
1836
1843
 
1841
1848
    return(MS_FAILURE);
1842
1849
  }
1843
1850
 
 
1851
/* -------------------------------------------------------------------- */
 
1852
/*      Clear previously loaded shape.                                  */
 
1853
/* -------------------------------------------------------------------- */
 
1854
  msFreeShape(shape);
 
1855
  shape->type = MS_SHAPE_NULL;
 
1856
 
 
1857
/* -------------------------------------------------------------------- */
 
1858
/*      Support reading feature by fid.                                 */
 
1859
/* -------------------------------------------------------------------- */
 
1860
  if( record_is_fid )
 
1861
  {
 
1862
      ACQUIRE_OGR_LOCK;
 
1863
      if( (hFeature = OGR_L_GetFeature( psInfo->hLayer, record )) == NULL )
 
1864
      {
 
1865
          RELEASE_OGR_LOCK;
 
1866
          return MS_FAILURE;
 
1867
      }
 
1868
  }
 
1869
 
 
1870
/* -------------------------------------------------------------------- */
 
1871
/*      Support reading shape by offset within the current              */
 
1872
/*      resultset.                                                      */
 
1873
/* -------------------------------------------------------------------- */
 
1874
  else if( !record_is_fid )
 
1875
  {
 
1876
      ACQUIRE_OGR_LOCK;
 
1877
      if( record <= psInfo->last_record_index_read 
 
1878
          || psInfo->last_record_index_read == -1 )
 
1879
      {
 
1880
          OGR_L_ResetReading( psInfo->hLayer );
 
1881
          psInfo->last_record_index_read = -1;
 
1882
      }
 
1883
 
 
1884
      hFeature = NULL;
 
1885
      while( psInfo->last_record_index_read < record )
 
1886
      {
 
1887
          if( hFeature != NULL )
 
1888
          {
 
1889
              OGR_F_Destroy( hFeature );
 
1890
              hFeature = NULL;
 
1891
          }
 
1892
          if( (hFeature = OGR_L_GetNextFeature( psInfo->hLayer )) == NULL )
 
1893
          {
 
1894
              RELEASE_OGR_LOCK;
 
1895
              return MS_FAILURE;
 
1896
          }
 
1897
          psInfo->last_record_index_read++;
 
1898
      }
 
1899
  }
 
1900
 
1844
1901
/* ------------------------------------------------------------------
1845
1902
 * Handle shape geometry... 
1846
1903
 * ------------------------------------------------------------------ */
1847
 
  msFreeShape(shape);
1848
 
  shape->type = MS_SHAPE_NULL;
1849
 
 
1850
 
  ACQUIRE_OGR_LOCK;
1851
 
  if( (hFeature = OGR_L_GetFeature( psInfo->hLayer, record )) == NULL )
1852
 
  {
1853
 
      RELEASE_OGR_LOCK;
1854
 
      return MS_FAILURE;
1855
 
  }
1856
 
 
1857
1904
  // shape->type will be set if geom is compatible with layer type
1858
1905
  if (ogrConvertGeometry(OGR_F_GetGeometryRef( hFeature ), shape,
1859
1906
                         layer->type) != MS_SUCCESS)
1886
1933
 
1887
1934
  }   
1888
1935
 
1889
 
  shape->index = OGR_F_GetFID( hFeature );
 
1936
  shape->index = record;
1890
1937
  shape->tileindex = psInfo->nTileId;
1891
1938
 
1892
1939
  // Keep ref. to last feature read in case we need style info.
2509
2556
/**********************************************************************
2510
2557
 *                     msOGRLayerGetShape()
2511
2558
 *
2512
 
 * Returns shape from OGR data source by id.
 
2559
 * Returns shape from OGR data source by fid.
2513
2560
 *
2514
2561
 * Returns MS_SUCCESS/MS_FAILURE
2515
2562
 **********************************************************************/
2516
2563
int msOGRLayerGetShape(layerObj *layer, shapeObj *shape, int tile, 
2517
 
                       long record)
2518
 
{
2519
 
#ifdef USE_OGR
2520
 
  msOGRFileInfo *psInfo =(msOGRFileInfo*)layer->layerinfo;
2521
 
 
2522
 
  if (psInfo == NULL || psInfo->hLayer == NULL)
2523
 
  {
2524
 
    msSetError(MS_MISCERR, "Assertion failed: OGR layer not opened!!!", 
2525
 
               "msOGRLayerNextShape()");
2526
 
    return(MS_FAILURE);
2527
 
  }
2528
 
 
2529
 
  if( layer->tileindex == NULL )
2530
 
      return msOGRFileGetShape(layer, shape, record, psInfo );
2531
 
  else
2532
 
  {
2533
 
      if( psInfo->poCurTile == NULL
2534
 
          || psInfo->poCurTile->nTileId != tile )
2535
 
      {
2536
 
          if( msOGRFileReadTile( layer, psInfo, tile ) != MS_SUCCESS )
2537
 
              return MS_FAILURE;
2538
 
      }
2539
 
 
2540
 
      return msOGRFileGetShape(layer, shape, record, psInfo->poCurTile );
 
2564
                       long fid)
 
2565
{
 
2566
#ifdef USE_OGR
 
2567
  msOGRFileInfo *psInfo =(msOGRFileInfo*)layer->layerinfo;
 
2568
 
 
2569
  if (psInfo == NULL || psInfo->hLayer == NULL)
 
2570
  {
 
2571
    msSetError(MS_MISCERR, "Assertion failed: OGR layer not opened!!!", 
 
2572
               "msOGRLayerNextShape()");
 
2573
    return(MS_FAILURE);
 
2574
  }
 
2575
 
 
2576
  if( layer->tileindex == NULL )
 
2577
      return msOGRFileGetShape(layer, shape, fid, psInfo, TRUE );
 
2578
  else
 
2579
  {
 
2580
      if( psInfo->poCurTile == NULL
 
2581
          || psInfo->poCurTile->nTileId != tile )
 
2582
      {
 
2583
          if( msOGRFileReadTile( layer, psInfo, tile ) != MS_SUCCESS )
 
2584
              return MS_FAILURE;
 
2585
      }
 
2586
 
 
2587
      return msOGRFileGetShape(layer, shape, fid, psInfo->poCurTile, TRUE );
 
2588
  }
 
2589
#else
 
2590
/* ------------------------------------------------------------------
 
2591
 * OGR Support not included...
 
2592
 * ------------------------------------------------------------------ */
 
2593
 
 
2594
  msSetError(MS_MISCERR, "OGR support is not available.", 
 
2595
             "msOGRLayerGetShape()");
 
2596
  return(MS_FAILURE);
 
2597
 
 
2598
#endif /* USE_OGR */
 
2599
}
 
2600
 
 
2601
/**********************************************************************
 
2602
 *                     msOGRLayerResultGetShape()
 
2603
 *
 
2604
 * Returns shape from OGR data source by index into the current results
 
2605
 * set.
 
2606
 *
 
2607
 * Returns MS_SUCCESS/MS_FAILURE
 
2608
 **********************************************************************/
 
2609
int msOGRLayerResultGetShape(layerObj *layer, shapeObj *shape, int tile, 
 
2610
                             long record)
 
2611
{
 
2612
#ifdef USE_OGR
 
2613
  msOGRFileInfo *psInfo =(msOGRFileInfo*)layer->layerinfo;
 
2614
 
 
2615
  if (psInfo == NULL || psInfo->hLayer == NULL)
 
2616
  {
 
2617
    msSetError(MS_MISCERR, "Assertion failed: OGR layer not opened!!!", 
 
2618
               "msOGRLayerNextShape()");
 
2619
    return(MS_FAILURE);
 
2620
  }
 
2621
 
 
2622
  if( layer->tileindex == NULL )
 
2623
      return msOGRFileGetShape(layer, shape, record, psInfo, FALSE );
 
2624
  else
 
2625
  {
 
2626
      if( psInfo->poCurTile == NULL
 
2627
          || psInfo->poCurTile->nTileId != tile )
 
2628
      {
 
2629
          if( msOGRFileReadTile( layer, psInfo, tile ) != MS_SUCCESS )
 
2630
              return MS_FAILURE;
 
2631
      }
 
2632
 
 
2633
      return msOGRFileGetShape(layer, shape, record, psInfo->poCurTile, FALSE );
2541
2634
  }
2542
2635
#else
2543
2636
/* ------------------------------------------------------------------
2684
2777
 * ------------------------------------------------------------------ */
2685
2778
  ACQUIRE_OGR_LOCK;
2686
2779
  if (psInfo->hLastFeature == NULL || 
2687
 
      OGR_F_GetFID( psInfo->hLastFeature ) != record)
 
2780
      psInfo->last_record_index_read != record)
2688
2781
  {
2689
 
      if (psInfo->hLastFeature)
2690
 
          OGR_F_Destroy( psInfo->hLastFeature );
2691
 
 
2692
 
      psInfo->hLastFeature = OGR_L_GetFeature( psInfo->hLayer, record );
 
2782
      RELEASE_OGR_LOCK;
 
2783
      msSetError(MS_MISCERR, 
 
2784
                 "Assertion failed: AutoStyle not requested on loaded shape.",
 
2785
                 "msOGRLayerGetAutoStyle()");
 
2786
      return(MS_FAILURE);
2693
2787
  }
2694
2788
 
2695
2789
/* ------------------------------------------------------------------
3378
3472
    layer->vtable->LayerIsOpen = msOGRLayerIsOpen;
3379
3473
    layer->vtable->LayerWhichShapes = msOGRLayerWhichShapes;
3380
3474
    layer->vtable->LayerNextShape = msOGRLayerNextShape;
3381
 
    layer->vtable->LayerResultsGetShape = msOGRLayerGetShape; /* no special version, use ...GetShape() */
 
3475
    layer->vtable->LayerResultsGetShape = msOGRLayerResultGetShape; 
3382
3476
    layer->vtable->LayerGetShape = msOGRLayerGetShape;
3383
3477
    layer->vtable->LayerClose = msOGRLayerClose;
3384
3478
    layer->vtable->LayerGetItems = msOGRLayerGetItems;