[mapserver-commits] r9185 - sandbox/davidK

svn at osgeo.org svn at osgeo.org
Sun Jul 19 18:22:48 EDT 2009


Author: davidK
Date: 2009-07-19 18:22:47 -0400 (Sun, 19 Jul 2009)
New Revision: 9185

Modified:
   sandbox/davidK/layerobject.c
   sandbox/davidK/legend.c
   sandbox/davidK/mapgeos.c
   sandbox/davidK/maphash.c
   sandbox/davidK/mapjoin.c
   sandbox/davidK/mapkml.cpp
   sandbox/davidK/mapkml.h
   sandbox/davidK/mapkmlrenderer.cpp
   sandbox/davidK/mapkmlrenderer.h
   sandbox/davidK/mapmygis.c
   sandbox/davidK/maptclutf.c
   sandbox/davidK/maptime.c
   sandbox/davidK/mapxbase.c
   sandbox/davidK/scalebar.c
   sandbox/davidK/shptreevis.c
Log:
added new strategy for KML placemark creating and styling

Modified: sandbox/davidK/layerobject.c
===================================================================
--- sandbox/davidK/layerobject.c	2009-07-19 22:05:05 UTC (rev 9184)
+++ sandbox/davidK/layerobject.c	2009-07-19 22:22:47 UTC (rev 9185)
@@ -1,5 +1,5 @@
 /******************************************************************************
- * $Id:$
+ * $Id$
  *
  * Project:  MapServer
  * Purpose:  Functions for operating on a layerObj that don't belong in a

Modified: sandbox/davidK/legend.c
===================================================================
--- sandbox/davidK/legend.c	2009-07-19 22:05:05 UTC (rev 9184)
+++ sandbox/davidK/legend.c	2009-07-19 22:22:47 UTC (rev 9185)
@@ -1,5 +1,5 @@
 /******************************************************************************
- * $Id:$
+ * $Id$
  *
  * Project:  MapServer
  * Purpose:  Mainline of commandline legend generation test utility.

Modified: sandbox/davidK/mapgeos.c
===================================================================
--- sandbox/davidK/mapgeos.c	2009-07-19 22:05:05 UTC (rev 9184)
+++ sandbox/davidK/mapgeos.c	2009-07-19 22:22:47 UTC (rev 9185)
@@ -1,5 +1,5 @@
 /******************************************************************************
- * $Id:$
+ * $Id$
  *
  * Project:  MapServer
  * Purpose:  MapServer-GEOS integration.

Modified: sandbox/davidK/maphash.c
===================================================================
--- sandbox/davidK/maphash.c	2009-07-19 22:05:05 UTC (rev 9184)
+++ sandbox/davidK/maphash.c	2009-07-19 22:22:47 UTC (rev 9185)
@@ -1,5 +1,5 @@
 /******************************************************************************
- * $Id:$
+ * $Id$
  *
  * Project:  MapServer
  * Purpose:  Implement hashTableObj class.

Modified: sandbox/davidK/mapjoin.c
===================================================================
--- sandbox/davidK/mapjoin.c	2009-07-19 22:05:05 UTC (rev 9184)
+++ sandbox/davidK/mapjoin.c	2009-07-19 22:22:47 UTC (rev 9185)
@@ -1,5 +1,5 @@
 /******************************************************************************
- * $Id:$
+ * $Id$
  *
  * Project:  MapServer
  * Purpose:  Implements MapServer joins. 

Modified: sandbox/davidK/mapkml.cpp
===================================================================
--- sandbox/davidK/mapkml.cpp	2009-07-19 22:05:05 UTC (rev 9184)
+++ sandbox/davidK/mapkml.cpp	2009-07-19 22:22:47 UTC (rev 9185)
@@ -163,10 +163,22 @@
 {
 }
 
-int msPopulateRendererVTableKML( rendererVTableObj *renderer )
-{
-#ifdef USE_KML
-
+void msStartShapeKml(imageObj *img, shapeObj *shape)
+{
+	KmlRenderer* renderer = getKmlRenderer(img);
+	renderer->startShape(img, shape);
+}
+
+void msEndShapeKml(imageObj *img, shapeObj *shape)
+{
+	KmlRenderer* renderer = getKmlRenderer(img);
+	renderer->endShape(img, shape);
+}
+
+int msPopulateRendererVTableKML( rendererVTableObj *renderer )
+{
+#ifdef USE_KML
+
 	renderer->supports_transparent_layers = 1;
 	renderer->supports_pixel_buffer = 0;
 	renderer->supports_imagecache = 0;
@@ -196,14 +208,17 @@
     renderer->renderLineTiled = &msRenderLineTiledKml;
     renderer->freeTile = &msFreeTileKml;
     renderer->freeSymbol = &msFreeSymbolKml;
-    renderer->freeImage=&msFreeImageKml;
-
-    return MS_SUCCESS;
-#else
-    msSetError(MS_MISCERR, "KML Driver requested but is not built in", 
-            "msPopulateRendererVTableKML()");
-    return MS_FAILURE;
-#endif
+    renderer->freeImage=&msFreeImageKml;
+
+	renderer->startShape=&msStartShapeKml;
+	renderer->endShape=&msEndShapeKml;
+
+    return MS_SUCCESS;
+#else
+    msSetError(MS_MISCERR, "KML Driver requested but is not built in", 
+            "msPopulateRendererVTableKML()");
+    return MS_FAILURE;
+#endif
 }
 
 #ifdef __cplusplus

Modified: sandbox/davidK/mapkml.h
===================================================================
--- sandbox/davidK/mapkml.h	2009-07-19 22:05:05 UTC (rev 9184)
+++ sandbox/davidK/mapkml.h	2009-07-19 22:22:47 UTC (rev 9185)
@@ -52,6 +52,10 @@
 
 void msStartNewLayerKml(imageObj *img, layerObj *layer);
 void msCloseNewLayerKml(imageObj *img, layerObj *layer);
+
+void msStartShapeKml(imageObj *img, shapeObj *shape);
+void msEndShapeKml(imageObj *img, shapeObj *shape);
+
 void msTransformShapeKml(shapeObj *shape, rectObj extend, double cellsize);
 void msFreeImageKml(imageObj *image);
 void msFreeTileKml(imageObj *tile);

Modified: sandbox/davidK/mapkmlrenderer.cpp
===================================================================
--- sandbox/davidK/mapkmlrenderer.cpp	2009-07-19 22:05:05 UTC (rev 9184)
+++ sandbox/davidK/mapkmlrenderer.cpp	2009-07-19 22:22:47 UTC (rev 9185)
@@ -10,8 +10,9 @@
 
 KmlRenderer::KmlRenderer(int width, int height, colorObj* color/*=NULL*/) 
 	:	XmlDoc(NULL), LayerNode(NULL), Width(width), Height(height),
