[gdal-dev] OGR_G_ExportToWkt make MEX crash
Hi, I wrote a OGR C MEX wrapper to use in Matlab which already works in many cases. However, I had a situation when trying to fetch the reference info. The chunk of code below now works, but if I use the commented line that calls OGR_G_ExportToWkt than Matlab crashes at that line. However, using the OSRExportTo... functions works fine. I'm I doing something forbidden or ... heers Joaquim hSRS = OGR_L_GetSpatialRef(hLayer);/* Do not free it later */ if (hSRS) { char*pszWKT = NULL, *pszProj4 = NULL; mxArray*mxPrjRef; /*OGR_G_ExportToWkt (hSRS, &pszWKT); */ <== THIS CALL MAKE THE MEX CRASH if (OSRExportToProj4(hSRS, &pszProj4) == OGRERR_NONE) { mxPrjRef = mxCreateString (pszProj4); mxSetField (out_struct, 0, "SRSProj4", mxPrjRef); } if (OSRExportToPrettyWkt(hSRS, &pszWKT, 1) == OGRERR_NONE) { mxPrjRef = mxCreateString (pszWKT); mxSetField (out_struct, 0, "SRSWkt", mxPrjRef); } } ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] OGR_G_ExportToWkt make MEX crash
On 11-09-06 08:10 AM, Joaquim Luis wrote: Hi, I wrote a OGR C MEX wrapper to use in Matlab which already works in many cases. However, I had a situation when trying to fetch the reference info. The chunk of code below now works, but if I use the commented line that calls OGR_G_ExportToWkt than Matlab crashes at that line. However, using the OSRExportTo... functions works fine. I'm I doing something forbidden or ... ... hSRS = OGR_L_GetSpatialRef(hLayer); /* Do not free it later */ if (hSRS) { char *pszWKT = NULL, *pszProj4 = NULL; mxArray *mxPrjRef; /*OGR_G_ExportToWkt (hSRS, &pszWKT); */ <== THIS CALL MAKE THE MEX CRASH if (OSRExportToProj4(hSRS, &pszProj4) == OGRERR_NONE) { Joaquim, OGR_G_* functions are intended to operate on OGRGeometry objects while OSR* functions operate on OGRSpatialReferences. Your hSRS object is an OGRSpatialReference and not suitable to pass to OGR_G_ExportToWkt(). You should use OSRExportToWkt() to translate an OGRSpatialReference into it's WKT representation. Best regards, -- ---+-- I set the clouds in motion - turn up | Frank Warmerdam, warmer...@pobox.com light and sound - activate the windows | http://pobox.com/warmerda and watch the world go round - Rush| Geospatial Software Developer ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] OGR_G_ExportToWkt make MEX crash
OGR_G_* functions are intended to operate on OGRGeometry objects while OSR* functions operate on OGRSpatialReferences. Your hSRS object is an OGRSpatialReference and not suitable to pass to OGR_G_ExportToWkt(). You should use OSRExportToWkt() to translate an OGRSpatialReference into it's WKT representation. Best regards, Thanks Frank. This is also a result of my attempt to understand all the OGR model plus inventing a way of wrapping it all inside a single StructureArray (the C-MEX API). So let me ask one further question about the model. Is is possible to have the case Dataset --> SRS --> Feature1 --> Geom1 --> SRS1 --> Feature2 --> Geom2 --> SRS2 --> ... that is, different SpatialReferences inside the same Dataset? Thanks Joaquim ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] OGR_G_ExportToWkt make MEX crash
On Tue, Sep 6, 2011 at 8:48 AM, Joaquim Luis wrote: > >> OGR_G_* functions are intended to operate on OGRGeometry objects while >> OSR* functions operate on OGRSpatialReferences. Your hSRS object is an >> OGRSpatialReference and not suitable to pass to OGR_G_ExportToWkt(). >> >> You should use OSRExportToWkt() to translate an OGRSpatialReference into >> it's >> WKT representation. >> >> Best regards, > > Thanks Frank. > > This is also a result of my attempt to understand all the OGR model plus > inventing a way of wrapping it all inside a single StructureArray (the C-MEX > API). So let me ask one further question about the model. Is is possible to > have the case > > Dataset --> SRS > --> Feature1 --> Geom1 --> SRS1 > --> Feature2 --> Geom2 --> SRS2 > --> ... > > that is, different SpatialReferences inside the same Dataset? Joaquim, While not nailed down strictly, it is expected that all geometries in a layer will share the same coordinate system. It is however common for the geometries to be lacking the spatial reference object even though it is set on the layer. Best regards, -- ---+-- I set the clouds in motion - turn up | Frank Warmerdam, warmer...@pobox.com light and sound - activate the windows | http://pobox.com/~warmerdam and watch the world go round - Rush | Geospatial Software Developer ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] OGR_G_ExportToWkt make MEX crash
On 06-09-2011 17:48, Frank Warmerdam wrote: On Tue, Sep 6, 2011 at 8:48 AM, Joaquim Luis wrote: OGR_G_* functions are intended to operate on OGRGeometry objects while OSR* functions operate on OGRSpatialReferences. Your hSRS object is an OGRSpatialReference and not suitable to pass to OGR_G_ExportToWkt(). You should use OSRExportToWkt() to translate an OGRSpatialReference into it's WKT representation. Best regards, Thanks Frank. This is also a result of my attempt to understand all the OGR model plus inventing a way of wrapping it all inside a single StructureArray (the C-MEX API). So let me ask one further question about the model. Is is possible to have the case Dataset --> SRS --> Feature1 --> Geom1 --> SRS1 --> Feature2 --> Geom2 --> SRS2 --> ... that is, different SpatialReferences inside the same Dataset? Joaquim, While not nailed down strictly, it is expected that all geometries in a layer will share the same coordinate system. It is however common for the geometries to be lacking the spatial reference object even though it is set on the layer. Best regards,ject OK, that's what I assumed too and the root of my error when tried to call OGR_G_ExportToWkt on a spatial reference object. Thanks again Joaquim ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev