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

image.readRasters bbox unit #390

Open
am2222 opened this issue Aug 25, 2023 · 2 comments
Open

image.readRasters bbox unit #390

am2222 opened this issue Aug 25, 2023 · 2 comments

Comments

@am2222
Copy link

am2222 commented Aug 25, 2023

Hi,
I am trying to read data from a raster file using bbox. I could not find any information of the unit of the coordinates in bbox. I assume since it is mentioned geographic coordinates, it should be EPSG:4326. However, if our COG file is in another CRS like EPSG:3005 does the library internally convert the coordinates, or do we need to perform any kind of conversion?

Here is gdalinfo of one of my rasters.

Driver: GTiff/GeoTIFF
Files: C:\Users\---\Downloads\harvest_propha_COG.tif
Size is 1987, 2293
Warning 1: PROJ: proj_create_from_database: G:\Program Files\PostgreSQL\14\share\contrib\postgis-3.1\proj\proj.db lacks DATABASE.LAYOUT.VERSION.MAJOR / DATABASE.LAYOUT.VERSION.MINOR metadata. It comes from another PROJ installation.
Warning 1: The definition of projected CRS EPSG:3005 got from GeoTIFF keys is not the same as the one from the EPSG registry, which may cause issues during reprojection operations. Set GTIFF_SRS_SOURCE configuration option to EPSG to use official parameters (overriding the ones from GeoTIFF keys), or to GEOKEYS to use custom values from GeoTIFF keys and drop the EPSG code.
Coordinate System is:
ENGCRS["NAD_1983_BC_Environment_Albers",
    EDATUM[""],
    CS[Cartesian,2],
        AXIS["(E)",east,
            ORDER[1],
            LENGTHUNIT["metre",1,
                ID["EPSG",9001]]],
        AXIS["(N)",north,
            ORDER[2],
            LENGTHUNIT["metre",1,
                ID["EPSG",9001]]]]
Data axis to CRS axis mapping: 1,2
Origin = (1355352.187799997627735,685678.698000006843358)
Pixel Size = (100.000000000000000,-100.000000000000000)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  COMPRESSION=LZW
  INTERLEAVE=BAND
  LAYOUT=COG
Corner Coordinates:
Upper Left  ( 1355352.188,  685678.698)
Lower Left  ( 1355352.188,  456378.698)
Upper Right ( 1554052.188,  685678.698)
Lower Right ( 1554052.188,  456378.698)
Center      ( 1454702.188,  571028.698)
Band 1 Block=256x256 Type=Float64, ColorInterp=Gray
  Min=0.000 Max=100.051
  Minimum=0.000, Maximum=100.051, Mean=23.269, StdDev=38.879
  NoData Value=-1.79769313486231571e+308
  Overviews: 994x1147, 497x574, 249x287
  Metadata:
    STATISTICS_MAXIMUM=100.050693491
    STATISTICS_MEAN=23.26927534151
    STATISTICS_MINIMUM=0
    STATISTICS_SKIPFACTORX=1
    STATISTICS_SKIPFACTORY=1
    STATISTICS_STDDEV=38.879092139159

So I try to read the file as follows. I convert my coordinates to EPSG:4326 while my raster is in EPSG:3857

 const url_to_geotiff_file = "https://lpat-base-data.s3.us-west-2.amazonaws.com/test_cog/harvest_propha_COG.tif";
const tiff = await GeoTIFF.fromUrl(url);
const pool = new GeoTIFF.Pool();
const bboxMer = merc(x, y, z); //coordinates are in `EPSG:3857`
const minC = proj4FullyLoaded( "EPSG:3857","EPSG:4326",).forward([bboxMer[0],bboxMer[1]]);
const maxC = proj4FullyLoaded( "EPSG:3857","EPSG:4326",).forward([bboxMer[2],bboxMer[3]]);
const bbox = [...minC,...maxC]
const size = 256;
tiff.readRasters({
  bbox,
  width: size,
  height: size,
  interleave: true,
  pool,
}).then((data) => {
  //Data are always 0
});

But I don't get any non-zero data.

@am2222 am2222 changed the title image.readRasters bbox units image.readRasters bbox unit Aug 25, 2023
@constantinius
Copy link
Member

geotiff.js does not concern itself with coordinate systems translations. Neither in bbox nor raster space. So all BBox values have to be expressed in the TIFFs coordinate system. It is up to the user to translate the BBox to the files CRS.

@DanielJDufour
Copy link
Contributor

Hi @am2222 . You could consider trying https://github.com/GeoTIFF/geotiff-tile. It's a library that uses geotiff.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants