[mapserver-commits] r10765 - trunk/mapserver
svn at osgeo.org
svn at osgeo.org
Fri Nov 26 14:15:50 EST 2010
Author: assefa
Date: 2010-11-26 11:15:50 -0800 (Fri, 26 Nov 2010)
New Revision: 10765
Modified:
trunk/mapserver/mapkmlrenderer.cpp
trunk/mapserver/mapoutput.c
Log:
add kmz support #3620
Modified: trunk/mapserver/mapkmlrenderer.cpp
===================================================================
--- trunk/mapserver/mapkmlrenderer.cpp 2010-11-25 20:28:32 UTC (rev 10764)
+++ trunk/mapserver/mapkmlrenderer.cpp 2010-11-26 19:15:50 UTC (rev 10765)
@@ -35,6 +35,12 @@
#include "mapio.h"
+#if defined(USE_OGR)
+# include "cpl_conv.h"
+# include "cpl_vsi.h"
+#endif
+
+
KmlRenderer::KmlRenderer(int width, int height, outputFormatObj *format, colorObj* color/*=NULL*/)
: XmlDoc(NULL), LayerNode(NULL), GroundOverlayNode(NULL), Width(width), Height(height),
FirstLayer(MS_TRUE), MapCellsize(1.0),
@@ -105,7 +111,7 @@
return NULL;
}
-int KmlRenderer::saveImage(imageObj *, FILE *fp, outputFormatObj*)
+int KmlRenderer::saveImage(imageObj *, FILE *fp, outputFormatObj *format)
{
/* -------------------------------------------------------------------- */
@@ -115,15 +121,72 @@
int bufSize = 0;
xmlChar *buf = NULL;
msIOContext *context = NULL;
-
+ int chunkSize = 4096;
+
+ int bZip = MS_FALSE;
+
if( msIO_needBinaryStdout() == MS_FAILURE )
return MS_FAILURE;
- xmlDocDumpFormatMemoryEnc(XmlDoc, &buf, &bufSize, "UTF-8", 1);
+ xmlDocDumpFormatMemoryEnc(XmlDoc, &buf, &bufSize, "UTF-8", 1);
+#if defined(USE_OGR)
+ if (format && format->driver && strcasecmp(format->driver, "kmz") == 0)
+ {
+#if defined(CPL_ZIP_API_OFFERED)
+ bZip = MS_TRUE;
+#else
+ msSetError( MS_MISCERR, "kmz format support unavailable, perhaps you need to upgrade to GDAL/OGR 1.8?",
+ "KmlRenderer::saveImage()");
+ xmlFree(buf);
+ return MS_FAILURE;
+#endif
+ }
+
+#if defined(CPL_ZIP_API_OFFERED)
+ if (bZip)
+ {
+ VSILFILE *fpZip;
+ int bytes_read;
+ char buffer[1024];
+ char *zip_filename =NULL;
+ void *hZip=NULL;
+
+ zip_filename = msTmpFile( NULL, "/vsimem/kmlzip/", "kmz" );
+ hZip = CPLCreateZip( zip_filename, NULL );
+ CPLCreateFileInZip( hZip, "mapserver.kml", NULL );
+ for (int i=0; i<bufSize; i+=chunkSize)
+ {
+ int size = chunkSize;
+ if (i + size > bufSize)
+ size = bufSize - i;
+ CPLWriteFileInZip( hZip, buf+i, size);
+ }
+ CPLCloseFileInZip( hZip );
+ CPLCloseZip( hZip );
+
+ context = msIO_getHandler(fp);
+ fpZip = VSIFOpenL( zip_filename, "r" );
+
+ while( (bytes_read = VSIFReadL( buffer, 1, sizeof(buffer), fpZip )) > 0 )
+ {
+ if (context)
+ msIO_contextWrite(context, buffer, bytes_read);
+ else
+ msIO_fwrite( buffer, 1, bytes_read, fp );
+ }
+ VSIFCloseL( fpZip );
+ msFree( zip_filename);
+ xmlFree(buf);
+ return(MS_SUCCESS);
+ }
+#endif
+
+#endif
+
context = msIO_getHandler(fp);
- int chunkSize = 4096;
+
for (int i=0; i<bufSize; i+=chunkSize)
{
int size = chunkSize;
Modified: trunk/mapserver/mapoutput.c
===================================================================
--- trunk/mapserver/mapoutput.c 2010-11-25 20:28:32 UTC (rev 10764)
+++ trunk/mapserver/mapoutput.c 2010-11-26 19:15:50 UTC (rev 10765)
@@ -255,7 +255,17 @@
format->imagemode = MS_IMAGEMODE_RGB;
format->extension = strdup("kml");
format->renderer = MS_RENDER_WITH_KML;
+ msSetOutputFormatOption( format, "ATTACHMENT", "mapserver.kml");
}
+ if( strcasecmp(driver,"KMZ") == 0 )
+ {
+ format = msAllocOutputFormat( map, "kmz", driver );
+ format->mimetype = strdup("application/vnd.google-earth.kmz");
+ format->imagemode = MS_IMAGEMODE_RGB;
+ format->extension = strdup("kmz");
+ format->renderer = MS_RENDER_WITH_KML;
+ msSetOutputFormatOption( format, "ATTACHMENT", "mapserver.kmz");
+ }
#endif
#ifdef USE_MING_FLASH
@@ -385,6 +395,8 @@
#if defined(USE_KML)
if( msSelectOutputFormat( map, "kml" ) == NULL )
msCreateDefaultOutputFormat( map, "kml" );
+ if( msSelectOutputFormat( map, "kmz" ) == NULL )
+ msCreateDefaultOutputFormat( map, "kmz" );
#endif
if( map->imagetype != NULL )
@@ -943,7 +955,8 @@
strncasecmp(map->outputformatlist[i]->driver, "GDAL/", 5)==0 ||
strncasecmp(map->outputformatlist[i]->driver, "AGG/", 4)==0 ||
strcasecmp(map->outputformatlist[i]->driver, "svg")==0 ||
- strcasecmp(map->outputformatlist[i]->driver, "kml")==0))
+ strcasecmp(map->outputformatlist[i]->driver, "kml")==0 ||
+ strcasecmp(map->outputformatlist[i]->driver, "kmz")==0))
mime_list[mime_count++] = map->outputformatlist[i]->mimetype;
}
}
More information about the mapserver-commits
mailing list