[mapserver-commits] r12906 - sandbox/inspire_soc2011/mapserver

svn at osgeo.org svn at osgeo.org
Wed Dec 21 11:15:38 EST 2011


Author: schpidi
Date: 2011-12-21 08:15:38 -0800 (Wed, 21 Dec 2011)
New Revision: 12906

Modified:
   sandbox/inspire_soc2011/mapserver/mapdraw.c
   sandbox/inspire_soc2011/mapserver/maputil.c
Log:
Adding patches from #4126 to inspire sandbox.


Modified: sandbox/inspire_soc2011/mapserver/mapdraw.c
===================================================================
--- sandbox/inspire_soc2011/mapserver/mapdraw.c	2011-12-21 15:50:34 UTC (rev 12905)
+++ sandbox/inspire_soc2011/mapserver/mapdraw.c	2011-12-21 16:15:38 UTC (rev 12906)
@@ -593,12 +593,16 @@
 
 /*
  * Test whether a layer should be drawn or not in the current map view and
- * at the current scale.  
+ * at the current scale and in the current extent.  
  * Returns TRUE if layer is visible, FALSE if not.
 */
 int msLayerIsVisible(mapObj *map, layerObj *layer)
 {
   int i;
+  int shouldFreeProjection = MS_FALSE;
+  projectionObj projection;
+  rectObj ext;
+  const char *value;
 
   if(!layer->data && !layer->tileindex && !layer->connection && !layer->features && !layer->layerinfo)
     return(MS_FALSE); /* no data associated with this layer, not an error since layer may be used as a template from MapScript */
@@ -668,6 +672,59 @@
       }
   }
 
+  /* With wms_respect_extent true, mark layer is invisible if the request bbox is
+     fully outside of the layer extent */
+  value = msOWSLookupMetadata(&(layer->metadata), "MO", "respect_extent");
+  if(value && strncasecmp(value, "true", 5) == 0) {
+
+#ifdef USE_PROJ
+    /* Use a temporary projectionObj which does not affect further layer handling */
+    if (layer->projection.numargs == 0) {
+      msInitProjection(&projection);
+      shouldFreeProjection = MS_TRUE;
+
+      /* If layer has no projection (e.g. annotation layer), read it from wms_srs metadata */
+      if ((value = (char*)msOWSGetEPSGProj(NULL, &(layer->metadata), "MO", MS_TRUE)) != NULL) {
+        msLoadProjectionStringEPSG(&projection, (char *)value);
+      }
+    }
+    /* Or use a pointer to the current layer projection, which we do not free afterwards */
+    else {
+      projection = layer->projection;
+    }
+
+    /* Check presence of projection again */
+    if ( projection.numargs == 0 ) {
+      msDebug("msLayerIsVisible(): cannot comply with respect_extent metadata, layer has no projection.\n");
+    }
+    /* Get the bounding box of this layer */
+    else if (msOWSGetLayerExtent(map, layer, "MO", &ext) != MS_SUCCESS) {
+      msDebug("msLayerIsVisible(): cannot comply with respect_extent metadata, layer has no extent.\n");
+    }
+    else
+    {
+      /* reproject layer extent to request srs */
+      if (msProjectionsDiffer(&(map->projection), &projection) == MS_TRUE)
+      {
+        msProjectRect(&projection, &(map->projection), &ext);
+      }
+#endif
+      /* compare request extent to layer extent */
+      if (MS_FALSE == msRectOverlap(&(map->extent), &ext)) {
+        if (MS_TRUE == shouldFreeProjection) {
+          msFreeProjection(&projection);
+        }
+        return MS_FALSE;
+      }
+#ifdef USE_PROJ
+    }
+
+    if (MS_TRUE == shouldFreeProjection) {
+      msFreeProjection(&projection);
+    }
+#endif
+  }
+
   return MS_TRUE;  /* All tests passed.  Layer is visible. */
 }
 /*

Modified: sandbox/inspire_soc2011/mapserver/maputil.c
===================================================================
--- sandbox/inspire_soc2011/mapserver/maputil.c	2011-12-21 15:50:34 UTC (rev 12905)
+++ sandbox/inspire_soc2011/mapserver/maputil.c	2011-12-21 16:15:38 UTC (rev 12906)
@@ -2097,10 +2097,24 @@
 {
     rectObj map_extent;
     rectObj layer_extent;
+    int haveOwnProjection = MS_FALSE;
+    projectionObj projection;
+    const char *value;
     
     /* No extent info? Nothing we can do, return MS_UNKNOWN. */
