2

I have some problems with gdal compiled on iOS ( gdal internally uses proj for some operations )

I'm developing for iOS, and want to use this library to perform coordinate transformation, but some functions requires proj dll and at runtime i get this error :

ERROR 6: Unable to load PROJ.4 library (libproj.dylib), creation of
OGRCoordinateTransformation failed.
Transformation failed.

I suppose that the proj dll should be included as a static library , but i can't find how todo this

( other problems, just to mention: i can't access EPSG database and gcs.csv neither, so that only SetGeogCS() methos seems available to set coordinate system, bu i don't' know which parameters i should use to get a "EPSG:3003" coordinate system, "Italia fuso ovest" )

CLLocationCoordinate2D transform( char *s_srs, double x, double y)

{
    OGRSpatialReference oSourceSRS, oTargetSRS;
    OGRCoordinateTransformation *poCT;

    /* oSourceSRS.importFromEPSG( atoi(papszArgv[i+1]) );
    //oTargetSRS.importFromEPSG( atoi(papszArgv[i+2]) ); */

    /*
    oSourceSRS.SetWellKnownGeogCS(s_srs);
    */
    oSourceSRS.SetGeogCS( "My geographic coordinate system",
                         "WGS_1984",
                         "My WGS84 Spheroid",
                         SRS_WGS84_SEMIMAJOR, SRS_WGS84_INVFLATTENING,
                         "Greenwich", 0.0,
                         "degree",
                         atof(SRS_UA_DEGREE_CONV) );

    /*
    oTargetSRS.SetWellKnownGeogCS("WGS84");
    */
    oTargetSRS.SetGeogCS( "My geographic coordinate system",
                   "WGS_1984",
                   "My WGS84 Spheroid",
                   SRS_WGS84_SEMIMAJOR, SRS_WGS84_INVFLATTENING,
                   "Greenwich", 0.0,
                   "degree",
                         atof(SRS_UA_DEGREE_CONV) );


    poCT = OGRCreateCoordinateTransformation( &oSourceSRS,
                                             &oTargetSRS );


    if( poCT == NULL || !poCT->Transform( 1, &x, &y ) ) {
        printf( "Transformation failed.\n" );
        return CLLocationCoordinate2DMake(x, y);
    } else {
        return CLLocationCoordinate2DMake(x, y);
    }

}
atrebbi
  • 553
  • 3
  • 20

2 Answers2

1

You need to download and build proj4 for iOS first. Then you can point GDAL to your iOS build of proj4 using the ./configure flag

--with-static-proj4=/path/to/your/libproj

Make sure the path is the parent directory that has the include directory and lib directory for proj4.

For instance my directory on my Mac is:

/Users/myUsername/iOS_builds/{device_arch}/iphoneos.platform/iphoneos.7.0.sdk

Where device arch can be i386, armv7 or armv7s depending on which target I am compiling for. That directory has subdirectories of "include" and "lib", which in turn have the .h files and the libproj.a file for linking into GDAL.

I have a script in development for helping to build GDAL and associated libraries on github. https://github.com/afarnham/preflight

You might have to make some edits to the compilers specified in that script to get it to work if you don't have Xcode 5 installed. Also some of the configure flags probably need updating for GDAL. It should help you get started though.

Aaron
  • 2,403
  • 1
  • 24
  • 25
  • I did manage to compile at last... but only with an old release of gdal , 1.9.2 , did not manage to compile 10.1 – atrebbi Jul 10 '13 at 08:41
0

According to this post, you can resolve the problem in iOS by adding

export PROJSO=/Library/Frameworks/PROJ.framework/PROJ

to your .bash_profile. I'm facing the same problem on Linux, any suggestions appreciated :)

Community
  • 1
  • 1
xandriksson
  • 101
  • 5
  • It's OSX , not iOS ; I did resolve the problem with some changes to cfg files ( parameter extra_cflags -DPROJ_STATIC=1 ) and compiling proj sources in the static library. – atrebbi Jun 28 '13 at 22:13
  • for other problems I mentioned ( epsg database not found ), I have fixed adding this line : setenv("GDAL_DATA", [NSBundle mainBundle].bundlePath.UTF8String, TRUE); – atrebbi Jun 29 '13 at 07:10
  • xandriksson, also have similar issue: https://stackoverflow.com/q/61164590/630169. Have You found any solution yet? Thanks! – Aleksey Kontsevich Apr 13 '20 at 20:45