[GRASS5] Re: GPJ_osr_to_grass

Paul Kelly paul-grass at stjohnspoint.co.uk
Fri Jan 27 11:45:40 EST 2006

Hello Radim

On Fri, 27 Jan 2006, Radim Blazek wrote:

> but in the body it is used as OGRSpatialReferenceH not OGRSpatialReferenceH*,
> for example OSRMorphFromESRI( hSRS ) which is defined as
> OGRErr OSRMorphFromESRI( OGRSpatialReferenceH hSRS )
> The parameter should be changed to OGRSpatialReferenceH hSRS
> or should it be used in the body as *hSRS? It seems that in GRASS
> is the function called with OGRSpatialReferenceH*.
> How can it work on Linux? On Windows it either crashes if
> the parameter is passed as (void **) OGRSpatialReferenceH or
> does not work if passed as OGRSpatialReferenceH*.

Yes I think there is a bug there. I remember not totally understanding it 
when I was writing it and being confused by the abstraction in the OGR 
function definitions. I think the OSRMorphFromESRI() function might be a 
problem, as it changes the contents of the OGRSpatialReferenceH structure. All
the other function calls just read from it, but it writes to it. Could you 
try the attached patch which creates a copy of the OGRSpatialReferenceH 
structure only for use in the GPJ_osr_to_grass() function, and see if it 
fixes the problem or changes anything? I am still not 100% sure what is 

-------------- next part --------------
Index: convert.c
RCS file: /grassrepository/grass6/lib/proj/convert.c,v
retrieving revision 1.18
diff -u -r1.18 convert.c
--- convert.c	4 Dec 2005 14:37:08 -0000	1.18
+++ convert.c	27 Jan 2006 16:40:15 -0000
@@ -225,17 +225,22 @@
     return hSRS2;
-int GPJ_osr_to_grass(struct Cell_head *cellhd, struct Key_Value **projinfo, 
-                     struct Key_Value **projunits, OGRSpatialReferenceH *hSRS,
+int GPJ_osr_to_grass(struct Cell_head *cellhd, struct Key_Value **projinfo,
+                     struct Key_Value **projunits, OGRSpatialReferenceH *inhSRS,
 		     int interactive)
     struct Key_Value *temp_projinfo;
     char *pszProj4 = NULL, *pszRemaining;
     char *pszProj = NULL;
+    OGRSpatialReferenceH *hSRS;
-    if( hSRS == NULL )
+    if( inhSRS == NULL )
         goto default_to_xy;
+    else
+        /* Clone a local copy of the co-ordinate system to use in
+	 * this function */
+        hSRS = OSRClone( inhSRS );
     /* Set finder function for locating OGR csv co-ordinate system tables */
     SetCSVFilenameHook( GPJ_set_csv_loc );
@@ -521,6 +526,8 @@
         G_set_key_value( "meters", szFormatBuf, *projunits );
+    OSRDestroySpatialReference( hSRS );
     return 2;

More information about the grass-dev mailing list