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

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


Author: tbonfort
Date: 2011-08-26 04:07:12 -0700 (Fri, 26 Aug 2011)
New Revision: 12207

Modified:
   trunk/mapserver/mapcache/geocache.xml
   trunk/mapserver/mapcache/include/geocache.h
   trunk/mapserver/mapcache/src/configuration.c
   trunk/mapserver/mapcache/src/services.c
   trunk/mapserver/mapcache/src/util.c
Log:
add -std=c99 to cflags
thomas.bonfort | 2011-01-07 10:57:27 +0100 (Fri, 07 Jan 2011)

Modified: trunk/mapserver/mapcache/geocache.xml
===================================================================
--- trunk/mapserver/mapcache/geocache.xml	2011-08-26 11:07:06 UTC (rev 12206)
+++ trunk/mapserver/mapcache/geocache.xml	2011-08-26 11:07:12 UTC (rev 12207)
@@ -84,5 +84,6 @@
         <wms>true</wms>
         <tms>true</tms>
         <wmts>true</wmts>
+        <demo>true</demo>
     </services>
 </geocache>

Modified: trunk/mapserver/mapcache/include/geocache.h
===================================================================
--- trunk/mapserver/mapcache/include/geocache.h	2011-08-26 11:07:06 UTC (rev 12206)
+++ trunk/mapserver/mapcache/include/geocache.h	2011-08-26 11:07:12 UTC (rev 12207)
@@ -73,6 +73,7 @@
 typedef struct geocache_service_wms geocache_service_wms;
 typedef struct geocache_service_wmts geocache_service_wmts;
 typedef struct geocache_service_tms geocache_service_tms;
+typedef struct geocache_service_demo geocache_service_demo;
 typedef struct geocache_server_cfg geocache_server_cfg;
 typedef struct geocache_image geocache_image;
 typedef struct geocache_grid geocache_grid;
@@ -352,19 +353,26 @@
    char *version;
 };
 
+
+
 /** \defgroup services Services*/
 /** @{ */
 
-#define GEOCACHE_SERVICES_COUNT 3
+#define GEOCACHE_SERVICES_COUNT 4
 
 typedef enum {
-    GEOCACHE_SERVICE_WMS = 0, GEOCACHE_SERVICE_TMS, GEOCACHE_SERVICE_WMTS
+    GEOCACHE_SERVICE_WMS = 0, GEOCACHE_SERVICE_TMS, GEOCACHE_SERVICE_WMTS,
+    GEOCACHE_SERVICE_DEMO
 } geocache_service_type;
 
+#define GEOCACHE_UNITS_COUNT 3
 typedef enum {
-    GEOCACHE_UNIT_UNSET = 0, GEOCACHE_UNIT_METERS, GEOCACHE_UNIT_DEGREES, GEOCACHE_UNIT_FEET
+    GEOCACHE_UNIT_METERS=0, GEOCACHE_UNIT_DEGREES, GEOCACHE_UNIT_FEET
 } geocache_unit;
 
+/* defined in util.c*/
+extern const double geocache_meters_per_unit[GEOCACHE_UNITS_COUNT];
+
 /** \interface geocache_service
  * \brief a standard service (eg WMS, TMS)
  */
@@ -414,6 +422,14 @@
     geocache_service service;
 };
 
