[mapserver-commits] r12311 - in trunk/mapserver/mapcache: include src

svn at osgeo.org svn at osgeo.org
Fri Aug 26 07:16:01 EDT 2011


Author: tbonfort
Date: 2011-08-26 04:16:01 -0700 (Fri, 26 Aug 2011)
New Revision: 12311

Modified:
   trunk/mapserver/mapcache/include/geocache.h
   trunk/mapserver/mapcache/src/configuration.c
   trunk/mapserver/mapcache/src/grid.c
   trunk/mapserver/mapcache/src/service_kml.c
   trunk/mapserver/mapcache/src/service_wms.c
   trunk/mapserver/mapcache/src/service_wmts.c
   trunk/mapserver/mapcache/src/tileset.c
Log:
add delete function to memcache cache backend
thomas.bonfort | 2011-02-14 13:30:23 +0100 (Mon, 14 Feb 2011)

Modified: trunk/mapserver/mapcache/include/geocache.h
===================================================================
--- trunk/mapserver/mapcache/include/geocache.h	2011-08-26 11:15:54 UTC (rev 12310)
+++ trunk/mapserver/mapcache/include/geocache.h	2011-08-26 11:16:01 UTC (rev 12311)
@@ -841,9 +841,9 @@
     char *name;
 
     /**
-     * the extent of the tileset that can be cached
+     * the extent of the tileset in lonlat
      */
-    double restricted_extent[4];
+    double wgs84bbox[4];
 
     /**
      * list of grids that will be cached
@@ -881,12 +881,6 @@
     geocache_image_format *format;
 
     /**
-     * the format to use when storing a tile coming from a source
-     * if NULL, store what the source has produced without processing
-     */
-    geocache_image_format *cache_format;
-
-    /**
      * a list of parameters that can be forwarded from the client to the geocache_tileset::source
      */
     apr_array_header_t *dimensions;
@@ -988,15 +982,7 @@
  */
 geocache_tileset* geocache_tileset_create(geocache_context *ctx);
 
-/**
- * \brief compute the bounding box of a tile
- * @param tile the input tile
- * @param bbox the bounding box to populate
- */
-void geocache_tileset_tile_bbox(geocache_tile *tile, double *bbox);
 
-
-
 /**
  * lock the tile
  */
@@ -1035,6 +1021,8 @@
 const char* geocache_grid_get_crs(geocache_context *ctx, geocache_grid *grid);
 const char* geocache_grid_get_srs(geocache_context *ctx, geocache_grid *grid);
 