+    /* Otherwise copy extents and leave the originals intact, */
+    /* beacuse we will need to transform our rectangles for comparison. */
     if( (map->extent.minx == -1) && (map->extent.miny == -1) && (map->extent.maxx == -1 ) && (map->extent.maxy == -1) ) return MS_UNKNOWN;
-    if( (layer->extent.minx == -1) && (layer->extent.miny == -1) && (layer->extent.maxx == -1 ) && (layer->extent.maxy == -1) ) return MS_UNKNOWN;
+    else MS_COPYRECT(&map_extent, &(map->extent) );
+
+    /* For the layer extent, do a second try to read the extent */
+    /* from wms_extent or layer data */
+    if( (layer->extent.minx == -1) && (layer->extent.miny == -1) && (layer->extent.maxx == -1 ) && (layer->extent.maxy == -1) ) {
+      if (msOWSGetLayerExtent(map, layer, "MO", &layer_extent) != MS_SUCCESS) {
+        return MS_UNKNOWN;
+      }
+    }
+    else MS_COPYRECT(&layer_extent, &(layer->extent) );
         
 #ifdef USE_PROJ
 
@@ -2108,24 +2122,47 @@
     if( ! (map->projection.numargs > 0) ) 
         return MS_UNKNOWN;
 
-    /* No layer projection? Perform naive comparison, because they are 
-    ** in the same projection. */
-    if( ! (layer->projection.numargs > 0) ) 
-        return msRectOverlap( &(map->extent), &(layer->extent) );
+    /* No layer projection? Try to get it from wms_srs. */
+    if( ! (layer->projection.numargs > 0) ) {
+      value = (char*)msOWSGetEPSGProj(NULL, &(layer->metadata), "MO", MS_TRUE);
+      if (value != NULL) {
+        msInitProjection(&projection);
+        haveOwnProjection = MS_TRUE;
+        msLoadProjectionStringEPSG(&projection, (char *)value);
+      }
+    }
+
+    /* Agaian no layer projection? Return MS_UNKNOWN. We can not perform */
+    /* naive comparison, because in WMS mode, map->extent is expressed in */
+    /* the request SRS. */
+    if( ! (layer->projection.numargs > 0) && ! (projection.numargs > 0) ) {
+        if ( MS_TRUE == haveOwnProjection ) msFreeProjection(&projection);
+        return MS_UNKNOWN;
+    }
     
-    /* We need to transform our rectangles for comparison, 
-    ** so we will work with copies and leave the originals intact. */
-    MS_COPYRECT(&map_extent, &(map->extent) );
-    MS_COPYRECT(&layer_extent, &(layer->extent) );
-
     /* Transform map extents into geographics for comparison. */
-    if( msProjectRect(&(map->projection), &(map->latlon), &map_extent) )
+    if( msProjectRect(&(map->projection), &(map->latlon), &map_extent) ) {
+        if ( MS_TRUE == haveOwnProjection ) msFreeProjection(&projection);
         return MS_UNKNOWN;
+    }
         
     /* Transform layer extents into geographics for comparison. */
-    if( msProjectRect(&(layer->projection), &(map->latlon), &layer_extent) )
-        return MS_UNKNOWN;
+    /* First case: using layer projection */
+    /* Second case: using temporarily read projection from wms_srs */
+    if( MS_FALSE == haveOwnProjection ) {
+      if( msProjectRect(&(layer->projection), &(map->latlon), &layer_extent) ) 
+          return MS_UNKNOWN;
+    }
+    else {
+      if( msProjectRect(&(projection), &(map->latlon), &layer_extent) ) {
+          if ( MS_TRUE == haveOwnProjection ) msFreeProjection(&projection);
+          return MS_UNKNOWN;
+      }
+    }
 
+    /* Finally free the possibly created projectionObj agaian */
+    if ( MS_TRUE == haveOwnProjection ) msFreeProjection(&projection);
+
     /* Simple case? Return simple answer. */
     if ( map_extent.minx < map_extent.maxx && layer_extent.minx < layer_extent.maxx )
         return msRectOverlap( &(map_extent), &(layer_extent) );
@@ -2136,7 +2173,7 @@
    
 #else
     /* No proj? Naive comparison. */
-    if( msRectOverlap( &(map->extent), &(layer->extent) ) ) return MS_TRUE;
+    if( msRectOverlap( &(map_extent), &(layer_extent) ) ) return MS_TRUE;
     return MS_FALSE;
 #endif
 



More information about the mapserver-commits mailing list