[mapserver-commits] r10789 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Thu Dec 9 09:10:15 EST 2010


Author: assefa
Date: 2010-12-09 06:10:15 -0800 (Thu, 09 Dec 2010)
New Revision: 10789

Modified:
   trunk/mapserver/mapkmlrenderer.cpp
   trunk/mapserver/mapkmlrenderer.h
Log:
add support to use attributes as z values (#3633)

Modified: trunk/mapserver/mapkmlrenderer.cpp
===================================================================
--- trunk/mapserver/mapkmlrenderer.cpp	2010-12-08 21:10:41 UTC (rev 10788)
+++ trunk/mapserver/mapkmlrenderer.cpp	2010-12-09 14:10:15 UTC (rev 10789)
@@ -45,7 +45,7 @@
 	:	XmlDoc(NULL), LayerNode(NULL), GroundOverlayNode(NULL), Width(width), Height(height),
 		FirstLayer(MS_TRUE), MapCellsize(1.0),
 		PlacemarkNode(NULL), GeomNode(NULL),
-		Items(NULL), NumItems(0), map(NULL), currentLayer(NULL)
+                Items(NULL), NumItems(0), map(NULL), currentLayer(NULL), mElevationFromAttribute( false ), mElevationAttributeIndex( -1 ), mCurrentElevationValue(0.0)
 
 {
     /*private variables*/        
@@ -301,10 +301,7 @@
           xmlNewChild(LayerNode, NULL, BAD_CAST "styleUrl", BAD_CAST "#LayerFolder_check");
     }
 
-   
-
-    
-
+  
     /*Init few things on the first layer*/
     if (FirstLayer)
     {
@@ -338,14 +335,10 @@
                  break;
              }
          } 
-
-        
     }
 
     currentLayer = layer;
 
-   
-
      if (!msLayerIsOpen(layer))
      {
          if (msLayerOpen(layer) != MS_SUCCESS)
@@ -368,21 +361,10 @@
      if (value)
        papszLayerIncludeItems = msStringSplit(value, ',', &nIncludeItems);
 
-     
-     DumpAttributes = MS_FALSE;
-     char *attribVal = msLookupHashTable(&layer->metadata, "kml_dumpattributes");
-     if (attribVal && strlen(attribVal) > 0)
-     {
+     /*get all attributes*/
+     msLayerWhichItems(layer, MS_TRUE, NULL);
 
-         DumpAttributes = MS_TRUE;
-         msLayerWhichItems(layer, MS_FALSE, attribVal);
 
-     }
-     else
-     {
-         msLayerWhichItems(layer, MS_TRUE, NULL);
-     }
-
      NumItems = layer->numitems;
      if (NumItems)
      {
@@ -392,6 +374,18 @@
      }
 
     
+     char* elevationAttribute = msLookupHashTable(&layer->metadata, "kml_elevation_attribute");
+     if( elevationAttribute )
+     {
+         mElevationFromAttribute = true;
+         for( int i = 0; i < layer->numitems; ++i )
+         {
+             if( strcasecmp( layer->items[i], elevationAttribute ) == 0 )
+             {
+                 mElevationAttributeIndex = i;
+             }
+         }
+     }  
 
     setupRenderingParams(&layer->metadata);
     return MS_SUCCESS;
@@ -627,18 +621,22 @@
 
     for (int i=0; i<numPts; i++)
     {
-      if (AltitudeMode == relativeToGround || AltitudeMode == absolute)
-      {
+        if( mElevationFromAttribute )
+        {
+            sprintf(lineBuf, "\t%.8f,%.8f,%.8f\n", pts[i].x, pts[i].y, mCurrentElevationValue);
+        }
+        else if (AltitudeMode == relativeToGround || AltitudeMode == absolute)
+        {
 #ifdef USE_POINT_Z_M
-        sprintf(lineBuf, "\t%.8f,%.8f,%.8f\n", pts[i].x, pts[i].y, pts[i].z);
+            sprintf(lineBuf, "\t%.8f,%.8f,%.8f\n", pts[i].x, pts[i].y, pts[i].z);
 #else
-        msSetError(MS_MISCERR, "Z coordinates support not available  (mapserver not compiled with USE_POINT_Z_M option)", "KmlRenderer::addCoordsNode()");
+            msSetError(MS_MISCERR, "Z coordinates support not available  (mapserver not compiled with USE_POINT_Z_M option)", "KmlRenderer::addCoordsNode()");
 #endif
-      }
-      else
-        sprintf(lineBuf, "\t%.8f,%.8f\n", pts[i].x, pts[i].y);
+        }
+        else
+          sprintf(lineBuf, "\t%.8f,%.8f\n", pts[i].x, pts[i].y);
 
-      xmlNodeAddContent(coordsNode, BAD_CAST lineBuf);
+        xmlNodeAddContent(coordsNode, BAD_CAST lineBuf);
     }
     xmlNodeAddContent(coordsNode, BAD_CAST "\t");
 }
@@ -862,6 +860,13 @@
 
     DescriptionNode = createDescriptionNode(shape);
 
+    if( mElevationFromAttribute && shape->numvalues > mElevationAttributeIndex && 
+        mElevationAttributeIndex >= 0 && shape->values[mElevationAttributeIndex])
+    {
+        mCurrentElevationValue = atof( shape->values[mElevationAttributeIndex] );
+    }
+
+
     memset(SymbologyFlag, 0, NumSymbologyFlag);
 }
 

Modified: trunk/mapserver/mapkmlrenderer.h
===================================================================
--- trunk/mapserver/mapkmlrenderer.h	2010-12-08 21:10:41 UTC (rev 10788)
+++ trunk/mapserver/mapkmlrenderer.h	2010-12-09 14:10:15 UTC (rev 10789)
@@ -95,7 +95,13 @@
 	int				Extrude;
 
 	enum altitudeModeEnum { undefined, clampToGround, relativeToGround, absolute };
-	
+        /**True if elevation is taken from a feature attribute*/
+        bool mElevationFromAttribute;
+        /**Attribute index of elevation (or -1 if elevation is not attribute driven*/
+        int mElevationAttributeIndex;
+        double mCurrentElevationValue;
+ 	
+
 	outputFormatObj *aggFormat;
 
 protected:



More information about the mapserver-commits mailing list