+void geocache_grid_get_extent(geocache_context *ctx, geocache_grid *grid,
+      int x, int y, int z, double *bbox);
 /**
  * \brief compute x y value for given lon/lat (dx/dy) and given zoomlevel
  * @param ctx

Modified: trunk/mapserver/mapcache/src/configuration.c
===================================================================
--- trunk/mapserver/mapcache/src/configuration.c	2011-08-26 11:15:54 UTC (rev 12310)
+++ trunk/mapserver/mapcache/src/configuration.c	2011-08-26 11:16:01 UTC (rev 12311)
@@ -569,6 +569,7 @@
    geocache_tileset *tileset = NULL;
    ezxml_t cur_node;
    char* value;
+   int havewgs84bbox=0;
    name = (char*)ezxml_attr(node,"name");
    if(!name || !strlen(name)) {
       ctx->set_error(ctx, 400, "mandatory attribute \"name\" not found in <tileset>");
@@ -584,6 +585,31 @@
    }
    tileset = geocache_tileset_create(ctx);
    tileset->name = name;
+   
+   if ((cur_node = ezxml_child(node,"metadata")) != NULL) {
+      parseMetadata(ctx, cur_node, tileset->metadata);
+      GC_CHECK_ERROR(ctx);
+   }
+   
+   
+   if ((value = (char*)apr_table_get(tileset->metadata,"wgs84boundingbox")) != NULL) {
+      double *values;
+      int nvalues;
+      value = apr_pstrdup(ctx->pool,value);
+      if(GEOCACHE_SUCCESS != geocache_util_extract_double_list(ctx, value, ' ', &values, &nvalues) ||
+            nvalues != 4) {
+         ctx->set_error(ctx, 400, "failed to parse extent array %s."
+               "(expecting 4 space separated numbers, got %d (%f %f %f %f)"
+               "eg <wgs84bbox>-180 -90 180 90</wgs84bbox>",
+               value,nvalues,values[0],values[1],values[2],values[3]);
+         return;
+      }
+      tileset->wgs84bbox[0] = values[0];
+      tileset->wgs84bbox[1] = values[1];
+      tileset->wgs84bbox[2] = values[2];
+      tileset->wgs84bbox[3] = values[3];
+      havewgs84bbox = 1;
+   }
 
    for(cur_node = ezxml_child(node,"grid"); cur_node; cur_node = cur_node->next) {
       int i;
@@ -603,6 +629,7 @@
       for(i=0;i<grid->nlevels;i++) {
          gridlink->grid_limits[i] = apr_pcalloc(ctx->pool,4*sizeof(int));
       }
+      double *extent;
       restrictedExtent = (char*)ezxml_attr(cur_node,"restricted_extent");
       if(restrictedExtent) {
          int nvalues;
@@ -615,19 +642,22 @@
                   restrictedExtent);
             return;
          }
-         geocache_grid_compute_limits(grid,gridlink->restricted_extent,gridlink->grid_limits);
-
+         extent = gridlink->restricted_extent;
       } else {
-         geocache_grid_compute_limits(grid,grid->extent,gridlink->grid_limits);
+         extent = grid->extent;
       }
+      geocache_grid_compute_limits(grid,extent,gridlink->grid_limits);
+      
+      /* compute wgs84 bbox if it wasn't supplied already */
+      if(!havewgs84bbox && !strcasecmp(grid->srs,"epsg:4326")) {
+         tileset->wgs84bbox[0] = extent[0];
+         tileset->wgs84bbox[1] = extent[1];
+         tileset->wgs84bbox[2] = extent[2];
+         tileset->wgs84bbox[3] = extent[3];
+      }
       APR_ARRAY_PUSH(tileset->grid_links,geocache_grid_link*) = gridlink;
    }
 