-		FirstLayer(true), RasterizerOutputFormat(NULL),
-		VectorMode(true), RasterMode(false), MapCellsize(1.0)
+		FirstLayer(true), RasterizerOutputFormat(NULL), InternalImg(NULL),
+		VectorMode(true), RasterMode(false), MapCellsize(1.0),
+		PlacemarkNode(NULL), GeomNode(NULL)
 {
 	//	Create document.
     XmlDoc = xmlNewDoc(BAD_CAST "1.0");
@@ -43,14 +44,14 @@
 
 	xmlCleanupParser();
 
-	if (RasterizerOutputFormat)
-		msFreeOutputFormat(RasterizerOutputFormat);
+	//if (RasterizerOutputFormat)
+	//	msFreeOutputFormat(RasterizerOutputFormat);
 }
 
 imageObj* KmlRenderer::createInternalImage()
 {
 	rendererVTableObj *r = RasterizerOutputFormat->vtable;
-	imageObj *img = r->createImage(Width, Height, RasterizerOutputFormat, NULL);
+	imageObj *img = r->createImage(Width, Height, RasterizerOutputFormat, &BgColor);
 
 	return img;
 }
@@ -63,7 +64,7 @@
 int KmlRenderer::saveImage(imageObj *img, FILE *fp, outputFormatObj *format)
 {
 	// 
-	if (InternalImg)
+	if (false && InternalImg)
 	{
 		char fileName[512];
 
@@ -204,6 +205,7 @@
 		// map rect for ground overlay
 		MapExtent = layer->map->extent;
 		MapCellsize = layer->map->cellsize;
+		BgColor = layer->map->imagecolor;
 
 		if (layer->map->name)
 			xmlNewChild(DocNode, NULL, BAD_CAST "name", BAD_CAST layer->map->name);
@@ -216,8 +218,10 @@
 			outputFormatObj *iFormat = layer->map->outputformatlist[i];
 			if(!strcasecmp(iFormat->driver,"cairo/png"))
 			{
-				RasterizerOutputFormat = msCloneOutputFormat(iFormat);
+				//RasterizerOutputFormat = msCloneOutputFormat(iFormat);
+				RasterizerOutputFormat = iFormat;
 				InternalImg = createInternalImage();
+				break;
 			}
 		}
 	}
@@ -225,7 +229,7 @@
 
 void KmlRenderer::closeNewLayer(imageObj *img, layerObj *layer)
 {
-
+	flushPlacemark();
 }
 
 xmlNodePtr KmlRenderer::createPlacemarkNode(xmlNodePtr parentNode, char *styleUrl)
@@ -240,23 +244,34 @@
 
 void KmlRenderer::renderLineVector(imageObj *img, shapeObj *p, strokeStyleObj *style)
 {
-	xmlNodePtr placemarkNode = createPlacemarkNode(LayerNode, lookupLineStyle(style));
+	if (p->numlines == 0)
+		return;
 
-	if (p->numlines == 1)
+	if (PlacemarkNode == NULL)
+		PlacemarkNode = createPlacemarkNode(LayerNode, NULL);
+
+	memcpy(&LineStyle, style, sizeof(strokeStyleObj));
+	SymbologyFlag[Line] = 1;
+
+	if (p != CurrentShape)
 	{
-		xmlNodePtr geomNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "LineString", NULL);
+		xmlNodePtr geomNode = getGeomParentNode("LineString");
 		addAddRenderingSpecifications(geomNode);
 		addCoordsNode(geomNode, p->line[0].point, p->line[0].numpoints);
-	}
-	else
-	{
-		xmlNodePtr multiGeomNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "MultiGeometry", NULL);
-		for (int i=0; i<p->numlines; i++)
+
+		// more than one line => MultiGeometry
+		if (p->numlines > 1)
 		{
-			xmlNodePtr lineStringNode = xmlNewChild(multiGeomNode, NULL, BAD_CAST "LineString", NULL);
-			addAddRenderingSpecifications(lineStringNode);
-			addCoordsNode(lineStringNode, p->line[i].point, p->line[i].numpoints);
+			geomNode = getGeomParentNode("LineString"); // returns MultiGeom Node
+			for (int i=1; i<p->numlines; i++)
+			{
+				xmlNodePtr lineStringNode = xmlNewChild(geomNode, NULL, BAD_CAST "LineString", NULL);
+				addAddRenderingSpecifications(lineStringNode);
+				addCoordsNode(lineStringNode, p->line[i].point, p->line[i].numpoints);
+			}
 		}