+/**\class geocache_service_demo
+ * \brief a demo service
+ * \implements geocache_service
+ */
+struct geocache_service_demo {
+    geocache_service service;
+};
+
 /**
  * \brief create and initialize a geocache_service_wms
  * \memberof geocache_service_wms
@@ -433,6 +449,12 @@
 geocache_service* geocache_service_wmts_create(geocache_context *ctx);
 
 /**
+ * \brief create and initialize a geocache_service_demo
+ * \memberof geocache_service_demo
+ */
+geocache_service* geocache_service_demo_create(geocache_context *ctx);
+
+/**
  * \brief return the request that corresponds to the given url
  */
 void geocache_service_dispatch_request(geocache_context *ctx,
@@ -653,6 +675,7 @@
    char *name;
    int levels;
    char *srs;
+   geocache_unit unit;
    int tile_sx, tile_sy; /**<width and height of a tile in pixels */
    double *resolutions;
    double **extents; /**< array of extents (one for each resolution) */

Modified: trunk/mapserver/mapcache/src/configuration.c
===================================================================
--- trunk/mapserver/mapcache/src/configuration.c	2011-08-26 11:07:06 UTC (rev 12206)
+++ trunk/mapserver/mapcache/src/configuration.c	2011-08-26 11:07:12 UTC (rev 12207)
@@ -90,6 +90,7 @@
    grid = geocache_grid_create(pool);
    grid->name = "WGS84";
    grid->srs = "epsg:4326";
+   grid->unit = GEOCACHE_UNIT_DEGREES;
    grid->tile_sx = grid->tile_sy = 256;
    grid->resolutions = wgs84_resolutions;
    grid->levels = 16;
@@ -111,6 +112,7 @@
    grid->tile_sx = grid->tile_sy = 256;
    grid->resolutions = google_resolutions;
    grid->levels = 19;
+   grid->unit = GEOCACHE_UNIT_METERS;
    grid->extents = (double**)apr_pcalloc(pool,grid->levels*sizeof(double*));
    grid->resolutions = (double*)apr_pcalloc(pool,grid->levels*sizeof(double));
    for(i=0; i<grid->levels; i++) {
@@ -677,6 +679,12 @@
                      config->services[GEOCACHE_SERVICE_WMTS] = geocache_service_wmts_create(ctx);
                   }
                   xmlFree(value);
+               } else if(!xmlStrcmp(service_node->name, BAD_CAST "demo")) {
+                  xmlChar* value = xmlNodeGetContent(service_node);
+                  if(!value || !*value || xmlStrcmp(value, BAD_CAST "false")) {
+                     config->services[GEOCACHE_SERVICE_DEMO] = geocache_service_demo_create(ctx);
+                  }
+                  xmlFree(value);
                }
                
             }

Modified: trunk/mapserver/mapcache/src/services.c
===================================================================
--- trunk/mapserver/mapcache/src/services.c	2011-08-26 11:07:06 UTC (rev 12206)
+++ trunk/mapserver/mapcache/src/services.c	2011-08-26 11:07:12 UTC (rev 12207)
@@ -144,16 +144,155 @@
    request->request.mime_type = apr_pstrdup(ctx->pool,"text/xml");
 }
 
