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.
Thanks.

#include "ogr_api.h"
#include "ogr_srs_api.h"
#include "stdio.h"

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";
        char c[100];
        OGRSFDriverH driver;
        OGRDataSourceH ds;
        OGRCoordinateTransformationH ctrans;
        OGRLayerH layer;
        OGRFieldDefnH fieldDefn;
        OGRGeometryH line;
        OGRFeatureDefnH featureDefn;
        OGRFeatureH feature;
        FILE *file;

        //~ working directory
        chdir(dir);

        OGRRegisterAll();

        //~ get driver and create ds
        driver = OGRGetDriverByName("ESRI Shapefile");
        ds = OGR_Dr_CreateDataSource(driver, "testc.shp", NULL);

        if(ds == NULL) {
                printf("Creation of output file failed.\n");
                exit(1);
        }

        printf("HERE1\n");

        //~ create spatrefs and trans
        OSRNewSpatialReference(source);
        OSRNewSpatialReference(target);

        OSRSetFromUserInput(source, sprj);

        printf("HERE2\n");

        OSRSetFromUserInput(target, tprj);

        printf("HERE3\n");

        ctrans = OCTNewCoordinateTransformation(target, source);

        //~ create the layer
        layer = OGR_DS_CreateLayer(ds, "testc", source, wkbMultiLineString,
NULL);

        //~ add an id field
        fieldDefn = OGR_Fld_Create("id", OFTInteger);
        OGR_L_CreateField(layer, fieldDefn, FALSE);

        //~ create geometry
        line = OGR_G_CreateGeometry(wkbMultiLineString);

        //~ layer def and create feature
        featureDefn = OGR_L_GetLayerDefn(layer);
        feature = OGR_F_Create(featureDefn);

        //~ open file
        file = fopen("2006track.csv","r");

        if(file==NULL) {
                printf("Error: can't open file.\n");
                /* fclose(file); DON'T PASS A NULL POINTER TO fclose !! */
                return 1;
        }
        else {
                printf("File opened successfully. Contents:\n\n");

                while(fgets(c, 100, file)!=NULL) {
                        /* keep looping until NULL pointer... */
                        printf("String: %s", c);
                        /* print the file one line at a time  */
                }

                printf("\n\nNow closing file...\n");
        }

        //~ close file
        fclose(file);
}


On Mar 3, 5:15 am, Mateusz Loskot <mate...@loskot.net> wrote:
> You need to buy a book about C/C++ or ask on comp.lang.c or comp.lang.c++
>
> Best regards,
>
> -----
> --
> Mateusz Loskothttp://mateusz.loskot.net
> --
> View this message in 
> context:http://n2.nabble.com/gdal-dev-C-GDAL-beginner-tp4665330p4666854.html
> Sent from the GDAL - Dev mailing list archive at Nabble.com.
> _______________________________________________
> gdal-dev mailing list
> gdal-...@lists.osgeo.orghttp://lists.osgeo.org/mailman/listinfo/gdal-dev
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to