GRASS GIS 8 Programmer's Manual  8.4.0dev(2024)-6c790bf5c0
convert.c File Reference

GProj Library - Functions for manipulating co-ordinate system representations. More...

#include <grass/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <grass/gis.h>
#include <grass/gprojects.h>
#include <grass/glocale.h>
#include <cpl_csv.h>
#include "local_proto.h"
Include dependency graph for convert.c:

Go to the source code of this file.

Macros

#define CSVDIR   "/etc/proj/ogr_csv"
 

Functions

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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
const char * GPJ_set_csv_loc (const char *name)
 

Variables

struct gpj_units gpj_units []
 

Detailed Description

GProj Library - Functions for manipulating co-ordinate system representations.

(C) 2003-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.

Author
Paul Kelly, Frank Warmerdam, Markus Metz

Definition in file convert.c.

Macro Definition Documentation

◆ CSVDIR

#define CSVDIR   "/etc/proj/ogr_csv"

Definition at line 30 of file convert.c.

Function Documentation

◆ GPJ_grass_to_osr()

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.

Parameters
proj_infoSet of GRASS PROJ_INFO key/value pairs
proj_unitsSet of GRASS PROJ_UNIT key/value pairs
Returns
OGRSpatialReferenceH object representing the co-ordinate system defined by proj_info and proj_units or NULL if it fails

Definition at line 168 of file convert.c.

◆ GPJ_grass_to_osr2()

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.

Todo:
Merge with GPJ_grass_to_osr() in GRASS 8.
Parameters
proj_infoSet of GRASS PROJ_INFO key/value pairs
proj_unitsSet of GRASS PROJ_UNIT key/value pairs
proj_epsgSet of GRASS PROJ_EPSG key/value pairs
Returns
OGRSpatialReferenceH object representing the co-ordinate system defined by proj_info and proj_units or NULL if it fails

Definition at line 359 of file convert.c.

◆ GPJ_grass_to_wkt()

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.

Parameters
proj_infoSet of GRASS PROJ_INFO key/value pairs
proj_unitsSet of GRASS PROJ_UNIT key/value pairs
esri_styleboolean Output ESRI-style WKT (Use OSRMorphToESRI() function provided by OGR library)
prettifyboolean Use linebreaks and indents to 'prettify' output WKT string (Use OSRExportToPrettyWkt() function in OGR)
Returns
Pointer to a string containing the co-ordinate system in WKT format
NULL on error

Definition at line 119 of file convert.c.

◆ GPJ_grass_to_wkt2()

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.

Todo:
Merge with GPJ_grass_to_wkt() in GRASS 8.
Parameters
proj_infoSet of GRASS PROJ_INFO key/value pairs
proj_unitsSet of GRASS PROJ_UNIT key/value pairs
proj_epsgSet of GRASS PROJ_EPSG key/value pairs
esri_styleboolean Output ESRI-style WKT (Use OSRMorphToESRI() function provided by OGR library)
prettifyboolean Use linebreaks and indents to 'prettify' output WKT string (Use OSRExportToPrettyWkt() function in OGR)
Returns
Pointer to a string containing the co-ordinate system in WKT format
NULL on error

Definition at line 150 of file convert.c.

◆ GPJ_osr_to_grass()

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.

Parameters
cellhdPointer to a GRASS Cell_head structure that will have its projection-related members populated with appropriate values
projinfoPointer to a pointer which will have a GRASS Key_Value structure allocated containing a set of GRASS PROJ_INFO values
projunitsPointer to a pointer which will have a GRASS Key_Value structure allocated containing a set of GRASS PROJ_UNITS values
hSRSOGRSpatialReferenceH object containing the co-ordinate system to be converted
datumtransIndex number of datum parameter set to use, 0 to leave unspecified
Returns
2 if a projected or lat/long co-ordinate system has been defined
1 if an unreferenced XY co-ordinate system has been defined

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().

◆ GPJ_set_csv_loc()

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.

◆ GPJ_wkt_to_grass()

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.

Parameters
cellhdPointer to a GRASS Cell_head structure that will have its projection-related members populated with appropriate values
projinfoPointer to a pointer which will have a GRASS Key_Value structure allocated containing a set of GRASS PROJ_INFO values
projunitsPointer to a pointer which will have a GRASS Key_Value structure allocated containing a set of GRASS PROJ_UNITS values
wktWell-known Text (WKT) description of the co-ordinate system to be converted
datumtransIndex number of datum parameter set to use, 0 to leave unspecified
Returns
2 if a projected or lat/long co-ordinate system has been defined
1 if an unreferenced XY co-ordinate system has been defined
-1 on error

Definition at line 978 of file convert.c.

References GPJ_osr_to_grass(), and NULL.

Variable Documentation

◆ gpj_units

struct gpj_units gpj_units[]
Initial value:
= {
{"km", "1000.", "Kilometer", 1000.0},
{"m", "1.", "Meter", 1.0},
{"dm", "1/10", "Decimeter", 0.1},
{"cm", "1/100", "Centimeter", 0.01},
{"mm", "1/1000", "Millimeter", 0.001},
{"kmi", "1852.0", "International Nautical Mile", 1852.0},
{"in", "0.0254", "International Inch", 0.0254},
{"ft", "0.3048", "International Foot", 0.3048},
{"yd", "0.9144", "International Yard", 0.9144},
{"mi", "1609.344", "International Statute Mile", 1609.344},
{"fath", "1.8288", "International Fathom", 1.8288},
{"ch", "20.1168", "International Chain", 20.1168},
{"link", "0.201168", "International Link", 0.201168},
{"us-in", "1./39.37", "U.S. Surveyor's Inch", 0.0254},
{"us-ft", "0.304800609601219", "U.S. Surveyor's Foot", 0.304800609601219},
{"us-yd", "0.914401828803658", "U.S. Surveyor's Yard", 0.914401828803658},
{"us-ch", "20.11684023368047", "U.S. Surveyor's Chain", 20.11684023368047},
{"us-mi", "1609.347218694437", "U.S. Surveyor's Statute Mile",
1609.347218694437},
{"ind-yd", "0.91439523", "Indian Yard", 0.91439523},
{"ind-ft", "0.30479841", "Indian Foot", 0.30479841},
{"ind-ch", "20.11669506", "Indian Chain", 20.11669506},
{NULL, NULL, NULL, 0.0}}
#define NULL
Definition: ccmath.h:32

Definition at line 32 of file convert.c.