+
+		CurrentShape = p;
 	}
 }
 
@@ -284,21 +299,31 @@
 
 void KmlRenderer::renderPolygonVector(imageObj *img, shapeObj *p, colorObj *color)
 {
-	xmlNodePtr placemarkNode = createPlacemarkNode(LayerNode, lookupPolyStyle(color));
-	xmlNodePtr polygonNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "Polygon", NULL);
+	if (PlacemarkNode == NULL)
+		PlacemarkNode = createPlacemarkNode(LayerNode, NULL);
 
-	for (int i=0; i<p->numlines; i++)
+	memcpy(&PolygonColor, color, sizeof(colorObj));
+	SymbologyFlag[Polygon] = 1;
+
+	if (p != CurrentShape)
 	{
-		xmlNodePtr bdryNode = NULL;
+		xmlNodePtr geomParentNode = getGeomParentNode("Polygon");
 
-		if (i==0) // __TODO__ check ring order
-			bdryNode = xmlNewChild(polygonNode, NULL, BAD_CAST "outerBoundaryIs", NULL);
-		else
-			bdryNode = xmlNewChild(polygonNode, NULL, BAD_CAST "innerBoundaryIs", NULL);
+		for (int i=0; i<p->numlines; i++)
+		{
+			xmlNodePtr bdryNode = NULL;
 
-		xmlNodePtr ringNode = xmlNewChild(bdryNode, NULL, BAD_CAST "LinearRing", NULL);
-		addAddRenderingSpecifications(ringNode);
-		addCoordsNode(ringNode, p->line[i].point, p->line[i].numpoints);
+			if (i==0) // __TODO__ check ring order
+				bdryNode = xmlNewChild(geomParentNode, NULL, BAD_CAST "outerBoundaryIs", NULL);
+			else
+				bdryNode = xmlNewChild(geomParentNode, NULL, BAD_CAST "innerBoundaryIs", NULL);
+
+			xmlNodePtr ringNode = xmlNewChild(bdryNode, NULL, BAD_CAST "LinearRing", NULL);
+			addAddRenderingSpecifications(ringNode);
+			addCoordsNode(ringNode, p->line[i].point, p->line[i].numpoints);
+		}
+
+		CurrentShape = p;
 	}
 }
 
@@ -349,106 +374,22 @@
 	xmlNodeAddContent(coordsNode, BAD_CAST "\t");
 }
 
-char* KmlRenderer::lookupLineStyle(strokeStyleObj *strokeStyle)
+void KmlRenderer::renderGlyphsVector(imageObj *img, double x, double y, labelStyleObj *style, char *text)
 {
-	/*
-	<LineStyle id="ID">
-	  <!-- inherited from ColorStyle -->
-	  <color>ffffffff</color>            <!-- kml:color -->
-	  <colorMode>normal</colorMode>      <!-- colorModeEnum: normal or random -->
+	if (PlacemarkNode == NULL)
+		PlacemarkNode = createPlacemarkNode(LayerNode, NULL);
 
-	  <!-- specific to LineStyle -->
-	  <width>1</width>                   <!-- float -->
-	</LineStyle>
-	*/
+	memcpy(&LabelStyle, style, sizeof(labelStyleObj));
+	SymbologyFlag[Label] = 1;
 
-	char hexColor[16];
-	sprintf(hexColor,"%02x%02x%02x%02x", strokeStyle->color.alpha, strokeStyle->color.blue,
-											strokeStyle->color.green, strokeStyle->color.red);
+	xmlNewChild(PlacemarkNode, NULL, BAD_CAST "name", BAD_CAST text);
 
-	char styleName[32];
-	sprintf(styleName, "lineStyle%s_w%.1f", hexColor, strokeStyle->width);
+	xmlNodePtr geomNode = getGeomParentNode("Point");
+	addAddRenderingSpecifications(geomNode);
 
-	char *styleUrl = msLookupHashTable(StyleHashTable, styleName);
-	if (!styleUrl)
-	{
-		char styleValue[32];
-		sprintf(styleValue, "#%s", styleName);
-
-		hashObj *hash = msInsertHashTable(StyleHashTable, styleName, styleValue);
-		styleUrl = hash->data;
-
-		// Insert new PolyStyle node into Document node
-		xmlNodePtr styleNode = xmlNewChild(DocNode, NULL, BAD_CAST "Style", NULL);
-		xmlNewProp(styleNode, BAD_CAST "id", BAD_CAST styleName);
-
-		xmlNodePtr lineStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "LineStyle", NULL);
-		xmlNewChild(lineStyleNode, NULL, BAD_CAST "color", BAD_CAST hexColor);
-
-		char width[16];
-		sprintf(width, "%.1f", strokeStyle->width);
-		xmlNewChild(lineStyleNode, NULL, BAD_CAST "width", BAD_CAST width);
-	}
-
-	return styleUrl;
-}
-
-char* KmlRenderer::lookupPolyStyle(colorObj *color)
-{
-	/*
-	<PolyStyle id="ID">
-	  <!-- inherited from ColorStyle -->
-	  <color>ffffffff</color>            <!-- kml:color -->
-	  <colorMode>normal</colorMode>      <!-- kml:colorModeEnum: normal or random -->
-
-	  <!-- specific to PolyStyle -->
-	  <fill>1</fill>                     <!-- boolean -->
-	  <outline>1</outline>               <!-- boolean -->
-	</PolyStyle>
-	*/
-
-	char hexColor[16];
-	sprintf(hexColor,"%02x%02x%02x%02x", color->alpha, color->blue, color->green, color->red);
-
-	char styleName[32];
-	sprintf(styleName, "polyStyle%s", hexColor);
-
-	char *styleUrl = msLookupHashTable(StyleHashTable, styleName);
-	if (!styleUrl)
-	{
-		char styleValue[32];
-		sprintf(styleValue, "#%s", styleName);
-
-		hashObj *hash = msInsertHashTable(StyleHashTable, styleName, styleValue);
-		styleUrl = hash->data;
-
-		// Insert new PolyStyle node into Document node
-		xmlNodePtr styleNode = xmlNewChild(DocNode, NULL, BAD_CAST "Style", NULL);
-		xmlNewProp(styleNode, BAD_CAST "id", BAD_CAST styleName);
-
-		xmlNodePtr polyStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "PolyStyle", NULL);
-		xmlNewChild(polyStyleNode, NULL, BAD_CAST "color", BAD_CAST hexColor);
-	}
-
-	return styleUrl;
-}
-
-char* KmlRenderer::lookupPointStyle(colorObj *color)
-{
-	return NULL;
-}
-
-void KmlRenderer::renderGlyphsVector(imageObj *img, double x, double y, labelStyleObj *style, char *text)
-{
-	xmlNodePtr placemarkNode = createPlacemarkNode(LayerNode, lookupPointStyle(&style->color));
-	xmlNewChild(placemarkNode, NULL, BAD_CAST "name", BAD_CAST text);
-	xmlNodePtr pointNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "Point", NULL);
-
-	addAddRenderingSpecifications(pointNode);
-
 	pointObj pt;
 	pt.x = x; pt.y = y;
