Преглед изворни кода

ps.map: use new GRASS API for coordinate transformation

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@72522 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz пре 7 година
родитељ
комит
b4cc804b35
1 измењених фајлова са 62 додато и 54 уклоњено
  1. 62 54
      ps/ps.map/do_geogrid.c

+ 62 - 54
ps/ps.map/do_geogrid.c

@@ -22,14 +22,11 @@
 /* number of segments in curved geographic lines */
 /* number of segments in curved geographic lines */
 #define SEGS 10
 #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 get_ll_bounds(double *, double *, double *, double *);
 static void check_coords(double, double, double *, double *, int);
 static void check_coords(double, double, double *, double *, int);
-static struct pj_info info_in;
 
 
 /********************************************
 /********************************************
  * Use proj library to create geographic grid
  * Use proj library to create geographic grid
@@ -68,10 +65,8 @@ int do_geogrid(void)
      * start with first grid line just south of the window north
      * start with first grid line just south of the window north
      */
      */
 
 
-#ifndef HAVE_PROJ_H
     /* initialize projection stuff */
     /* initialize projection stuff */
-    init_proj(&info_in, &info_out);
-#endif
+    init_proj();
 
 
     /* get lat long min max */
     /* get lat long min max */
     /* probably need something like boardwalk ?? */
     /* probably need something like boardwalk ?? */
@@ -90,13 +85,15 @@ int do_geogrid(void)
 	    n1 = n2 = g;
 	    n1 = n2 = g;
 	    e1 = west + (ll * ((east - west) / SEGS));
 	    e1 = west + (ll * ((east - west) / SEGS));
 	    e2 = e1 + ((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);
 	    check_coords(e1, n1, &lon, &lat, 1);
 	    e1 = lon;
 	    e1 = lon;
 	    n1 = lat;
 	    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);
 	    check_coords(e2, n2, &lon, &lat, 1);
 	    e2 = lon;
 	    e2 = lon;
 	    n2 = lat;
 	    n2 = lat;
@@ -119,13 +116,15 @@ int do_geogrid(void)
 	    e1 = e2 = g;
 	    e1 = e2 = g;
 	    n1 = south + (ll * ((north - south) / SEGS));
 	    n1 = south + (ll * ((north - south) / SEGS));
 	    n2 = n1 + ((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);
 	    check_coords(e1, n1, &lon, &lat, 2);
 	    e1 = lon;
 	    e1 = lon;
 	    n1 = lat;
 	    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);
 	    check_coords(e2, n2, &lon, &lat, 2);
 	    e2 = lon;
 	    e2 = lon;
 	    n2 = lat;
 	    n2 = lat;
@@ -160,10 +159,8 @@ int do_geogrid_numbers(void)
     if (PS.geogrid <= 0 || PS.geogrid_numbers <= 0)
     if (PS.geogrid <= 0 || PS.geogrid_numbers <= 0)
 	return 1;
 	return 1;
 
 
-#ifndef HAVE_PROJ_H
     /* initialize projection stuff */
     /* initialize projection stuff */
-    init_proj(&info_in, &info_out);
-#endif
+    init_proj();
 
 
     grid = (double)PS.geogrid;	/* default to degrees */
     grid = (double)PS.geogrid;	/* default to degrees */
     if (strncmp(PS.geogridunit, "d", 1) == 0)
     if (strncmp(PS.geogridunit, "d", 1) == 0)
@@ -198,8 +195,9 @@ int do_geogrid_numbers(void)
     for (; g > south; g -= grid) {
     for (; g > south; g -= grid) {
 	e1 = east;		/* draw at east boundary */
 	e1 = east;		/* draw at east boundary */
 	n1 = g;
 	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);
 	check_coords(e1, n1, &lon, &lat, 1);
 	e1 = lon;
 	e1 = lon;
 	n1 = lat;
 	n1 = lat;
@@ -239,8 +237,9 @@ int do_geogrid_numbers(void)
     for (; g < east; g += grid) {
     for (; g < east; g += grid) {
 	e1 = g;
 	e1 = g;
 	n1 = south;		/* draw at south edge */
 	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);
 	check_coords(e1, n1, &lon, &lat, 2);
 	e1 = lon;
 	e1 = lon;
 	n1 = lat;
 	n1 = lat;
@@ -270,31 +269,31 @@ int do_geogrid_numbers(void)
     return 0;
     return 0;
 }
 }
 
 
-#ifndef HAVE_PROJ_H
 /******************************************************
 /******************************************************
  * initialize projection stuff and return proj structures
  * 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 */
     /* 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_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;
     return;
 
 
 }
 }
-#endif
 
 
 /******************************************************
 /******************************************************
  * Use Proj to get min max bounds of region in lat long
  * Use Proj to get min max bounds of region in lat long
@@ -317,8 +316,9 @@ void get_ll_bounds(double *w, double *e, double *s, double *n)
     for (ew = PS.w.west; ew <= PS.w.east; ew += PS.w.ew_res) {
     for (ew = PS.w.west; ew <= PS.w.east; ew += PS.w.ew_res) {
 	e1 = ew;
 	e1 = ew;
 	n1 = PS.w.north;
 	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) {
 	if (!first) {
 	    north = n1;
 	    north = n1;
 	    first = 1;
 	    first = 1;
@@ -333,8 +333,9 @@ void get_ll_bounds(double *w, double *e, double *s, double *n)
     for (ew = PS.w.west; ew <= PS.w.east; ew += PS.w.ew_res) {
     for (ew = PS.w.west; ew <= PS.w.east; ew += PS.w.ew_res) {
 	e1 = ew;
 	e1 = ew;
 	s1 = PS.w.south;
 	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) {
 	if (!first) {
 	    south = s1;
 	    south = s1;
 	    first = 1;
 	    first = 1;
@@ -350,8 +351,9 @@ void get_ll_bounds(double *w, double *e, double *s, double *n)
     for (ns = PS.w.south; ns <= PS.w.north; ns += PS.w.ns_res) {
     for (ns = PS.w.south; ns <= PS.w.north; ns += PS.w.ns_res) {
 	e1 = PS.w.east;
 	e1 = PS.w.east;
 	n1 = ns;
 	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) {
 	if (!first) {
 	    east = e1;
 	    east = e1;
 	    first = 1;
 	    first = 1;
@@ -367,8 +369,9 @@ void get_ll_bounds(double *w, double *e, double *s, double *n)
     for (ns = PS.w.south; ns <= PS.w.north; ns += PS.w.ns_res) {
     for (ns = PS.w.south; ns <= PS.w.north; ns += PS.w.ns_res) {
 	w1 = PS.w.west;
 	w1 = PS.w.west;
 	n1 = ns;
 	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) {
 	if (!first) {
 	    west = w1;
 	    west = w1;
 	    first = 1;
 	    first = 1;
@@ -423,30 +426,35 @@ void check_coords(double e, double n, double *lon, double *lat, int par)
 
 
     if (proj) {
     if (proj) {
 	/* convert original coords to ll */
 	/* 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) {
 	if (par == 1) {
 	    /* lines of latitude -- const. northing */
 	    /* lines of latitude -- const. northing */
 	    /* convert correct UTM to ll */
 	    /* 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 */
 	    /* 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;
 	    *lat = n;
 	    *lon = x;
 	    *lon = x;
 	}
 	}
 	if (par == 2) {
 	if (par == 2) {
 	    /* lines of longitude -- const. easting */
 	    /* lines of longitude -- const. easting */
 	    /* convert correct UTM to ll */
 	    /* 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 */
 	    /* 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;
 	    *lat = y;
 	    *lon = e;
 	    *lon = e;
 	}
 	}