[GRASS-SVN] r72443 - grass/trunk/ps/ps.map
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Mar 20 13:10:29 PDT 2018
Author: mmetz
Date: 2018-03-20 13:10:29 -0700 (Tue, 20 Mar 2018)
New Revision: 72443
Modified:
grass/trunk/ps/ps.map/do_geogrid.c
Log:
ps.map: use new PROJ 5+ API if available
Modified: grass/trunk/ps/ps.map/do_geogrid.c
===================================================================
--- grass/trunk/ps/ps.map/do_geogrid.c 2018-03-20 20:00:20 UTC (rev 72442)
+++ grass/trunk/ps/ps.map/do_geogrid.c 2018-03-20 20:10:29 UTC (rev 72443)
@@ -22,11 +22,14 @@
/* number of segments in curved geographic lines */
#define SEGS 10
+#ifndef HAVE_PROJ_H
static void init_proj(struct pj_info *, struct pj_info *);
+static struct pj_info info_out;
+#endif
+
static void get_ll_bounds(double *, double *, double *, double *);
static void check_coords(double, double, double *, double *, int);
static struct pj_info info_in;
-static struct pj_info info_out;
/********************************************
* Use proj library to create geographic grid
@@ -43,6 +46,9 @@
if (PS.geogrid <= 0)
return 1;
+ if (color_none(&PS.geogrid_color))
+ return 1;
+
grid = (double)PS.geogrid; /* default to degrees */
if (strncmp(PS.geogridunit, "d", 1) == 0)
@@ -62,8 +68,10 @@
* start with first grid line just south of the window north
*/
+#ifndef HAVE_PROJ_H
/* initialize projection stuff */
init_proj(&info_in, &info_out);
+#endif
/* get lat long min max */
/* probably need something like boardwalk ?? */
@@ -82,12 +90,20 @@
n1 = n2 = g;
e1 = west + (ll * ((east - west) / SEGS));
e2 = e1 + ((east - west) / SEGS);
+#ifdef HAVE_PROJ_H
+ if (GPJ_do_proj_ll(&e1, &n1, &info_in, PJ_INV) < 0)
+#else
if (pj_do_proj(&e1, &n1, &info_in, &info_out) < 0)
+#endif
G_fatal_error(_("Error in pj_do_proj"));
check_coords(e1, n1, &lon, &lat, 1);
e1 = lon;
n1 = lat;
+#ifdef HAVE_PROJ_H
+ if (GPJ_do_proj_ll(&e2, &n2, &info_in, PJ_INV) < 0)
+#else
if (pj_do_proj(&e2, &n2, &info_in, &info_out) < 0)
+#endif
G_fatal_error(_("Error in pj_do_proj"));
check_coords(e2, n2, &lon, &lat, 1);
e2 = lon;
@@ -111,12 +127,20 @@
e1 = e2 = g;
n1 = south + (ll * ((north - south) / SEGS));
n2 = n1 + ((north - south) / SEGS);
+#ifdef HAVE_PROJ_H
+ if (GPJ_do_proj_ll(&e1, &n1, &info_in, PJ_INV) < 0)
+#else
if (pj_do_proj(&e1, &n1, &info_in, &info_out) < 0)
+#endif
G_fatal_error(_("Error in pj_do_proj"));
check_coords(e1, n1, &lon, &lat, 2);
e1 = lon;
n1 = lat;
+#ifdef HAVE_PROJ_H
+ if (GPJ_do_proj_ll(&e2, &n2, &info_in, PJ_INV) < 0)
+#else
if (pj_do_proj(&e2, &n2, &info_in, &info_out) < 0)
+#endif
G_fatal_error(_("Error in pj_do_proj"));
check_coords(e2, n2, &lon, &lat, 2);
e2 = lon;
@@ -152,6 +176,11 @@
if (PS.geogrid <= 0 || PS.geogrid_numbers <= 0)
return 1;
+#ifndef HAVE_PROJ_H
+ /* initialize projection stuff */
+ init_proj(&info_in, &info_out);
+#endif
+
grid = (double)PS.geogrid; /* default to degrees */
if (strncmp(PS.geogridunit, "d", 1) == 0)
grid = (double)PS.geogrid; /* degrees */
@@ -185,7 +214,11 @@
for (; g > south; g -= grid) {
e1 = east; /* draw at east boundary */
n1 = g;
+#ifdef HAVE_PROJ_H
+ if (GPJ_do_proj_ll(&e1, &n1, &info_in, PJ_INV) < 0)
+#else
if (pj_do_proj(&e1, &n1, &info_in, &info_out) < 0)
+#endif
G_fatal_error(_("Error in pj_do_proj"));
check_coords(e1, n1, &lon, &lat, 1);
e1 = lon;
@@ -226,7 +259,11 @@
for (; g < east; g += grid) {
e1 = g;
n1 = south; /* draw at south edge */
+#ifdef HAVE_PROJ_H
+ if (GPJ_do_proj_ll(&e1, &n1, &info_in, PJ_INV) < 0)
+#else
if (pj_do_proj(&e1, &n1, &info_in, &info_out) < 0)
+#endif
G_fatal_error(_("Error in pj_do_proj"));
check_coords(e1, n1, &lon, &lat, 2);
e1 = lon;
@@ -257,6 +294,7 @@
return 0;
}
+#ifndef HAVE_PROJ_H
/******************************************************
* initialize projection stuff and return proj structures
********************************************************/
@@ -280,6 +318,7 @@
return;
}
+#endif
/******************************************************
* Use Proj to get min max bounds of region in lat long
@@ -302,7 +341,11 @@
for (ew = PS.w.west; ew <= PS.w.east; ew += PS.w.ew_res) {
e1 = ew;
n1 = PS.w.north;
+#ifdef HAVE_PROJ_H
+ if (GPJ_do_proj_ll(&e1, &n1, &info_in, PJ_FWD) < 0)
+#else
if (pj_do_proj(&e1, &n1, &info_out, &info_in) < 0)
+#endif
G_fatal_error(_("Error in pj_do_proj"));
if (!first) {
north = n1;
@@ -318,7 +361,11 @@
for (ew = PS.w.west; ew <= PS.w.east; ew += PS.w.ew_res) {
e1 = ew;
s1 = PS.w.south;
+#ifdef HAVE_PROJ_H
+ if (GPJ_do_proj_ll(&e1, &s1, &info_in, PJ_FWD) < 0)
+#else
if (pj_do_proj(&e1, &s1, &info_out, &info_in) < 0)
+#endif
G_fatal_error(_("Error in pj_do_proj"));
if (!first) {
south = s1;
@@ -335,7 +382,11 @@
for (ns = PS.w.south; ns <= PS.w.north; ns += PS.w.ns_res) {
e1 = PS.w.east;
n1 = ns;
+#ifdef HAVE_PROJ_H
+ if (GPJ_do_proj_ll(&e1, &n1, &info_in, PJ_FWD) < 0)
+#else
if (pj_do_proj(&e1, &n1, &info_out, &info_in) < 0)
+#endif
G_fatal_error(_("Error in pj_do_proj"));
if (!first) {
east = e1;
@@ -352,7 +403,11 @@
for (ns = PS.w.south; ns <= PS.w.north; ns += PS.w.ns_res) {
w1 = PS.w.west;
n1 = ns;
+#ifdef HAVE_PROJ_H
+ if (GPJ_do_proj_ll(&w1, &n1, &info_in, PJ_FWD) < 0)
+#else
if (pj_do_proj(&w1, &n1, &info_out, &info_in) < 0)
+#endif
G_fatal_error(_("Error in pj_do_proj"));
if (!first) {
west = w1;
@@ -408,17 +463,29 @@
if (proj) {
/* convert original coords to ll */
+#ifdef HAVE_PROJ_H
+ if (GPJ_do_proj_ll(&e, &n, &info_in, PJ_FWD) < 0)
+#else
if (pj_do_proj(&e, &n, &info_out, &info_in) < 0)
+#endif
G_fatal_error(_("Error in pj_do_proj"));
if (par == 1) {
/* lines of latitude -- const. northing */
/* convert correct UTM to ll */
+#ifdef HAVE_PROJ_H
+ if (GPJ_do_proj_ll(&x, &y, &info_in, PJ_FWD) < 0)
+#else
if (pj_do_proj(&x, &y, &info_out, &info_in) < 0)
+#endif
G_fatal_error(_("Error in pj_do_proj"));
/* convert new ll back to coords */
+#ifdef HAVE_PROJ_H
+ if (GPJ_do_proj_ll(&x, &n, &info_in, PJ_INV) < 0)
+#else
if (pj_do_proj(&x, &n, &info_in, &info_out) < 0)
+#endif
G_fatal_error(_("Error in pj_do_proj"));
*lat = n;
*lon = x;
@@ -426,11 +493,19 @@
if (par == 2) {
/* lines of longitude -- const. easting */
/* convert correct UTM to ll */
+#ifdef HAVE_PROJ_H
+ if (GPJ_do_proj_ll(&x, &y, &info_in, PJ_FWD) < 0)
+#else
if (pj_do_proj(&x, &y, &info_out, &info_in) < 0)
+#endif
G_fatal_error(_("Error in pj_do_proj"));
/* convert new ll back to coords */
+#ifdef HAVE_PROJ_H
+ if (GPJ_do_proj_ll(&e, &y, &info_in, PJ_INV) < 0)
+#else
if (pj_do_proj(&e, &y, &info_in, &info_out) < 0)
+#endif
G_fatal_error(_("Error in pj_do_proj"));
*lat = y;
*lon = e;
More information about the grass-commit
mailing list