Loading...
Searching...
No Matches
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 | get_pj_area (const struct pj_info *iproj, double *xmin, double *xmax, double *ymin, double *ymax)
char * | get_pj_type_string (PJ *pj)
PJ * | get_pj_object (const struct pj_info *in_gpj, char **in_defstr)
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.
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().
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().
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.
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.

## 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,
|  |  | m )

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

Definition at line 34 of file do_proj.c.

## MULTIPLY_LOOP

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

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

Definition at line 26 of file do_proj.c.

## Function Documentation

## get_pj_area()

int get_pj_area | ( | const struct pj_info * | iproj,
|  | double * | xmin,
|  | double * | xmax,
|  | double * | ymin,
|  | double * | ymax )

Definition at line 44 of file do_proj.c.

References G_asprintf(), G_debug(), G_free(), G_get_set_window(), G_store(), G_warning(), GPJ_transform_array(), NULL, and x.

Referenced by GPJ_init_transform().

## get_pj_object()

PJ * get_pj_object | ( | const struct pj_info * | in_gpj,
|  | char ** | in_defstr )

Definition at line 315 of file do_proj.c.

References G_debug(), G_store(), G_warning(), and NULL.

Referenced by GPJ_init_transform().

## get_pj_type_string()

char * get_pj_type_string | ( | PJ * | pj | ) |

Abstract type, not returned by proj_get_type()

proj_get_type() will never return that type, but PJ_TYPE_GEOGRAPHIC_2D_CRS or PJ_TYPE_GEOGRAPHIC_3D_CRS.

Definition at line 222 of file do_proj.c.

References G_asprintf(), and NULL.

Referenced by GPJ_init_transform().

## 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

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

Parameters

  info_in | pointer to pj_info struct for input co-ordinate system
  info_out | pointer to pj_info struct for output co-ordinate system
  info_trans | pointer to pj_info struct for a transformation object (PROJ 5+)

Returns
  1 on success, -1 on failure

Definition at line 425 of file do_proj.c.

References G_asprintf(), G_debug(), G_fatal_error(), G_free(), G_important_message(), G_store(), G_store_upper(), G_warning(), get_pj_area(), get_pj_object(), get_pj_type_string(), and NULL.

Referenced by pj_do_proj(), and pj_do_transform().

## 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_in | pointer to pj_info struct for input co-ordinate system
  info_out | pointer to pj_info struct for output co-ordinate system
  info_trans | pointer to pj_info struct for a transformation object (PROJ 5+)
  dir | direction of the transformation (PJ_FWD or PJ_INV)
  x | Pointer to a double containing easting or longitude
  y | Pointer to a double containing northing or latitude
  z | Pointer to a double containing height, or NULL

Returns
  Return value from PROJ proj_trans() function

Definition at line 873 of file do_proj.c.

References G_debug(), G_fatal_error(), G_warning(), NULL, and x.

## 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_in | pointer to pj_info struct for input co-ordinate system
  info_out | pointer to pj_info struct for output co-ordinate system
  info_trans | pointer to pj_info struct for a transformation object (PROJ 5+)
  dir | direction of the transformation (PJ_FWD or PJ_INV)
  x | pointer to an array of type double containing easting or longitude
  y | pointer to an array of type double containing northing or latitude
  z | pointer to an array of type double containing height, or NULL
  n | number of points in the arrays to be transformed

Returns
  Return value from PROJ proj_trans() function

Definition at line 1031 of file do_proj.c.

References G_fatal_error(), G_free(), G_warning(), NULL, and x.

Referenced by get_pj_area().

## 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

  x | Pointer to a double containing easting or longitude
  y | Pointer to a double containing northing or latitude
  info_in | pointer to pj_info struct for input co-ordinate system
  info_out | pointer to pj_info struct for output co-ordinate system

Returns
  Return value from PROJ proj_trans() function

Definition at line 1232 of file do_proj.c.

References G_warning(), GPJ_init_transform(), and x.

## 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

  count | Number of points in the arrays to be transformed
  x | Pointer to an array of type double containing easting or longitude
  y | Pointer to an array of type double containing northing or latitude
  h | Pointer to an array of type double containing ellipsoidal height. May be null in which case a two-dimensional re-projection will be done
  info_in | pointer to pj_info struct for input co-ordinate system
  info_out | pointer to pj_info struct for output co-ordinate system

Returns
  Return value from PROJ proj_trans() function

Definition at line 1318 of file do_proj.c.

References count, G_free(), G_warning(), GPJ_init_transform(), NULL, and x.