[mapserver-commits] r10612 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Mon Oct 18 10:02:46 EDT 2010


Author: warmerdam
Date: 2010-10-18 07:02:45 -0700 (Mon, 18 Oct 2010)
New Revision: 10612

Modified:
   trunk/mapserver/mapogroutput.c
   trunk/mapserver/mapoutput.c
Log:
tweak some error handling and geometry type management (#3570)

Modified: trunk/mapserver/mapogroutput.c
===================================================================
--- trunk/mapserver/mapogroutput.c	2010-10-18 13:48:55 UTC (rev 10611)
+++ trunk/mapserver/mapogroutput.c	2010-10-18 14:02:45 UTC (rev 10612)
@@ -193,6 +193,7 @@
     OGRFeatureH hFeat;
     OGRErr eErr;
     int i, out_field;
+    OGRwkbGeometryType eLayerGType, eFeatureGType = wkbUnknown;
 
 /* -------------------------------------------------------------------- */
 /*      Transform point geometry.                                       */
@@ -272,6 +273,40 @@
     }
 
 /* -------------------------------------------------------------------- */
+/*      Consider trying to force the geometry to a new type if it       */
+/*      doesn't match the layer.                                        */
+/* -------------------------------------------------------------------- */
+    eLayerGType = 
+        wkbFlatten(OGR_FD_GetGeomType(OGR_L_GetLayerDefn(hOGRLayer)));
+
+    if( hGeom != NULL )
+        eFeatureGType = wkbFlatten(OGR_G_GetGeometryType( hGeom ));
+    
+#if defined(GDAL_VERSION_NUM) && (GDAL_VERSION_NUM >= 1800)
+
+    if( hGeom != NULL 
+        && eLayerGType == wkbPolygon
+        && eFeatureGType != eLayerGType )
+        hGeom = OGR_G_ForceToPolygon( hGeom );
+
+    else if( hGeom != NULL 
+             && eLayerGType == wkbMultiPolygon
+             && eFeatureGType != eLayerGType )
+        hGeom = OGR_G_ForceToMultiPolygon( hGeom );
+        
+    else if( hGeom != NULL 
+             && eLayerGType == wkbMultiPoint
+             && eFeatureGType != eLayerGType )
+        hGeom = OGR_G_ForceToMultiPoint( hGeom );
+        
+    else if( hGeom != NULL 
+             && eLayerGType == wkbMultiLineString
+             && eFeatureGType != eLayerGType )
+        hGeom = OGR_G_ForceToMultiLineString( hGeom );
+        
+#endif /* GDAL/OGR 1.8 or later */
+
+/* -------------------------------------------------------------------- */
 /*      Create the feature, and attach the geometry.                    */
 /* -------------------------------------------------------------------- */
     hFeat = OGR_F_Create( OGR_L_GetLayerDefn( hOGRLayer ) );
@@ -436,6 +471,19 @@
     
     msFree( request_dir );
 
+/* -------------------------------------------------------------------- */
+/*      Emit content type headers for stream output now.                */
+/* -------------------------------------------------------------------- */
+    if( EQUAL(storage,"stream") )
+    {
+        if( sendheaders && format->mimetype )
+            msIO_fprintf( stdout, 
+                          "Content-Type: %s%c%c",
+                          format->mimetype, 10, 10 );
+        else
+            msIO_fprintf( stdout, "%c", 10 );
+    }
+
 /* ==================================================================== */
 /*      Create the datasource.                                          */
 /* ==================================================================== */
@@ -464,22 +512,54 @@
         OGRwkbGeometryType eGeomType;
         OGRSpatialReferenceH srs = NULL;
         gmlItemListObj *item_list = NULL;
+        const char *value;
 
         if( !layer->resultcache || layer->resultcache->numresults == 0 )
             continue;
 
 /* -------------------------------------------------------------------- */
-/*      Create the corresponding OGR Layer.                             */
+/*      Establish the geometry type to use for the created layer.       */
+/*      First we consult the wfs_geomtype field and fallback to         */
+/*      deriving something from the type of the mapserver layer.        */
 /* -------------------------------------------------------------------- */
-        if( layer->type == MS_LAYER_POINT )
+        value = msOWSLookupMetadata(&(layer->metadata), "FO", "geomtype");
+        if( value == NULL )
+        {
+            if( layer->type == MS_LAYER_POINT )
+                value = "Point";
+            else if( layer->type == MS_LAYER_LINE )
+                value = "LineString";
+            else if( layer->type == MS_LAYER_POLYGON )
+                value = "Polygon";
+            else
+                value = "Geometry";
+        }
+
+        if( strcasecmp(value,"Point") == 0 )
             eGeomType = wkbPoint;
