[GRASS-SVN] r53305 - grass/trunk/general/g.proj

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Oct 3 05:56:00 PDT 2012


Author: pkelly
Date: 2012-10-03 05:55:59 -0700 (Wed, 03 Oct 2012)
New Revision: 53305

Modified:
   grass/trunk/general/g.proj/Makefile
   grass/trunk/general/g.proj/datumtrans.c
   grass/trunk/general/g.proj/g.proj.html
   grass/trunk/general/g.proj/local_proto.h
   grass/trunk/general/g.proj/main.c
Log:
Always also change the ellipsoid when overriding the datum


Modified: grass/trunk/general/g.proj/Makefile
===================================================================
--- grass/trunk/general/g.proj/Makefile	2012-10-03 12:26:25 UTC (rev 53304)
+++ grass/trunk/general/g.proj/Makefile	2012-10-03 12:55:59 UTC (rev 53305)
@@ -2,7 +2,7 @@
 
 PGM = g.proj
 
-EXTRA_INC = $(PROJINC)
+EXTRA_INC = $(PROJINC) -Wall
 LIBES = $(GPROJLIB) $(GISLIB) $(GDALLIBS) $(PROJLIB)
 DEPENDENCIES = $(GPROJDEP) $(GISDEP)
 

Modified: grass/trunk/general/g.proj/datumtrans.c
===================================================================
--- grass/trunk/general/g.proj/datumtrans.c	2012-10-03 12:26:25 UTC (rev 53304)
+++ grass/trunk/general/g.proj/datumtrans.c	2012-10-03 12:55:59 UTC (rev 53305)
@@ -25,12 +25,71 @@
 
 /**
  * 
- * \brief Add or replace datum transformation parameters to the current
- *        co-ordinate system definition
+ * \brief Add or replace datum to the current co-ordinate system definition
  * 
  * \param datum       Use this datum (overrides any datum found in the
  *                    current co-ordinate system definition).
  * 
+ * \return            1 if a change was made, 0 if not.
+ **/
+
+int set_datum(char *datum)
+{
+    struct gpj_datum dstruct;
+    struct Key_Value *temp_projinfo;
+    int i;
+
+    if (cellhd.proj == PROJECTION_XY)
+	return 0;
+
+    if (!datum || GPJ_get_datum_by_name(datum, &dstruct) < 0)
+    {
+	G_fatal_error(_("Invalid datum code <%s>"), datum);
+	return 0;
+    }
+
+    temp_projinfo = G_create_key_value();
+
+    /* Copy old PROJ_INFO, skipping out any keys related
+     * to datum or ellipsoid parameters */
+    for (i = 0; i < projinfo->nitems; i++) {
+        if (strcmp(projinfo->key[i], "datum") == 0
+	    || strcmp(projinfo->key[i], "dx") == 0
+	    || strcmp(projinfo->key[i], "dy") == 0
+	    || strcmp(projinfo->key[i], "dz") == 0
+	    || strcmp(projinfo->key[i], "datumparams") == 0
+	    || strcmp(projinfo->key[i], "nadgrids") == 0
+	    || strcmp(projinfo->key[i], "towgs84") == 0
+	    || strcmp(projinfo->key[i], "ellps") == 0
+	    || strcmp(projinfo->key[i], "a") == 0
+	    || strcmp(projinfo->key[i], "b") == 0
+	    || strcmp(projinfo->key[i], "es") == 0
+	    || strcmp(projinfo->key[i], "f") == 0
+	    || strcmp(projinfo->key[i], "rf") == 0)
+	    continue;
+
+	G_set_key_value(projinfo->key[i], projinfo->value[i],
+			temp_projinfo);
+    }
+
+    /* Finally add datum and ellipsoid names */
+    G_set_key_value("datum", dstruct.name, temp_projinfo);
+    G_message(_("Datum set to <%s>"), dstruct.name);
+    G_set_key_value("ellps", dstruct.ellps, temp_projinfo);
+    G_message(_("Ellipsoid set to <%s>"), dstruct.ellps);
+
+    /* Destroy original key/value structure and replace with new one */
+    G_free_key_value(projinfo);
+    projinfo = temp_projinfo;
+
+    return 1;
+}
+
+/**
+ * 
+ * \brief Add or replace datum transformation parameters to the current
+ *        co-ordinate system definition
+ * 
  * \param datumtrans  Index number of parameter set to use, 0 to leave
  *                    unspecifed (or remove specific parameters, leaving just
  *                    the datum name), -1 to list the available parameter
@@ -42,25 +101,18 @@
  * \return            1 if a change was made, 0 if not.
  **/
 
