aboutsummaryrefslogtreecommitdiff
path: root/src/pj_datum_set.c
diff options
context:
space:
mode:
authorFrank Warmerdam <warmerdam@pobox.com>2000-07-06 23:32:27 +0000
committerFrank Warmerdam <warmerdam@pobox.com>2000-07-06 23:32:27 +0000
commitc5487d590fd83070fa595e0c93ab57e0acc09489 (patch)
tree3bb8bb64da4ed5f84169355f15490ba9c310063a /src/pj_datum_set.c
parente786437af7935bbfc6519e25826ac647a1602c74 (diff)
downloadPROJ-c5487d590fd83070fa595e0c93ab57e0acc09489.tar.gz
PROJ-c5487d590fd83070fa595e0c93ab57e0acc09489.zip
New
git-svn-id: http://svn.osgeo.org/metacrs/proj/trunk@848 4e78687f-474d-0410-85f9-8d5e500ac6b2
Diffstat (limited to 'src/pj_datum_set.c')
-rw-r--r--src/pj_datum_set.c132
1 files changed, 132 insertions, 0 deletions
diff --git a/src/pj_datum_set.c b/src/pj_datum_set.c
new file mode 100644
index 00000000..417479a5
--- /dev/null
+++ b/src/pj_datum_set.c
@@ -0,0 +1,132 @@
+/******************************************************************************
+ * $Id$
+ *
+ * Project: PROJ.4
+ * Purpose: Apply datum definition to PJ structure from initialization string.
+ * Author: Frank Warmerdam, warmerda@home.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2000, Frank Warmerdam
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ******************************************************************************
+ *
+ * $Log$
+ * Revision 1.1 2000/07/06 23:32:27 warmerda
+ * New
+ *
+ */
+
+#include <projects.h>
+#include <string.h>
+
+/************************************************************************/
+/* pj_datum_set() */
+/************************************************************************/
+
+int pj_datum_set(paralist *pl, PJ *projdef)
+
+{
+ const char *name, *towgs84, *nadgrids;
+
+ projdef->datum_type = PJD_UNKNOWN;
+
+/* -------------------------------------------------------------------- */
+/* Is there a datum definition in the parameters list? If so, */
+/* add the defining values to the parameter list. Note that */
+/* this will append the ellipse definition as well as the */
+/* towgs84= and related parameters. It should also be pointed */
+/* out that the addition is permanent rather than temporary */
+/* like most other keyword expansion so that the ellipse */
+/* definition will last into the pj_ell_set() function called */
+/* after this one. */
+/* -------------------------------------------------------------------- */
+ if( (name = pj_param(pl,"sdatum").s) != NULL )
+ {
+ paralist *curr;
+ const char *s;
+ int i;
+
+ /* find the end of the list, so we can add to it */
+ for (curr = pl; curr && curr->next ; curr = curr->next) {}
+
+ /* find the datum definition */
+ for (i = 0; (s = pj_datums[i].id) && strcmp(name, s) ; ++i) {}
+
+ if (!s) { pj_errno = -9; return 1; }
+
+ if( pj_datums[i].ellipse_id && strlen(pj_datums[i].ellipse_id) > 0 )
+ {
+ char entry[100];
+
+ strcpy( entry, "ellps=" );
+ strncat( entry, pj_datums[i].ellipse_id, 80 );
+ curr = curr->next = pj_mkparam(entry);
+ }
+
+ if( pj_datums[i].defn && strlen(pj_datums[i].defn) > 0 )
+ curr = curr->next = pj_mkparam(pj_datums[i].defn);
+ }
+
+/* -------------------------------------------------------------------- */
+/* Check for nadgrids parameter. */
+/* -------------------------------------------------------------------- */
+ if( (nadgrids = pj_param(pl,"snadgrids").s) != NULL )
+ {
+ /* We don't actually save the value separately. It will continue
+ to exist int he param list for use in pj_apply_gridshift.c */
+
+ projdef->datum_type = PJD_GRIDSHIFT;
+ }
+
+/* -------------------------------------------------------------------- */
+/* Check for towgs84 parameter. */
+/* -------------------------------------------------------------------- */
+ else if( (towgs84 = pj_param(pl,"stowgs84").s) != NULL )
+ {
+ int parm_count = 0;
+ const char *s;
+
+ memset( projdef->datum_params, 0, sizeof(double) * 7);
+
+ /* parse out the parameters */
+ s = towgs84;
+ for( s = towgs84; *s != '\0'; )
+ {
+ projdef->datum_params[parm_count++] = atof(s);
+ while( *s != '\0' && *s != ',' )
+ s++;
+ if( *s == ',' )
+ s++;
+ }
+
+ if( projdef->datum_params[3] != 0.0
+ || projdef->datum_params[4] != 0.0
+ || projdef->datum_params[5] != 0.0
+ || projdef->datum_params[6] != 0.0 )
+ projdef->datum_type = PJD_7PARAM;
+ else
+ projdef->datum_type = PJD_3PARAM;
+
+ /* Note that pj_init() will later switch datum_type to
+ PJD_WGS84 if shifts are all zero, and ellipsoid is WGS84 or GRS80 */
+ }
+
+ return 0;
+}