+static const char *wmts_0 = 
+      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+      "<Capabilities xmlns=\"http://www.opengis.net/wmts/1.0\"\n"
+      "xmlns:ows=\"http://www.opengis.net/ows/1.1\"\n"
+      "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
+      "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+      "xmlns:gml=\"http://www.opengis.net/gml\" xsi:schemaLocation=\"http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd\"\n"
+      "version=\"1.0.0\">\n"
+      "<ows:ServiceIdentification>\n"
+      "  <ows:Title>%s</ows:Title>\n"
+      "  <ows:ServiceType>OGC WMTS</ows:ServiceType>\n"
+      "  <ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>\n"
+      "</ows:ServiceIdentification>\n"
+      "<ows:ServiceProvider>\n"
+      "  <ows:ProviderName>%s</ows:ProviderName>\n"
+      "  <ows:ProviderSite xlink:href=\"%s\" />\n"
+      "  <ows:ServiceContact>\n"
+      "    <ows:IndividualName>%s</ows:IndividualName>\n"
+      "  </ows:ServiceContact>\n"
+      "</ows:ServiceProvider>\n"
+      "<ows:OperationsMetadata>\n"
+      "  <ows:Operation name=\"GetCapabilities\">\n"
+      "    <ows:DCP>\n"
+      "      <ows:HTTP>\n"
+      "        <ows:Get xlink:href=\"%s\">\n"
+      "          <ows:Constraint name=\"GetEncoding\">\n"
+      "            <ows:AllowedValues>\n"
+      "              <ows:Value>KVP</ows:Value>\n"
+      "            </ows:AllowedValues>\n"
+      "          </ows:Constraint>\n"
+      "        </ows:Get>\n"
+      "      </ows:HTTP>\n"
+      "    </ows:DCP>\n"
+      "  </ows:Operation>\n"
+      "  <ows:Operation name=\"GetTile\">\n"
+      "    <ows:DCP>\n"
+      "      <ows:HTTP>\n"
+      "        <ows:Get xlink:href=\"%s\">\n"
+      "          <ows:Constraint name=\"GetEncoding\">\n"
+      "            <ows:AllowedValues>\n"
+      "              <ows:Value>KVP</ows:Value>\n"
+      "            </ows:AllowedValues>\n"
+      "          </ows:Constraint>\n"
+      "        </ows:Get>\n"
+      "      </ows:HTTP>\n"
+      "    </ows:DCP>\n"
+      "  </ows:Operation>\n"
+      "</ows:OperationsMetadata>\n"
+      "<Contents>\n";
+      
+
+static const char *wmts_matrix = 
+      "    <TileMatrix>\n"
+      "      <ows:Identifier>%s:%d</ows:Identifier>\n"
+      "      <ScaleDenominator>%.20f</ScaleDenominator>\n"
+      "      <TopLeftCorner>%f %f</TopLeftCorner>\n"
+      "      <TileWidth>%d</TileWidth>\n"
+      "      <TileHeight>%d</TileHeight>\n"
+      "      <MatrixWidth>%d</MatrixWidth>\n"
+      "      <MatrixHeight>%d</MatrixHeight>\n"
+      "    </TileMatrix>\n";
+
 void _create_capabilities_wmts(geocache_context *ctx, geocache_request_get_capabilities *req, char *url, char *path_info, geocache_cfg *cfg) {
    geocache_request_get_capabilities_wmts *request = (geocache_request_get_capabilities_wmts*)req;
+   char *caps;
+   char *onlineresource = apr_pstrcat(ctx->pool,url,"/",req->request.service->url_prefix,"?",NULL);
 #ifdef DEBUG
    if(request->request.request.type != GEOCACHE_REQUEST_GET_CAPABILITIES) {
       ctx->set_error(ctx,GEOCACHE_ERROR,"wrong wms capabilities request");
       return;
    }
 #endif
-   request->request.mime_type = apr_pstrdup(ctx->pool,"text/xml");
-   request->request.capabilities = "this is the wmts capabilitities";
+   request->request.mime_type = apr_pstrdup(ctx->pool,"application/xml");
+   
+   caps = apr_psprintf(ctx->pool,wmts_0,
+         "title_todo", "providername_todo", "individualname_todo",
+         onlineresource,onlineresource,onlineresource);
+   
+   
+   apr_hash_index_t *grid_index = apr_hash_first(ctx->pool,cfg->grids);
+
+   while(grid_index) {
+      geocache_grid *grid;
+      char *epsgnum;
+      const void *key; apr_ssize_t keylen;
+      char *matrix;
+      int level;
+      apr_hash_this(grid_index,&key,&keylen,(void**)&grid);
+      
+      /*locate the number after epsg: in the grd srs*/
+      epsgnum = strchr(grid->srs,':');
+      if(!epsgnum) {
+         epsgnum = grid->srs;
+      } else {
+         epsgnum++;
+      }
+      caps = apr_psprintf(ctx->pool,"%s"
+            "  <TileMatrixSet>\n"
+            "    <ows:Identifier>%s</ows:Identifier>\n"
+            "    <ows:SupportedCRS>urn:ogc:def:crs:EPSG::%s</ows:SupportedCRS>\n",
+            caps,grid->name,epsgnum);
+      for(level=0;level<grid->levels;level++) {
+         int matrixwidth, matrixheight;
+         double scaledenom, unitwidth, unitheight;
+         unitwidth = grid->tile_sx * grid->resolutions[level];
+         unitheight = grid->tile_sy * grid->resolutions[level];
+                  
+         scaledenom = grid->resolutions[level] * geocache_meters_per_unit[grid->unit] / 0.00028;
+         matrixwidth = ceil((grid->extents[level][2]-grid->extents[level][0] - 0.01 * unitwidth)/unitwidth);
+         matrixheight = ceil((grid->extents[level][3]-grid->extents[level][1] - 0.01* unitheight)/unitheight);      
+         matrix = apr_psprintf(ctx->pool,wmts_matrix,
+               grid->name, level,
+               scaledenom,
+               grid->extents[level][0],grid->extents[level][3],
+               grid->tile_sx, grid->tile_sy,
+               matrixwidth,matrixheight);
+         caps = apr_psprintf(ctx->pool,"%s%s",caps,matrix);
+      }
+      caps = apr_pstrcat(ctx->pool,caps,"  </TileMatrixSet>\n",NULL);
+      grid_index = apr_hash_next(grid_index);
+   }
+   
+   apr_hash_index_t *layer_index = apr_hash_first(ctx->pool,cfg->tilesets);
+   while(layer_index) {
+      geocache_tileset *tileset;
+      const void *key; apr_ssize_t keylen;
+      apr_hash_this(layer_index,&key,&keylen,(void**)&tileset);
+      caps = apr_psprintf(ctx->pool,"%s"
+            "  <Layer>\n"
+            "    <ows:Title>%s</ows:Title>\n"
+            "    <ows:Abstract>%s</ows:Abstract>\n"
+            /*"    <ows:WGS84BoundingBox>\n"
+            "      <ows:LowerCorner>%f %f</ows:LowerCorner>\n"
+            "      <ows:UpperCorner>%f %f</ows:UpperCorner>\n"
+            "    </ows:WGS84BoundingBox>\n"*/
+            "    <ows:Identifier>%s</ows:Identifier>\n"
+            "    <Style isDefault=\"true\">\n"
+            "      <ows:Identifier>_null</ows:Identifier>\n"
+            "    </Style>\n"
+            "    <Format>%s</Format>\n"
+            "    <TileMatrixSetLink>\n"
+            "      <TileMatrixSet>%s</TileMatrixSet>\n"
+            "    </TileMatrixSetLink>\n"
+            "  </Layer>",caps,tileset->name,"abstract_todo",
+            tileset->name,tileset->format->mime_type,tileset->grid->name);
+      layer_index = apr_hash_next(layer_index);
+   }
+   caps = apr_pstrcat(ctx->pool,caps,"</Contents>\n</Capabilities>\n",NULL);
+   request->request.capabilities = caps;
 }
 
 static const char *tms_0 = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