-	addCoordsNode(pointNode, &pt, 1);
+	addCoordsNode(geomNode, &pt, 1);
 }
 
 void KmlRenderer::renderGlyphs(imageObj *img, double x, double y, labelStyleObj *style, char *text)
@@ -507,59 +448,6 @@
 		xmlNewChild(node, NULL, BAD_CAST "altitudeMode", BAD_CAST "clampToGround");
 }
 
-char* KmlRenderer::lookupSymbolStyle(symbolObj *symbol, symbolStyleObj *style)
-{
-	/*	
-	<Style id="randomColorIcon">
-	  <IconStyle>
-		 <color>ff00ff00</color>
-		 <colorMode>random</colorMode>
-		 <scale>1.1</scale>
-		 <Icon>
-			<href>http://maps.google.com/mapfiles/kml/pal3/icon21.png</href>
-		 </Icon>
-	  </IconStyle>
-	</Style>
-	*/
-
-	char styleName[128];
-	sprintf(styleName, "symbol_%s_%.1f", symbol->name, style->scale);
-
-	char *styleUrl = msLookupHashTable(StyleHashTable, styleName);
-	if (!styleUrl)
-	{
-		char styleValue[32];
-		sprintf(styleValue, "#%s", styleName);
-
-		hashObj *hash = msInsertHashTable(StyleHashTable, styleName, styleValue);
-		styleUrl = hash->data;
-
-		// Insert new IconStyle node into Document node
-		xmlNodePtr styleNode = xmlNewChild(DocNode, NULL, BAD_CAST "Style", NULL);
-		xmlNewProp(styleNode, BAD_CAST "id", BAD_CAST styleName);
-
-		xmlNodePtr iconStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "IconStyle", NULL);
-		char scale[16];
-		sprintf(scale, "%.1f", style->scale);
-		xmlNewChild(iconStyleNode, NULL, BAD_CAST "scale", BAD_CAST scale);
-
-		char iconFileName[512];
-		sprintf(iconFileName, "symbol_%s_%.1f.%s", symbol->name, style->scale, MS_IMAGE_EXTENSION(RasterizerOutputFormat)); // __TODO__ add WEB IMAGEURL path
-		if (createIconImage(iconFileName, symbol, style) != MS_SUCCESS)
-		{
-			char errMsg[512];
-			sprintf(errMsg, "Error creating icon file '%s'", iconFileName);
-			msSetError(MS_IOERR, errMsg, "KmlRenderer::lookupSymbolStyle()" );
-			return NULL;
-		}
-
-		xmlNodePtr iconNode = xmlNewChild(iconStyleNode, NULL, BAD_CAST "Icon", NULL);
-		xmlNewChild(iconNode, NULL, BAD_CAST "href", BAD_CAST iconFileName);
-	}
-
-	return styleUrl;
-}
-
 int KmlRenderer::createIconImage(char *fileName, symbolObj *symbol, symbolStyleObj *style)
 {
 	// internal renderer used for rasterizing
@@ -617,25 +505,26 @@
 	return status;
 }
 
-void KmlRenderer::createSymbolPlacemark(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style)
+void KmlRenderer::renderSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style)
 {
-	char *symbolUrl = lookupSymbolStyle(symbol, style);
+	if (PlacemarkNode == NULL)
+		PlacemarkNode = createPlacemarkNode(LayerNode, NULL);
 
-	xmlNodePtr placemarkNode = createPlacemarkNode(LayerNode, symbolUrl);
-	xmlNewChild(placemarkNode, NULL, BAD_CAST "name", NULL);
-	xmlNodePtr pointNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "Point", NULL);
+	sprintf(SymbolUrl, "%s", lookupSymbolUrl(symbol, style));
+	SymbologyFlag[Symbol] = 1;
 