-int set_datumtrans(char *datum, int datumtrans, int force)
+int set_datumtrans(int datumtrans, int force)
 {
+    char *params, *datum = NULL;
     int paramsets, status;
 
     if (cellhd.proj == PROJECTION_XY)
 	return 0;
 
-    if (datum)
-	/* datum name provided; set status to 1 to indicate no parameters available */
-	status = 1;
-    else {
-	/* extract datum name and parameter status from input co-ordinate system */
-	char *params;
+    status = GPJ__get_datum_params(projinfo, &datum, &params);
+    G_debug(3, "set_datumtrans(): GPJ__get_datum_params() status=%d", status);
+    G_free(params);
 
-	status = GPJ__get_datum_params(projinfo, &datum, &params);
-	G_debug(3, "set_datumtrans(): GPJ__get_datum_params() status=%d", status);
-	G_free(params);
-    }
-
     if (datum) {
 	/* A datum name is specified; need to determine if
 	 * there are parameters to choose from for this datum */
@@ -147,8 +199,7 @@
 	/* Copy old PROJ_INFO, skipping out any keys related
 	 * to datum parameters */
 	for (i = 0; i < projinfo->nitems; i++) {
-	    if (strcmp(projinfo->key[i], "datum") == 0
-		|| strcmp(projinfo->key[i], "dx") == 0
+	    if (strcmp(projinfo->key[i], "dx") == 0
 		|| strcmp(projinfo->key[i], "dy") == 0
 		|| strcmp(projinfo->key[i], "dz") == 0
 		|| strcmp(projinfo->key[i], "datumparams") == 0
@@ -160,9 +211,7 @@
 			    temp_projinfo);
 	}
 
-	/* Finally (re-)add datum name and add new parameters (if we have them) */
-	G_set_key_value("datum", datum, temp_projinfo);
-	G_message(_("Datum set to <%s>"), datum);
+	/* Finally add new parameters (if we have them) */
 	if (chosenparams != NULL) {
 	    /* Now split 'chosenparams' into key/value format */
 	    paramkey = strtok(chosenparams, "=");

Modified: grass/trunk/general/g.proj/g.proj.html
===================================================================
--- grass/trunk/general/g.proj/g.proj.html	2012-10-03 12:26:25 UTC (rev 53304)
+++ grass/trunk/general/g.proj/g.proj.html	2012-10-03 12:55:59 UTC (rev 53305)
@@ -53,8 +53,7 @@
 supplied using the <em>datum</em> parameter. This will override any
 datum contained in the input co-ordinate system, and discard
 any datum transformation parameters. Enter datum=<em>list</em> to return a
-list of all the datums supported by GRASS. Note that the -t flag is
-implicit when a value for <em>datum</em> is specified. Since any
+list of all the datums supported by GRASS. Since any
 existing datum transformation parameters will have been discarded, the
 <em>datumtrans</em> parameter should in general always be used in
 conjunction with <em>datum</em>.

Modified: grass/trunk/general/g.proj/local_proto.h
===================================================================
--- grass/trunk/general/g.proj/local_proto.h	2012-10-03 12:26:25 UTC (rev 53304)
+++ grass/trunk/general/g.proj/local_proto.h	2012-10-03 12:55:59 UTC (rev 53305)
@@ -21,7 +21,8 @@
 #endif
 
 /* datumtrans.c */
-int set_datumtrans(char *, int, int);
+int set_datum(char *);
+int set_datumtrans(int, int);
 
 /* create.c */
 void create_location(char *);

Modified: grass/trunk/general/g.proj/main.c
===================================================================
--- grass/trunk/general/g.proj/main.c	2012-10-03 12:26:25 UTC (rev 53304)
+++ grass/trunk/general/g.proj/main.c	2012-10-03 12:55:59 UTC (rev 53305)
@@ -258,8 +258,12 @@
 	&& (projinfo == NULL || projunits == NULL))
 	G_fatal_error(_("Projection files missing"));
 
+    /* Override input datum if requested */
+    if(datum->answer)
+	set_datum(datum->answer);
+
     /* Set Datum Parameters if necessary or requested */
-    set_datumtrans(datum->answer, atoi(dtrans->answer), forcedatumtrans->answer);
+    set_datumtrans(atoi(dtrans->answer), forcedatumtrans->answer);
 
 
     /* Output */



More information about the grass-commit mailing list