Proj API Reference

Procedure pj_init() selects and initializes a cartographic projection with its argument control parameters. Argc is the number of elements in the array of control strings argv that each contain individual cartographic control keyword assignments (+ proj arguments). The list must contain at least the proj=projection and Earth's radius or elliptical parameters. If the initialization of the projection is successful a valid address is returned otherwise a NULL value.

The pj_init_plus() function operates similarly to pj_init() but takes a single string containing the definition, with each parameter prefixed with a plus sign. For example "+proj=utm +zone=11 +ellps=WGS84".

Once initialization is performed either forward or inverse projections can be performed with the returned value of pj_init() used as the argument proj. The argument structure projUV values u and v contain respective longitude and latitude or x and y. Latitude and longitude are in radians. If a projection operation fails, both elements of projUV are set to HUGE_VAL (defined in math.h).

Note: all projections have a forward mode, but some do not have an inverse projection. If the projection does not have an inverse the projPJ structure element inv will be NULL.  Jasa seo,  Jasa seo jakarta

The pj_transform function may be used to transform points between the two provided coordinate systems. In addition to converting between cartographic projection coordinates and geographic coordinates, this function also takes care of datum shifts if possible between the source and destination coordinate system. Unlike pj_fwd() and pj_inv() it is also allowable for the coordinate system definitions (projPJ *) to be geographic coordinate systems (defined as +proj=latlong). The x, y and z arrays contain the input values of the points, and are replaced with the output values. The function returns zero on success, or the error number (also in pj_errno) on failure.

Memory associated with the projection may be freed with pj_free().

EXAMPLE

The following program reads latitude and longitude values in decimal degress, performs Mercator projection with a Clarke 1866 ellipsoid and a 33° latitude of true scale and prints the projected cartesian values in meters:

       #include <proj_api.h>

       main(int argc, char **argv) {
            projPJ pj_merc, pj_latlong;
            double x, y;

            if (!(pj_merc = pj_init_plus("+proj=merc +ellps=clrk66 +lat_ts=33")) )
               exit(1);
            if (!(pj_latlong = pj_init_plus("+proj=latlong +ellps=clrk66")) )
               exit(1);
            while (scanf("%lf %lf", &x, &y) == 2) {
               x *= DEG_TO_RAD;
               y *= DEG_TO_RAD;
               p = pj_transform(pj_latlong, pj_merc, 1, 1, &x, &y, NULL );
               printf("%.2f\t%.2f\n", x, y);
            }
            exit(0);
       }

For this program, an input of "-16 20.25" would give a result of "-1495284.21 1920596.79".

API Functions

Basic API

int pj_transform( projPJ srcdefn, projPJ dstdefn, long point_count, int point_offset, double *x, double *y, double *z );

Transform the x/y/z points from the source coordinate system to the destination coordinate system.

projPJ pj_init_plus(const char *definition);

Create a projPJ coordinate system object from the string definition.

void pj_free( projPJ pj );

Frees all resources associated with pj.

Advanced Functions

int pj_is_latlong( projPJ pj );

Returns TRUE if the passed coordinate system is geographic (proj=latlong).

int pj_is_geocent( projPJ pj );

Returns TRUE if the coordinate system is geocentric (proj=geocent).

char *pj_get_def( projPJ pj, int options);

Returns the PROJ.4 initialization string suitable for use with pj_init_plus() that would produce this coordinate system, but with the definition expanded as much as possible (for instance +init= and +datum= definitions).

projPJ pj_latlong_from_proj( projPJ pj_in );

Returns a new coordinate system definition which is the geographic coordinate (lat/long) system underlying pj_in.

Environment Functions

void pj_set_finder( const char *(*new_finder)(const char *) );

Install a custom function for finding init and grid shift files.

void pj_set_searchpath ( int count, const char **path );

Set a list of directories to search for init and grid shift files.

void pj_deallocate_grids( void );

Frees all resources associated with loaded and cached datum shift grids.

char *pj_strerrno( int );

Returns the error text associated with the passed in error code.

int *pj_get_errno_ref( void );

Returns a pointer to the global pj_errno error variable.

const char *pj_get_release( void );

Returns an internal string describing the release version.

Obsolete Functions

XY pj_fwd( LP lp, PJ *P );

LP pj_inv( XY xy, PJ *P );

projPJ pj_init(int argc, char **argv);