-	addAddRenderingSpecifications(pointNode);
+	xmlNodePtr geomNode = getGeomParentNode("Point");
+	addAddRenderingSpecifications(geomNode);
 
 	pointObj pt;
 	pt.x = x; pt.y = y;
-	addCoordsNode(pointNode, &pt, 1);
+	addCoordsNode(geomNode, &pt, 1);
 }
 
 void KmlRenderer::renderPixmapSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style)
 {
 	if (VectorMode)
-		createSymbolPlacemark(img, x, y, symbol, style);
+		renderSymbol(img, x, y, symbol, style);
 
 	if (RasterMode)
 	{
@@ -647,7 +536,7 @@
 void KmlRenderer::renderVectorSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style)
 {
 	if (VectorMode)
-		createSymbolPlacemark(img, x, y, symbol, style);
+		renderSymbol(img, x, y, symbol, style);
 
 	if (RasterMode)
 	{
@@ -659,7 +548,7 @@
 void KmlRenderer::renderEllipseSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style)
 {
 	if (VectorMode)
-		createSymbolPlacemark(img, x, y, symbol, style);
+		renderSymbol(img, x, y, symbol, style);
 
 	if (RasterMode)
 	{
@@ -671,7 +560,7 @@
 void KmlRenderer::renderTruetypeSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style)
 {
 	if (VectorMode)
-		createSymbolPlacemark(img, x, y, symbol, style);
+		renderSymbol(img, x, y, symbol, style);
 
 	if (RasterMode)
 	{
@@ -730,4 +619,332 @@
 	xmlNewChild(latLonBoxNode, NULL, BAD_CAST "rotation", BAD_CAST "0.0");
 }
 
+void KmlRenderer::startShape(imageObj *img, shapeObj *shape)
+{
+	if (PlacemarkNode)
+		flushPlacemark();
+
+	CurrentShape = NULL;
+
+	PlacemarkNode = NULL;
+	GeomNode = NULL;
+
+	memset(SymbologyFlag, 0, NumSymbologyFlag);
+}
+
+void KmlRenderer::endShape(imageObj *img, shapeObj *shape)
+{
+
+}
+
+xmlNodePtr KmlRenderer::getGeomParentNode(char *geomName)
+{
+	if (GeomNode)
+	{
+		// placemark geometry already defined, we need multigeometry node
+		xmlNodePtr multiGeomNode = xmlNewNode(NULL, BAD_CAST "MultiGeometry");
+		xmlAddChild(multiGeomNode, GeomNode);
+		GeomNode = multiGeomNode;
+
+		xmlNodePtr geomNode = xmlNewChild(multiGeomNode, NULL, BAD_CAST geomName, NULL);
+		return geomNode;
+	}
+	else
+	{
+		GeomNode = xmlNewNode(NULL, BAD_CAST geomName);
+		return GeomNode;
+	}
+}
+
+char* KmlRenderer::lookupPointStyle(colorObj *color)
+{
+	return NULL;
+}
+
+char* KmlRenderer::lookupLineStyle(strokeStyleObj *strokeStyle)
+{
+	/*
+	<LineStyle id="ID">
+	  <!-- inherited from ColorStyle -->
+	  <color>ffffffff</color>            <!-- kml:color -->
+	  <colorMode>normal</colorMode>      <!-- colorModeEnum: normal or random -->
+
+	  <!-- specific to LineStyle -->
+	  <width>1</width>                   <!-- float -->
+	</LineStyle>
+	*/
+
+	char hexColor[16];
+	sprintf(hexColor,"%02x%02x%02x%02x", strokeStyle->color.alpha, strokeStyle->color.blue,
+											strokeStyle->color.green, strokeStyle->color.red);
+
+	char styleName[32];
+	sprintf(styleName, "lineStyle%s_w%.1f", hexColor, strokeStyle->width);
+
+	char *styleUrl = msLookupHashTable(StyleHashTable, styleName);
+	if (!styleUrl)
+	{
+		char styleValue[32];
+		sprintf(styleValue, "#%s", styleName);
+
+		hashObj *hash = msInsertHashTable(StyleHashTable, styleName, styleValue);
+		styleUrl = hash->data;
+
+		// Insert new PolyStyle node into Document node
+		xmlNodePtr styleNode = xmlNewChild(DocNode, NULL, BAD_CAST "Style", NULL);
+		xmlNewProp(styleNode, BAD_CAST "id", BAD_CAST styleName);
+
+		xmlNodePtr lineStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "LineStyle", NULL);
+		xmlNewChild(lineStyleNode, NULL, BAD_CAST "color", BAD_CAST hexColor);
+
+		char width[16];
+		sprintf(width, "%.1f", strokeStyle->width);
+		xmlNewChild(lineStyleNode, NULL, BAD_CAST "width", BAD_CAST width);
+	}
+
+	return styleUrl;
+}
+
+char* KmlRenderer::lookupPolygonStyle(colorObj *color)
+{
+	/*
+	<PolyStyle id="ID">
+	  <!-- inherited from ColorStyle -->
+	  <color>ffffffff</color>            <!-- kml:color -->
+	  <colorMode>normal</colorMode>      <!-- kml:colorModeEnum: normal or random -->
+
+	  <!-- specific to PolyStyle -->
+	  <fill>1</fill>                     <!-- boolean -->
+	  <outline>1</outline>               <!-- boolean -->
+	</PolyStyle>
+	*/
+
+	char hexColor[16];
+	sprintf(hexColor,"%02x%02x%02x%02x", color->alpha, color->blue, color->green, color->red);
+
+	char styleName[32];
+	sprintf(styleName, "polyStyle%s", hexColor);
+
+	char *styleUrl = msLookupHashTable(StyleHashTable, styleName);
+	if (!styleUrl)
+	{
+		char styleValue[32];
+		sprintf(styleValue, "#%s", styleName);
+
+		hashObj *hash = msInsertHashTable(StyleHashTable, styleName, styleValue);
+		styleUrl = hash->data;
+
+		// Insert new PolyStyle node into Document node
+		xmlNodePtr styleNode = xmlNewChild(DocNode, NULL, BAD_CAST "Style", NULL);
+		xmlNewProp(styleNode, BAD_CAST "id", BAD_CAST styleName);
+
+		xmlNodePtr polyStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "PolyStyle", NULL);
+		xmlNewChild(polyStyleNode, NULL, BAD_CAST "color", BAD_CAST hexColor);
+	}
+
+	return styleUrl;
+}
+
+
+char* KmlRenderer::lookupSymbolUrl(symbolObj *symbol, symbolStyleObj *style)
+{
+	/*	
+	<Style id="randomColorIcon">
+	  <IconStyle>
+		 <color>ff00ff00</color>
+		 <colorMode>random</colorMode>
+		 <scale>1.1</scale>
+		 <Icon>
+			<href>http://maps.google.com/mapfiles/kml/pal3/icon21.png</href>
+		 </Icon>
+	  </IconStyle>
+	</Style>
+	*/
+
+	sprintf(SymbolName, "symbol_%s_%.1f", symbol->name, style->scale);
+
+	char *symbolUrl = msLookupHashTable(StyleHashTable, SymbolName);
+	if (!symbolUrl)
+	{
+		// __TODO__ add WEB IMAGEURL path
+
+		char iconFileName[512];
+		sprintf(iconFileName, "symbol_%s_%.1f.%s", symbol->name, style->scale, MS_IMAGE_EXTENSION(RasterizerOutputFormat));
+		if (createIconImage(iconFileName, symbol, style) != MS_SUCCESS)
+		{
+			char errMsg[512];
+			sprintf(errMsg, "Error creating icon file '%s'", iconFileName);
+			msSetError(MS_IOERR, errMsg, "KmlRenderer::lookupSymbolStyle()" );
+			return NULL;
+		}
+
+		hashObj *hash = msInsertHashTable(StyleHashTable, SymbolName, iconFileName);
+		symbolUrl = hash->data;
+	}
+
+	return symbolUrl;
+}
+
+char* KmlRenderer::lookupPlacemarkStyle()
+{
+	char	lineHexColor[16];
+	char	polygonHexColor[16];
+	char	labelHexColor[16];
+
+	char styleName[128];
+	sprintf(styleName, "style");
+
+	if (SymbologyFlag[Line])
+	{
+		/*
+		<LineStyle id="ID">
+		<!-- inherited from ColorStyle -->
+		<color>ffffffff</color>            <!-- kml:color -->
+		<colorMode>normal</colorMode>      <!-- colorModeEnum: normal or random -->
+
+		<!-- specific to LineStyle -->
+		<width>1</width>                   <!-- float -->
+		</LineStyle>
+		*/
+
+		sprintf(lineHexColor,"%02x%02x%02x%02x", LineStyle.color.alpha, LineStyle.color.blue,
+											LineStyle.color.green, LineStyle.color.red);
+
+		char lineStyleName[32];
+		sprintf(lineStyleName, "_line_%s_w%.1f", lineHexColor, LineStyle.width);
+		strcat(styleName, lineStyleName);
+	}
+
+	if (SymbologyFlag[Polygon])
+	{
+		/*
+		<PolyStyle id="ID">
+		<!-- inherited from ColorStyle -->
+		<color>ffffffff</color>            <!-- kml:color -->
+		<colorMode>normal</colorMode>      <!-- kml:colorModeEnum: normal or random -->
+
+		<!-- specific to PolyStyle -->
+		<fill>1</fill>                     <!-- boolean -->
+		<outline>1</outline>               <!-- boolean -->
+		</PolyStyle>
+		*/
+
+		sprintf(polygonHexColor,"%02x%02x%02x%02x", PolygonColor.alpha, PolygonColor.blue, PolygonColor.green, PolygonColor.red);
+
+		char polygonStyleName[32];
+		sprintf(polygonStyleName, "_polygon_%s", polygonHexColor);
+		strcat(styleName, polygonStyleName);
+	}
+
+	if (SymbologyFlag[Label])
+	{
+		/*
+		<LabelStyle id="ID">
+		<!-- inherited from ColorStyle -->
+		<color>ffffffff</color>            <!-- kml:color -->
+		<colorMode>normal</colorMode>      <!-- kml:colorModeEnum: normal or random -->
+
+		<!-- specific to LabelStyle -->
+		<scale>1</scale>                   <!-- float -->
+		</LabelStyle>
+		*/
+
+		sprintf(labelHexColor,"%02x%02x%02x%02x", LabelStyle.color.alpha, LabelStyle.color.blue, LabelStyle.color.green, LabelStyle.color.red);
+
+		// __TODO__ add label scale
+
+		char labelStyleName[32];
+		sprintf(labelStyleName, "_label_%s", labelHexColor);
+		strcat(styleName, labelStyleName);
+	}
+
+	if (SymbologyFlag[Symbol])
+	{
+		/*	
+		<Style id="randomColorIcon">
+		  <IconStyle>
+			 <color>ff00ff00</color>
+			 <colorMode>random</colorMode>
+			 <scale>1.1</scale>
+			 <Icon>
+				<href>http://maps.google.com/mapfiles/kml/pal3/icon21.png</href>
+			 </Icon>
+		  </IconStyle>
+		</Style>
+		*/
+
+		// __TODO__ add label scale
+		char symbolStyleName[32];
+		sprintf(symbolStyleName, "_%s", SymbolName);
+		strcat(styleName, symbolStyleName);
+	}
+
+	char *styleUrl = msLookupHashTable(StyleHashTable, styleName);
+	if (!styleUrl)
+	{
+		char styleValue[32];
+		sprintf(styleValue, "#%s", styleName);
+
+		hashObj *hash = msInsertHashTable(StyleHashTable, styleName, styleValue);
+		styleUrl = hash->data;
+
+		// Insert new Style node into Document node
+		xmlNodePtr styleNode = xmlNewChild(DocNode, NULL, BAD_CAST "Style", NULL);
+		xmlNewProp(styleNode, BAD_CAST "id", BAD_CAST styleName);
+
+		if (SymbologyFlag[Polygon])
+		{
+			xmlNodePtr polyStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "PolyStyle", NULL);
+			xmlNewChild(polyStyleNode, NULL, BAD_CAST "color", BAD_CAST polygonHexColor);
+		}
+
+		if (SymbologyFlag[Line])
+		{
+			xmlNodePtr lineStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "LineStyle", NULL);
+			xmlNewChild(lineStyleNode, NULL, BAD_CAST "color", BAD_CAST lineHexColor);
+
+			char width[16];
+			sprintf(width, "%.1f", LineStyle.width);
+			xmlNewChild(lineStyleNode, NULL, BAD_CAST "width", BAD_CAST width);
+		}
+
+		if (SymbologyFlag[Symbol])
+		{
+			xmlNodePtr iconStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "IconStyle", NULL);
+
+			xmlNodePtr iconNode = xmlNewChild(iconStyleNode, NULL, BAD_CAST "Icon", NULL);
+			xmlNewChild(iconNode, NULL, BAD_CAST "href", BAD_CAST SymbolUrl);
+
+			//char scale[16];
+			//sprintf(scale, "%.1f", style->scale);
+			//xmlNewChild(iconStyleNode, NULL, BAD_CAST "scale", BAD_CAST scale);
+		}
+
+		if (SymbologyFlag[Label])
+		{
+			xmlNodePtr labelStyleNode = xmlNewChild(styleNode, NULL, BAD_CAST "LabelStyle", NULL);
+			xmlNewChild(labelStyleNode, NULL, BAD_CAST "color", BAD_CAST labelHexColor);
+
+			//char scale[16];
+			//sprintf(scale, "%.1f", style->scale);
+			//xmlNewChild(iconStyleNode, NULL, BAD_CAST "scale", BAD_CAST scale);
+		}
+	}
+
+	return styleUrl;
+}
+
+void KmlRenderer::flushPlacemark()
+{
+	if (PlacemarkNode)
+	{
+		char *styleUrl = lookupPlacemarkStyle();
+		xmlNewChild(PlacemarkNode, NULL, BAD_CAST "styleUrl", BAD_CAST styleUrl);
+
+		if (GeomNode)
+			xmlAddChild(PlacemarkNode, GeomNode);
+	}
+}
+
+
 #endif