-   if ((cur_node = ezxml_child(node,"metadata")) != NULL) {
-      parseMetadata(ctx, cur_node, tileset->metadata);
-      GC_CHECK_ERROR(ctx);
-   }
-   
    if ((cur_node = ezxml_child(node,"dimensions")) != NULL) {
       parseDimensions(ctx, cur_node, tileset);
       GC_CHECK_ERROR(ctx);
@@ -764,6 +794,14 @@
       ctx->set_error(ctx, 400, "tileset \"%s\" has no grids configured."
             " You must add a <grid> tag.", tileset->name);
       return;
+   } else if(!havewgs84bbox) {
+#ifdef USE_PROJ
+      geocache_grid_link *sgrid = APR_ARRAY_IDX(tileset->grid_links,0,geocache_grid_link*);
+      double *extent = sgrid->grid->extent;
+      if(sgrid->restricted_extent) {
+         extent = sgrid->restricted_extent;
+      }
+#endif
    }
 
    if(!tileset->format && (

Modified: trunk/mapserver/mapcache/src/grid.c
===================================================================
--- trunk/mapserver/mapcache/src/grid.c	2011-08-26 11:15:54 UTC (rev 12310)
+++ trunk/mapserver/mapcache/src/grid.c	2011-08-26 11:16:01 UTC (rev 12311)
@@ -26,6 +26,20 @@
    return grid;
 }
 
+
+/**
+ * \brief compute the extent of a given tile in the grid given its x, y, and z.
+ * \returns \extent the tile's extent
+ */
+void geocache_grid_get_extent(geocache_context *ctx, geocache_grid *grid,
+      int x, int y, int z, double *bbox) {
+   double res  = grid->levels[z]->resolution;
+   bbox[0] = grid->extent[0] + (res * x * grid->tile_sx);
+   bbox[1] = grid->extent[1] + (res * y * grid->tile_sy);
+   bbox[2] = grid->extent[0] + (res * (x + 1) * grid->tile_sx);
+   bbox[3] = grid->extent[1] + (res * (y + 1) * grid->tile_sy);
+}
+
 const char* geocache_grid_get_crs(geocache_context *ctx, geocache_grid *grid) {
    char *epsgnum;
 

Modified: trunk/mapserver/mapcache/src/service_kml.c
===================================================================
--- trunk/mapserver/mapcache/src/service_kml.c	2011-08-26 11:15:54 UTC (rev 12310)
+++ trunk/mapserver/mapcache/src/service_kml.c	2011-08-26 11:16:01 UTC (rev 12311)
@@ -32,7 +32,8 @@
    }
    request->request.mime_type = apr_pstrdup(ctx->pool,"application/vnd.google-earth.kml+xml");
 
-   geocache_tileset_tile_bbox(request->tile,bbox);
+   geocache_grid_get_extent(ctx,request->tile->grid_link->grid,
+         request->tile->x, request->tile->y, request->tile->z, bbox);
 
 
    caps = apr_psprintf(ctx->pool,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
@@ -73,7 +74,8 @@
             t->x = (request->tile->x << 1) +i;
             t->y = (request->tile->y << 1) +j;
             t->z = request->tile->z + 1;
-            geocache_tileset_tile_bbox(t,bb);
+            geocache_grid_get_extent(ctx,t->grid_link->grid,
+                  t->x, t->y, t->z, bb);
 
             caps = apr_psprintf(ctx->pool,"%s"
                   "    <NetworkLink>\n"

Modified: trunk/mapserver/mapcache/src/service_wms.c
===================================================================
--- trunk/mapserver/mapcache/src/service_wms.c	2011-08-26 11:15:54 UTC (rev 12310)
+++ trunk/mapserver/mapcache/src/service_wms.c	2011-08-26 11:16:01 UTC (rev 12311)
@@ -176,23 +176,26 @@
                dimensions = apr_pstrcat(ctx->pool,dimensions,"</Dimension>\n",NULL);
             }
          }
+         if(tileset->wgs84bbox[0] != tileset->wgs84bbox[2]) {
+            char *wgs84bbox = apr_psprintf(ctx->pool,"<LatLonBoundingBox minx=\"%f\" miny=\"%f\" maxx=\"%f\" maxy=\"%f\"/>\n",
+                  tileset->wgs84bbox[0], tileset->wgs84bbox[1],
+                  tileset->wgs84bbox[2], tileset->wgs84bbox[3]);
+            srss = apr_pstrcat(ctx->pool,srss,wgs84bbox,NULL);
+         }
+
          for(i=0;i<tileset->grid_links->nelts;i++) {
-            geocache_grid *grid = APR_ARRAY_IDX(tileset->grid_links,i,geocache_grid_link*)->grid;
+            geocache_grid_link *gridlink = APR_ARRAY_IDX(tileset->grid_links,i,geocache_grid_link*);
+            double *extent = gridlink->grid->extent;
+            if(gridlink->restricted_extent)
+               extent = gridlink->restricted_extent;
             char *bbox = apr_psprintf(ctx->pool,wms_bbox,
-                  grid->srs,
-                  grid->extent[0],
-                  grid->extent[1],
-                  grid->extent[2],
-                  grid->extent[3],
-                  grid->srs);
+                  gridlink->grid->srs,
+                  extent[0],
+                  extent[1],
+                  extent[2],
+                  extent[3],
+                  gridlink->grid->srs);
             srss = apr_pstrcat(ctx->pool,srss,bbox,NULL);
-            if(!strcasecmp(grid->srs,"epsg:4326")) {
-               char *wgs84bbox = apr_psprintf(ctx->pool,"<LatLonBoundingBox minx=\"%f\" miny=\"%f\" maxx=\"%f\" maxy=\"%f\"/>",
-                     grid->extent[0], grid->extent[1],
-                     grid->extent[2], grid->extent[3]);
-               srss = apr_pstrcat(ctx->pool,srss,wgs84bbox,NULL);
-
-            }
          }
          char *layercaps = apr_psprintf(ctx->pool,wms_layer,
                tileset->name,

Modified: trunk/mapserver/mapcache/src/service_wmts.c
===================================================================
--- trunk/mapserver/mapcache/src/service_wmts.c	2011-08-26 11:15:54 UTC (rev 12310)
+++ trunk/mapserver/mapcache/src/service_wmts.c	2011-08-26 11:16:01 UTC (rev 12311)
@@ -157,6 +157,16 @@
       }
       char *tmsets = "";
       char *bboxes = "";
