GRASS GIS 8 Programmer's Manual
8.5.0dev(2024)-d6dec75dd4
|
Go to the source code of this file.
Functions | |
int | GPJ_init_transform (const struct pj_info *, const struct pj_info *, struct pj_info *) |
Create a PROJ transformation object to transform coordinates from an input SRS to an output SRS. More... | |
int | GPJ_transform (const struct pj_info *, const struct pj_info *, const struct pj_info *, int, double *, double *, double *) |
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 *, const struct pj_info *, const struct pj_info *, int, double *, double *, double *, int) |
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 *, double *, const struct pj_info *, const struct pj_info *) |
Re-project a point between two co-ordinate systems. More... | |
int | pj_do_transform (int, double *, double *, double *, const struct pj_info *, const struct pj_info *) |
Re-project an array of points between two co-ordinate systems with optional ellipsoidal height conversion. More... | |
int | pj_get_kv (struct pj_info *, const struct Key_Value *, const struct Key_Value *) |
Create a pj_info struct Co-ordinate System definition from a set of PROJ_INFO / PROJ_UNITS-style key-value pairs. More... | |
int | pj_get_string (struct pj_info *, char *) |
Create a pj_info struct Co-ordinate System definition from a string with a sequence of key=value pairs. More... | |
int | GPJ_get_equivalent_latlong (struct pj_info *, struct pj_info *) |
const char * | set_proj_share (const char *) |
int | pj_print_proj_params (const struct pj_info *, const struct pj_info *) |
Print projection parameters as used by PROJ.4 for input and output co-ordinate systems. More... | |
char * | GPJ_grass_to_wkt (const struct Key_Value *, const struct Key_Value *, int, int) |
Converts a GRASS co-ordinate system representation to WKT style. More... | |
char * | GPJ_grass_to_wkt2 (const struct Key_Value *, const struct Key_Value *, const struct Key_Value *, int, int) |
Converts a GRASS co-ordinate system representation to WKT style. EPSG code is preferred if available. More... | |
OGRSpatialReferenceH | GPJ_grass_to_osr (const struct Key_Value *, const struct Key_Value *) |
Converts a GRASS co-ordinate system to an OGRSpatialReferenceH object. More... | |
OGRSpatialReferenceH | GPJ_grass_to_osr2 (const struct Key_Value *, const struct Key_Value *, const struct Key_Value *) |
Converts a GRASS co-ordinate system to an OGRSpatialReferenceH object. EPSG code is preferred if available. More... | |
const char * | GPJ_set_csv_loc (const char *) |
int | GPJ_osr_to_grass (struct Cell_head *, struct Key_Value **, struct Key_Value **, OGRSpatialReferenceH, int) |
Converts an OGRSpatialReferenceH object to a GRASS co-ordinate system. More... | |
int | GPJ_wkt_to_grass (struct Cell_head *, struct Key_Value **, struct Key_Value **, const char *, int) |
Converts a WKT projection description to a GRASS co-ordinate system. More... | |
int | GPJ_get_datum_by_name (const char *, struct gpj_datum *) |
Look up a string in datum.table file to see if it is a valid datum name and if so place its information into a gpj_datum struct. More... | |
int | GPJ_get_default_datum_params_by_name (const char *, char **) |
"Last resort" function to retrieve a "default" set of datum parameters for a datum (N.B. there really is no such thing as a catch-all default!) More... | |
int | GPJ_get_datum_params (char **, char **) |
Extract the datum transformation-related parameters for the current location. More... | |
int | GPJ__get_datum_params (const struct Key_Value *, char **, char **) |
Extract the datum transformation-related parameters from a set of general PROJ_INFO parameters. More... | |
void | GPJ_free_datum (struct gpj_datum *) |
Free the memory used for the strings in a gpj_datum struct. More... | |
struct gpj_datum_transform_list * | GPJ_get_datum_transform_by_name (const char *) |
Internal function to find all possible sets of transformation parameters for a particular datum. More... | |
void | GPJ_free_datum_transform (struct gpj_datum_transform_list *) |
Free the memory used by a gpj_datum_transform_list struct. More... | |
int | GPJ_get_ellipsoid_by_name (const char *, struct gpj_ellps *) |
Looks up ellipsoid in ellipsoid table and returns the a, e2 parameters for the ellipsoid. More... | |
int | GPJ_get_ellipsoid_params (double *, double *, double *) |
Get the ellipsoid parameters from the database. More... | |
int | GPJ__get_ellipsoid_params (const struct Key_Value *, double *, double *, double *) |
Get the ellipsoid parameters from proj keys structure. More... | |
void | GPJ_free_ellps (struct gpj_ellps *) |
Free ellipsoid data structure. More... | |
int | pj_factors (LP, void *, double, struct FACTORS *) |
int GPJ__get_datum_params | ( | const struct Key_Value * | projinfo, |
char ** | datumname, | ||
char ** | params | ||
) |
Extract the datum transformation-related parameters from a set of general PROJ_INFO parameters.
This function can be used to test if a location's co-ordinate system set-up supports datum transformation.
projinfo | Set of key_value pairs containing projection information in PROJ_INFO file format |
datumname | Pointer to a pointer which will have memory allocated and into which a string containing the datum name (if present) will be placed. Otherwise set to NULL. |
params | Pointer to a pointer which will have memory allocated and into which a string containing the datum parameters (if present) will be placed. Otherwise set to NULL. |
Definition at line 173 of file proj/datum.c.
References G_asprintf(), G_debug(), G_find_key_value(), G_store(), and NULL.
Referenced by GPJ_get_datum_params(), and GPJ_osr_to_grass().
int GPJ__get_ellipsoid_params | ( | const struct Key_Value * | proj_keys, |
double * | a, | ||
double * | e2, | ||
double * | rf | ||
) |
Get the ellipsoid parameters from proj keys structure.
If the PROJECTION_FILE exists in the PERMANENT mapset, read info from that file, otherwise return WGS 84 values.
Dies with diagnostic if there is an error.
proj_keys | proj definition | |
[out] | a | semi-major axis |
[out] | e2 | first eccentricity squared |
[out] | rf | reciprocal of the ellipsoid flattening term |
void GPJ_free_datum | ( | struct gpj_datum * | dstruct | ) |
Free the memory used for the strings in a gpj_datum struct.
dstruct | gpj_datum struct to be freed |
Definition at line 396 of file proj/datum.c.
References gpj_datum::ellps, G_free(), gpj_datum::longname, and gpj_datum::name.
void GPJ_free_datum_transform | ( | struct gpj_datum_transform_list * | item | ) |
Free the memory used by a gpj_datum_transform_list struct.
item | gpj_datum_transform_list struct to be freed |
Definition at line 323 of file proj/datum.c.
References gpj_datum_transform_list::comment, G_free(), gpj_datum_transform_list::params, and gpj_datum_transform_list::where_used.
Referenced by GPJ_get_default_datum_params_by_name().
void GPJ_free_ellps | ( | struct gpj_ellps * | estruct | ) |
Free ellipsoid data structure.
estruct | data structure to be freed |
Definition at line 303 of file ellipse.c.
References G_free(), gpj_ellps::longname, and gpj_ellps::name.
int GPJ_get_datum_by_name | ( | const char * | name, |
struct gpj_datum * | dstruct | ||
) |
Look up a string in datum.table file to see if it is a valid datum name and if so place its information into a gpj_datum struct.
name | String containing datum name to look up |
dstruct | gpj_datum struct into which datum parameters will be placed if found |
Definition at line 38 of file proj/datum.c.
References gpj_datum::dx, gpj_datum::dy, gpj_datum::dz, gpj_datum::ellps, free_datum_list(), G_store(), G_strcasecmp(), list, gpj_datum::longname, gpj_datum::name, name, NULL, and read_datum_table().
int GPJ_get_datum_params | ( | char ** | name, |
char ** | params | ||
) |
Extract the datum transformation-related parameters for the current location.
This function can be used to test if a location's co-ordinate system set-up supports datum transformation.
name | Pointer to a pointer which will have memory allocated and into which a string containing the datum name (if present) will be placed. Otherwise set to NULL. |
params | Pointer to a pointer which will have memory allocated and into which a string containing the datum parameters (if present) will be placed. Otherwise set to NULL. |
Definition at line 135 of file proj/datum.c.
References G_free_key_value(), G_get_projinfo(), GPJ__get_datum_params(), and name.
struct gpj_datum_transform_list* GPJ_get_datum_transform_by_name | ( | const char * | inputname | ) |
Internal function to find all possible sets of transformation parameters for a particular datum.
inputname | String containing the datum name we are going to look up parameters for |
Definition at line 237 of file proj/datum.c.
References file, and GPATH_MAX.
Referenced by GPJ_get_default_datum_params_by_name().
int GPJ_get_default_datum_params_by_name | ( | const char * | name, |
char ** | params | ||
) |
"Last resort" function to retrieve a "default" set of datum parameters for a datum (N.B. there really is no such thing as a catch-all default!)
Kind of a "last resort" function as there really is no such thing as a default set of datum transformation parameters. Only should really be used where user interaction to choose a set of parameters is not desirable. Use of this function is not likely to result in selection of the optimum set of datum transformation parameters for the location
name | String containing GRASS datum name for which default parameters are to be retrieved |
params | Pointer to a pointer which will have memory allocated and into which a string containing the datum parameters (if present) will be placed |
Definition at line 86 of file proj/datum.c.
References count, G_store(), GPJ_free_datum_transform(), GPJ_get_datum_transform_by_name(), list, name, NULL, and gpj_datum_transform_list::params.
int GPJ_get_ellipsoid_by_name | ( | const char * | name, |
struct gpj_ellps * | estruct | ||
) |
Looks up ellipsoid in ellipsoid table and returns the a, e2 parameters for the ellipsoid.
name | ellipsoid name | |
[out] | estruct | ellipsoid |
Definition at line 160 of file ellipse.c.
References gpj_ellps::a, gpj_ellps::es, free_ellps_list(), G_store(), G_strcasecmp(), list, gpj_ellps::longname, gpj_ellps::name, name, NULL, read_ellipsoid_table(), and gpj_ellps::rf.
int GPJ_get_ellipsoid_params | ( | double * | a, |
double * | e2, | ||
double * | rf | ||
) |
Get the ellipsoid parameters from the database.
If the PROJECTION_FILE exists in the PERMANENT mapset, read info from that file, otherwise return WGS 84 values.
Dies with diagnostic if there is an error.
[out] | a | semi-major axis |
[out] | e2 | first eccentricity squared |
[out] | rf | reciprocal of the ellipsoid flattening term |
OGRSpatialReferenceH GPJ_grass_to_osr | ( | const struct Key_Value * | proj_info, |
const struct Key_Value * | proj_units | ||
) |
Converts a GRASS co-ordinate system to an OGRSpatialReferenceH object.
proj_info | Set of GRASS PROJ_INFO key/value pairs |
proj_units | Set of GRASS PROJ_UNIT key/value pairs |
OGRSpatialReferenceH GPJ_grass_to_osr2 | ( | const struct Key_Value * | proj_info, |
const struct Key_Value * | proj_units, | ||
const struct Key_Value * | proj_epsg | ||
) |
Converts a GRASS co-ordinate system to an OGRSpatialReferenceH object. EPSG code is preferred if available.
The co-ordinate system definition is imported from EPSG (by GDAL) definition if available. TOWGS84 parameter is scanned from PROJ_INFO file and appended to co-ordinate system definition. If EPSG code is not available, PROJ_INFO file is used as GPJ_grass_to_osr() does.
proj_info | Set of GRASS PROJ_INFO key/value pairs |
proj_units | Set of GRASS PROJ_UNIT key/value pairs |
proj_epsg | Set of GRASS PROJ_EPSG key/value pairs |
char* GPJ_grass_to_wkt | ( | const struct Key_Value * | proj_info, |
const struct Key_Value * | proj_units, | ||
int | esri_style, | ||
int | prettify | ||
) |
Converts a GRASS co-ordinate system representation to WKT style.
Takes a GRASS co-ordinate system as specified by two sets of key/value pairs derived from the PROJ_INFO and PROJ_UNITS files, and converts it to the 'Well Known Text' format.
proj_info | Set of GRASS PROJ_INFO key/value pairs |
proj_units | Set of GRASS PROJ_UNIT key/value pairs |
esri_style | boolean Output ESRI-style WKT (Use OSRMorphToESRI() function provided by OGR library) |
prettify | boolean Use linebreaks and indents to 'prettify' output WKT string (Use OSRExportToPrettyWkt() function in OGR) |
char* GPJ_grass_to_wkt2 | ( | const struct Key_Value * | proj_info, |
const struct Key_Value * | proj_units, | ||
const struct Key_Value * | proj_epsg, | ||
int | esri_style, | ||
int | prettify | ||
) |
Converts a GRASS co-ordinate system representation to WKT style. EPSG code is preferred if available.
Takes a GRASS co-ordinate system as specified key/value pairs derived from the PROJ_EPSG file. TOWGS84 parameter is scanned from PROJ_INFO file and appended to co-ordinate system definition imported from EPSG code by GDAL library. PROJ_UNITS file is ignored. The function converts it to the 'Well Known Text' format.
proj_info | Set of GRASS PROJ_INFO key/value pairs |
proj_units | Set of GRASS PROJ_UNIT key/value pairs |
proj_epsg | Set of GRASS PROJ_EPSG key/value pairs |
esri_style | boolean Output ESRI-style WKT (Use OSRMorphToESRI() function provided by OGR library) |
prettify | boolean Use linebreaks and indents to 'prettify' output WKT string (Use OSRExportToPrettyWkt() function in OGR) |
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
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+) |
Definition at line 434 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.
int GPJ_osr_to_grass | ( | struct Cell_head * | cellhd, |
struct Key_Value ** | projinfo, | ||
struct Key_Value ** | projunits, | ||
OGRSpatialReferenceH | hSRS1, | ||
int | datumtrans | ||
) |
Converts an OGRSpatialReferenceH object to a GRASS co-ordinate system.
cellhd | Pointer to a GRASS Cell_head structure that will have its projection-related members populated with appropriate values |
projinfo | Pointer to a pointer which will have a GRASS Key_Value structure allocated containing a set of GRASS PROJ_INFO values |
projunits | Pointer to a pointer which will have a GRASS Key_Value structure allocated containing a set of GRASS PROJ_UNITS values |
hSRS | OGRSpatialReferenceH object containing the co-ordinate system to be converted |
datumtrans | Index number of datum parameter set to use, 0 to leave unspecified |
Definition at line 421 of file convert.c.
References _, G_create_key_value(), G_debug(), G_find_key_value(), G_free(), G_gisbase(), G_lookup_key_value_from_file(), G_set_key_value(), G_store(), G_strcasecmp(), G_warning(), GPJ__get_datum_params(), list, name, NULL, Cell_head::proj, PROJECTION_LL, PROJECTION_OTHER, PROJECTION_UTM, and Cell_head::zone.
Referenced by GPJ_wkt_to_grass().
const char* GPJ_set_csv_loc | ( | const char * | name | ) |
Definition at line 1010 of file convert.c.
References CSVDIR, G_asprintf(), G_free(), G_gisbase(), name, and NULL.
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.
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 |
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.
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 |
int GPJ_wkt_to_grass | ( | struct Cell_head * | cellhd, |
struct Key_Value ** | projinfo, | ||
struct Key_Value ** | projunits, | ||
const char * | wkt, | ||
int | datumtrans | ||
) |
Converts a WKT projection description to a GRASS co-ordinate system.
cellhd | Pointer to a GRASS Cell_head structure that will have its projection-related members populated with appropriate values |
projinfo | Pointer to a pointer which will have a GRASS Key_Value structure allocated containing a set of GRASS PROJ_INFO values |
projunits | Pointer to a pointer which will have a GRASS Key_Value structure allocated containing a set of GRASS PROJ_UNITS values |
wkt | Well-known Text (WKT) description of the co-ordinate system to be converted |
datumtrans | Index number of datum parameter set to use, 0 to leave unspecified |
Definition at line 978 of file convert.c.
References GPJ_osr_to_grass(), and NULL.
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.
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 |
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.
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 |
int pj_factors | ( | LP | , |
void * | , | ||
double | , | ||
struct FACTORS * | |||
) |
int pj_get_kv | ( | struct pj_info * | info, |
const struct Key_Value * | in_proj_keys, | ||
const struct Key_Value * | in_units_keys | ||
) |
Create a pj_info struct Co-ordinate System definition from a set of PROJ_INFO / PROJ_UNITS-style key-value pairs.
This function takes a GRASS-style co-ordinate system definition as stored in the PROJ_INFO and PROJ_UNITS files and processes it to create a pj_info representation for use in re-projecting with pj_do_proj(). In addition to the parameters passed to it it may also make reference to the system ellipse.table and datum.table files if necessary.
info | Pointer to a pj_info struct (which must already exist) into which the co-ordinate system definition will be placed |
in_proj_keys | PROJ_INFO-style key-value pairs |
in_units_keys | PROJ_UNITS-style key-value pairs |
Definition at line 60 of file get_proj.c.
int pj_get_string | ( | struct pj_info * | info, |
char * | str | ||
) |
Create a pj_info struct Co-ordinate System definition from a string with a sequence of key=value pairs.
This function takes a GRASS- or PROJ style co-ordinate system definition and processes it to create a pj_info representation for use in re-projecting with pj_do_proj(). In addition to the parameters passed to it it may also make reference to the system ellipse.table and datum.table files if necessary.
info | Pointer to a pj_info struct (which must already exist) into which the co-ordinate system definition will be placed |
str | input string with projection definition |
in_units_keys | PROJ_UNITS-style key-value pairs |
Definition at line 339 of file get_proj.c.
Print projection parameters as used by PROJ.4 for input and output co-ordinate systems.
iproj | 'Input' co-ordinate system |
oproj | 'Output' co-ordinate system |
Definition at line 554 of file get_proj.c.
References _, pj_info::def, pj_info::meters, and NULL.