mapbox / rio-rgbify

Encoded arbitrary bit depth rasters in pseudo base-256
MIT License
99 stars 36 forks source link

rasterio._err.CPLE_AppDefinedError: densify_pts must be at least 2 if the output is geograpic #39

Open ahmadiqbalpk opened 2 years ago

ahmadiqbalpk commented 2 years ago

I am getting this error. I have installed python 3.8 and pip install rio-rgbify. When ever i run this command "rio rgbify --format png --min-z 0 --max-z 15 input.tif output.mbtiles

I am getting this error "_rasterio._err.CPLE_AppDefinedError: densifypts must be at least 2 if the output is geograpic."

Kindly tell me what is the issue. I have checked all the online forums and also try your tif dataset.

rumicuna commented 2 years ago

I'm also stuck with this same issue except in this case: When I run against .hgt files from the NASA SRTM DEM's I don't see this error, but I get it if I run it with any other tif file (including one generated from gdalwarping the .hgt SRTM files into geotifs in EPSG3857)

zdila commented 2 years ago

I also encounter this error when producing mbtiles. If the output is tif then there is no such error.

Input tif:

Driver: GTiff/GeoTIFF
Files: smooth-sk-warped.tif
Size is 475105, 293083
Coordinate System is:
PROJCRS["WGS 84 / Pseudo-Mercator",
    BASEGEOGCRS["WGS 84",
        ENSEMBLE["World Geodetic System 1984 ensemble",
            MEMBER["World Geodetic System 1984 (Transit)"],
            MEMBER["World Geodetic System 1984 (G730)"],
            MEMBER["World Geodetic System 1984 (G873)"],
            MEMBER["World Geodetic System 1984 (G1150)"],
            MEMBER["World Geodetic System 1984 (G1674)"],
            MEMBER["World Geodetic System 1984 (G1762)"],
            MEMBER["World Geodetic System 1984 (G2139)"],
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]],
            ENSEMBLEACCURACY[2.0]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4326]],
    CONVERSION["Popular Visualisation Pseudo-Mercator",
        METHOD["Popular Visualisation Pseudo Mercator",
            ID["EPSG",1024]],
        PARAMETER["Latitude of natural origin",0,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",0,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["False easting",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["easting (X)",east,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["northing (Y)",north,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Web mapping and visualisation."],
        AREA["World between 85.06°S and 85.06°N."],
        BBOX[-85.06,-180,85.06,180]],
    ID["EPSG",3857]]
Data axis to CRS axis mapping: 1,2
Origin = (1849822.663334832992405,6393767.517880097031593)
Pixel Size = (1.194328566968441,-1.194328566968441)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  COMPRESSION=DEFLATE
  INTERLEAVE=BAND
  PREDICTOR=2
Corner Coordinates:
Upper Left  ( 1849822.663, 6393767.518) ( 16d37' 2.06"E, 49d41'45.05"N)
Lower Left  ( 1849822.663, 6043730.118) ( 16d37' 2.06"E, 47d37' 9.00"N)
Upper Right ( 2417254.137, 6393767.518) ( 21d42'52.43"E, 49d41'45.05"N)
Lower Right ( 2417254.137, 6043730.118) ( 21d42'52.43"E, 47d37' 9.00"N)
Center      ( 2133538.400, 6218748.818) ( 19d 9'57.25"E, 48d40' 5.53"N)
Band 1 Block=256x256 Type=Float32, ColorInterp=Gray
ahmadiqbalpk commented 2 years ago

In my case it was issue with "no data points" I delete it using - gdalwarp, then run the "rio rgbify --format png --min-z 0 --max-z 15 input.tif output.mbtiles". it works fine

gqdc commented 2 years ago

I have same issue : no problem with geotiff output, but with mbtiles, it crashs.

I tested on tiff with, and without "No Data" value, and the result is every time the same.

There was not any problem with 1.2.0 version of rasterio from Debian packages repositories.

utagawal commented 2 years ago

@dnomadb Do you also reproduce the issue ? Any idea what it could be ?

NasH5169 commented 1 year ago

Same here.

swork1 commented 1 year ago

Using Python 3.8 and rasterio 1.2.0 worked for me

luo-geng commented 1 year ago

pay a eye

kannes commented 1 year ago

In my case it was issue with "no data points" I delete it using - gdalwarp, then run the "rio rgbify --format png --min-z 0 --max-z 15 input.tif output.mbtiles". it works fine

What does that mean, what exactly did you do with gdalwarp? Please share more information so others can fix it too.

kannes commented 1 year ago

edit: Don't edit source files without thinking, what I wrote below is wrong.

Ah, this is a weird one. Apparently you need to have some NODATA value set in the input?

I had followed https://github.com/acalcutt/jaxa_AW3D30_to_MBTiles/blob/main/create_terrainrgb.sh but skipped the initial gdalbuildvrt invocation as I already had a nice COG (in EPSG:4326) and thought it would be a fine input for the gdalwarp invocation. Using that warped VRT as input for rio rgbify let me to the densify_pts error.

When I built an initial VRT on my existing dataset with -vrtnodata -9999, I could then run rio rgbify without further issues (at least so far ;) ).

Super weird error...

kannes commented 1 year ago

You can remove the densify_pts=0 in mbtiler.py's _make_tiles method but who knows why that was put there and if it is important. GDAL uses 21 by default.

https://github.com/mapbox/rio-rgbify/commit/be25542bb7e4f791b9d4a3012100295198a59975 cc @dnomadb

I can create tiles if I remove it but have no idea of the potential implications so don't do this unless you don't care :D

bwenzel2 commented 5 months ago

If you want to continue using the official library from pypi, you can monkey patch the transform_bounds call in mbtiler.py to modify the densify_pts kwarg value like so:

import rio_rgbify
from rasterio.warp import transform_bounds

def fixed_transform_bounds(*args, **kwargs):
    if 'densify_pts' in kwargs:
         kwargs['densify_pts'] = 2
    return transform_bounds(*args, **kwargs)

rio_rgbify.mbtiler.transform_bounds = fixed_transform_bounds

if __name__ == '__main__':
    with rio_rgbify.mbtiler.RGBTiler(
            "input.tif",
            "output.mbtiles",
            interval=0.1,
            base_val=-10000,
            format="png",
            max_z=18,
            min_z=10,
        ) as tiler:
            tiler.run(24)

In my case I'm calling this from python code already as part of a pipeline, so while it's not the most elegant solution, it gets the job done for what I need.