[GRASS-SVN] r72522 - grass/trunk/ps/ps.map

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Mar 23 02:27:40 PDT 2018


Author: mmetz
Date: 2018-03-23 02:27:40 -0700 (Fri, 23 Mar 2018)
New Revision: 72522

Modified:
   grass/trunk/ps/ps.map/do_geogrid.c
Log:
ps.map: use new GRASS API for coordinate transformation

Modified: grass/trunk/ps/ps.map/do_geogrid.c
===================================================================
--- grass/trunk/ps/ps.map/do_geogrid.c	2018-03-23 09:27:06 UTC (rev 72521)
+++ grass/trunk/ps/ps.map/do_geogrid.c	2018-03-23 09:27:40 UTC (rev 72522)
@@ -22,14 +22,11 @@
 /* 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 init_proj(void);
+static struct pj_info info_in, info_out, info_trans;
 
 static void get_ll_bounds(double *, double *, double *, double *);
 static void check_coords(double, double, double *, double *, int);
-static struct pj_info info_in;
 
 /********************************************
  * Use proj library to create geographic grid
@@ -68,10 +65,8 @@
      * 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
+    init_proj();
 
     /* get lat long min max */
     /* probably need something like boardwalk ?? */
@@ -90,13 +85,15 @@
 	    n1 = n2 = g;
 	    e1 = west + (ll * ((east - west) / SEGS));
 	    e2 = e1 + ((east - west) / SEGS);
-	    if (GPJ_do_proj_ll(&e1, &n1, &info_in, PJ_INV) < 0)
-		G_fatal_error(_("Error in pj_do_proj"));
+	    if (GPJ_transform(&info_in, &info_out, &info_trans, PJ_INV,
+			      &e1, &n1, NULL) < 0)
+		G_fatal_error(_("Error in GPJ_transform"));
 	    check_coords(e1, n1, &lon, &lat, 1);
 	    e1 = lon;
 	    n1 = lat;
-	    if (GPJ_do_proj_ll(&e2, &n2, &info_in, PJ_INV) < 0)
-		G_fatal_error(_("Error in pj_do_proj"));
+	    if (GPJ_transform(&info_in, &info_out, &info_trans, PJ_INV,
+			      &e2, &n2, NULL) < 0)
+		G_fatal_error(_("Error in GPJ_transform"));
 	    check_coords(e2, n2, &lon, &lat, 1);
 	    e2 = lon;
 	    n2 = lat;
@@ -119,13 +116,15 @@
 	    e1 = e2 = g;
 	    n1 = south + (ll * ((north - south) / SEGS));
 	    n2 = n1 + ((north - south) / SEGS);
-	    if (GPJ_do_proj_ll(&e1, &n1, &info_in, PJ_INV) < 0)
-		G_fatal_error(_("Error in pj_do_proj"));
+	    if (GPJ_transform(&info_in, &info_out, &info_trans, PJ_INV,
+			      &e1, &n1, NULL) < 0)
+		G_fatal_error(_("Error in GPJ_transform"));
 	    check_coords(e1, n1, &lon, &lat, 2);
 	    e1 = lon;
 	    n1 = lat;
-	    if (GPJ_do_proj_ll(&e2, &n2, &info_in, PJ_INV) < 0)
-		G_fatal_error(_("Error in pj_do_proj"));
+	    if (GPJ_transform(&info_in, &info_out, &info_trans, PJ_INV,
+			      &e2, &n2, NULL) < 0)
+		G_fatal_error(_("Error in GPJ_transform"));
 	    check_coords(e2, n2, &lon, &lat, 2);
 	    e2 = lon;
 	    n2 = lat;
@@ -160,10 +159,8 @@
     if (PS.geogrid <= 0 || PS.geogrid_numbers <= 0)
 	return 1;
 
-#ifndef HAVE_PROJ_H
     /* initialize projection stuff */
-    init_proj(&info_in, &info_out);
-#endif
+    init_proj();
 
     grid = (double)PS.geogrid;	/* default to degrees */
     if (strncmp(PS.geogridunit, "d", 1) == 0)
