Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

listgeo: fix corner coordinates for images with RasterPixelIsPoint #36

Merged
merged 3 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions libgeotiff/bin/listgeo.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ static void GTIFPrintCorners( GTIF *, GTIFDefn *, FILE *, int, int, int, int );
static TIFF *st_setup_test_info();

void Usage()

{
printf(
"%s",
"Usage: listgeo [-d] [-tfw] [-proj4] [-no_norm] [-t tabledir] filename\n"
"\n"
" -d: report lat/long corners in decimal degrees instead of DMS.\n"
" -tfw: Generate a .tfw (ESRI TIFF World) file for the target file.\n"
" -proj4: Report PROJ.4 equivelent projection definition.\n"
" -proj4: Report PROJ.4 equivalent projection definition.\n"
" -no_norm: Don't report 'normalized' parameter values.\n"
" filename: Name of the GeoTIFF file to report on.\n" );

Expand Down Expand Up @@ -227,20 +226,29 @@ static void GTIFPrintCorners( GTIF *gtif, GTIFDefn *defn, FILE * fp_out,

{
printf( "\nCorner Coordinates:\n" );

unsigned short raster_type = RasterPixelIsArea;
GTIFKeyGet(gtif, GTRasterTypeGeoKey, &raster_type, 0, 1);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not entirely pleased with this solution to obtain the value of the key, as it ignores the return value and doesn't check for any undesired values in raster_type. Should one be strict here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use GTIFKeyGetSHORT() instead of GTIFKeyGet() ? This is safer in case of corrupted files.
Your current logic otherwise looks reasonable to me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use GTIFKeyGetSHORT() instead of GTIFKeyGet() ?

Unfortunately GTIFKeyGetSHORT and related functionality is declared static in geo_normalize.c, so not without further changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I think it could be worth exporting GTIFKeyGetSHORT() and GTIFKeyGetDOUBLE() in geotiff.h

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good idea, but should probably go into another PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine if it goes into that PR as a separate commit. By the way if you rebase your PR on top of latest master, the CI failure on Mac should now be resolved

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased, will look into exposing the mentioned functionality next.


double xmin = (raster_type == RasterPixelIsArea) ? 0.0 : -0.5;
double ymin = xmin;
double ymax = ymin + ysize;
double xmax = xmin + xsize;

if( !GTIFReportACorner( gtif, defn, fp_out,
"Upper Left", 0.0, 0.0, inv_flag, dec_flag ) )
"Upper Left", xmin, ymin, inv_flag, dec_flag ) )
{
printf( " ... unable to transform points between pixel/line and PCS space\n" );
return;
}

GTIFReportACorner( gtif, defn, fp_out, "Lower Left", 0.0, ysize,
GTIFReportACorner( gtif, defn, fp_out, "Lower Left", xmin, ymax,
inv_flag, dec_flag );
GTIFReportACorner( gtif, defn, fp_out, "Upper Right", xsize, 0.0,
GTIFReportACorner( gtif, defn, fp_out, "Upper Right", xmax, ymin,
inv_flag, dec_flag );
GTIFReportACorner( gtif, defn, fp_out, "Lower Right", xsize, ysize,
GTIFReportACorner( gtif, defn, fp_out, "Lower Right", xmax, ymax,
inv_flag, dec_flag );
GTIFReportACorner( gtif, defn, fp_out, "Center", xsize/2.0, ysize/2.0,
GTIFReportACorner( gtif, defn, fp_out, "Center", xmin + xsize/2.0, ymin + ysize/2.0,
inv_flag, dec_flag );
}

Expand Down
3 changes: 2 additions & 1 deletion libgeotiff/test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ EXTRA_DIST = testlistgeo testlistgeo_out.dist \
data/ProjectedCSTypeGeoKey_3410_lambert_cylindrical_equal_area.tif \
data/lambert_cylindrical_equal_area.tif \
data/ProjectedCSTypeGeoKey_4087_equidistant_cylindrical.tif \
data/equidistant_cylindrical.tif
data/equidistant_cylindrical.tif \
data/pixel_is_point_wgs84.tif

check-local:
$(TESTLISTGEO) $(LISTGEOEXE)
Expand Down
Binary file added libgeotiff/test/data/pixel_is_point_wgs84.tif
Binary file not shown.
4 changes: 4 additions & 0 deletions libgeotiff/test/testlistgeo
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ echo "Testing listgeo equidistant_cylindrical.tif" >> ${OUT}
$EXE ${DATA_DIR}/equidistant_cylindrical.tif >>${OUT}
echo "" >>${OUT}

echo "Testing listgeo pixel_is_point_wgs84.tif" >> ${OUT}
$EXE ${DATA_DIR}/pixel_is_point_wgs84.tif >>${OUT}
echo "" >>${OUT}

# Normalize for results depending on the exact version of PROJ / EPSG database
sed "s/ETRS89-extended/ETRS89/g" < ${OUT} > ${OUT}.tmp
mv ${OUT}.tmp ${OUT}
Expand Down
32 changes: 32 additions & 0 deletions libgeotiff/test/testlistgeo_out.dist
Original file line number Diff line number Diff line change
Expand Up @@ -1987,3 +1987,35 @@ Upper Right ( 440780.000, 3751320.000) ( 3d57'34.54"E, 33d41'55.25"N)
Lower Right ( 440780.000, 3751260.000) ( 3d57'34.54"E, 33d41'53.31"N)
Center ( 440750.000, 3751290.000) ( 3d57'33.57"E, 33d41'54.28"N)

Testing listgeo pixel_is_point_wgs84.tif
Geotiff_Information:
Version: 1
Key_Revision: 1.0
Tagged_Information:
ModelTiepointTag (2,3):
0 0 0
-1 53 0
ModelPixelScaleTag (1,3):
2 2 0
End_Of_Tags.
Keyed_Information:
GTModelTypeGeoKey (Short,1): ModelTypeGeographic
GTRasterTypeGeoKey (Short,1): RasterPixelIsPoint
GeographicTypeGeoKey (Short,1): GCS_WGS_84
GeogAngularUnitsGeoKey (Short,1): Angular_Degree
End_Of_Keys.
End_Of_Geotiff.

GCS: 4326/WGS 84
Datum: 6326/World Geodetic System 1984
Ellipsoid: 7030/WGS 84 (6378137.00,6356752.31)
Prime Meridian: 8901/Greenwich (0.000000/ 0d 0' 0.00"E)
Projection Linear Units: User-Defined (1.000000m)

Corner Coordinates:
Upper Left ( 2d 0' 0.00"W, 54d 0' 0.00"N)
Lower Left ( 2d 0' 0.00"W, 50d 0' 0.00"N)
Upper Right ( 2d 0' 0.00"E, 54d 0' 0.00"N)
Lower Right ( 2d 0' 0.00"E, 50d 0' 0.00"N)
Center ( 0d 0' 0.00"E, 52d 0' 0.00"N)