diff options
| author | Frank Warmerdam <warmerdam@pobox.com> | 2012-06-19 04:18:00 +0000 |
|---|---|---|
| committer | Frank Warmerdam <warmerdam@pobox.com> | 2012-06-19 04:18:00 +0000 |
| commit | 0c8a7fc8b2b7176fca1b37b223a3197f3075422f (patch) | |
| tree | 19997c83ad9b5ef142db21fbad9d5ed2f654b13d /src | |
| parent | fcb186942ec8532655ff6cf4cc990e5da669a3bc (diff) | |
| download | PROJ-0c8a7fc8b2b7176fca1b37b223a3197f3075422f.tar.gz PROJ-0c8a7fc8b2b7176fca1b37b223a3197f3075422f.zip | |
first nearly working grid catalog implementation
git-svn-id: http://svn.osgeo.org/metacrs/proj/trunk@2219 4e78687f-474d-0410-85f9-8d5e500ac6b2
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.in | 51 | ||||
| -rw-r--r-- | src/pj_apply_gridshift.c | 4 | ||||
| -rw-r--r-- | src/pj_datum_set.c | 17 | ||||
| -rw-r--r-- | src/pj_gc_reader.c | 26 | ||||
| -rw-r--r-- | src/pj_gridcatalog.c | 202 | ||||
| -rw-r--r-- | src/pj_init.c | 3 | ||||
| -rw-r--r-- | src/projects.h | 8 |
7 files changed, 212 insertions, 99 deletions
diff --git a/src/Makefile.in b/src/Makefile.in index 345147bf..a5caf5d6 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -1,9 +1,9 @@ -# Makefile.in generated by automake 1.11.1 from Makefile.am. +# Makefile.in generated by automake 1.11.3 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, -# Inc. +# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software +# Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -71,6 +71,12 @@ am__nobase_list = $(am__nobase_strip_setup); \ am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \ "$(DESTDIR)$(includedir)" LTLIBRARIES = $(lib_LTLIBRARIES) @@ -166,6 +172,7 @@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ @@ -191,6 +198,7 @@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ MUTEX_SETTING = @MUTEX_SETTING@ NM = @NM@ @@ -217,6 +225,7 @@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ @@ -249,7 +258,6 @@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ -lt_ECHO = @lt_ECHO@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ @@ -360,10 +368,8 @@ $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) $(am__aclocal_m4_deps): proj_config.h: stamp-h1 - @if test ! -f $@; then \ - rm -f stamp-h1; \ - $(MAKE) $(AM_MAKEFLAGS) stamp-h1; \ - else :; fi + @if test ! -f $@; then rm -f stamp-h1; else :; fi + @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) stamp-h1; else :; fi stamp-h1: $(srcdir)/proj_config.h.in $(top_builddir)/config.status @rm -f stamp-h1 @@ -406,7 +412,7 @@ clean-libLTLIBRARIES: echo "rm -f \"$${dir}/so_locations\""; \ rm -f "$${dir}/so_locations"; \ done -libproj.la: $(libproj_la_OBJECTS) $(libproj_la_DEPENDENCIES) +libproj.la: $(libproj_la_OBJECTS) $(libproj_la_DEPENDENCIES) $(EXTRA_libproj_la_DEPENDENCIES) $(libproj_la_LINK) -rpath $(libdir) $(libproj_la_OBJECTS) $(libproj_la_LIBADD) $(LIBS) install-binPROGRAMS: $(bin_PROGRAMS) @$(NORMAL_INSTALL) @@ -451,19 +457,19 @@ clean-binPROGRAMS: list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ echo " rm -f" $$list; \ rm -f $$list -cs2cs$(EXEEXT): $(cs2cs_OBJECTS) $(cs2cs_DEPENDENCIES) +cs2cs$(EXEEXT): $(cs2cs_OBJECTS) $(cs2cs_DEPENDENCIES) $(EXTRA_cs2cs_DEPENDENCIES) @rm -f cs2cs$(EXEEXT) $(LINK) $(cs2cs_OBJECTS) $(cs2cs_LDADD) $(LIBS) -geod$(EXEEXT): $(geod_OBJECTS) $(geod_DEPENDENCIES) +geod$(EXEEXT): $(geod_OBJECTS) $(geod_DEPENDENCIES) $(EXTRA_geod_DEPENDENCIES) @rm -f geod$(EXEEXT) $(LINK) $(geod_OBJECTS) $(geod_LDADD) $(LIBS) -multistresstest$(EXEEXT): $(multistresstest_OBJECTS) $(multistresstest_DEPENDENCIES) +multistresstest$(EXEEXT): $(multistresstest_OBJECTS) $(multistresstest_DEPENDENCIES) $(EXTRA_multistresstest_DEPENDENCIES) @rm -f multistresstest$(EXEEXT) $(LINK) $(multistresstest_OBJECTS) $(multistresstest_LDADD) $(LIBS) -nad2bin$(EXEEXT): $(nad2bin_OBJECTS) $(nad2bin_DEPENDENCIES) +nad2bin$(EXEEXT): $(nad2bin_OBJECTS) $(nad2bin_DEPENDENCIES) $(EXTRA_nad2bin_DEPENDENCIES) @rm -f nad2bin$(EXEEXT) $(LINK) $(nad2bin_OBJECTS) $(nad2bin_LDADD) $(LIBS) -proj$(EXEEXT): $(proj_OBJECTS) $(proj_DEPENDENCIES) +proj$(EXEEXT): $(proj_OBJECTS) $(proj_DEPENDENCIES) $(EXTRA_proj_DEPENDENCIES) @rm -f proj$(EXEEXT) $(LINK) $(proj_OBJECTS) $(proj_LDADD) $(LIBS) @@ -678,9 +684,7 @@ uninstall-includeHEADERS: @$(NORMAL_UNINSTALL) @list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ - test -n "$$files" || exit 0; \ - echo " ( cd '$(DESTDIR)$(includedir)' && rm -f" $$files ")"; \ - cd "$(DESTDIR)$(includedir)" && rm -f $$files + dir='$(DESTDIR)$(includedir)'; $(am__uninstall_files_from_dir) ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ @@ -783,10 +787,15 @@ install-am: all-am installcheck: installcheck-am install-strip: - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - `test -z '$(STRIP)' || \ - echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi mostlyclean-generic: clean-generic: diff --git a/src/pj_apply_gridshift.c b/src/pj_apply_gridshift.c index 54ef376b..379eebe2 100644 --- a/src/pj_apply_gridshift.c +++ b/src/pj_apply_gridshift.c @@ -85,6 +85,10 @@ int pj_apply_gridshift_2( PJ *defn, int inverse, double *x, double *y, double *z ) { + if( defn->catalog_name != NULL ) + return pj_gc_apply_gridshift( defn, inverse, point_count, point_offset, + x, y, z ); + if( defn->gridlist == NULL ) { defn->gridlist = diff --git a/src/pj_datum_set.c b/src/pj_datum_set.c index 8bfe796d..5e351b21 100644 --- a/src/pj_datum_set.c +++ b/src/pj_datum_set.c @@ -40,7 +40,7 @@ int pj_datum_set(projCtx ctx, paralist *pl, PJ *projdef) { - const char *name, *towgs84, *nadgrids; + const char *name, *towgs84, *nadgrids, *catalog; projdef->datum_type = PJD_UNKNOWN; @@ -93,6 +93,21 @@ int pj_datum_set(projCtx ctx, paralist *pl, PJ *projdef) } /* -------------------------------------------------------------------- */ +/* Check for grid catalog parameter, and optional date. */ +/* -------------------------------------------------------------------- */ + else if( (catalog = pj_param(ctx, pl,"scatalog").s) != NULL ) + { + const char *date; + + projdef->datum_type = PJD_GRIDSHIFT; + projdef->catalog_name = strdup(catalog); + + date = pj_param(ctx, pl, "sdate").s; + if( date != NULL) + projdef->datum_date = pj_gc_parsedate( ctx, date); + } + +/* -------------------------------------------------------------------- */ /* Check for towgs84 parameter. */ /* -------------------------------------------------------------------- */ else if( (towgs84 = pj_param(ctx, pl,"stowgs84").s) != NULL ) diff --git a/src/pj_gc_reader.c b/src/pj_gc_reader.c index ef9479ff..e22aa993 100644 --- a/src/pj_gc_reader.c +++ b/src/pj_gc_reader.c @@ -33,7 +33,7 @@ #include <string.h> static int pj_gc_readentry( projCtx ctx, FILE *fp, PJ_GridCatalogEntry *entry ); - +static void pj_gc_sortcatalog( projCtx ctx, PJ_GridCatalog *catalog ); /************************************************************************/ /* pj_gc_readcatalog() */ @@ -46,11 +46,15 @@ PJ_GridCatalog *pj_gc_readcatalog( projCtx ctx, const char *catalog_name ) FILE *fp; PJ_GridCatalog *catalog; int entry_max, err; + char line[302]; fp = pj_open_lib( ctx, (char *) catalog_name, "r" ); if (fp == NULL) return NULL; - + + /* discard title line */ + fgets(line, sizeof(line)-1, fp); + catalog = (PJ_GridCatalog *) calloc(1,sizeof(PJ_GridCatalog)); if( !catalog ) return NULL; @@ -77,9 +81,22 @@ PJ_GridCatalog *pj_gc_readcatalog( projCtx ctx, const char *catalog_name ) } } + pj_gc_sortcatalog( ctx, catalog ); + return catalog; } +/************************************************************************/ +/* pj_gc_sortcatalog() */ +/* */ +/* Sort all the entries in ascending date and within a date in */ +/* descending priority order. */ +/************************************************************************/ + +static void pj_gc_sortcatalog( projCtx ctx, PJ_GridCatalog *catalog ) + +{ +} /************************************************************************/ /* pj_gc_read_csv_line() */ @@ -105,7 +122,7 @@ static int pj_gc_read_csv_line( projCtx ctx, FILE *fp, if( next[0] == '#' || next[0] == '\0' ) continue; - while( token_count < max_tokens && next != '\0' ) + while( token_count < max_tokens && *next != '\0' ) { const char *start = next; @@ -176,7 +193,8 @@ static int pj_gc_readentry( projCtx ctx, FILE *fp, PJ_GridCatalogEntry *entry ) if( token_count < 5 ) { error = 1; /* TODO: need real error codes */ - pj_log( ctx, PJ_LOG_ERROR, "Short line in grid catalog." ); + if( token_count != 0 ) + pj_log( ctx, PJ_LOG_ERROR, "Short line in grid catalog." ); } else { diff --git a/src/pj_gridcatalog.c b/src/pj_gridcatalog.c index 48808368..c3873093 100644 --- a/src/pj_gridcatalog.c +++ b/src/pj_gridcatalog.c @@ -31,6 +31,7 @@ #include <projects.h> #include <string.h> +#include <assert.h> static PJ_GridCatalog *grid_catalog_list = NULL; @@ -112,108 +113,169 @@ int pj_gc_apply_gridshift( PJ *defn, int inverse, return defn->ctx->last_errno; } - ctx->last_errno = 0; + defn->ctx->last_errno = 0; for( i = 0; i < point_count; i++ ) { long io = i * point_offset; - LP input, output; + LP input, output_after, output_before; int itable; + double mix_ratio; input.phi = y[io]; input.lam = x[io]; - output.phi = HUGE_VAL; - output.lam = HUGE_VAL; - /* make sure we have appropriate "before" shift file available */ - if( defn->last_before_grid == NULL - || input.lam < defn->last_before_region.ll_long - || input.lam > defn->last_before_region.ur_long - || input.phi < defn->last_before_region.ll_lat - || input.phi > defn->last_before_region.ll_lat ) { - defn->last_before_grid = pj_gc_findgrid( - defn->ctx, defn->catalog, 0, ll, 0.0, - &(defn->last_before_region), NULL); + /* make sure we have appropriate "after" shift file available */ + if( defn->last_after_grid == NULL + || input.lam < defn->last_after_region.ll_long + || input.lam > defn->last_after_region.ur_long + || input.phi < defn->last_after_region.ll_lat + || input.phi > defn->last_after_region.ll_lat ) { + defn->last_after_grid = + pj_gc_findgrid( defn->ctx, defn->catalog, + 1, input, defn->datum_date, + &(defn->last_after_region), + &(defn->last_after_date)); } + PJ_GRIDINFO *gi = defn->last_after_grid; + assert( gi->child == NULL ); - PJ_GRIDINFO *gi = defn->last_before_grid; - struct CTABLE *ct = gi->ct; - double epsilon = (fabs(ct->del.phi)+fabs(ct->del.lam))/10000.0; - - /* If we have child nodes, check to see if any of them apply. */ - if( gi->child != NULL ) + /* load the grid shift info if we don't have it. */ + if( gi->ct->cvs == NULL && !pj_gridinfo_load( defn->ctx, gi ) ) { - PJ_GRIDINFO *child; + pj_ctx_set_errno( defn->ctx, -38 ); + return -38; + } - for( child = gi->child; child != NULL; child = child->next ) + output_after = nad_cvt( input, inverse, gi->ct ); + if( output_after.lam == HUGE_VAL ) + { + if( defn->ctx->debug_level >= PJ_LOG_DEBUG_MAJOR ) { - struct CTABLE *ct1 = child->ct; - double epsilon = - (fabs(ct1->del.phi)+fabs(ct1->del.lam))/10000.0; - - if( ct1->ll.phi - epsilon > input.phi - || ct1->ll.lam - epsilon > input.lam - || (ct1->ll.phi+(ct1->lim.phi-1)*ct1->del.phi + epsilon - < input.phi) - || (ct1->ll.lam+(ct1->lim.lam-1)*ct1->del.lam + epsilon - < input.lam) ) - continue; - - break; + pj_log( defn->ctx, PJ_LOG_DEBUG_MAJOR, + "pj_apply_gridshift(): failed to find a grid shift table for\n" + " location (%.7fdW,%.7fdN)", + x[io] * RAD_TO_DEG, + y[io] * RAD_TO_DEG ); } + continue; + } - /* we found a more refined child node to use */ - if( child != NULL ) - { - gi = child; - ct = child->ct; - } + if( defn->datum_date == 0.0 ) + { + y[io] = output_after.phi; + x[io] = output_after.lam; + continue; } + /* make sure we have appropriate "before" shift file available */ + if( defn->last_before_grid == NULL + || input.lam < defn->last_before_region.ll_long + || input.lam > defn->last_before_region.ur_long + || input.phi < defn->last_before_region.ll_lat + || input.phi > defn->last_before_region.ll_lat ) { + defn->last_before_grid = + pj_gc_findgrid( defn->ctx, defn->catalog, + 0, input, defn->datum_date, + &(defn->last_before_region), + &(defn->last_before_date)); + } + + gi = defn->last_before_grid; + assert( gi->child == NULL ); + /* load the grid shift info if we don't have it. */ - if( ct->cvs == NULL && !pj_gridinfo_load( ctx, gi ) ) + if( gi->ct->cvs == NULL && !pj_gridinfo_load( defn->ctx, gi ) ) { - pj_ctx_set_errno( ctx, -38 ); + pj_ctx_set_errno( defn->ctx, -38 ); return -38; } - output = nad_cvt( input, inverse, ct ); - if( output.lam != HUGE_VAL ) + output_before = nad_cvt( input, inverse, gi->ct ); + if( output_before.lam == HUGE_VAL ) { - if( debug_count++ < 20 ) - pj_log( ctx, PJ_LOG_DEBUG_MINOR, - "pj_apply_gridshift(): used %s", ct->id ); - break; - } - - - if( output.lam == HUGE_VAL ) - { - if( ctx->debug_level >= PJ_LOG_DEBUG_MAJOR ) + if( defn->ctx->debug_level >= PJ_LOG_DEBUG_MAJOR ) { - pj_log( ctx, PJ_LOG_DEBUG_MAJOR, + pj_log( defn->ctx, PJ_LOG_DEBUG_MAJOR, "pj_apply_gridshift(): failed to find a grid shift table for\n" " location (%.7fdW,%.7fdN)", x[io] * RAD_TO_DEG, y[io] * RAD_TO_DEG ); - for( itable = 0; itable < grid_count; itable++ ) - { - PJ_GRIDINFO *gi = tables[itable]; - if( itable == 0 ) - pj_log( ctx, PJ_LOG_DEBUG_MAJOR, - " tried: %s", gi->gridname ); - else - pj_log( ctx, PJ_LOG_DEBUG_MAJOR, - ",%s", gi->gridname ); - } } + continue; } - else - { - y[io] = output.phi; - x[io] = output.lam; - } + + mix_ratio = (defn->datum_date - defn->last_before_date) + / (defn->last_after_date - defn->last_before_date); + + y[io] = mix_ratio * output_after.phi + + (1.0-mix_ratio) * output_before.phi; + x[io] = mix_ratio * output_after.lam + + (1.0-mix_ratio) * output_before.lam; } return 0; } + +/************************************************************************/ +/* pj_c_findgrid() */ +/************************************************************************/ + +PJ_GRIDINFO *pj_gc_findgrid( projCtx ctx, PJ_GridCatalog *catalog, int after, + LP location, double date, + PJ_Region *optimal_region, + double *grid_date ) +{ + int iEntry; + PJ_GridCatalogEntry *entry = NULL; + + for( iEntry = 0; iEntry < catalog->entry_count; iEntry++ ) + { + entry = catalog->entries + iEntry; + + if( (after && entry->date < date) + || (!after && entry->date > date) ) + continue; + + if( location.lam < entry->region.ll_long + || location.lam > entry->region.ur_long + || location.phi < entry->region.ll_lat + || location.phi > entry->region.ur_lat ) + continue; + + if( entry->available == -1 ) + continue; + + break; + } + + if( iEntry == catalog->entry_count ) + { + if( grid_date ) + *grid_date = 0.0; + if( optimal_region != NULL ) + memset( optimal_region, 0, sizeof(PJ_Region)); + return NULL; + } + + if( grid_date ) + *grid_date = entry->date; + + if( optimal_region ) + { + + } + + if( entry->gridinfo == NULL ) + { + PJ_GRIDINFO **gridlist = NULL; + int grid_count = 0; + gridlist = pj_gridlist_from_nadgrids( ctx, entry->definition, + &grid_count); + if( grid_count == 1 ) + entry->gridinfo = gridlist[0]; + } + + return entry->gridinfo; +} + diff --git a/src/pj_init.c b/src/pj_init.c index e951660c..67ca4a5e 100644 --- a/src/pj_init.c +++ b/src/pj_init.c @@ -503,6 +503,9 @@ pj_free(PJ *P) { if( P->vgridlist_geoid != NULL ) pj_dalloc( P->vgridlist_geoid ); + if( P->catalog != NULL ) + pj_dalloc( P->catalog ); + /* free projection parameters */ P->pfree(P); } diff --git a/src/projects.h b/src/projects.h index a15ed596..f9dcea64 100644 --- a/src/projects.h +++ b/src/projects.h @@ -273,9 +273,11 @@ typedef struct PJconsts { struct _pj_gi *last_before_grid; PJ_Region last_before_region; + double last_before_date; struct _pj_gi *last_after_grid; PJ_Region last_after_region; + double last_after_date; #ifdef PROJ_PARMS__ PROJ_PARMS__ @@ -367,7 +369,7 @@ typedef struct _pj_gi { struct _pj_gi *child; } PJ_GRIDINFO; -typedef struct _PJ_GridCatalog { +typedef struct { PJ_Region region; int priority; /* higher used before lower */ double date; /* year.fraction */ @@ -377,7 +379,7 @@ typedef struct _PJ_GridCatalog { int available; /* 0=unknown, 1=true, -1=false */ } PJ_GridCatalogEntry; -typedef struct _pj_gc { +typedef struct _PJ_GridCatalog { char *catalog_name; PJ_Region region; /* maximum extent of catalog data */ @@ -385,7 +387,7 @@ typedef struct _pj_gc { int entry_count; PJ_GridCatalogEntry *entries; - struct _pj_gc *next; + struct _PJ_GridCatalog *next; } PJ_GridCatalog; |
