[mapserver-commits] r9709 - branches/branch-5-6/mapserver

svn at osgeo.org svn at osgeo.org
Mon Jan 18 13:55:31 EST 2010


Author: aboudreault
Date: 2010-01-18 13:55:29 -0500 (Mon, 18 Jan 2010)
New Revision: 9709

Modified:
   branches/branch-5-6/mapserver/HISTORY.TXT
   branches/branch-5-6/mapserver/mapogr.cpp
Log:
Backporting implementation of RFC 52 LayerResultsGetShape support for OGR connection type in branch 5-6. (#3069)

Modified: branches/branch-5-6/mapserver/HISTORY.TXT
===================================================================
--- branches/branch-5-6/mapserver/HISTORY.TXT	2010-01-18 18:22:36 UTC (rev 9708)
+++ branches/branch-5-6/mapserver/HISTORY.TXT	2010-01-18 18:55:29 UTC (rev 9709)
@@ -15,6 +15,8 @@
 Current Version (SVN branch-5-6):
 --------------------------------
 
+- Implemented RFC 52 LayerResultsGetShape support for OGR connection type. (#3069)
+
 - Fixed problem with the oracle driver w/FUNCTION=NONE (#3260)
 
 Version 5.6.1 (2010-01-08):

Modified: branches/branch-5-6/mapserver/mapogr.cpp
===================================================================
--- branches/branch-5-6/mapserver/mapogr.cpp	2010-01-18 18:22:36 UTC (rev 9708)
+++ branches/branch-5-6/mapserver/mapogr.cpp	2010-01-18 18:55:29 UTC (rev 9709)
@@ -75,6 +75,8 @@
   struct ms_ogr_file_info_t *poCurTile; /* exists on tile index, -> tiles */
   rectObj     rect;                     /* set by WhichShapes */
 
+  int         last_record_index_read;
+
 } msOGRFileInfo;
 
 static int msOGRLayerIsOpen(layerObj *layer);
@@ -1485,6 +1487,7 @@
   psInfo->poCurTile = NULL;
   psInfo->rect.minx = psInfo->rect.maxx = 0;
   psInfo->rect.miny = psInfo->rect.maxy = 0;
+  psInfo->last_record_index_read = -1;
 
   return psInfo;
 }
@@ -1629,6 +1632,7 @@
  * Reset current feature pointer
  * ------------------------------------------------------------------ */
   OGR_L_ResetReading( psInfo->hLayer );
+  psInfo->last_record_index_read = -1;
 
   RELEASE_OGR_LOCK;
 
@@ -1741,6 +1745,7 @@
 
       if( (hFeature = OGR_L_GetNextFeature( psInfo->hLayer )) == NULL )
       {
+          psInfo->last_record_index_read = -1;
           if( CPLGetLastErrorType() == CE_Failure )
           {
               msSetError(MS_OGRERR, "%s", "msOGRFileNextShape()",
@@ -1757,6 +1762,8 @@
           }
       }
 
+      psInfo->last_record_index_read++;
+
       if(layer->numitems > 0) 
       {
           shape->values = msOGRGetValues(layer, hFeature);
@@ -1804,7 +1811,7 @@
       shape->type = MS_SHAPE_NULL;
   }
 
-  shape->index = OGR_F_GetFID( hFeature );
+  shape->index = psInfo->last_record_index_read;
   shape->tileindex = psInfo->nTileId;
 
   if (layer->debug >= MS_DEBUGLEVEL_VVV)
@@ -1830,7 +1837,7 @@
  **********************************************************************/
 static int 
 msOGRFileGetShape(layerObj *layer, shapeObj *shape, long record,
-                  msOGRFileInfo *psInfo )
+                  msOGRFileInfo *psInfo, int record_is_fid )
 {
   OGRFeatureH hFeature;
 
@@ -1841,19 +1848,59 @@
     return(MS_FAILURE);
   }
 
-/* ------------------------------------------------------------------
- * Handle shape geometry... 
- * ------------------------------------------------------------------ */
+/* -------------------------------------------------------------------- */
+/*      Clear previously loaded shape.                                  */
+/* -------------------------------------------------------------------- */
   msFreeShape(shape);
   shape->type = MS_SHAPE_NULL;
 
-  ACQUIRE_OGR_LOCK;
-  if( (hFeature = OGR_L_GetFeature( psInfo->hLayer, record )) == NULL )
+/* -------------------------------------------------------------------- */
+/*      Support reading feature by fid.                                 */
+/* -------------------------------------------------------------------- */
+  if( record_is_fid )
   {
-      RELEASE_OGR_LOCK;
-      return MS_FAILURE;
+      ACQUIRE_OGR_LOCK;
+      if( (hFeature = OGR_L_GetFeature( psInfo->hLayer, record )) == NULL )
+      {
+          RELEASE_OGR_LOCK;
+          return MS_FAILURE;
+      }
   }
 
+/* -------------------------------------------------------------------- */
+/*      Support reading shape by offset within the current              */
+/*      resultset.                                                      */
+/* -------------------------------------------------------------------- */
+  else if( !record_is_fid )
+  {
+      ACQUIRE_OGR_LOCK;
+      if( record <= psInfo->last_record_index_read 
+          || psInfo->last_record_index_read == -1 )
+      {
+          OGR_L_ResetReading( psInfo->hLayer );
+          psInfo->last_record_index_read = -1;
+      }
+
+      hFeature = NULL;
+      while( psInfo->last_record_index_read < record )
+      {
+          if( hFeature != NULL )
+          {
+              OGR_F_Destroy( hFeature );
+              hFeature = NULL;
+          }
+          if( (hFeature = OGR_L_GetNextFeature( psInfo->hLayer )) == NULL )
+          {
+              RELEASE_OGR_LOCK;
+              return MS_FAILURE;
+          }
+          psInfo->last_record_index_read++;
+      }
+  }
+
+/* ------------------------------------------------------------------
+ * Handle shape geometry... 
+ * ------------------------------------------------------------------ */
   // shape->type will be set if geom is compatible with layer type
   if (ogrConvertGeometry(OGR_F_GetGeometryRef( hFeature ), shape,
                          layer->type) != MS_SUCCESS)
@@ -1886,7 +1933,7 @@
 
   }   
 
