GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
do_proj.c File Reference

GProj library - Functions for re-projecting point data. More...

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <grass/gis.h>
#include <grass/gprojects.h>
#include <grass/glocale.h>
Include dependency graph for do_proj.c:

Go to the source code of this file.

Macros

#define MULTIPLY_LOOP(x, y, c, m)
 
#define DIVIDE_LOOP(x, y, c, m)
 

Functions

int GPJ_init_transform (const struct pj_info *info_in, const struct pj_info *info_out, struct pj_info *info_trans)
 Create a PROJ transformation object to transform coordinates from an input SRS to an output SRS. More...
 
int GPJ_transform (const struct pj_info *info_in, const struct pj_info *info_out, const struct pj_info *info_trans, int dir, double *x, double *y, double *z)
 Re-project a point between two co-ordinate systems using a transformation object prepared with GPJ_prepare_pj() More...
 
int GPJ_transform_array (const struct pj_info *info_in, const struct pj_info *info_out, const struct pj_info *info_trans, int dir, double *x, double *y, double *z, int n)
 Re-project an array of points between two co-ordinate systems using a transformation object prepared with GPJ_prepare_pj() More...
 
int pj_do_proj (double *x, double *y, const struct pj_info *info_in, const struct pj_info *info_out)
 Re-project a point between two co-ordinate systems. More...
 
int pj_do_transform (int count, double *x, double *y, double *h, const struct pj_info *info_in, const struct pj_info *info_out)
 Re-project an array of points between two co-ordinate systems with optional ellipsoidal height conversion. More...
 

Detailed Description

GProj library - Functions for re-projecting point data.

Author
Original Author unknown, probably Soil Conservation Service Eric Miller, Paul Kelly, Markus Metz

(C) 2003-2008,2018 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Definition in file do_proj.c.

Macro Definition Documentation

◆ DIVIDE_LOOP

#define DIVIDE_LOOP (   x,
  y,
  c,
 
)
Value:
do {\
for (i = 0; i < c; ++i) {\
x[i] /= m; \
y[i] /= m; \
}\
} while (0)

Definition at line 35 of file do_proj.c.

◆ MULTIPLY_LOOP

#define MULTIPLY_LOOP (   x,
  y,
  c,
 
)
Value:
do {\
for (i = 0; i < c; ++i) {\
x[i] *= m; \
y[i] *= m; \
}\
} while (0)

Definition at line 27 of file do_proj.c.

Function Documentation

◆ GPJ_init_transform()

int GPJ_init_transform ( const struct pj_info info_in,
const struct pj_info info_out,
struct pj_info info_trans 
)

Create a PROJ transformation object to transform coordinates from an input SRS to an output SRS.

After the transformation has been initialized with this function, coordinates can be transformed from input SRS to output SRS with GPJ_transform() and direction = PJ_FWD, and back from output SRS to input SRS with direction = OJ_INV. If coordinates should be transformed between the input SRS and its latlong equivalent, an uninitialized info_out with info_out->pj = NULL can be passed to the function. In this case, coordinates will be transformed between the input SRS and its latlong equivalent, and for PROJ 5+, the transformation object is created accordingly, while for PROJ 4, the output SRS is created as latlong equivalent of the input SRS

PROJ 5+: info_in->pj must not be null if info_out->pj is null, assume info_out to be the ll equivalent of info_in create info_trans as conversion from info_in to its ll equivalent NOTE: this is the inverse of the logic of PROJ 5 which by default converts from ll to a given SRS, not from a given SRS to ll thus PROJ 5+ itself uses an inverse transformation in the first step of the pipeline for proj_create_crs_to_crs() if info_trans->def is not NULL, this pipeline definition will be used to create a transformation object PROJ 4: info_in->pj must not be null if info_out->pj is null, create info_out as ll equivalent else do nothing, info_trans is not used

Parameters
info_inpointer to pj_info struct for input co-ordinate system
info_outpointer to pj_info struct for output co-ordinate system
info_transpointer to pj_info struct for a transformation object (PROJ 5+)
Returns
1 on success, -1 on failure

Definition at line 430 of file do_proj.c.

References _, pj_info::def, G_asprintf(), G_debug(), G_fatal_error(), G_free(), G_important_message(), G_store(), G_store_upper(), G_warning(), pj_info::meters, NULL, pj_info::pj, pj_info::proj, pj_info::srid, and pj_info::zone.

