[gdal-dev] C GDAL beginner

brian rush at winkey.org
Tue Mar 2 23:48:03 EST 2010


deadpickle,


The types in the OGR C api pretty much end in H.

OGRCoordinateTransformation ctrans;
should read
OGRCoordinateTransformationH ctrans;

The function your looking for is OCTNewCoordinateTransformation().


Brian

On Tue, 2010-03-02 at 19:22 -0800, deadpickle wrote:
> I'm trying to write a simple C program that creates and populates a
> shapefile (have one done in python). I'm very new to C and GDAL both
> and could use some help. I'm trying to apply coordinatetransformation
> to my points but first I have to create the coordinatetransformation.
> In python I can do this simply by:
> coordtrans = osr.CoordinateTransformation(target, source)
> but in C I cant seem to find the right call for this. Any ideas?
> 
> #include "ogr_api.h"
> #include "ogr_srs_api.h"
> 
> int main()
> {
> 	//~ variable declaration
> 	const char *format = "ESRI Shapefile", *name = "testc.shp", *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";
> 	OGRSFDriverH driver;
> 	OGRDataSourceH ds;
> 	OGRCoordinateTransformation ctrans;
> 
> 	//~ get driver and create ds
> 	OGRRegisterAll();
> 	driver = OGRGetDriverByName(format);
> 	ds = OGR_Dr_CreateDataSource(driver, "testc.shp", NULL);
> 
> 	//~ create spatrefs and trans
> 	OSRNewSpatialReference(source);
> 	OSRNewSpatialReference(target);
> 	OSRSetFromUserInput(source, sprj);
> 	OSRSetFromUserInput(target, tprj);
> 	ctrans = OGRCreateCoordinateTransformation(target, source);
> }
> 
> [thor at updraft ~/Programs]$ gcc -o gdal_test_convert
> gdal_test_convert.c
> gdal_test_convert.c: In function âmainâ™:
> gdal_test_convert.c:12: error: âOGRCoordinateTransformationâ™
> undeclared (first use in this function)
> gdal_test_convert.c:12: error: (Each undeclared identifier is reported
> only once
> gdal_test_convert.c:12: error: for each function it appears in.)
> gdal_test_convert.c:12: error: expected â;â™ before âctransâ™
> gdal_test_convert.c:22: warning: passing argument 1 of â
> OSRSetFromUserInputâ™ discards qualifiers from pointer target type
> gdal_test_convert.c:23: warning: passing argument 1 of â
> OSRSetFromUserInputâ™ discards qualifiers from pointer target type
> gdal_test_convert.c:24: error: âctransâ™ undeclared (first use in
> this function)
> 
> 
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev



More information about the gdal-dev mailing list