[gdal-dev] Re: C GDAL beginner

Frank Warmerdam warmerdam at pobox.com
Wed Mar 3 22:53:18 EST 2010


deadpickle wrote:
> Thanks for the replies. Just as a note, the warnings are caused by the
> variable being a const. Omitting the const solved it.
> I'm not sure if this is a C program or a GDAL thing, thats why I'm not
> sure where to post this at, but I get a segfault. I know segfaults are
> generally caused by ordinary, and sometimes strange, syntax but it
> involves a GDAL C API call, so I'll post it here. Basically, from what
> I understand from printing, the esgfault is caused by
> OSRSetFromUserInput(source, sprj);
> where char *source;
>  OSRNewSpatialReference(source);
>  and const char *sprj = "+proj=lcc +lat_1=33.000000 +lat_2=45.000000
> +lat_0=39.000000 +lon_0=-96.000000 +x_0=0.0 +y_0=0.0 +datum=NAD83";.
>  what I'm wondering is if I'm calling these correctly? Is the proj4
> string right? If they are then I'll redirect my questions else where.
...
> int main()
> {
> 	//~ variable declaration
> 	const char *name = "testc.shp", *dir = "C:\\Users\\deadpickle\\Desktop
> \\case study\\verify\\";
> 	char *source, *target;
> 	const char *sprj = "+proj=lcc +lat_1=33.000000 +lat_2=45.000000
> +lat_0=39.000000 +lon_0=-96.000000 +x_0=0.0 +y_0=0.0 +datum=NAD83";
> 	const char *tprj = "WGS84";
...
> 	//~ create spatrefs and trans
> 	OSRNewSpatialReference(source);
> 	OSRNewSpatialReference(target);

No, it's quite wrong.

It should be
         OGRSpatialReferenceH source, target;

         source = OSRNewSpatialReference(NULL);
         OSRSetFromUserInput( source, sprj );

         target = OSRNewSpatialReference(NULL);
         OSRSetFromUserInput( target, tprj );

...
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the gdal-dev mailing list