aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--src/pj_apply_gridshift.c16
-rw-r--r--src/pj_apply_vgridshift.c13
-rw-r--r--src/pj_gridinfo.c49
4 files changed, 57 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index e9a6a6dd..b1141dfc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-09-16 Frank Warmerdam <warmerdam@pobox.com>
+
+ * src/pj_gridinfo.c, pj_apply_vgridshift.c, pj_apply_gridshift.c:
+ Fix problems with NTv2 files with improper parent structure (#177).
+
2014-09-13 Frank Warmerdam <warmerdam@pobox.com>
* Generate 4.9.0 release.
diff --git a/src/pj_apply_gridshift.c b/src/pj_apply_gridshift.c
index 379eebe2..a9441b5e 100644
--- a/src/pj_apply_gridshift.c
+++ b/src/pj_apply_gridshift.c
@@ -156,7 +156,7 @@ int pj_apply_gridshift_3( projCtx ctx, PJ_GRIDINFO **tables, int grid_count,
continue;
/* If we have child nodes, check to see if any of them apply. */
- if( gi->child != NULL )
+ while( gi->child )
{
PJ_GRIDINFO *child;
@@ -177,12 +177,14 @@ int pj_apply_gridshift_3( projCtx ctx, PJ_GRIDINFO **tables, int grid_count,
break;
}
- /* we found a more refined child node to use */
- if( child != NULL )
- {
- gi = child;
- ct = child->ct;
- }
+ /* If we didn't find a child then nothing more to do */
+
+ if( child == NULL ) break;
+
+ /* Otherwise use the child, first checking it's children */
+
+ gi = child;
+ ct = child->ct;
}
/* load the grid shift info if we don't have it. */
diff --git a/src/pj_apply_vgridshift.c b/src/pj_apply_vgridshift.c
index 1570d7ff..d26e902a 100644
--- a/src/pj_apply_vgridshift.c
+++ b/src/pj_apply_vgridshift.c
@@ -101,7 +101,7 @@ int pj_apply_vgridshift( PJ *defn, const char *listname,
continue;
/* If we have child nodes, check to see if any of them apply. */
- if( gi->child != NULL )
+ while( gi->child != NULL )
{
PJ_GRIDINFO *child;
@@ -117,12 +117,15 @@ int pj_apply_vgridshift( PJ *defn, const char *listname,
break;
}
- /* we found a more refined child node to use */
- if( child != NULL )
+ /* we didn't find a more refined child node to use, so go with current grid */
+ if( child == NULL )
{
- gi = child;
- ct = child->ct;
+ break;
}
+
+ /* Otherwise let's try for childrens children .. */
+ gi = child;
+ ct = child->ct;
}
/* load the grid shift info if we don't have it. */
diff --git a/src/pj_gridinfo.c b/src/pj_gridinfo.c
index 37c8d7c0..0e94a816 100644
--- a/src/pj_gridinfo.c
+++ b/src/pj_gridinfo.c
@@ -41,7 +41,7 @@
* TODO - mloskot: re-implement porting friendly assert
*/
# define assert(exp) ((void)0)
-#else
+#else/
# include <assert.h>
#endif /* _WIN32_WCE */
@@ -396,11 +396,32 @@ int pj_gridinfo_load( projCtx ctx, PJ_GRIDINFO *gi )
/************************************************************************/
/* pj_gridinfo_init_ntv2() */
/* */
+/* Seek a parent grid file by name from a grid list */
+/************************************************************************/
+
+static PJ_GRIDINFO* pj_gridinfo_parent( PJ_GRIDINFO *gilist,
+ const char *name, int length )
+{
+ while( gilist )
+ {
+ if( strncmp(gilist->ct->id,name,length) == 0 ) return gilist;
+ if( gilist->child )
+ {
+ PJ_GRIDINFO *parent=pj_gridinfo_parent( gilist->child, name, length );
+ if( parent ) return parent;
+ }
+ gilist=gilist->next;
+ }
+ return gilist;
+}
+
+/************************************************************************/
+/* pj_gridinfo_init_ntv2() */
+/* */
/* Load a ntv2 (.gsb) file. */
/************************************************************************/
static int pj_gridinfo_init_ntv2( projCtx ctx, PAFile fid, PJ_GRIDINFO *gilist )
-
{
unsigned char header[11*16];
int num_subfiles, subfile;
@@ -563,11 +584,8 @@ static int pj_gridinfo_init_ntv2( projCtx ctx, PAFile fid, PJ_GRIDINFO *gilist )
else
{
PJ_GRIDINFO *lnk;
- PJ_GRIDINFO *gp = gilist;
-
- while( gp != NULL
- && strncmp(gp->ct->id,(const char*)header+24,8) != 0 )
- gp = gp->next;
+ PJ_GRIDINFO *gp = pj_gridinfo_parent(gilist,
+ (const char*)header+24,8);
if( gp == NULL )
{
@@ -576,17 +594,20 @@ static int pj_gridinfo_init_ntv2( projCtx ctx, PAFile fid, PJ_GRIDINFO *gilist )
"failed to find parent %8.8s for %s.\n",
(const char *) header+24, gi->ct->id );
- for( lnk = gp; lnk->next != NULL; lnk = lnk->next ) {}
+ for( lnk = gilist; lnk->next != NULL; lnk = lnk->next ) {}
lnk->next = gi;
}
- else if( gp->child == NULL )
- {
- gp->child = gi;
- }
else
{
- for( lnk = gp->child; lnk->next != NULL; lnk = lnk->next ) {}
- lnk->next = gi;
+ if( gp->child == NULL )
+ {
+ gp->child = gi;
+ }
+ else
+ {
+ for( lnk = gp->child; lnk->next != NULL; lnk = lnk->next ) {}
+ lnk->next = gi;
+ }
}
}