Deadwood-ai / deadwood-api

Main FastAPI application for the deadwood backend
GNU General Public License v3.0
0 stars 0 forks source link

Compute the native resolution of the image #72

Open JesJehle opened 1 month ago

JesJehle commented 1 month ago

@cmosig could you provide me with the script you mentioned. we currently have a maximum resolution of 4 cm. Should we keep this?

cmosig commented 1 month ago

What do you mean by maximum resolution?

cmosig commented 1 month ago

This is what I use. It's super fast because it computes only from the transform, bounds, and CRS

      dr = rasterio.open("xxx.tif")        
      transform = rasterio.warp.calculate_default_transform(
          src_crs=dr.crs,
          dst_crs="EPSG:8857",
          width=dr.width,
          height=dr.height,
          left=dr.bounds[0],
          bottom=dr.bounds[1],
          right=dr.bounds[2],
          top=dr.bounds[3])
      resolution = transform[0][0]

Maybe an explantion... it computes the transform for the orthophoto in the CRS EPSG:8857, which is an equal area projection. This was accurate enough in my experience. More accurate would be to use the respective UTM CRS.

And the transform is a 3x3 matrix where the top left value always indicates the shift for each pixel, i.e.,, resolution.

cmosig commented 1 month ago

If you want to get the utm crs for an orthophoto do:


def get_utm_string_from_latlon(lat, lon):
    zone = utm.from_latlon(lat, lon)
    utm_code = 32600 + zone[2]
    if lat < 0:
        utm_code -= 100
    return f"EPSG:{utm_code}"
``
JesJehle commented 1 month ago

Hmm, I thought we would limit the resolution of the COG, but it seems this is not the case at the moment. Let's implement this, though, to avoid that the cogs are becoming too big.

cmosig commented 1 month ago

Hmm, I thought we would limit the resolution of the COG, but it seems this is not the case at the moment. Let's implement this, though, to avoid that the cogs are becoming too big.

Ah ok. Yes I think this was hardcoded somewherer.