test_geotiff.c (6844B)
1 /* 2 This file is part of libextractor. 3 Copyright (C) 2026 Vidyut Samanta and Christian Grothoff 4 5 libextractor is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published 7 by the Free Software Foundation; either version 3, or (at your 8 option) any later version. 9 10 libextractor is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with libextractor; see the file COPYING. If not, write to the 17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 Boston, MA 02110-1301, USA. 19 */ 20 /** 21 * @file plugins/test_geotiff.c 22 * @brief testcase for the geotiff plugin 23 * @author Christian Grothoff 24 */ 25 #include "platform.h" 26 #include "test_lib.h" 27 28 29 /** 30 * Main function for the geotiff testcase. 31 * 32 * The fixture is built by contrib/gen_geotiff_testdata.sh: a 16x16 33 * raster at EPSG:32633 whose tiepoint puts raster (0,0) at model 34 * (500000, 5400000) with a 10 m pixel. The bounding box below is the 35 * value that proves the plugin combined the tiepoint, the pixel scale 36 * and the image dimensions rather than reading any one of them alone. 37 * 38 * @param argc number of arguments (ignored) 39 * @param argv arguments (ignored) 40 * @return 0 on success 41 */ 42 int 43 main (int argc, char *argv[]) 44 { 45 struct SolutionData geotiff_sol[] = { 46 { 47 EXTRACTOR_METATYPE_MIMETYPE, 48 EXTRACTOR_METAFORMAT_UTF8, 49 "text/plain", 50 "image/tiff", 51 strlen ("image/tiff") + 1, 52 0 53 }, 54 { 55 EXTRACTOR_METATYPE_FORMAT, 56 EXTRACTOR_METAFORMAT_UTF8, 57 "text/plain", 58 "GeoTIFF", 59 strlen ("GeoTIFF") + 1, 60 0 61 }, 62 { 63 EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, 64 EXTRACTOR_METAFORMAT_UTF8, 65 "text/plain", 66 "16x16", 67 strlen ("16x16") + 1, 68 0 69 }, 70 { 71 EXTRACTOR_METATYPE_COLOR_DEPTH, 72 EXTRACTOR_METAFORMAT_UTF8, 73 "text/plain", 74 "8", 75 strlen ("8") + 1, 76 0 77 }, 78 { 79 EXTRACTOR_METATYPE_CHANNELS, 80 EXTRACTOR_METAFORMAT_UTF8, 81 "text/plain", 82 "1", 83 strlen ("1") + 1, 84 0 85 }, 86 { 87 EXTRACTOR_METATYPE_CODEC, 88 EXTRACTOR_METAFORMAT_UTF8, 89 "text/plain", 90 "none", 91 strlen ("none") + 1, 92 0 93 }, 94 { 95 EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE, 96 EXTRACTOR_METAFORMAT_UTF8, 97 "text/plain", 98 "libextractor gen_geotiff_testdata 1.0", 99 strlen ("libextractor gen_geotiff_testdata 1.0") + 1, 100 0 101 }, 102 { 103 EXTRACTOR_METATYPE_DESCRIPTION, 104 EXTRACTOR_METAFORMAT_UTF8, 105 "text/plain", 106 "libextractor GeoTIFF test fixture", 107 strlen ("libextractor GeoTIFF test fixture") + 1, 108 0 109 }, 110 { 111 EXTRACTOR_METATYPE_AUTHOR_NAME, 112 EXTRACTOR_METAFORMAT_UTF8, 113 "text/plain", 114 "Christian Grothoff", 115 strlen ("Christian Grothoff") + 1, 116 0 117 }, 118 { 119 EXTRACTOR_METATYPE_COPYRIGHT, 120 EXTRACTOR_METAFORMAT_UTF8, 121 "text/plain", 122 "CC0 1.0 Universal (public domain)", 123 strlen ("CC0 1.0 Universal (public domain)") + 1, 124 0 125 }, 126 { 127 EXTRACTOR_METATYPE_DEVICE_MANUFACTURER, 128 EXTRACTOR_METAFORMAT_UTF8, 129 "text/plain", 130 "libextractor", 131 strlen ("libextractor") + 1, 132 0 133 }, 134 { 135 EXTRACTOR_METATYPE_DEVICE_MODEL, 136 EXTRACTOR_METAFORMAT_UTF8, 137 "text/plain", 138 "synthetic raster", 139 strlen ("synthetic raster") + 1, 140 0 141 }, 142 /* TIFF DateTime is `2026:03:14 09:15:00' in the file */ 143 { 144 EXTRACTOR_METATYPE_CREATION_DATE, 145 EXTRACTOR_METAFORMAT_UTF8, 146 "text/plain", 147 "2026-03-14T09:15:00", 148 strlen ("2026-03-14T09:15:00") + 1, 149 0 150 }, 151 /* ProjectedCSTypeGeoKey 32633, resolved through the built-in 152 table of UTM zones */ 153 { 154 EXTRACTOR_METATYPE_COORDINATE_SYSTEM, 155 EXTRACTOR_METAFORMAT_UTF8, 156 "text/plain", 157 "EPSG:32633 (WGS 84 / UTM zone 33N)", 158 strlen ("EPSG:32633 (WGS 84 / UTM zone 33N)") + 1, 159 0 160 }, 161 /* GTCitationGeoKey / PCSCitationGeoKey, `|'-terminated inside 162 GeoAsciiParamsTag */ 163 { 164 EXTRACTOR_METATYPE_COORDINATE_SYSTEM, 165 EXTRACTOR_METAFORMAT_UTF8, 166 "text/plain", 167 "WGS 84 / UTM zone 33N", 168 strlen ("WGS 84 / UTM zone 33N") + 1, 169 0 170 }, 171 /* GeogCitationGeoKey */ 172 { 173 EXTRACTOR_METATYPE_COORDINATE_SYSTEM, 174 EXTRACTOR_METAFORMAT_UTF8, 175 "text/plain", 176 "WGS 84", 177 strlen ("WGS 84") + 1, 178 0 179 }, 180 { 181 EXTRACTOR_METATYPE_COMMENT, 182 EXTRACTOR_METAFORMAT_UTF8, 183 "text/plain", 184 "GeoTIFF model type: projected", 185 strlen ("GeoTIFF model type: projected") + 1, 186 0 187 }, 188 { 189 EXTRACTOR_METATYPE_COMMENT, 190 EXTRACTOR_METAFORMAT_UTF8, 191 "text/plain", 192 "GeoTIFF raster type: pixel is area", 193 strlen ("GeoTIFF raster type: pixel is area") + 1, 194 0 195 }, 196 /* ModelPixelScaleTag, in the linear unit named by 197 ProjLinearUnitsGeoKey (9001, metre) */ 198 { 199 EXTRACTOR_METATYPE_IMAGE_RESOLUTION, 200 EXTRACTOR_METAFORMAT_UTF8, 201 "text/plain", 202 "10 x 10 m/pixel", 203 strlen ("10 x 10 m/pixel") + 1, 204 0 205 }, 206 /* tiepoint (0,0) -> (500000, 5400000), 10 m pixel, 16x16 raster: 207 west,south,east,north in EPSG:32633 metres */ 208 { 209 EXTRACTOR_METATYPE_BOUNDING_BOX, 210 EXTRACTOR_METAFORMAT_UTF8, 211 "text/plain", 212 "500000,5399840,500160,5400000", 213 strlen ("500000,5399840,500160,5400000") + 1, 214 0 215 }, 216 { 217 EXTRACTOR_METATYPE_COMMENT, 218 EXTRACTOR_METAFORMAT_UTF8, 219 "text/plain", 220 "GDAL nodata value: 0", 221 strlen ("GDAL nodata value: 0") + 1, 222 0 223 }, 224 /* out of GDAL_METADATA's <Item name="..."> elements */ 225 { 226 EXTRACTOR_METATYPE_SOURCE_DEVICE, 227 EXTRACTOR_METAFORMAT_UTF8, 228 "text/plain", 229 "libextractor synthetic sensor", 230 strlen ("libextractor synthetic sensor") + 1, 231 0 232 }, 233 { 234 EXTRACTOR_METATYPE_COMMENT, 235 EXTRACTOR_METAFORMAT_UTF8, 236 "text/plain", 237 "ACQUISITIONDATETIME=2026-03-14T09:15:00Z", 238 strlen ("ACQUISITIONDATETIME=2026-03-14T09:15:00Z") + 1, 239 0 240 }, 241 { 242 EXTRACTOR_METATYPE_COMMENT, 243 EXTRACTOR_METAFORMAT_UTF8, 244 "text/plain", 245 "PROCESSING_LEVEL=L1C", 246 strlen ("PROCESSING_LEVEL=L1C") + 1, 247 0 248 }, 249 { 0, 0, NULL, NULL, 0, -1 } 250 }; 251 struct ProblemSet ps[] = { 252 { "testdata/geotiff_test.tif", 253 geotiff_sol }, 254 { NULL, NULL } 255 }; 256 257 (void) argc; 258 (void) argv; 259 return ET_main ("geotiff", ps); 260 } 261 262 263 /* end of test_geotiff.c */