+      
+      if(tileset->wgs84bbox[0] != tileset->wgs84bbox[2]) {
+         bboxes = apr_psprintf(ctx->pool,
+               "    <ows:WGS84BoundingBox>\n"
+               "      <ows:LowerCorner>%f %f</ows:LowerCorner>\n"
+               "      <ows:UpperCorner>%f %f</ows:UpperCorner>\n"
+               "    </ows:WGS84BoundingBox>\n",
+               tileset->wgs84bbox[0], tileset->wgs84bbox[1],
+               tileset->wgs84bbox[2], tileset->wgs84bbox[3]);
+      }
       for(i=0;i<tileset->grid_links->nelts;i++) {
          char *matrixlimits = "";
          geocache_grid_link *grid_link = APR_ARRAY_IDX(tileset->grid_links,i,geocache_grid_link*);

Modified: trunk/mapserver/mapcache/src/tileset.c
===================================================================
--- trunk/mapserver/mapcache/src/tileset.c	2011-08-26 11:15:54 UTC (rev 12310)
+++ trunk/mapserver/mapcache/src/tileset.c	2011-08-26 11:16:01 UTC (rev 12311)
@@ -101,7 +101,8 @@
    for(i=0;i<ntiles;i++) {
       geocache_tile *tile = tiles[i];
       double tileresolution = tile->grid_link->grid->levels[tile->z]->resolution;
-      geocache_tileset_tile_bbox(tile,tilebbox);
+      geocache_grid_get_extent(ctx,tile->grid_link->grid,
+            tile->x, tile->y, tile->z, tilebbox);
       geocache_image *im = geocache_imageio_decode(ctx,tile->data);
       cairo_surface_t* srcsurface= cairo_image_surface_create_for_data(im->data, CAIRO_FORMAT_ARGB32,
             im->w, im->h,im->stride);
@@ -198,16 +199,6 @@
    }
 }
 
-/*
- * compute the bounding box of a given tile
- */
-void geocache_tileset_tile_bbox(geocache_tile *tile, double *bbox) {
-   double res  = tile->grid_link->grid->levels[tile->z]->resolution;
-   bbox[0] = tile->grid_link->grid->extent[0] + (res * tile->x * tile->grid_link->grid->tile_sx);
-   bbox[1] = tile->grid_link->grid->extent[1] + (res * tile->y * tile->grid_link->grid->tile_sy);
-   bbox[2] = tile->grid_link->grid->extent[0] + (res * (tile->x + 1) * tile->grid_link->grid->tile_sx);
-   bbox[3] = tile->grid_link->grid->extent[1] + (res * (tile->y + 1) * tile->grid_link->grid->tile_sy);
-}
 
 /*
  * allocate and initialize a new tileset



More information about the mapserver-commits mailing list