◆ GPJ_transform()

int GPJ_transform ( const struct pj_info info_in,
const struct pj_info info_out,
const struct pj_info info_trans,
int  dir,
double *  x,
double *  y,
double *  z 
)

Re-project a point between two co-ordinate systems using a transformation object prepared with GPJ_prepare_pj()

This function takes pointers to three pj_info structures as arguments, and projects a point between the input and output co-ordinate system. The pj_info structure info_trans must have been initialized with GPJ_init_transform(). The direction determines if a point is projected from input CRS to output CRS (PJ_FWD) or from output CRS to input CRS (PJ_INV). The easting, northing, and height of the point are contained in the pointers passed to the function; these will be overwritten by the coordinates of the transformed point.

Parameters
info_inpointer to pj_info struct for input co-ordinate system
info_outpointer to pj_info struct for output co-ordinate system
info_transpointer to pj_info struct for a transformation object (PROJ 5+)
dirdirection of the transformation (PJ_FWD or PJ_INV)
xPointer to a double containing easting or longitude
yPointer to a double containing northing or latitude
zPointer to a double containing height, or NULL
Returns
Return value from PROJ proj_trans() function

Definition at line 980 of file do_proj.c.

◆ GPJ_transform_array()

int GPJ_transform_array ( const struct pj_info info_in,
const struct pj_info info_out,
const struct pj_info info_trans,
int  dir,
double *  x,
double *  y,
double *  z,
int  n 
)

Re-project an array of points between two co-ordinate systems using a transformation object prepared with GPJ_prepare_pj()

This function takes pointers to three pj_info structures as arguments, and projects an array of pointd between the input and output co-ordinate system. The pj_info structure info_trans must have been initialized with GPJ_init_transform(). The direction determines if a point is projected from input CRS to output CRS (PJ_FWD) or from output CRS to input CRS (PJ_INV). The easting, northing, and height of the point are contained in the pointers passed to the function; these will be overwritten by the coordinates of the transformed point.

Parameters
info_inpointer to pj_info struct for input co-ordinate system
info_outpointer to pj_info struct for output co-ordinate system
info_transpointer to pj_info struct for a transformation object (PROJ 5+)
dirdirection of the transformation (PJ_FWD or PJ_INV)
xpointer to an array of type double containing easting or longitude
ypointer to an array of type double containing northing or latitude
zpointer to an array of type double containing height, or NULL
nnumber of points in the arrays to be transformed
Returns
Return value from PROJ proj_trans() function

Definition at line 1200 of file do_proj.c.

◆ pj_do_proj()

int pj_do_proj ( double *  x,
double *  y,
const struct pj_info info_in,
const struct pj_info info_out 
)

Re-project a point between two co-ordinate systems.

This function takes pointers to two pj_info structures as arguments, and projects a point between the co-ordinate systems represented by them. The easting and northing of the point are contained in two pointers passed to the function; these will be overwritten by the co-ordinates of the re-projected point.

Parameters
xPointer to a double containing easting or longitude
yPointer to a double containing northing or latitude
info_inpointer to pj_info struct for input co-ordinate system
info_outpointer to pj_info struct for output co-ordinate system
Returns
Return value from PROJ proj_trans() function

Definition at line 1463 of file do_proj.c.

◆ pj_do_transform()

int pj_do_transform ( int  count,
double *  x,
double *  y,
double *  h,
const struct pj_info info_in,
const struct pj_info info_out 
)

Re-project an array of points between two co-ordinate systems with optional ellipsoidal height conversion.

This function takes pointers to two pj_info structures as arguments, and projects an array of points between the co-ordinate systems represented by them. Pointers to the three arrays of easting, northing, and ellipsoidal height of the point (this one may be NULL) are passed to the function; these will be overwritten by the co-ordinates of the re-projected points.

Parameters
countNumber of points in the arrays to be transformed
xPointer to an array of type double containing easting or longitude
yPointer to an array of type double containing northing or latitude
hPointer to an array of type double containing ellipsoidal height. May be null in which case a two-dimensional re-projection will be done
info_inpointer to pj_info struct for input co-ordinate system
info_outpointer to pj_info struct for output co-ordinate system
Returns
Return value from PROJ proj_trans() function

Definition at line 1592 of file do_proj.c.