-        else if( layer->type == MS_LAYER_LINE )
+        else if( strcasecmp(value,"LineString") == 0 )
             eGeomType = wkbLineString;
-        else if( layer->type == MS_LAYER_POLYGON )
+        else if( strcasecmp(value,"Polygon") == 0 )
             eGeomType = wkbPolygon;
+        else if( strcasecmp(value,"MultiPoint") == 0 )
+            eGeomType = wkbMultiPoint;
+        else if( strcasecmp(value,"MultiLineString") == 0 )
+            eGeomType = wkbMultiLineString;
+        else if( strcasecmp(value,"MultiPolygon") == 0 )
+            eGeomType = wkbMultiPolygon;
+        else if( strcasecmp(value,"GeometryCollection") == 0 )
+            eGeomType = wkbMultiPolygon;
+        else if( strcasecmp(value,"Unknown") == 0 
+                 || strcasecmp(value,"Geometry") == 0 )
+            eGeomType = wkbUnknown;
+        else if( strcasecmp(value,"None") == 0 )
+            eGeomType = wkbNone;
         else
             eGeomType = wkbUnknown;
-
+        
+/* -------------------------------------------------------------------- */
+/*      Create the corresponding OGR Layer.                             */
+/* -------------------------------------------------------------------- */
         hOGRLayer = OGR_DS_CreateLayer( hDS, layer->name, srs, eGeomType, 
                                         layer_options );
         if( hOGRLayer == NULL )
@@ -637,7 +717,11 @@
 /* -------------------------------------------------------------------- */
 /*      Get list of resulting files.                                    */
 /* -------------------------------------------------------------------- */
+#if !defined(CPL_ZIP_API_OFFERED)
+    form = msGetOutputFormatOption( format, "FORM", "multipart" );
+#else
     form = msGetOutputFormatOption( format, "FORM", "zip" );
+#endif
 
     if( EQUAL(form,"simple") )
     {
@@ -652,14 +736,28 @@
     }
 
 /* -------------------------------------------------------------------- */
+/*      If our "storage" is stream then the output has already been     */
+/*      sent back to the client and we don't need to copy it now.       */
+/* -------------------------------------------------------------------- */
+    if( EQUAL(storage,"stream") )
+    {
+        /* already done */
+    }
+
+/* -------------------------------------------------------------------- */
 /*      Handle case of simple file written to stdout.                   */
 /* -------------------------------------------------------------------- */
-    if( EQUAL(form,"simple") )
+    else if( EQUAL(form,"simple") )
     {
         char buffer[1024];
         int  bytes_read;
         FILE *fp;
 
+        if( sendheaders )
+            msIO_fprintf( stdout, 
+                          "Content-Disposition: attachment; filename=%s\n",
+                          CPLGetFilename( file_list[0] ) );
+
         if( sendheaders && format->mimetype )
             msIO_fprintf( stdout, 
                           "Content-Type: %s%c%c",
@@ -724,7 +822,10 @@
                 msIO_fwrite( buffer, 1, bytes_read, stdout );
             VSIFCloseL( fp );
 
-            msIO_fprintf( stdout, "\n--%s\n", boundary );
+            if (file_list[i+1] == NULL)
+                msIO_fprintf( stdout, "\n--%s--\n", boundary );
+            else
+                msIO_fprintf( stdout, "\n--%s\n", boundary );
         }
     }
 

Modified: trunk/mapserver/mapoutput.c
===================================================================
--- trunk/mapserver/mapoutput.c	2010-10-18 13:48:55 UTC (rev 10611)
+++ trunk/mapserver/mapoutput.c	2010-10-18 14:02:45 UTC (rev 10612)
@@ -375,14 +375,14 @@
         format = msAllocOutputFormat( map, "imagemap", driver );
         format->mimetype = strdup("text/html; driver=imagemap");
         format->extension = strdup("html");
-        format->imagemode = 0;
+        format->imagemode = MS_IMAGEMODE_NULL;
         format->renderer = MS_RENDER_WITH_IMAGEMAP;
     }
     if( strcasecmp(driver,"svg") == 0 )
     {
         format = msAllocOutputFormat( map, "svg", driver );
         format->mimetype = strdup("image/svg+xml");
-        format->imagemode = 0;
+        format->imagemode = MS_IMAGEMODE_NULL;
         format->extension = strdup("svg");
         format->renderer = MS_RENDER_WITH_SVG;
     }
@@ -391,7 +391,7 @@
         format = msAllocOutputFormat( map, "template", driver );
         format->mimetype = strdup("text/html");
         format->extension = strdup("html");
-        format->imagemode = 0;
+        format->imagemode = MS_IMAGEMODE_FEATURE;
         format->renderer = MS_RENDER_WITH_TEMPLATE;
     }
 



More information about the mapserver-commits mailing list