Skip to content

Instantly share code, notes, and snippets.

@refactor
Last active January 20, 2019 09:33
Show Gist options
  • Save refactor/d41a844c8f5826eca0bceca479a5f0b5 to your computer and use it in GitHub Desktop.
Save refactor/d41a844c8f5826eca0bceca479a5f0b5 to your computer and use it in GitHub Desktop.

Revisions

  1. refactor revised this gist Jan 20, 2019. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions osr_test.c
    Original file line number Diff line number Diff line change
    @@ -35,6 +35,7 @@ int main(void) {

    printf("x: %f, y: %f, z: %f\n", x, y, z);
    OCTDestroyCoordinateTransformation(hTransform);
    OSRDestroySpatialReference(sr);

    OGRSpatialReferenceH hUTM = OSRNewSpatialReference(NULL);
    OSRSetProjCS(hUTM, "UTM 20 / WGS84");
    @@ -46,5 +47,7 @@ int main(void) {
    printf("x: %f, y: %f, z: %f\n", x, y, z);

    OCTDestroyCoordinateTransformation(hTransform);
    OSRDestroySpatialReference(hUTM);

    return 0;
    }
  2. refactor revised this gist Jan 12, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion osr_test.c
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    int main(void) {
    OGRSpatialReferenceH sr = OSRNewSpatialReference(NULL);
    OSRImportFromEPSG(sr, 3857);
    OSRSetWellKnownGeogCS(sr, "WGS84");
    // OSRSetWellKnownGeogCS(sr, "WGS84");
    char* ppsz;
    OSRExportToPrettyWkt(sr, &ppsz, FALSE);
    printf("3857.wkt: \n%s\n", ppsz);
  3. refactor revised this gist Jan 12, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions osr_test.c
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ int main(void) {
    OSRSetWellKnownGeogCS(sr, "WGS84");
    char* ppsz;
    OSRExportToPrettyWkt(sr, &ppsz, FALSE);
    printf("3857.wkt: %s\n", ppsz);
    printf("3857.wkt: \n%s\n", ppsz);
    CPLFree(ppsz);
    printf("3857.au: %s\n", OSRGetAuthorityCode(sr,NULL));
    printf("3857.geogcs.au: %s\n", OSRGetAuthorityCode(sr, "GEOGCS"));
    @@ -41,7 +41,7 @@ int main(void) {
    OSRSetWellKnownGeogCS(hUTM, "WGS84");
    OSRSetUTM(hUTM, 20, TRUE);

    hTransform = OCTNewCoordinateTransformation(sr, hUTM);
    hTransform = OCTNewCoordinateTransformation(hLatLong, hUTM);
    OCTTransform(hTransform, 1, &x, &y, &z);
    printf("x: %f, y: %f, z: %f\n", x, y, z);

  4. refactor created this gist Jan 11, 2019.
    50 changes: 50 additions & 0 deletions osr_test.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    #include <ogr_srs_api.h>
    #include <cpl_conv.h>

    int main(void) {
    OGRSpatialReferenceH sr = OSRNewSpatialReference(NULL);
    OSRImportFromEPSG(sr, 3857);
    OSRSetWellKnownGeogCS(sr, "WGS84");
    char* ppsz;
    OSRExportToPrettyWkt(sr, &ppsz, FALSE);
    printf("3857.wkt: %s\n", ppsz);
    CPLFree(ppsz);
    printf("3857.au: %s\n", OSRGetAuthorityCode(sr,NULL));
    printf("3857.geogcs.au: %s\n", OSRGetAuthorityCode(sr, "GEOGCS"));
    printf("3857.geogcs|unit.au: %s\n", OSRGetAuthorityCode(sr, "GEOGCS|UNIT"));
    printf("3857.geogcs|datum.au: %s\n", OSRGetAuthorityCode(sr, "GEOGCS|DATUM"));
    printf("3857.geogcs|datum|spheroid.au: %s\n", OSRGetAuthorityCode(sr, "GEOGCS|DATUM|SPHEROID"));
    printf("3857.projcs.au: %s\n", OSRGetAuthorityCode(sr, "PROJCS"));

    //OGRSpatialReferenceH hLatLong = OSRCloneGeogCS(sr);
    OGRSpatialReferenceH hLatLong = OSRNewSpatialReference(NULL);
    OSRSetWellKnownGeogCS(hLatLong, "WGS84");
    printf("wgs84.au: %s\n", OSRGetAuthorityCode(hLatLong, NULL));
    printf("wgs84.geogcs.au: %s\n", OSRGetAuthorityCode(hLatLong, "GEOGCS"));
    printf("wgs84.geogcs|unit.au: %s\n", OSRGetAuthorityCode(hLatLong, "GEOGCS|UNIT"));
    printf("wgs84.geogcs|datum.au: %s\n", OSRGetAuthorityCode(hLatLong, "GEOGCS|DATUM"));
    printf("wgs84.geogcs|datum|spheroid.au: %s\n", OSRGetAuthorityCode(hLatLong, "GEOGCS|DATUM|SPHEROID"));
    printf("wgs84.projcs.au: %s\n", OSRGetAuthorityCode(hLatLong, "PROJCS"));

    OGRCoordinateTransformationH hTransform = OCTNewCoordinateTransformation(sr,hLatLong);

    double x = 12955467.346012;
    double y = 4854848.34787838;
    double z = 0;
    OCTTransform(hTransform, 1, &x, &y, &z);

    printf("x: %f, y: %f, z: %f\n", x, y, z);
    OCTDestroyCoordinateTransformation(hTransform);

    OGRSpatialReferenceH hUTM = OSRNewSpatialReference(NULL);
    OSRSetProjCS(hUTM, "UTM 20 / WGS84");
    OSRSetWellKnownGeogCS(hUTM, "WGS84");
    OSRSetUTM(hUTM, 20, TRUE);

    hTransform = OCTNewCoordinateTransformation(sr, hUTM);
    OCTTransform(hTransform, 1, &x, &y, &z);
    printf("x: %f, y: %f, z: %f\n", x, y, z);

    OCTDestroyCoordinateTransformation(hTransform);
    return 0;
    }