locationtech / rasterframes

Geospatial Raster support for Spark DataFrames
http://rasterframes.io
Apache License 2.0
240 stars 46 forks source link

UnsupportedOperationException: Unsupported band type (15, 1) #607

Closed arind123 closed 1 year ago

arind123 commented 1 year ago

I have translated the red band of a 10mt sentinel 2 image using gdal_translate: %sh /gdal_translate /T23KKS_20210723T132241_B04_10m.jp2 /T23KKS_20210723T132241_B04_10m.tif -of COG. When I try to read this tif file using rasterframes I get the folowing error: df = spark.read.raster('/T23KKS_20210723T132241_B04_10m.tif')

Error: IllegalArgumentException: Error fetching data for one of: JVMGeoTiffRasterSource(/dbfs/FileStore/shared_uploads/Remote_sensing_trial_data/Sentinal_1/Sentinel_2_tiff/S2_gdal_converted_tifs/T23KKS_20210723T132241_B04_10m.tif) Caused by: UnsupportedOperationException: Unsupported band type (15, 1)

Any help regarding what is causing the error or what am I doing wrong.

pomadchin commented 1 year ago

Hey @arind123 it means the generated TIFF has 15 bits per sample, and the UnsignedInt sample format.

Check out the GeoTrellis supported BandTypes: https://github.com/locationtech/geotrellis/blob/v3.7.0/raster/src/main/scala/geotrellis/raster/io/geotiff/BandTypes.scala#L38-L50

You may try using GDAL to overcome the java native reader limitations. Another one is to specify the output band type in the gdal_translate step.

arind123 commented 1 year ago

Thanks @pomadchin for the reply. I am having trouble connecting the installed GDAL with Raster frames. That is why I was trying to convert the jp2's to tiff and then read via Rasterframes. Below I have pasted the gdalinfo of the converted tiff. Could you please point out which one is the problem. Is it one of "Type=UInt16" or "NBITS =15"? And if it is NBITS, what is the ideal NBITS?

Apologies if this is a very trivial question. I am a newbie in this domain.

gdainfo X.tif:

Size is 1830, 1830 Coordinate System is: PROJCRS["WGS 84 / UTM zone 23S", BASEGEOGCRS["WGS 84", DATUM["World Geodetic System 1984", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1]]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433]], ID["EPSG",4326]], CONVERSION["UTM zone 23S", METHOD["Transverse Mercator", ID["EPSG",9807]], PARAMETER["Latitude of natural origin",0, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8801]], PARAMETER["Longitude of natural origin",-45, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8802]], PARAMETER["Scale factor at natural origin",0.9996, SCALEUNIT["unity",1], ID["EPSG",8805]], PARAMETER["False easting",500000, LENGTHUNIT["metre",1], ID["EPSG",8806]], PARAMETER["False northing",10000000, LENGTHUNIT["metre",1], ID["EPSG",8807]]], CS[Cartesian,2], AXIS["(E)",east, ORDER[1], LENGTHUNIT["metre",1]], AXIS["(N)",north, ORDER[2], LENGTHUNIT["metre",1]], USAGE[ SCOPE["Engineering survey, topographic mapping."], AREA["Between 48°W and 42°W, southern hemisphere between 80°S and equator, onshore and offshore. Brazil."], BBOX[-80,-48,0,-42]], ID["EPSG",32723]] Data axis to CRS axis mapping: 1,2 Origin = (199980.000000000000000,7700020.000000000000000) Pixel Size = (60.000000000000000,-60.000000000000000) Metadata: AREA_OR_POINT=Area Image Structure Metadata: INTERLEAVE=BAND Corner Coordinates: Upper Left ( 199980.000, 7700020.000) ( 47d52'53.69"W, 20d46'31.81"S) Lower Left ( 199980.000, 7590220.000) ( 47d54' 3.41"W, 21d45'58.74"S) Upper Right ( 309780.000, 7700020.000) ( 46d49'39.05"W, 20d47'23.88"S) Lower Right ( 309780.000, 7590220.000) ( 46d50'23.31"W, 21d46'53.53"S) Center ( 254880.000, 7645120.000) ( 47d21'44.87"W, 21d16'45.03"S) Band 1 Block=1830x2 Type=UInt16, ColorInterp=Gray Image Structure Metadata: NBITS=15

arind123 commented 1 year ago

This issue is solved by setting : outputType=gdal.GDT_Int16 while converting jp2 to tiff via gdal_translate.