[mapserver-commits] r8677 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Sun Mar 8 16:32:04 EDT 2009


Author: warmerdam
Date: 2009-03-08 16:32:04 -0400 (Sun, 08 Mar 2009)
New Revision: 8677

Modified:
   trunk/mapserver/mapows.c
   trunk/mapserver/maprasterquery.c
Log:
add a partial get layer implementation for single files only (#79)

Modified: trunk/mapserver/mapows.c
===================================================================
--- trunk/mapserver/mapows.c	2009-03-08 20:26:48 UTC (rev 8676)
+++ trunk/mapserver/mapows.c	2009-03-08 20:32:04 UTC (rev 8677)
@@ -1416,7 +1416,7 @@
     msFreeCharArray(tokens, n);
     return MS_SUCCESS;
   }
-  else if( lp->type != MS_LAYER_RASTER )
+  else
   {
       return msLayerGetExtent(lp, ext);
   }

Modified: trunk/mapserver/maprasterquery.c
===================================================================
--- trunk/mapserver/maprasterquery.c	2009-03-08 20:26:48 UTC (rev 8676)
+++ trunk/mapserver/maprasterquery.c	2009-03-08 20:32:04 UTC (rev 8677)
@@ -1252,13 +1252,6 @@
 }
 
 /************************************************************************/
-/*                       msRASTERLayerGetExtent()                       */
-/************************************************************************/
-
-int msRASTERLayerGetExtent(layerObj *layer, rectObj *extent)
-	{ return MS_FAILURE; }
-
-/************************************************************************/
 /*                       msRASTERLayerGetItems()                        */
 /************************************************************************/
 
@@ -1303,6 +1296,70 @@
 }
 
 /************************************************************************/
+/*                       msRASTERLayerGetExtent()                       */
+/************************************************************************/
+
+int msRASTERLayerGetExtent(layerObj *layer, rectObj *extent)
+
+{ 
+  char szPath[MS_MAXPATHLEN];
+  mapObj *map = layer->map;
+  double adfGeoTransform[6];
+  int nXSize, nYSize;
+  GDALDatasetH hDS;
+
+  /*
+  ** For the time being we only automatically derive extents from
+  ** single raster files.  Opening many raster files from a tile index
+  ** in order to get the extent would be potentially very expensive.  We
+  ** could - in theory - scan the tile index and build up an extent from
+  ** the polygons but that is quite complicated code wise, so I am leaving
+  ** that till someone cares more about the issue.  (#79)
+  */
+  if( !layer->data 
+      || strlen(layer->data) == 0 
+      || layer->tileindex != NULL )
+  {
+    /* should we be issuing a specific error about not supporting 
+       extents for tileindexed raster layers? */
+    return MS_FAILURE;
+  }
+
+  if( map == NULL )
+    return MS_FAILURE;
+
+  msBuildPath3(szPath, map->mappath, map->shapepath, layer->data);
+
+  msAcquireLock( TLOCK_GDAL );
+  hDS = GDALOpen(szPath, GA_ReadOnly );
+  
+  if( hDS != NULL )
+  {
+    nXSize = GDALGetRasterXSize( hDS );
+    nYSize = GDALGetRasterYSize( hDS );
+    GDALGetGeoTransform( hDS, adfGeoTransform );
+    
+    GDALClose( hDS );
+  }
+  
+  msReleaseLock( TLOCK_GDAL );
+
+  if( hDS == NULL )
+  {
+      return MS_FAILURE;
+  }
+  
+  extent->minx = adfGeoTransform[0];
+  extent->maxy = adfGeoTransform[3];
+  
+  extent->maxx = adfGeoTransform[0] + nXSize * adfGeoTransform[1];
+  extent->miny = adfGeoTransform[3] + nYSize * adfGeoTransform[5];
+  
+  return MS_SUCCESS;
+}
+
+
+/************************************************************************/
 /*                     msRASTERLayerSetTimeFilter()                     */
 /*                                                                      */
 /*      This function is actually just used in the context of           */



More information about the mapserver-commits mailing list