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

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

Open
ahmadiqbalpk opened this issue Jul 25, 2022 · 12 comments

Comments

@ahmadiqbalpk
Copy link

ahmadiqbalpk commented Jul 25, 2022

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: densify_pts 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
Copy link

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
Copy link

zdila commented Aug 11, 2022

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
Copy link
Author

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
Copy link

gqdc commented Aug 21, 2022

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
Copy link

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

@NasH5169
Copy link

Same here.

@swork1
Copy link

swork1 commented Nov 25, 2022

Using Python 3.8 and rasterio 1.2.0 worked for me

@luo-geng
Copy link

luo-geng commented Feb 1, 2023

pay a eye

@kannes
Copy link
Contributor

kannes commented Apr 5, 2023

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
Copy link
Contributor

kannes commented Apr 5, 2023

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
Copy link
Contributor

kannes commented Apr 5, 2023

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.

be25542 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

acalcutt added a commit to acalcutt/rio-rgbify that referenced this issue Jun 14, 2023
@bwenzel2
Copy link

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.

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

10 participants