@@ -198,8 +195,9 @@
     for (; g > south; g -= grid) {
 	e1 = east;		/* draw at east boundary */
 	n1 = g;
-	if (GPJ_do_proj_ll(&e1, &n1, &info_in, PJ_INV) < 0)
-	    G_fatal_error(_("Error in pj_do_proj"));
+	if (GPJ_transform(&info_in, &info_out, &info_trans, PJ_INV,
+			  &e1, &n1, NULL) < 0)
+	    G_fatal_error(_("Error in GPJ_transform"));
 	check_coords(e1, n1, &lon, &lat, 1);
 	e1 = lon;
 	n1 = lat;
@@ -239,8 +237,9 @@
     for (; g < east; g += grid) {
 	e1 = g;
 	n1 = south;		/* draw at south edge */
-	if (GPJ_do_proj_ll(&e1, &n1, &info_in, PJ_INV) < 0)
-	    G_fatal_error(_("Error in pj_do_proj"));
+	if (GPJ_transform(&info_in, &info_out, &info_trans, PJ_INV,
+			  &e1, &n1, NULL) < 0)
+	    G_fatal_error(_("Error in GPJ_transform"));
 	check_coords(e1, n1, &lon, &lat, 2);
 	e1 = lon;
 	n1 = lat;
@@ -270,31 +269,31 @@
     return 0;
 }
 
-#ifndef HAVE_PROJ_H
 /******************************************************
  * initialize projection stuff and return proj structures
 ********************************************************/
-void init_proj(struct pj_info *info_in, struct pj_info *info_out)
+void init_proj(void)
 {
-    struct Key_Value *out_proj_keys, *out_unit_keys;
+    struct Key_Value *in_proj_keys, *in_unit_keys;
 
     /* Proj stuff for geo grid */
-    /* Out Info */
-    out_proj_keys = G_get_projinfo();
-    out_unit_keys = G_get_projunits();
-    if (pj_get_kv(info_out, out_proj_keys, out_unit_keys) < 0)
+    /* In Info (current location) */
+    in_proj_keys = G_get_projinfo();
+    in_unit_keys = G_get_projunits();
+    if (pj_get_kv(&info_in, in_proj_keys, in_unit_keys) < 0)
 	G_fatal_error(_("Can't get projection key values of current location"));
-    G_free_key_value(out_proj_keys);
-    G_free_key_value(out_unit_keys);
+    G_free_key_value(in_proj_keys);
+    G_free_key_value(in_unit_keys);
 
-    /* In Info */
-    if (GPJ_get_equivalent_latlong(info_in, info_out) < 0)
-	G_fatal_error(_("Unable to set up lat/long projection parameters"));
+    /* Out Info (latlong equivalent of In Info */
+    info_out.pj = NULL;
 
+    if (GPJ_init_transform(&info_in, &info_out, &info_trans) < 0)
+	G_fatal_error(_("Unable to initialize coordinate transformation"));
+
     return;
 
 }
-#endif
 
 /******************************************************
  * Use Proj to get min max bounds of region in lat long
@@ -317,8 +316,9 @@
     for (ew = PS.w.west; ew <= PS.w.east; ew += PS.w.ew_res) {
 	e1 = ew;
 	n1 = PS.w.north;
-	if (GPJ_do_proj_ll(&e1, &n1, &info_in, PJ_FWD) < 0)
-	    G_fatal_error(_("Error in pj_do_proj"));
+	if (GPJ_transform(&info_in, &info_out, &info_trans, PJ_FWD,
+	                  &e1, &n1, NULL) < 0)
+	    G_fatal_error(_("Error in GPJ_transform"));
 	if (!first) {
 	    north = n1;
 	    first = 1;
@@ -333,8 +333,9 @@
     for (ew = PS.w.west; ew <= PS.w.east; ew += PS.w.ew_res) {
 	e1 = ew;
 	s1 = PS.w.south;
-	if (GPJ_do_proj_ll(&e1, &s1, &info_in, PJ_FWD) < 0)
-	    G_fatal_error(_("Error in pj_do_proj"));
+	if (GPJ_transform(&info_in, &info_out, &info_trans, PJ_FWD,
+	                  &e1, &s1, NULL) < 0)
+	    G_fatal_error(_("Error in GPJ_transform"));
 	if (!first) {
 	    south = s1;
 	    first = 1;
@@ -350,8 +351,9 @@
     for (ns = PS.w.south; ns <= PS.w.north; ns += PS.w.ns_res) {
 	e1 = PS.w.east;
 	n1 = ns;
-	if (GPJ_do_proj_ll(&e1, &n1, &info_in, PJ_FWD) < 0)
-	    G_fatal_error(_("Error in pj_do_proj"));
+	if (GPJ_transform(&info_in, &info_out, &info_trans, PJ_FWD,
+	                  &e1, &n1, NULL) < 0)
+	    G_fatal_error(_("Error in GPJ_transform"));
 	if (!first) {
 	    east = e1;
 	    first = 1;
@@ -367,8 +369,9 @@
     for (ns = PS.w.south; ns <= PS.w.north; ns += PS.w.ns_res) {
 	w1 = PS.w.west;
 	n1 = ns;
-	if (GPJ_do_proj_ll(&w1, &n1, &info_in, PJ_FWD) < 0)
-	    G_fatal_error(_("Error in pj_do_proj"));
+	if (GPJ_transform(&info_in, &info_out, &info_trans, PJ_FWD,
+	                  &w1, &n1, NULL) < 0)
+	    G_fatal_error(_("Error in GPJ_transform"));
 	if (!first) {
 	    west = w1;
 	    first = 1;
@@ -423,18 +426,21 @@
 
     if (proj) {
 	/* convert original coords to ll */
-	if (GPJ_do_proj_ll(&e, &n, &info_in, PJ_FWD) < 0)
-	    G_fatal_error(_("Error in pj_do_proj"));
+	if (GPJ_transform(&info_in, &info_out, &info_trans, PJ_FWD,
+	                  &e, &n, NULL) < 0)
+	    G_fatal_error(_("Error in GPJ_transform"));
 
 	if (par == 1) {
 	    /* lines of latitude -- const. northing */
 	    /* convert correct UTM to ll */
-	    if (GPJ_do_proj_ll(&x, &y, &info_in, PJ_FWD) < 0)
-		G_fatal_error(_("Error in pj_do_proj"));
+	    if (GPJ_transform(&info_in, &info_out, &info_trans, PJ_FWD,
+			      &x, &y, NULL) < 0)
+		G_fatal_error(_("Error in GPJ_transform"));
 
 	    /* convert new ll back to coords */
-	    if (GPJ_do_proj_ll(&x, &n, &info_in, PJ_INV) < 0)
-		G_fatal_error(_("Error in pj_do_proj"));
+	    if (GPJ_transform(&info_in, &info_out, &info_trans, PJ_INV,
+			      &x, &n, NULL) < 0)
+		G_fatal_error(_("Error in GPJ_transform"));
 	    *lat = n;
 	    *lon = x;
 	}
@@ -441,12 +447,14 @@
 	if (par == 2) {
 	    /* lines of longitude -- const. easting */
 	    /* convert correct UTM to ll */
-	    if (GPJ_do_proj_ll(&x, &y, &info_in, PJ_FWD) < 0)
-		G_fatal_error(_("Error in pj_do_proj"));
+	    if (GPJ_transform(&info_in, &info_out, &info_trans, PJ_FWD,
+			      &x, &y, NULL) < 0)
+		G_fatal_error(_("Error in GPJ_transform"));
 
 	    /* convert new ll back to coords */
-	    if (GPJ_do_proj_ll(&e, &y, &info_in, PJ_INV) < 0)
-		G_fatal_error(_("Error in pj_do_proj"));
+	    if (GPJ_transform(&info_in, &info_out, &info_trans, PJ_INV,
+			      &e, &y, NULL) < 0)
+		G_fatal_error(_("Error in GPJ_transform"));
 	    *lat = y;
 	    *lon = e;
 	}



More information about the grass-commit mailing list