[mapserver-commits] r9092 - sandbox/davidK
svn at osgeo.org
svn at osgeo.org
Sun Jun 7 04:49:02 EDT 2009
Author: davidK
Date: 2009-06-07 04:49:02 -0400 (Sun, 07 Jun 2009)
New Revision: 9092
Modified:
sandbox/davidK/mapkmlrenderer.cpp
sandbox/davidK/mapkmlrenderer.h
Log:
Modified: sandbox/davidK/mapkmlrenderer.cpp
===================================================================
--- sandbox/davidK/mapkmlrenderer.cpp 2009-06-07 08:31:18 UTC (rev 9091)
+++ sandbox/davidK/mapkmlrenderer.cpp 2009-06-07 08:49:02 UTC (rev 9092)
@@ -11,14 +11,14 @@
// Create document.
XmlDoc = xmlNewDoc(BAD_CAST "1.0");
- RootNode = xmlNewNode(NULL, BAD_CAST "kml");
+ xmlNodePtr rootNode = xmlNewNode(NULL, BAD_CAST "kml");
// Name spaces
- xmlSetNs(RootNode, xmlNewNs(RootNode, BAD_CAST "http://www.opengis.net/kml/2.2", NULL));
+ xmlSetNs(rootNode, xmlNewNs(rootNode, BAD_CAST "http://www.opengis.net/kml/2.2", NULL));
- xmlDocSetRootElement(XmlDoc, RootNode);
+ xmlDocSetRootElement(XmlDoc, rootNode);
- xmlNodePtr docNode = xmlNewChild(RootNode, NULL, BAD_CAST "Document", NULL);
+ DocNode = xmlNewChild(rootNode, NULL, BAD_CAST "Document", NULL);
}
KmlRenderer::~KmlRenderer()
@@ -51,25 +51,24 @@
context = msIO_getHandler(fp);
if (context)
- {
msIO_printf("Content-type: %s%c%c",format->mimetype,10,10);
- int chunkSize = 4096;
- for (int i=0; i<bufSize; i+=chunkSize)
- {
- int size = chunkSize;
- if (i + size > bufSize)
- size = bufSize - i;
+ int chunkSize = 4096;
+ for (int i=0; i<bufSize; i+=chunkSize)
+ {
+ int size = chunkSize;
+ if (i + size > bufSize)
+ size = bufSize - i;
+ if (context)
msIO_contextWrite(context, buf+i, size);
- }
+ else
+ msIO_fwrite(buf+i, 1, size, fp);
}
- else
- {
- //msIO_fprintf(fp, "%s", buffer);
- }
+ //msIO_fprintf(fp, "%s", buffer);
+
xmlFree(buf);
return(MS_SUCCESS);
@@ -81,8 +80,8 @@
void KmlRenderer::startNewLayer(imageObj *img, layerObj *layer)
{
- LayerNode = xmlNewChild(RootNode, NULL, BAD_CAST "Folder", NULL);
- xmlAddChild(RootNode, LayerNode);
+ LayerNode = xmlNewChild(DocNode, NULL, BAD_CAST "Folder", NULL);
+ //xmlAddChild(RootNode, LayerNode);
xmlNodePtr layerNameNode = xmlNewChild(LayerNode, NULL, BAD_CAST "name", NULL);
xmlNodeAddContent(layerNameNode, BAD_CAST layer->name);
@@ -103,23 +102,45 @@
xmlNodePtr styleUrlNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "styleUrl", NULL);
xmlNodeAddContent(styleUrlNode, BAD_CAST "#");
- int includeZ = 1;
+ int includeZ = 0;
if (p->numlines == 1)
{
- xmlNodePtr lineStringNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "LineString", NULL);
- addCoordsNode(lineStringNode, &p->line[0], includeZ);
+ xmlNodePtr geomNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "LineString", NULL);
+ addCoordsNode(geomNode, &p->line[0], includeZ);
}
else
{
-
-
+ xmlNodePtr multiGeomNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "MultiGeometry", NULL);
+ for (int i=0; i<p->numlines; i++)
+ {
+ xmlNodePtr lineStringNode = xmlNewChild(multiGeomNode, NULL, BAD_CAST "LineString", NULL);
+ addCoordsNode(lineStringNode, &p->line[i], includeZ);
+ }
}
}
void KmlRenderer::renderPolygon(imageObj *img, shapeObj *p, colorObj *color)
{
+ xmlNodePtr placemarkNode = xmlNewChild(LayerNode, NULL, BAD_CAST "Placemark", NULL);
+ xmlNodePtr styleUrlNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "styleUrl", BAD_CAST "#");
+ xmlNodePtr polygonNode = xmlNewChild(placemarkNode, NULL, BAD_CAST "Polygon", NULL);
+
+ int includeZ = 0;
+
+ for (int i=0; i<p->numlines; i++)
+ {
+ xmlNodePtr bdryNode = NULL;
+
+ if (i==0) // __TODO__ check ring order
+ bdryNode = xmlNewChild(polygonNode, NULL, BAD_CAST "outerBoundaryIs", NULL);
+ else
+ bdryNode = xmlNewChild(polygonNode, NULL, BAD_CAST "innerBoundaryIs", NULL);
+
+ xmlNodePtr ringNode = xmlNewChild(bdryNode, NULL, BAD_CAST "LinearRing", NULL);
+ addCoordsNode(ringNode, &p->line[i], includeZ);
+ }
}
void KmlRenderer::addCoordsNode(xmlNodePtr node, lineObj *line, int includeZ)
@@ -131,7 +152,11 @@
for (int i=0; i<line->numpoints; i++)
{
- sprintf(lineBuf, "\t%.8f,%.8f,%.8f\n", line->point[i].x, line->point[i].y,line->point[i].z);
+ if (includeZ)
+ sprintf(lineBuf, "\t%.8f,%.8f,%.8f\n", line->point[i].x, line->point[i].y,line->point[i].z);
+ else
+ sprintf(lineBuf, "\t%.8f,%.8f\n", line->point[i].x, line->point[i].y);
+
xmlNodeAddContent(coordsNode, BAD_CAST lineBuf);
}
xmlNodeAddContent(coordsNode, BAD_CAST "\t");
Modified: sandbox/davidK/mapkmlrenderer.h
===================================================================
--- sandbox/davidK/mapkmlrenderer.h 2009-06-07 08:31:18 UTC (rev 9091)
+++ sandbox/davidK/mapkmlrenderer.h 2009-06-07 08:49:02 UTC (rev 9092)
@@ -12,7 +12,7 @@
protected:
xmlDocPtr XmlDoc; /* document pointer */
- xmlNodePtr RootNode;
+ xmlNodePtr DocNode;
xmlNodePtr LayerNode;
protected:
More information about the mapserver-commits
mailing list