[Gdal-dev] Nitf Creation Spanning International Date Line

Even Rouault even.rouault at mines-paris.org
Mon Aug 24 17:01:03 EDT 2009


Selon nsolomon <noah.solomon at ngc.com>:

>
> Hi,
>
> I'm having some troubles creating a Nitf image that spans the International
> Date Line (180/-180 degrees longitude).  If I have an image that has a
> western edge of around 150 degrees and an eastern edge of -150 degrees, I am
> getting the following error "Attempt to write geographic bound outside of
> legal range."  Are there any special considerations I need to take in order
> to do this?  Has anyone seen any errors doing this type of thing before?

Generally speaking, GDAL would have trouble to handle such images that spans the
anti-meridian. I had pushed in the past a patch in the NITF driver to recognize
(reading only) some CADRG tiles that have that property but it appeared to be
fairly fragile logic. It has been changed a few times because some users
reported that non north-up images could trigger the first version of the test in
the fix...

See nitfimage.c at line 1050 in trunk :

    /* Bug #1750 */
    /* Fix for cjnc/cjncz01/000k1023.jn1 (and similar) from NIMA GNCJNCN CDROM:
*/
    /* this product is crossing meridian 180deg and the upper and lower right
longitudes are negative (<-170) */
    /* while the upper and lower left longitudes are positive (> 170) which
causes problems in OpenEV, etc... */
    /* So we are adjusting the upper and lower right longitudes by setting them
above +180 */
    if( (psImage->chICORDS == 'G' || psImage->chICORDS == 'D') &&
        (psImage->dfULX > 170 && psImage->dfLLX > 170 && psImage->dfURX < -170
&& psImage->dfLRX < -170 &&
         psImage->dfULY > psImage->dfLLY && psImage->dfURY > psImage->dfLRY) )
    {
        psImage->dfURX += 360;
        psImage->dfLRX += 360;
    }


As far as writting such images is concerned, GDAL checks that the 4 corner
coordinates are valid in frmts/nitf/nitfimage.c at line 1887 and 1911 (in trunk)

        if( fabs(dfULX) > 180 || fabs(dfURX) > 180
            || fabs(dfLRX) > 180 || fabs(dfLLX) > 180
            || fabs(dfULY) >  90 || fabs(dfURY) >  90
            || fabs(dfLRY) >  90 || fabs(dfLLY) >  90 )
        {
            CPLError( CE_Failure, CPLE_AppDefined,
                      "Attempt to write geographic bound outside of legal
range." );
            return FALSE;
        }

I suppose that your topleft coordinates (adfGeoTransform[0], adfGeoTransform[3])
are around longitude 150 and that the computed east coordinates by GDAL are 150
+ east-west-resolution * width = 210, which is -150 + 360. 210 is not a legal
longitude, hence the above tests fails on dfLRX and dfURX. I suppose you could
fix that by adding the following code just before the tests.

       if ( dfURX > 180 ) dfURX -= 360;
       if ( dfLRX > 180 ) dfLRX -= 360;

We could perhaps push that change (maybe restricted to the north-up case)
without causing regressions, but I'm not too sure to what to do with the reading
part. In your example, for reading it back correctly, you should change the 170
value in the first code extract to 150.

>
> Thanks.
> --
> View this message in context:
>
http://n2.nabble.com/Nitf-Creation-Spanning-International-Date-Line-tp3505900p3505900.html
> Sent from the GDAL - Dev mailing list archive at Nabble.com.
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>




More information about the gdal-dev mailing list