[mapserver-commits] r10620 - trunk/mapserver
svn at osgeo.org
svn at osgeo.org
Mon Oct 18 23:54:36 EDT 2010
Author: warmerdam
Date: 2010-10-18 20:54:36 -0700 (Mon, 18 Oct 2010)
New Revision: 10620
Modified:
trunk/mapserver/mapgdal.c
trunk/mapserver/mapogroutput.c
trunk/mapserver/mapproject.h
Log:
expose msProjectionObj2OGCWKT(), reproject ogrout shapes, write projection via ogr (#3570)
Modified: trunk/mapserver/mapgdal.c
===================================================================
--- trunk/mapserver/mapgdal.c 2010-10-19 03:47:58 UTC (rev 10619)
+++ trunk/mapserver/mapgdal.c 2010-10-19 03:54:36 UTC (rev 10620)
@@ -40,7 +40,6 @@
#include "cpl_conv.h"
#include "cpl_string.h"
-static char *msProjectionObjToWKT( projectionObj *proj );
static int bGDALInitialized = 0;
/************************************************************************/
@@ -389,11 +388,11 @@
GDALSetGeoTransform( hMemDS, map->gt.geotransform );
- pszWKT = msProjectionObjToWKT( &(map->projection) );
+ pszWKT = msProjectionObj2OGCWKT( &(map->projection) );
if( pszWKT != NULL )
{
GDALSetProjection( hMemDS, pszWKT );
- CPLFree( pszWKT );
+ msFree( pszWKT );
}
}
@@ -574,20 +573,38 @@
return MS_SUCCESS;
}
+#else
+
+void msGDALInitialize( void ) {}
+void msGDALCleanup(void) {}
+
+
+#endif /* def USE_GDAL */
+
+
/************************************************************************/
-/* msProjectionObjToWKT() */
+/* msProjectionObj2OGCWKT() */
/* */
/* We stick to the C API for OGRSpatialReference object access */
/* to allow MapServer+GDAL to be built without C++ */
/* complications. */
/* */
/* Note that this function will return NULL on failure, and the */
-/* returned string must be freed with CPLFree(), not msFree(). */
+/* returned string should be freed with msFree(). */
/************************************************************************/
-char *msProjectionObjToWKT( projectionObj *projection )
+char *msProjectionObj2OGCWKT( projectionObj *projection )
{
+
+#if !defined(USE_GDAL) && !defined(USE_OGR)
+ msSetError(MS_OGRERR,
+ "Not implemented since neither OGR nor GDAL is enabled.",
+ "msProjectionObj2OGCWKT()");
+ return NULL;
+
+#else /* defined USE_GDAL or USE_OGR */
+
OGRSpatialReferenceH hSRS;
char *pszWKT=NULL, *pszProj4;
int nLength = 0, i;
@@ -626,14 +643,17 @@
eErr = OSRExportToWkt( hSRS, &pszWKT );
OSRDestroySpatialReference( hSRS );
-
- return pszWKT;
-}
-#else
+ if( pszWKT )
+ {
+ char *pszWKT2 = strdup(pszWKT);
+ CPLFree( pszWKT );
-void msGDALInitialize( void ) {}
-void msGDALCleanup(void) {}
+ return pszWKT2;
+ }
+ else
+ return NULL;
+#endif /* defined USE_GDAL or USE_OGR */
+}
-#endif /* def USE_GDAL */
Modified: trunk/mapserver/mapogroutput.c
===================================================================
--- trunk/mapserver/mapogroutput.c 2010-10-19 03:47:58 UTC (rev 10619)
+++ trunk/mapserver/mapogroutput.c 2010-10-19 03:54:36 UTC (rev 10620)
@@ -35,6 +35,7 @@
#if defined(USE_OGR)
# define __USE_LARGEFILE64 1
# include "ogr_api.h"
+# include "ogr_srs_api.h"
# include "cpl_conv.h"
# include "cpl_vsi.h"
# include "cpl_string.h"
@@ -513,11 +514,22 @@
OGRSpatialReferenceH srs = NULL;
gmlItemListObj *item_list = NULL;
const char *value;
+ char *pszWKT;
+ int reproject = MS_FALSE;
if( !layer->resultcache || layer->resultcache->numresults == 0 )
continue;
/* -------------------------------------------------------------------- */
+/* Will we need to reproject? */
+/* -------------------------------------------------------------------- */
+ if(layer->transform == MS_TRUE
+ && layer->project
+ && msProjectionsDiffer(&(layer->projection),
+ &(layer->map->projection)) )
+ reproject = MS_TRUE;
+
+/* -------------------------------------------------------------------- */
/* 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. */
@@ -556,6 +568,16 @@
eGeomType = wkbNone;
else
eGeomType = wkbUnknown;
+
+/* -------------------------------------------------------------------- */
+/* Create a spatial reference. */
+/* -------------------------------------------------------------------- */
+ pszWKT = msProjectionObj2OGCWKT( &(map->projection) );
+ if( pszWKT != NULL )
+ {
+ srs = OSRNewSpatialReference( pszWKT );
+ msFree( pszWKT );
+ }
/* -------------------------------------------------------------------- */
/* Create the corresponding OGR Layer. */
@@ -693,12 +715,22 @@
}
}
}
+
+ if( reproject )
+ {
+ status =
+ msProjectShape(&layer->projection, &layer->map->projection,
+ &resultshape);
+ }
/*
** Write out the feature to OGR.
*/
- status = msOGRWriteShape( layer, hOGRLayer, &resultshape,
- item_list );
+
+ if( status == MS_SUCCESS )
+ status = msOGRWriteShape( layer, hOGRLayer, &resultshape,
+ item_list );
+
if(status != MS_SUCCESS) {
msOGRCleanupDS( datasource_name );
return status;
Modified: trunk/mapserver/mapproject.h
===================================================================
--- trunk/mapserver/mapproject.h 2010-10-19 03:47:58 UTC (rev 10619)
+++ trunk/mapserver/mapproject.h 2010-10-19 03:54:36 UTC (rev 10620)
@@ -70,6 +70,7 @@
MS_DLL_EXPORT int msProjectionsDiffer(projectionObj *, projectionObj *);
MS_DLL_EXPORT int msOGCWKT2ProjectionObj( const char *pszWKT, projectionObj *proj, int
debug_flag );
+MS_DLL_EXPORT char *msProjectionObj2OGCWKT( projectionObj *proj );
MS_DLL_EXPORT void msFreeProjection(projectionObj *p);
MS_DLL_EXPORT int msInitProjection(projectionObj *p);
More information about the mapserver-commits
mailing list