[mapserver-commits] r7553 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Thu May 1 19:51:43 EDT 2008


Author: pramsey
Date: 2008-05-01 19:51:43 -0400 (Thu, 01 May 2008)
New Revision: 7553

Modified:
   trunk/mapserver/mapserv.c
   trunk/mapserver/maptemplate.h
   trunk/mapserver/maptile.c
   trunk/mapserver/maptile.h
Log:
Update to reflect new tilemode behavior (gmap and ve modes)


Modified: trunk/mapserver/mapserv.c
===================================================================
--- trunk/mapserver/mapserv.c	2008-05-01 23:51:09 UTC (rev 7552)
+++ trunk/mapserver/mapserv.c	2008-05-01 23:51:43 UTC (rev 7553)
@@ -861,31 +861,22 @@
 
     if(strcasecmp(msObj->request->ParamNames[i], "tilemode") == 0) { 
       /* currently, only valid tilemode is "spheremerc" */
-      if( strcasecmp(msObj->request->ParamValues[i], "spheremerc") != 0) {
-        msSetError(MS_WEBERR, "Invalid tilemode. Use one of: spheremerc", "loadForm()");
+      if( strcasecmp(msObj->request->ParamValues[i], "gmap") == 0) {
+        msObj->TileMode = TILE_GMAP;
+      } else if ( strcasecmp(msObj->request->ParamValues[i], "ve") == 0 ) {
+        msObj->TileMode = TILE_VE;
+      } else {
+        msSetError(MS_WEBERR, "Invalid tilemode. Use one of: gmap, ve", "loadForm()");
         writeError();
       }
-      msObj->TileMode = SPHEREMERC;
       continue;
     }
 
     if(strcasecmp(msObj->request->ParamNames[i],"tile") == 0) { 
 
-      int num_coords = 0;
-      char **coords = NULL;
-      int l = 0;
-      
       msObj->CoordSource = FROMTILE;
-      coords = msStringSplit(msObj->request->ParamValues[i], ' ', &(num_coords));
-      if( num_coords != 3 ) {
-        msSetError(MS_WEBERR, "Invalid number of tile coordinates (should be three).", "loadForm()");
-        writeError();
-      }
-
-      msObj->TileCoords = (long *) malloc(sizeof(long) * 3);
-      for(l = 0; l < num_coords; l++) {
-        *(msObj->TileCoords + l) = strtol(coords[l], NULL, 10);
-      }
+      msObj->TileCoords = strdup(msObj->request->ParamValues[i]);
+      
       continue;
     }
 

Modified: trunk/mapserver/maptemplate.h
===================================================================
--- trunk/mapserver/maptemplate.h	2008-05-01 23:51:09 UTC (rev 7552)
+++ trunk/mapserver/maptemplate.h	2008-05-01 23:51:43 UTC (rev 7553)
@@ -94,10 +94,10 @@
    /* can be BROWSE, QUERY, etc. */
    int Mode; 
    
-   /* can be SPHEREMERC */
+   /* can be GMAP, VE */
    int TileMode;
-   /* three integral coordinates, X, Y, Zoom */
-   long *TileCoords;
+   /* for GMAP: 0 0 1; for VE: 013021023 */
+   char *TileCoords;
    
    /* big enough for time + pid */
    char Id[IDSIZE]; 

Modified: trunk/mapserver/maptile.c
===================================================================
--- trunk/mapserver/maptile.c	2008-05-01 23:51:09 UTC (rev 7552)
+++ trunk/mapserver/maptile.c	2008-05-01 23:51:43 UTC (rev 7553)
@@ -43,62 +43,74 @@
 
   /* 
   ** Ensure all the LAYERs have a projection. 
-  **/  
+  */  
   if( msTileSetProjections(msObj->Map) != 0 ) {
     return(MS_FAILURE);
   }
 
   /* 
   ** Set the projection string for this mode. 
-  **/
-  if( msObj->TileMode == SPHEREMERC ) {
+  */
+  if( msObj->TileMode == TILE_GMAP || msObj->TileMode == TILE_VE ) {
     outProjStr = SPHEREMERC_PROJ4;
   } else {
     return(MS_FAILURE); /* Huh? No mode? */
   }
   if( msLoadProjectionString(&(msObj->Map->projection), outProjStr) != 0 ) {
-    msSetError(MS_CGIERR, "Unable to load projection string.", "msTileSetExtent()");
+    msSetError(MS_CGIERR, "Unable to load projection string.", "msTileSetup()");
     return(MS_FAILURE);
   }
   
   /*
   ** Set up the output extents for this tilemode and tile coordinates 
-  **/
-  if( msObj->TileMode == SPHEREMERC ) {
+  */
+  if( msObj->TileMode == TILE_GMAP ) {
+
+    int num_coords = 0;
+    char **coords = NULL;
+    int x, y, zoom;
+    double zoomfactor;
     
-    int x = msObj->TileCoords[0];
-    int y = msObj->TileCoords[1];
-    int zoom = msObj->TileCoords[2];
-    double zoomfactor = pow(2.0, (double)zoom);
+    coords = msStringSplit(msObj->TileCoords, ' ', &(num_coords));
+    if( num_coords != 3 ) {
+      msSetError(MS_WEBERR, "Invalid number of tile coordinates (should be three).", "msTileSetup()");
+      return(MS_FAILURE);
+    }
     
+    x = strtol(coords[0], NULL, 10);
+    y = strtol(coords[1], NULL, 10);
+    zoom = strtol(coords[2], NULL, 10);
+
+    zoomfactor = pow(2.0, (double)zoom);
+    
     /*
     ** Check the input request for sanity.
-    **/
+    */
     if( x >= zoomfactor || y >= zoomfactor ) {
-      msSetError(MS_CGIERR, "Tile coordinates are too large for supplied zoom.", "msTileSetExtent()");
+      msSetError(MS_CGIERR, "GMap tile coordinates are too large for supplied zoom.", "msTileSetup()");
       return(MS_FAILURE);
     }
     if( x < 0 || y < 0 ) {
-      msSetError(MS_CGIERR, "Tile coordinates should not be less than zero.", "msTileSetExtent()");
+      msSetError(MS_CGIERR, "GMap tile coordinates should not be less than zero.", "msTileSetup()");
       return(MS_FAILURE);
     }
 
-    /* 
-    ** Set the output tile size.
-    **/
-    msObj->ImgCols = SPHEREMERC_IMAGE_SIZE;
-    msObj->ImgRows = SPHEREMERC_IMAGE_SIZE;
-    msObj->Map->width = SPHEREMERC_IMAGE_SIZE;
-    msObj->Map->height = SPHEREMERC_IMAGE_SIZE;
+  }
+  else if ( msObj->TileMode == TILE_VE ) {
+    
+    if( strspn( msObj->TileCoords, "0123" ) < strlen( msObj->TileCoords ) ) {
+      msSetError(MS_CGIERR, "VE tile name should only include characters 0, 1, 2 and 3.", "msTileSetup()");
+      return(MS_FAILURE);
+    }
 
   }
   else {
     return(MS_FAILURE); /* Huh? Should have a mode. */
   }
-  
+     
   return MS_SUCCESS;
 #else
-  msSetError(MS_CGIERR, "Tile API is not available.", "msTileSetExtent()");
+  msSetError(MS_CGIERR, "Tile API is not available.", "msTileSetup()");
   return(MS_FAILURE);
 #endif
 }
@@ -112,57 +124,94 @@
 #ifdef USE_TILE_API 
   
   mapObj *map = msObj->Map;
+  double	dx, dy;
 
-  if( msObj->TileMode == SPHEREMERC ) {
+  if( msObj->TileMode == TILE_GMAP ) {
 
-    double	dx, dy;
+    int num_coords = 0;
+    char **coords = NULL;
+    int x, y, zoom;
+    double zoomfactor, tilesize, xmin, xmax, ymin, ymax;
+    
+    coords = msStringSplit(msObj->TileCoords, ' ', &(num_coords));
+    if( num_coords != 3 ) {
+      msSetError(MS_WEBERR, "Invalid number of tile coordinates (should be three).", "msTileSetExtent()");
+      return(MS_FAILURE);
+    }
+    
+    x = strtol(coords[0], NULL, 10);
+    y = strtol(coords[1], NULL, 10);
+    zoom = strtol(coords[2], NULL, 10);
 
-    int x = msObj->TileCoords[0];
-    int y = msObj->TileCoords[1];
-    int zoom = msObj->TileCoords[2];
-
-    double zoomfactor = pow(2.0, (double)zoom);
+    zoomfactor = pow(2.0, (double)zoom);
     
     /*
      * Calculate the ground extents of the tile request.
      */
     /* printf("X: %i  Y: %i  Z: %i\n",x,y,zoom); */
-    double tilesize = SPHEREMERC_GROUND_SIZE / zoomfactor;
-    double xmin = (x * tilesize) - (SPHEREMERC_GROUND_SIZE / 2.0);
-    double xmax = ((x + 1) * tilesize) - (SPHEREMERC_GROUND_SIZE / 2.0);
-    double ymin = (SPHEREMERC_GROUND_SIZE / 2.0) - ((y + 1) * tilesize);
-    double ymax = (SPHEREMERC_GROUND_SIZE / 2.0) - (y * tilesize);
+    tilesize = SPHEREMERC_GROUND_SIZE / zoomfactor;
+    xmin = (x * tilesize) - (SPHEREMERC_GROUND_SIZE / 2.0);
+    xmax = ((x + 1) * tilesize) - (SPHEREMERC_GROUND_SIZE / 2.0);
+    ymin = (SPHEREMERC_GROUND_SIZE / 2.0) - ((y + 1) * tilesize);
+    ymax = (SPHEREMERC_GROUND_SIZE / 2.0) - (y * tilesize);
     
     map->extent.minx = xmin;
     map->extent.maxx = xmax;
     map->extent.miny = ymin;
     map->extent.maxy = ymax;
+  
+  }
+  else if( msObj->TileMode == TILE_VE ) {
 
-    /* 
-     * Set the output tile size.
-     */
-    msObj->ImgCols = SPHEREMERC_IMAGE_SIZE;
-    msObj->ImgRows = SPHEREMERC_IMAGE_SIZE;
-    map->width = SPHEREMERC_IMAGE_SIZE;
-    map->height = SPHEREMERC_IMAGE_SIZE;
+    double minx = SPHEREMERC_GROUND_SIZE / -2.0;
+    double miny = SPHEREMERC_GROUND_SIZE / -2.0;
+    double maxx = SPHEREMERC_GROUND_SIZE / 2.0;
+    double maxy = SPHEREMERC_GROUND_SIZE / 2.0;
+    double zoom = 2.0;
+    double tsize;
+    int i = 0;
+    char j = 0;
+    
+    for( i = 0; i < strlen( msObj->TileCoords ); i++ ) {
+      j = msObj->TileCoords[i];
+      tsize = SPHEREMERC_GROUND_SIZE / zoom;
+      if( j == '1' || j == '3' ) minx += tsize;
+      if( j == '0' || j == '2' ) maxx -= tsize;
+      if( j == '2' || j == '3' ) maxy -= tsize;
+      if( j == '0' || j == '1' ) miny += tsize;
+      zoom *= 2.0;
+    }
+    
+    map->extent.minx = minx;
+    map->extent.maxx = maxx;
+    map->extent.miny = miny;
+    map->extent.maxy = maxy;
 
-    /* 
-     * Adjust the extents inwards by 1/2 pixel so they are from
-     * center-of-pixel to center-of-pixel, instead of edge-to-edge.
-     * This is the way mapserver does it.
-     */
-    dx = (map->extent.maxx - map->extent.minx) / map->width;
-    map->extent.minx += dx*0.5;
-    map->extent.maxx -= dx*0.5;
-    dy = (map->extent.maxy - map->extent.miny) / map->height;
-    map->extent.miny += dy*0.5;
-    map->extent.maxy -= dy*0.5;
-    
   }
   else {
     return(MS_FAILURE); /* Huh? Should have a mode. */
   }
   
+  /* 
+  ** Adjust the extents inwards by 1/2 pixel so they are from
+  ** center-of-pixel to center-of-pixel, instead of edge-to-edge.
+  ** This is the way mapserver does it.
+  */
+  dx = (map->extent.maxx - map->extent.minx) / map->width;
+  map->extent.minx += dx*0.5;
+  map->extent.maxx -= dx*0.5;
+  dy = (map->extent.maxy - map->extent.miny) / map->height;
+  map->extent.miny += dy*0.5;
+  map->extent.maxy -= dy*0.5;
+  
+  /* 
+  ** Set the output tile size.
+  */
+  msObj->ImgCols = SPHEREMERC_IMAGE_SIZE;
+  msObj->ImgRows = SPHEREMERC_IMAGE_SIZE;
+  map->width = SPHEREMERC_IMAGE_SIZE;
+  map->height = SPHEREMERC_IMAGE_SIZE;
+  
   return MS_SUCCESS;
 #else
   msSetError(MS_CGIERR, "Tile API is not available.", "msTileSetExtent()");
@@ -170,6 +219,7 @@
 #endif
 }
 
+
 /************************************************************************
  *                            msTileSetProjections                      *
  *                                                                      * 
@@ -187,7 +237,7 @@
     msSetError(MS_WMSERR, "Cannot set new SRS on a map that doesn't "
                           "have any projection set. Please make sure your mapfile "
                           "has a PROJECTION defined at the top level.", 
-                          "msTileSetExtent()");
+                          "msTileSetProjectionst()");
     return(MS_FAILURE);
   }
 
@@ -203,7 +253,7 @@
       
       /* Set the projection to the map file projection */  
       if (msLoadProjectionString(&(GET_LAYER(map, i)->projection), mapProjStr) != 0) {
-        msSetError(MS_CGIERR, "Unable to set projection on layer.", "msTileSetExtent()");
+        msSetError(MS_CGIERR, "Unable to set projection on layer.", "msTileSetProjectionst()");
         return(MS_FAILURE);
       }
       GET_LAYER(map, i)->project = MS_TRUE;

Modified: trunk/mapserver/maptile.h
===================================================================
--- trunk/mapserver/maptile.h	2008-05-01 23:51:09 UTC (rev 7552)
+++ trunk/mapserver/maptile.h	2008-05-01 23:51:43 UTC (rev 7553)
@@ -30,14 +30,15 @@
 #include "mapserver.h"
 #include "maptemplate.h"
 
-/* TODO: add this to build environment */
+#ifdef USE_PROJ
 #define USE_TILE_API 1
+#endif 
 
 #define SPHEREMERC_PROJ4 "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +units=m +k=1.0 +nadgrids=@null"
 #define SPHEREMERC_GROUND_SIZE (20037508.34*2)
 #define SPHEREMERC_IMAGE_SIZE 256
 
-enum tileModes {SPHEREMERC};
+enum tileModes { TILE_GMAP, TILE_VE };
  
 MS_DLL_EXPORT int msTileSetup(mapservObj *msObj); 
 MS_DLL_EXPORT int msTileSetExtent(mapservObj *msObj); 



More information about the mapserver-commits mailing list