@@ -434,7 +573,103 @@
       return;
    }
 }
+
 /**
+ * \brief parse a demo request
+ * \private \memberof geocache_service_demo
+ * \sa geocache_service::parse_request()
+ */
+void _geocache_service_demo_parse_request(geocache_context *ctx, geocache_request **request,
+      const char *cpathinfo, apr_table_t *params, geocache_cfg *config) {
+   *request = (geocache_request*)apr_pcalloc(
+               ctx->pool,sizeof(geocache_request_get_capabilities));
+   (*request)->type = GEOCACHE_REQUEST_GET_CAPABILITIES;
+}
+
+
+static char *demo_head = 
+      "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
+      "  <head>\n"
+      "    <style type=\"text/css\">\n"
+      "    #map {\n"
+      "    width: 100%;\n"
+      "    height: 100%;\n"
+      "    border: 1px solid black;\n"
+      "    }\n"
+      "    </style>\n"
+      "    <script src=\"http://www.openlayers.org/api/OpenLayers.js\"></script>\n"
+      "    <script type=\"text/javascript\">\n"
+      "var map;\n"
+      "function init(){\n"
+      "    map = new OpenLayers.Map( 'map' );\n";
+
+static char *demo_layer =
+      "    var %s_layer = new OpenLayers.Layer.WMS( \"%s\",\n"
+      "        \"%s\",{layers: '%s'},\n"
+      "        { gutter:0,ratio:1,isBaseLayer:true,transitionEffect:'resize',\n"
+      "          resolutions:[%s],\n"
+      "          maxExtent: new OpenLayers.Bounds(%f,%f,%f,%f),\n"
+      "          projection: new OpenLayers.Projection(\"%s\")\n"
+      "        }\n"
+      "    );\n";      
+
+
+
+
+
+void _create_capabilities_demo(geocache_context *ctx, geocache_request_get_capabilities *req,
+      char *url, char *path_info, geocache_cfg *cfg) {
+   geocache_request_get_capabilities *request = (geocache_request_get_capabilities*)req;
+   request->mime_type = apr_pstrdup(ctx->pool,"text/html");
+   char *caps = apr_pstrdup(ctx->pool,demo_head);
+   apr_hash_index_t *tileindex_index = apr_hash_first(ctx->pool,cfg->tilesets);
+   char *layers="";
+   while(tileindex_index) {
+      geocache_tileset *tileset;
+      const void *key; apr_ssize_t keylen;
+      apr_hash_this(tileindex_index,&key,&keylen,(void**)&tileset);
+      char *resolutions="";
+      layers = apr_psprintf(ctx->pool,"%s,%s_layer",layers,tileset->name);
+      int i;
+      resolutions = apr_psprintf(ctx->pool,"%s%.20f",resolutions,tileset->grid->resolutions[0]);
+      for(i=1;i<tileset->grid->levels;i++) {
+         resolutions = apr_psprintf(ctx->pool,"%s,%.20f",resolutions,tileset->grid->resolutions[i]);
+      }
+      char *ol_layer = apr_psprintf(ctx->pool,demo_layer,
+            tileset->name,
+            tileset->name,
+            apr_pstrcat(ctx->pool,url,"/wms?",NULL),
+            tileset->name,resolutions,
+            tileset->grid->extents[0][0],
+            tileset->grid->extents[0][1],
+            tileset->grid->extents[0][2],
+            tileset->grid->extents[0][3],
+            tileset->grid->srs);
+      caps = apr_psprintf(ctx->pool,"%s%s",caps,ol_layer);
+      tileindex_index = apr_hash_next(tileindex_index);
+   }
+   layers++;
+   caps = apr_psprintf(ctx->pool,"%s"
+         "    map.addLayers([%s]);\n"
+               "    if(!map.getCenter())\n"
+               "     map.zoomToMaxExtent();\n"
+               "    map.addControl(new OpenLayers.Control.LayerSwitcher());\n"
+               "    map.addControl(new OpenLayers.Control.MousePosition());\n"
+               "}\n"
+               "    </script>\n"
+               "  </head>\n"
+               "\n"
+               "<body onload=\"init()\">\n"
+               "    <div id=\"map\">\n"
+               "    </div>\n"
+               "</body>\n"
+               "</html>\n",caps,layers);
+   
+   request->capabilities = caps;
+   
+}
+
+/**
  * \brief parse a TMS request
  * \private \memberof geocache_service_tms
  * \sa geocache_service::parse_request()
@@ -563,6 +798,19 @@
    return (geocache_service*)service;
 }
 
+geocache_service* geocache_service_demo_create(geocache_context *ctx) {
+   geocache_service_demo* service = (geocache_service_demo*)apr_pcalloc(ctx->pool, sizeof(geocache_service_demo));
+   if(!service) {
+      ctx->set_error(ctx, GEOCACHE_ALLOC_ERROR, "failed to allocate demo service");
+      return NULL;
+   }
+   service->service.url_prefix = apr_pstrdup(ctx->pool,"demo");
+   service->service.type = GEOCACHE_SERVICE_DEMO;
+   service->service.parse_request = _geocache_service_demo_parse_request;
+   service->service.create_capabilities_response = _create_capabilities_demo;
+   return (geocache_service*)service;
+}
+
 void geocache_service_dispatch_request(geocache_context *ctx, geocache_request **request, char *pathinfo, apr_table_t *params, geocache_cfg *config) {
    int i;
    

Modified: trunk/mapserver/mapcache/src/util.c
===================================================================
--- trunk/mapserver/mapcache/src/util.c	2011-08-26 11:07:06 UTC (rev 12206)
+++ trunk/mapserver/mapcache/src/util.c	2011-08-26 11:07:12 UTC (rev 12207)
@@ -20,6 +20,8 @@
 #include <apr_tables.h>
 #include <curl/curl.h>
 
+const double geocache_meters_per_unit[GEOCACHE_UNITS_COUNT] = {1.0,6378137.0 * 2.0 * M_PI / 360,0.3048};
+
 int geocache_util_extract_int_list(geocache_context *ctx, const char* cargs, const char sep, int **numbers,
       int *numbers_count) {
    char *last, *key, *endptr;



More information about the mapserver-commits mailing list