From b42ff8f3eeb887bcde93ff3f70186a279e7bd307 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 10 Oct 2023 01:06:17 +0200 Subject: [PATCH 1/2] VRTMDArraySourceFromArray: fix taking into account relativeToVRT=1 --- frmts/vrt/vrtmultidim.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frmts/vrt/vrtmultidim.cpp b/frmts/vrt/vrtmultidim.cpp index 71eec08b0bdc..6baff2c4cd2d 100644 --- a/frmts/vrt/vrtmultidim.cpp +++ b/frmts/vrt/vrtmultidim.cpp @@ -1936,7 +1936,7 @@ bool VRTMDArraySourceFromArray::Read(const GUInt64 *arrayStartIdx, else { poSrcDS = GDALDataset::Open( - m_osFilename.c_str(), + osFilename.c_str(), (m_osBand.empty() ? GDAL_OF_MULTIDIM_RASTER : GDAL_OF_RASTER) | GDAL_OF_INTERNAL | GDAL_OF_VERBOSE_ERROR, nullptr, nullptr, nullptr); From 2b26a15a73bdabe5832ae3c6b656ed2b5b8d0a2c Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 9 Oct 2023 23:37:30 +0200 Subject: [PATCH 2/2] VRT: allow a element containing a 2D multidimensional array as a VRTRasterBand source and through the use of a make it possible to create a 2D array from a 3D or more multidimensional one, by slicing, transposing, resampling, gridding, etc. --- autotest/gdrivers/data/netcdf/byte.nc | Bin 0 -> 3364 bytes autotest/gdrivers/data/netcdf/test_gridded.nc | Bin 0 -> 9054 bytes .../gdrivers/data/vrt/arraysource_array.vrt | 18 + .../vrt/arraysource_derivedarray_getmask.vrt | 18 + .../arraysource_derivedarray_getunscaled.vrt | 18 + .../vrt/arraysource_derivedarray_grid.vrt | 35 ++ .../vrt/arraysource_derivedarray_no_step.vrt | 15 + .../vrt/arraysource_derivedarray_resample.vrt | 18 + ...aysource_derivedarray_resample_options.vrt | 24 + .../arraysource_derivedarray_transpose.vrt | 18 + .../vrt/arraysource_derivedarray_view.vrt | 18 + .../vrt/arraysource_singlesourcearray.vrt | 13 + .../data/vrt/arraysource_srcrect_dstrect.vrt | 20 + autotest/gdrivers/vrtmultidim.py | 554 ++++++++++++++++++ data/gdalvrt.xsd | 161 +++++ doc/source/drivers/raster/vrt.rst | 210 ++++++- frmts/vrt/vrtdataset.h | 10 + frmts/vrt/vrtdriver.cpp | 1 + frmts/vrt/vrtmultidim.cpp | 444 ++++++++++++++ frmts/vrt/vrtsources.cpp | 13 +- 20 files changed, 1605 insertions(+), 3 deletions(-) create mode 100644 autotest/gdrivers/data/netcdf/byte.nc create mode 100644 autotest/gdrivers/data/netcdf/test_gridded.nc create mode 100644 autotest/gdrivers/data/vrt/arraysource_array.vrt create mode 100644 autotest/gdrivers/data/vrt/arraysource_derivedarray_getmask.vrt create mode 100644 autotest/gdrivers/data/vrt/arraysource_derivedarray_getunscaled.vrt create mode 100644 autotest/gdrivers/data/vrt/arraysource_derivedarray_grid.vrt create mode 100644 autotest/gdrivers/data/vrt/arraysource_derivedarray_no_step.vrt create mode 100644 autotest/gdrivers/data/vrt/arraysource_derivedarray_resample.vrt create mode 100644 autotest/gdrivers/data/vrt/arraysource_derivedarray_resample_options.vrt create mode 100644 autotest/gdrivers/data/vrt/arraysource_derivedarray_transpose.vrt create mode 100644 autotest/gdrivers/data/vrt/arraysource_derivedarray_view.vrt create mode 100644 autotest/gdrivers/data/vrt/arraysource_singlesourcearray.vrt create mode 100644 autotest/gdrivers/data/vrt/arraysource_srcrect_dstrect.vrt diff --git a/autotest/gdrivers/data/netcdf/byte.nc b/autotest/gdrivers/data/netcdf/byte.nc new file mode 100644 index 0000000000000000000000000000000000000000..49ccc7bab63b0a9c10488e30183aa50ed28b39e2 GIT binary patch literal 3364 zcmeHJO>Epm6i%Q&v}ubdNI+1LWeyZ+v$1!R{pp38%{EEZWTVZlR1#H|Gxly=@7j^a zno`W(s4c`uq5E5a1Db`&W4XDQvH9w+}&c54=am$CNXwQZ6cLsjSYFCZ{VA z32pZ%uAu=A6dZfmuszeUDGuV;zQU;?IXQ~mzCGvz5Wg$f7ShRFQqqm(A=jwU;YCB! z>5y)^-fBW{jfSC7Ll;s~Dm^Sq!%|*2t{V%jy0FkP8~RJ=v9E9cqDei+jTEEb{FGx0 zCE^J{mvbjl*%Rr}$i)dEidX=to>6d?R*wq{tDcdxNkT{_lS1ro0DRzlpY&YKrpty) z4Yg^wM1vskIeIWBhv9vq?wY#V)RvY^yRO<=)8ON%<3aYv8jf8zy_RmMPE93{Emvz` z1XDLPo7?XL=>P28N#284HLU?MARQhA>f$KRv)5zN5zet4*IV2qMSkLOgkufO+X}tp zI_C|7Yo$7_SvR|5ci9M(XbnTHX#^6WYF;nNQJj}=|Mlq$AGNWJ4&WSj<>N@9JS*r% z&9qI78AW(*M=q9Jvl-=jD-*l*KTeIN3Hd&cN>2zUsUYu6OQdwbGs8*(g*Bsjr zWO-Ulj2BDeTccuPOsQ0-fQuPd65T$&u47Yhx|wZKg- zlMxe{bT*fgGRcudDnF9UXLFf+E+waP`CLM&Rwhd2$;zwqVsU16Tug{rNy>@m&h;3{ zq%v6?nJG_B6+y_jYZ&$glPrn}sRuommt>?@rzb1(qHffI4$Pz^XGccUseEcw&gVzc z=^mzeIhE?IVPs1~>2$GBnJi7uin?2q-%-FW0T13Gy7P&5l3wR(bT1RoP?&Bt7YtY6 z4i2bQo0@go(9v7GUY^^+Bo8cW4Y;_#|LJ;^b6hKocOTwE-FKS!`-AQ>ps)XJa2Eov zPZ|8?8pm(1a=dwo<98Q1eji;imBCw!y#K>ljz3Ot{3*xr_Hm9sKg02t$6~z4@z
  • x@@$OR7^^WxC8nIY@=o0U zIL0qyyv6ao12MiBV=+b&;~O!)AL9n%`g%KTx7+J1q|CyH6039f{tadYe#q9=!hrb} z{Mze5$7h84rz!D+Hd_k5|j984Vg>4_b1cbsj%IKU=11p%bs5M7? zN~!OMG$br!%<>747zt?T6Xu6OCnP?EBGyL7qSPXR)d_s~0)Hr-vpOgbh?Fsg2381i zK$R770sX)Cw`YANVK@=IWDmVtw8TgMgvufFZDsPd7T9 z5SbR(w?Q~#H!Rj>K)^YK{+bWzVr|F~h{I6uvuFqt2gg8*W=%l{8lWbaZb;W47d~o- TDUdd31XFOyKsM%sw!^;xv}2%r literal 0 HcmV?d00001 diff --git a/autotest/gdrivers/data/netcdf/test_gridded.nc b/autotest/gdrivers/data/netcdf/test_gridded.nc new file mode 100644 index 0000000000000000000000000000000000000000..b7e58d821e7139e691b03eb8e5b0bb1a8ca775ea GIT binary patch literal 9054 zcmeI2&rcIU6vy9gf7sxns32%eTs1Kqw1QSVA&_l>N-d-XqbAx`yM!8TO}i3fOgtJB z_3p)!e}os~m6KGobK)44V!JwH%301r~w>qJm zI>gSOst~WRQ$Rh)?$hgJ^$d5*!87jT9b&8P1BM}2F=UUa9N7jsDX2~M5JpX97-H)o zR>xK30$){h&(*k~MgG#4n(mK9Hj@n)Oo9)LnFals_0dQJ$p~htk!%+0#ERyS@dCt? z#}nynax$IEIwPqBSbM3@fRGrK9yy*s=N||QlwidG=mW)D74fF^_XiC#G#a4)C5b`qf;G39Z zDYL?Vn^NA7(lD;fY^Uc+H5-2lcG>lu_^4ehU2@Ac%v<~170)hLyrr)BLbX&lchQa7 zTn7G-uUtLu)V@f<@Oy+?8F=P^>iA*Bx zByuu_t$39whGM}h)Lf6J^tBvo3w$L_D}O`5hZ&O#ahfSR<_vwD!*8sV+HNzO!Dn_7ZkpY literal 0 HcmV?d00001 diff --git a/autotest/gdrivers/data/vrt/arraysource_array.vrt b/autotest/gdrivers/data/vrt/arraysource_array.vrt new file mode 100644 index 000000000000..3fb28569d4a8 --- /dev/null +++ b/autotest/gdrivers/data/vrt/arraysource_array.vrt @@ -0,0 +1,18 @@ + + PROJCS["NAD27 / UTM zone 11N",GEOGCS["NAD27",DATUM["North_American_Datum_1927",SPHEROID["Clarke 1866",6378206.4,294.978698213898,AUTHORITY["EPSG","7008"]],AUTHORITY["EPSG","6267"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4267"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","26711"]] + 4.4072000000000000e+05, 6.0000000000000000e+01, 0.0000000000000000e+00, 3.7513200000000000e+06, 0.0000000000000000e+00, -6.0000000000000000e+01 + + Gray + + + Byte + + + + ../netcdf/byte.nc + /Band1 + + + + + diff --git a/autotest/gdrivers/data/vrt/arraysource_derivedarray_getmask.vrt b/autotest/gdrivers/data/vrt/arraysource_derivedarray_getmask.vrt new file mode 100644 index 000000000000..e511b14c5f75 --- /dev/null +++ b/autotest/gdrivers/data/vrt/arraysource_derivedarray_getmask.vrt @@ -0,0 +1,18 @@ + + PROJCS["NAD27 / UTM zone 11N",GEOGCS["NAD27",DATUM["North_American_Datum_1927",SPHEROID["Clarke 1866",6378206.4,294.978698213898,AUTHORITY["EPSG","7008"]],AUTHORITY["EPSG","6267"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4267"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","26711"]] + 4.4072000000000000e+05, 6.0000000000000000e+01, 0.0000000000000000e+00, 3.7513200000000000e+06, 0.0000000000000000e+00, -6.0000000000000000e+01 + + Gray + + + + ../netcdf/byte_no_cf.nc + /Band1 + + + + + + + + diff --git a/autotest/gdrivers/data/vrt/arraysource_derivedarray_getunscaled.vrt b/autotest/gdrivers/data/vrt/arraysource_derivedarray_getunscaled.vrt new file mode 100644 index 000000000000..9ddde7126028 --- /dev/null +++ b/autotest/gdrivers/data/vrt/arraysource_derivedarray_getunscaled.vrt @@ -0,0 +1,18 @@ + + PROJCS["NAD27 / UTM zone 11N",GEOGCS["NAD27",DATUM["North_American_Datum_1927",SPHEROID["Clarke 1866",6378206.4,294.978698213898,AUTHORITY["EPSG","7008"]],AUTHORITY["EPSG","6267"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4267"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","26711"]] + 4.4072000000000000e+05, 6.0000000000000000e+01, 0.0000000000000000e+00, 3.7513200000000000e+06, 0.0000000000000000e+00, -6.0000000000000000e+01 + + Gray + + + + ../netcdf/byte_no_cf.nc + /Band1 + + + + + + + + diff --git a/autotest/gdrivers/data/vrt/arraysource_derivedarray_grid.vrt b/autotest/gdrivers/data/vrt/arraysource_derivedarray_grid.vrt new file mode 100644 index 000000000000..dfc0cf8ee1d4 --- /dev/null +++ b/autotest/gdrivers/data/vrt/arraysource_derivedarray_grid.vrt @@ -0,0 +1,35 @@ + + PROJCS["NAD27 / UTM zone 11N",GEOGCS["NAD27",DATUM["North_American_Datum_1927",SPHEROID["Clarke 1866",6378206.4,294.978698213898,AUTHORITY["EPSG","7008"]],AUTHORITY["EPSG","6267"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4267"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","26711"]] + 4.4072000000000000e+05, 6.0000000000000000e+01, 0.0000000000000000e+00, 3.7513200000000000e+06, 0.0000000000000000e+00, -6.0000000000000000e+01 + + Gray + + + + ../netcdf/test_gridded.nc + /ar + + + + invdist + + + ../netcdf/test_gridded.nc + /varX + + + + + ../netcdf/test_gridded.nc + /varY + + + + + + + + + + + diff --git a/autotest/gdrivers/data/vrt/arraysource_derivedarray_no_step.vrt b/autotest/gdrivers/data/vrt/arraysource_derivedarray_no_step.vrt new file mode 100644 index 000000000000..21544f2a091f --- /dev/null +++ b/autotest/gdrivers/data/vrt/arraysource_derivedarray_no_step.vrt @@ -0,0 +1,15 @@ + + PROJCS["NAD27 / UTM zone 11N",GEOGCS["NAD27",DATUM["North_American_Datum_1927",SPHEROID["Clarke 1866",6378206.4,294.978698213898,AUTHORITY["EPSG","7008"]],AUTHORITY["EPSG","6267"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4267"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","26711"]] + 4.4072000000000000e+05, 6.0000000000000000e+01, 0.0000000000000000e+00, 3.7513200000000000e+06, 0.0000000000000000e+00, -6.0000000000000000e+01 + + Gray + + + + ../netcdf/byte_no_cf.nc + /Band1 + + + + + diff --git a/autotest/gdrivers/data/vrt/arraysource_derivedarray_resample.vrt b/autotest/gdrivers/data/vrt/arraysource_derivedarray_resample.vrt new file mode 100644 index 000000000000..71506d7e886e --- /dev/null +++ b/autotest/gdrivers/data/vrt/arraysource_derivedarray_resample.vrt @@ -0,0 +1,18 @@ + + PROJCS["NAD27 / UTM zone 11N",GEOGCS["NAD27",DATUM["North_American_Datum_1927",SPHEROID["Clarke 1866",6378206.4,294.978698213898,AUTHORITY["EPSG","7008"]],AUTHORITY["EPSG","6267"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4267"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","26711"]] + 4.4072000000000000e+05, 6.0000000000000000e+01, 0.0000000000000000e+00, 3.7513200000000000e+06, 0.0000000000000000e+00, -6.0000000000000000e+01 + + Gray + + + + ../netcdf/byte.nc + /Band1 + + + + + + + + diff --git a/autotest/gdrivers/data/vrt/arraysource_derivedarray_resample_options.vrt b/autotest/gdrivers/data/vrt/arraysource_derivedarray_resample_options.vrt new file mode 100644 index 000000000000..6978aa9deadd --- /dev/null +++ b/autotest/gdrivers/data/vrt/arraysource_derivedarray_resample_options.vrt @@ -0,0 +1,24 @@ + + PROJCS["NAD27 / UTM zone 11N",GEOGCS["NAD27",DATUM["North_American_Datum_1927",SPHEROID["Clarke 1866",6378206.4,294.978698213898,AUTHORITY["EPSG","7008"]],AUTHORITY["EPSG","6267"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4267"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","26711"]] + 4.4072000000000000e+05, 6.0000000000000000e+01, 0.0000000000000000e+00, 3.7513200000000000e+06, 0.0000000000000000e+00, -6.0000000000000000e+01 + + Gray + + + + ../netcdf/byte.nc + /Band1 + + + + + + Bilinear + EPSG:4267 + + + + + + + diff --git a/autotest/gdrivers/data/vrt/arraysource_derivedarray_transpose.vrt b/autotest/gdrivers/data/vrt/arraysource_derivedarray_transpose.vrt new file mode 100644 index 000000000000..b353b86f1b20 --- /dev/null +++ b/autotest/gdrivers/data/vrt/arraysource_derivedarray_transpose.vrt @@ -0,0 +1,18 @@ + + PROJCS["NAD27 / UTM zone 11N",GEOGCS["NAD27",DATUM["North_American_Datum_1927",SPHEROID["Clarke 1866",6378206.4,294.978698213898,AUTHORITY["EPSG","7008"]],AUTHORITY["EPSG","6267"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4267"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","26711"]] + 4.4072000000000000e+05, 6.0000000000000000e+01, 0.0000000000000000e+00, 3.7513200000000000e+06, 0.0000000000000000e+00, -6.0000000000000000e+01 + + Gray + + + + ../netcdf/byte_no_cf.nc + /Band1 + + + + + + + + diff --git a/autotest/gdrivers/data/vrt/arraysource_derivedarray_view.vrt b/autotest/gdrivers/data/vrt/arraysource_derivedarray_view.vrt new file mode 100644 index 000000000000..e96fa3f23813 --- /dev/null +++ b/autotest/gdrivers/data/vrt/arraysource_derivedarray_view.vrt @@ -0,0 +1,18 @@ + + PROJCS["NAD27 / UTM zone 11N",GEOGCS["NAD27",DATUM["North_American_Datum_1927",SPHEROID["Clarke 1866",6378206.4,294.978698213898,AUTHORITY["EPSG","7008"]],AUTHORITY["EPSG","6267"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4267"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","26711"]] + 4.4072000000000000e+05, 6.0000000000000000e+01, 0.0000000000000000e+00, 3.7513200000000000e+06, 0.0000000000000000e+00, -6.0000000000000000e+01 + + Gray + + + + ../netcdf/byte_no_cf.nc + /Band1 + + + + + + + + diff --git a/autotest/gdrivers/data/vrt/arraysource_singlesourcearray.vrt b/autotest/gdrivers/data/vrt/arraysource_singlesourcearray.vrt new file mode 100644 index 000000000000..08a65351dfe4 --- /dev/null +++ b/autotest/gdrivers/data/vrt/arraysource_singlesourcearray.vrt @@ -0,0 +1,13 @@ + + PROJCS["NAD27 / UTM zone 11N",GEOGCS["NAD27",DATUM["North_American_Datum_1927",SPHEROID["Clarke 1866",6378206.4,294.978698213898,AUTHORITY["EPSG","7008"]],AUTHORITY["EPSG","6267"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4267"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","26711"]] + 4.4072000000000000e+05, 6.0000000000000000e+01, 0.0000000000000000e+00, 3.7513200000000000e+06, 0.0000000000000000e+00, -6.0000000000000000e+01 + + Gray + + + ../netcdf/byte_no_cf.nc + /Band1 + + + + diff --git a/autotest/gdrivers/data/vrt/arraysource_srcrect_dstrect.vrt b/autotest/gdrivers/data/vrt/arraysource_srcrect_dstrect.vrt new file mode 100644 index 000000000000..0e1a67f1f929 --- /dev/null +++ b/autotest/gdrivers/data/vrt/arraysource_srcrect_dstrect.vrt @@ -0,0 +1,20 @@ + + PROJCS["NAD27 / UTM zone 11N",GEOGCS["NAD27",DATUM["North_American_Datum_1927",SPHEROID["Clarke 1866",6378206.4,294.978698213898,AUTHORITY["EPSG","7008"]],AUTHORITY["EPSG","6267"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4267"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","26711"]] + 4.4072000000000000e+05, 6.0000000000000000e+01, 0.0000000000000000e+00, 3.7513200000000000e+06, 0.0000000000000000e+00, -6.0000000000000000e+01 + + Gray + + + + ../netcdf/byte_no_cf.nc + /Band1 + + + + + + + + + + diff --git a/autotest/gdrivers/vrtmultidim.py b/autotest/gdrivers/vrtmultidim.py index bb6498f32a6b..1c701a6b0b54 100755 --- a/autotest/gdrivers/vrtmultidim.py +++ b/autotest/gdrivers/vrtmultidim.py @@ -1382,3 +1382,557 @@ def test_vrtmultidim_createmultidimensional(): _validate(got_data) gdal.Unlink(tmpfile) + + +@pytest.mark.require_driver("netCDF") +def test_vrtmultidim_arraysource_singlesourcearray(): + + ds = gdal.Open("data/vrt/arraysource_singlesourcearray.vrt") + assert ds.GetRasterBand(1).Checksum() == 4855 + + +@pytest.mark.require_driver("netCDF") +def test_vrtmultidim_arraysource_statistics_and_serialization(tmp_vsimem): + + netcdf_tmp_file = str(tmp_vsimem / "tmp.nc") + gdal.FileFromMemBuffer(netcdf_tmp_file, open("data/netcdf/byte.nc", "rb").read()) + tmp_file = str(tmp_vsimem / "tmp.vrt") + data = open("data/vrt/arraysource_singlesourcearray.vrt", "r").read() + data = data.replace( + """../netcdf/byte_no_cf.nc""", + f"""{netcdf_tmp_file}""", + ) + gdal.FileFromMemBuffer(tmp_file, data) + ds = gdal.Open(tmp_file, gdal.GA_Update) + assert ds.GetRasterBand(1).GetMinimum() is None + assert ds.GetRasterBand(1).GetMaximum() is None + ds.GetRasterBand(1).ComputeStatistics(0) + src_ds = gdal.Open(netcdf_tmp_file) + assert ( + ds.GetRasterBand(1).GetDefaultHistogram() + == src_ds.GetRasterBand(1).GetDefaultHistogram() + ) + ds = None + ds = gdal.Open(tmp_file) + assert ds.GetRasterBand(1).Checksum() == 4855 + assert ds.GetRasterBand(1).GetMinimum() == 74 + assert ds.GetRasterBand(1).GetMaximum() == 255 + + +@pytest.mark.require_driver("netCDF") +def test_vrtmultidim_arraysource_derivedarray_no_step(): + + ds = gdal.Open("data/vrt/arraysource_derivedarray_no_step.vrt") + assert ds.GetRasterBand(1).Checksum() == 4855 + + +@pytest.mark.require_driver("netCDF") +def test_vrtmultidim_arraysource_array(): + + ds = gdal.Open("data/vrt/arraysource_array.vrt") + assert ds.GetRasterBand(1).Checksum() == 4855 + + +@pytest.mark.require_driver("netCDF") +def test_vrtmultidim_arraysource_derivedarray_view(): + + ds = gdal.Open("data/vrt/arraysource_derivedarray_view.vrt") + assert ds.GetRasterBand(1).Checksum() == 4672 + + +@pytest.mark.require_driver("netCDF") +def test_vrtmultidim_arraysource_srcrect_dstrect(): + + ds = gdal.Open("data/vrt/arraysource_srcrect_dstrect.vrt") + assert ds.GetRasterBand(1).Checksum() == 1136 + + +@pytest.mark.require_driver("netCDF") +def test_vrtmultidim_arraysource_derivedarray_transpose(): + + ds = gdal.Open("data/vrt/arraysource_derivedarray_transpose.vrt") + assert ds.GetRasterBand(1).Checksum() == 4567 + + +@pytest.mark.require_driver("netCDF") +def test_vrtmultidim_arraysource_derivedarray_resample(): + + ds = gdal.Open("data/vrt/arraysource_derivedarray_resample.vrt") + assert ds.GetRasterBand(1).Checksum() == 4672 + + +@pytest.mark.require_driver("netCDF") +def test_vrtmultidim_arraysource_derivedarray_resample_options(): + + ds = gdal.Open("data/vrt/arraysource_derivedarray_resample_options.vrt") + assert ds.GetRasterBand(1).Checksum() == 19827 + + +@pytest.mark.require_driver("netCDF") +def test_vrtmultidim_arraysource_derivedarray_grid(): + + ds = gdal.Open("data/vrt/arraysource_derivedarray_grid.vrt") + assert ds.GetRasterBand(1).Checksum() == 21 + + +@pytest.mark.require_driver("netCDF") +def test_vrtmultidim_arraysource_derivedarray_getunscaled(): + + ds = gdal.Open("data/vrt/arraysource_derivedarray_getunscaled.vrt") + assert ds.GetRasterBand(1).Checksum() == 4855 + + +@pytest.mark.require_driver("netCDF") +def test_vrtmultidim_arraysource_derivedarray_getmask(): + + ds = gdal.Open("data/vrt/arraysource_derivedarray_getmask.vrt") + assert ds.GetRasterBand(1).Checksum() == 400 + + +@pytest.mark.require_driver("netCDF") +@gdaltest.enable_exceptions() +def test_vrtmultidim_arraysource_error_no_array_in_array_source(): + + with pytest.raises( + Exception, + match="Cannot find a , or in ", + ): + gdal.Open( + """ + + Gray + + + + """ + ) + + +@pytest.mark.require_driver("netCDF") +@gdaltest.enable_exceptions() +def test_vrtmultidim_arraysource_error_no_SourceFilename(): + + with pytest.raises( + Exception, match="Cannot find in " + ): + gdal.Open( + """ + + Gray + + + + /Band1 + + + + """ + ) + + +@pytest.mark.require_driver("netCDF") +@gdaltest.enable_exceptions() +def test_vrtmultidim_arraysource_error_no_SourceArray(): + + with pytest.raises( + Exception, match="Cannot find in " + ): + gdal.Open( + """ + + Gray + + + data/netcdf/byte_no_cf.nc + + + + + """ + ) + + +@pytest.mark.require_driver("netCDF") +@gdaltest.enable_exceptions() +def test_vrtmultidim_arraysource_error_wrong_SourceFilename(): + + with pytest.raises(Exception, match="i/do/not/exist.nc"): + gdal.Open( + """ + + Gray + + + i/do/not/exist.nc + /Band1 + + + + """ + ) + + +@pytest.mark.require_driver("netCDF") +@gdaltest.enable_exceptions() +def test_vrtmultidim_arraysource_error_wrong_SourceArray(): + + with pytest.raises(Exception, match="Cannot find array"): + gdal.Open( + """ + + Gray + + + data/netcdf/byte_no_cf.nc + /i/do/not/exist + + + + """ + ) + + +@pytest.mark.require_driver("netCDF") +@gdaltest.enable_exceptions() +def test_vrtmultidim_arraysource_error_not_a_2D_array(): + + with pytest.raises( + Exception, + match="Array referenced in should be a two-dimensional array", + ): + gdal.Open( + """ + + Gray + + + data/netcdf/byte.nc + /x + + + + """ + ) + + +@pytest.mark.require_driver("netCDF") +@gdaltest.enable_exceptions() +def test_vrtmultidim_arraysource_error_no_source_array_in_DerivedArray(): + + with pytest.raises( + Exception, + match="Cannot find a , or in ", + ): + gdal.Open( + """ + + Gray + + + + + """ + ) + + +@pytest.mark.require_driver("netCDF") +@gdaltest.enable_exceptions() +def test_vrtmultidim_arraysource_error_unknown_step(): + + with pytest.raises(Exception, match="Unknown . element"): + gdal.Open( + """ + + Gray + + + + data/netcdf/byte_no_cf.nc + /Band1 + + + + + + """ + ) + + +@pytest.mark.require_driver("netCDF") +@gdaltest.enable_exceptions() +def test_vrtmultidim_arraysource_error_view_missing_expr(): + + with pytest.raises( + Exception, match="Cannot find 'expr' attribute in element" + ): + gdal.Open( + """ + + Gray + + + + data/netcdf/byte_no_cf.nc + /Band1 + + + + + + """ + ) + + +@pytest.mark.require_driver("netCDF") +@gdaltest.enable_exceptions() +def test_vrtmultidim_arraysource_error_transpose_missing_order(): + + with pytest.raises( + Exception, match="Cannot find 'newOrder' attribute in element" + ): + gdal.Open( + """ + + Gray + + + + data/netcdf/byte_no_cf.nc + /Band1 + + + + + + """ + ) + + +@pytest.mark.require_driver("netCDF") +@gdaltest.enable_exceptions() +def test_vrtmultidim_arraysource_error_resample_wrong_dimension(): + + with pytest.raises(Exception, match="Missing name attribute on Dimension"): + gdal.Open( + """ + + Gray + + + + data/netcdf/byte_no_cf.nc + /Band1 + + + + + + + + + + """ + ) + + +@pytest.mark.require_driver("netCDF") +@gdaltest.enable_exceptions() +def test_vrtmultidim_arraysource_error_resample_wrong_srs(): + + with pytest.raises(Exception, match="Invalid value for "): + gdal.Open( + """ + + Gray + + + + data/netcdf/byte_no_cf.nc + /Band1 + + + + invalid + + + + + + """ + ) + + +@pytest.mark.require_driver("netCDF") +@gdaltest.enable_exceptions() +def test_vrtmultidim_arraysource_error_resample_wrong_option(): + + with pytest.raises( + Exception, match="Cannot find 'name' attribute in