\ No newline at end of file

Modified: sandbox/davidK/mapkmlrenderer.h
===================================================================
--- sandbox/davidK/mapkmlrenderer.h	2009-07-19 22:05:05 UTC (rev 9184)
+++ sandbox/davidK/mapkmlrenderer.h	2009-07-19 22:22:47 UTC (rev 9185)
@@ -11,33 +11,53 @@
 {
 protected:
 
-    xmlDocPtr	XmlDoc;	/* document pointer */
+	// map properties
+	int				Width, Height;
+	rectObj			MapExtent;
+	double			MapCellsize;
+	colorObj		BgColor;
+
+	// xml nodes pointers
+    xmlDocPtr	XmlDoc;
 	xmlNodePtr	DocNode;
 	xmlNodePtr	LayerNode;
 
-	int			Width, Height;
+	xmlNodePtr	PlacemarkNode;
+	xmlNodePtr	GeomNode;
 
-	hashTableObj *StyleHashTable;
+	shapeObj	*CurrentShape;
 
-	int			AltitudeMode;
-	int			Tessellate;
-	int			Extrude;
+	// placemark symbology
+	hashTableObj	*StyleHashTable;
 
-	int			FirstLayer;
+	labelStyleObj	LabelStyle;
+	strokeStyleObj	LineStyle;
+	colorObj		PolygonColor;
 
+	char			SymbolName[128];
+	char			SymbolUrl[128];
+
+	enum			{ NumSymbologyFlag = 4};
+	char			SymbologyFlag[NumSymbologyFlag];
+
+	enum			symbFlagsEnum { Label, Line, Polygon, Symbol };
+
 	// internal output format containing cairo renderer used for rasterizing and rendering symbols
 	outputFormatObj	*RasterizerOutputFormat;
 	imageObj		*InternalImg;
 
-	rectObj			MapExtent;
-	double			MapCellsize;
-
 	// if true - features are rasterized
-	int	VectorMode;
+	int				VectorMode;
 
 	// if true - features are written directly in kml
-	int	RasterMode;
+	int				RasterMode;
 
+	int				AltitudeMode;
+	int				Tessellate;
+	int				Extrude;
+
+	int				FirstLayer;
+
 	enum altitudeModeEnum { undefined, clampToGround, relativeToGround, absolute };
 
 protected:
@@ -48,9 +68,9 @@
 
 	char* lookupPointStyle(colorObj *color);
 	char* lookupLineStyle(strokeStyleObj *strokeStyle);
-	char* lookupPolyStyle(colorObj *color);
+	char* lookupPolygonStyle(colorObj *color);
 
-	char* lookupSymbolStyle(symbolObj *symbol, symbolStyleObj *style);
+	char* lookupSymbolUrl(symbolObj *symbol, symbolStyleObj *style);
 
 	void addCoordsNode(xmlNodePtr parentNode, pointObj *pts, int numPts);
 
@@ -61,7 +81,7 @@
 
 	int createIconImage(char *fileName, symbolObj *symbol, symbolStyleObj *style);
 
-	void createSymbolPlacemark(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style);
+	void renderSymbol(imageObj *img, double x, double y, symbolObj *symbol, symbolStyleObj *style);
 
 	//////////////////////////////////////////////////////////////////////////////
 
@@ -69,6 +89,10 @@
 	void renderPolygonVector(imageObj *img, shapeObj *p, colorObj *color);
 	void renderGlyphsVector(imageObj *img, double x, double y, labelStyleObj *style, char *text);
 
+	char* lookupPlacemarkStyle();
+	void flushPlacemark();
+	xmlNodePtr getGeomParentNode(char *geomName);
+
 public:
 
 	KmlRenderer(int width, int height, colorObj* color = NULL);
@@ -81,6 +105,9 @@
 	void startNewLayer(imageObj *img, layerObj *layer);
 	void closeNewLayer(imageObj *img, layerObj *layer);
 
+	void startShape(imageObj *img, shapeObj *shape);
+	void endShape(imageObj *img, shapeObj *shape);
+
 	void renderLine(imageObj *img, shapeObj *p, strokeStyleObj *style);
 	void renderPolygon(imageObj *img, shapeObj *p, colorObj *color);
 

Modified: sandbox/davidK/mapmygis.c
===================================================================
--- sandbox/davidK/mapmygis.c	2009-07-19 22:05:05 UTC (rev 9184)
+++ sandbox/davidK/mapmygis.c	2009-07-19 22:22:47 UTC (rev 9185)
@@ -1,5 +1,5 @@
 /******************************************************************************
- * $Id:$
+ * $Id$
  *
  * Project:  MapServer
  * Purpose:  Implements the MySQL/"MyGIS" connection type support.

Modified: sandbox/davidK/maptclutf.c
===================================================================
--- sandbox/davidK/maptclutf.c	2009-07-19 22:05:05 UTC (rev 9184)
+++ sandbox/davidK/maptclutf.c	2009-07-19 22:22:47 UTC (rev 9185)
@@ -1,5 +1,5 @@
 /******************************************************************************
- * $Id:$
+ * $Id$
  *
  * Project:  MapServer
  * Purpose:  Implementation of msUTF8ToUniChar()

Modified: sandbox/davidK/maptime.c
===================================================================
--- sandbox/davidK/maptime.c	2009-07-19 22:05:05 UTC (rev 9184)
+++ sandbox/davidK/maptime.c	2009-07-19 22:22:47 UTC (rev 9185)
@@ -1,5 +1,5 @@
 /******************************************************************************
- * $Id:$
+ * $Id$
  *
  * Project:  MapServer
  * Purpose:  Date/Time utility functions.

Modified: sandbox/davidK/mapxbase.c
===================================================================
--- sandbox/davidK/mapxbase.c	2009-07-19 22:05:05 UTC (rev 9184)
+++ sandbox/davidK/mapxbase.c	2009-07-19 22:22:47 UTC (rev 9185)
@@ -1,5 +1,5 @@
 /******************************************************************************
- * $Id:$
+ * $Id$
  *
  * Project:  MapServer
  * Purpose:  .dbf access API.  Derived from shapelib, and relicensed with 

Modified: sandbox/davidK/scalebar.c
===================================================================
--- sandbox/davidK/scalebar.c	2009-07-19 22:05:05 UTC (rev 9184)
+++ sandbox/davidK/scalebar.c	2009-07-19 22:22:47 UTC (rev 9185)
@@ -1,5 +1,5 @@
 /******************************************************************************
- * $Id:$
+ * $Id$
  *
  * Project:  MapServer
  * Purpose:  Commandline scalebar generating utility, mostly for testing.

Modified: sandbox/davidK/shptreevis.c
===================================================================
--- sandbox/davidK/shptreevis.c	2009-07-19 22:05:05 UTC (rev 9184)
+++ sandbox/davidK/shptreevis.c	2009-07-19 22:22:47 UTC (rev 9185)
@@ -1,5 +1,5 @@
 /******************************************************************************
- * $Id:$
+ * $Id$
  *
  * Project:  MapServer
  * Purpose:  Utility program to visualize a quadtree



More information about the mapserver-commits mailing list