-  shape->index = OGR_F_GetFID( hFeature );
+  shape->index = record;
   shape->tileindex = psInfo->nTileId;
 
   // Keep ref. to last feature read in case we need style info.
@@ -2509,12 +2556,12 @@
 /**********************************************************************
  *                     msOGRLayerGetShape()
  *
- * Returns shape from OGR data source by id.
+ * Returns shape from OGR data source by fid.
  *
  * Returns MS_SUCCESS/MS_FAILURE
  **********************************************************************/
 int msOGRLayerGetShape(layerObj *layer, shapeObj *shape, int tile, 
-                       long record)
+                       long fid)
 {
 #ifdef USE_OGR
   msOGRFileInfo *psInfo =(msOGRFileInfo*)layer->layerinfo;
@@ -2527,7 +2574,7 @@
   }
 
   if( layer->tileindex == NULL )
-      return msOGRFileGetShape(layer, shape, record, psInfo );
+      return msOGRFileGetShape(layer, shape, fid, psInfo, TRUE );
   else
   {
       if( psInfo->poCurTile == NULL
@@ -2537,7 +2584,7 @@
               return MS_FAILURE;
       }
 
-      return msOGRFileGetShape(layer, shape, record, psInfo->poCurTile );
+      return msOGRFileGetShape(layer, shape, fid, psInfo->poCurTile, TRUE );
   }
 #else
 /* ------------------------------------------------------------------
@@ -2552,6 +2599,52 @@
 }
 
 /**********************************************************************
+ *                     msOGRLayerResultGetShape()
+ *
+ * Returns shape from OGR data source by index into the current results
+ * set.
+ *
+ * Returns MS_SUCCESS/MS_FAILURE
+ **********************************************************************/
+int msOGRLayerResultGetShape(layerObj *layer, shapeObj *shape, int tile, 
+                             long record)
+{
+#ifdef USE_OGR
+  msOGRFileInfo *psInfo =(msOGRFileInfo*)layer->layerinfo;
+
+  if (psInfo == NULL || psInfo->hLayer == NULL)
+  {
+    msSetError(MS_MISCERR, "Assertion failed: OGR layer not opened!!!", 
+               "msOGRLayerNextShape()");
+    return(MS_FAILURE);
+  }
+
+  if( layer->tileindex == NULL )
+      return msOGRFileGetShape(layer, shape, record, psInfo, FALSE );
+  else
+  {
+      if( psInfo->poCurTile == NULL
+          || psInfo->poCurTile->nTileId != tile )
+      {
+          if( msOGRFileReadTile( layer, psInfo, tile ) != MS_SUCCESS )
+              return MS_FAILURE;
+      }
+
+      return msOGRFileGetShape(layer, shape, record, psInfo->poCurTile, FALSE );
+  }
+#else
+/* ------------------------------------------------------------------
+ * OGR Support not included...
+ * ------------------------------------------------------------------ */
+
+  msSetError(MS_MISCERR, "OGR support is not available.", 
+             "msOGRLayerGetShape()");
+  return(MS_FAILURE);
+
+#endif /* USE_OGR */
+}
+
+/**********************************************************************
  *                     msOGRLayerGetExtent()
  *
  * Returns the layer extents.
@@ -2684,12 +2777,13 @@
  * ------------------------------------------------------------------ */
   ACQUIRE_OGR_LOCK;
   if (psInfo->hLastFeature == NULL || 
-      OGR_F_GetFID( psInfo->hLastFeature ) != record)
+      psInfo->last_record_index_read != record)
   {
-      if (psInfo->hLastFeature)
-          OGR_F_Destroy( psInfo->hLastFeature );
-
-      psInfo->hLastFeature = OGR_L_GetFeature( psInfo->hLayer, record );
+      RELEASE_OGR_LOCK;
+      msSetError(MS_MISCERR, 
+                 "Assertion failed: AutoStyle not requested on loaded shape.",
+                 "msOGRLayerGetAutoStyle()");
+      return(MS_FAILURE);
   }
 
 /* ------------------------------------------------------------------
@@ -3378,7 +3472,7 @@
     layer->vtable->LayerIsOpen = msOGRLayerIsOpen;
     layer->vtable->LayerWhichShapes = msOGRLayerWhichShapes;
     layer->vtable->LayerNextShape = msOGRLayerNextShape;
-    layer->vtable->LayerResultsGetShape = msOGRLayerGetShape; /* no special version, use ...GetShape() */
+    layer->vtable->LayerResultsGetShape = msOGRLayerResultGetShape; 
     layer->vtable->LayerGetShape = msOGRLayerGetShape;
     layer->vtable->LayerClose = msOGRLayerClose;
     layer->vtable->LayerGetItems = msOGRLayerGetItems;



More information about the mapserver-commits mailing list