openstreetmap / mod_tile

Renders map tiles with mapnik and serves them using apache
http://wiki.openstreetmap.org/wiki/Mod_tile
GNU General Public License v2.0
285 stars 186 forks source link

getting blank tile while using mod_tile with mapnik to serve geotiff file #432

Open pdpsinghr opened 2 months ago

pdpsinghr commented 2 months ago

Hi, I stuck in one issue where i have geotiff files and i want to use mod_tile but problem is after trying everything i am still getting balnk tile in api response but i tride to generate same tile using python and mapnik i am able to do so.

i am adding all information here

1) mapnik.xml

<?xml version="1.0" encoding="utf-8"?>

raster-style gdal /usr/share/renderd/mod_tile_poc/AQ.tif true /usr/share/renderd/mod_tile_poc/mapnik.log debug

2) /etc/renderd.conf

[renderd] pid_file=/run/renderd/renderd.pid socketname=/run/renderd/renderd.sock stats_file=/run/renderd/renderd.stats tile_dir=/var/cache/renderd/tiles

[mapnik] font_dir=/usr/share/fonts font_dir_recurse=0 plugins_dir=/usr/lib/mapnik/3.0/input

[default] URI=/osm_tiles/ TILEDIR=/var/lib/mod_tile XML=/usr/share/renderd/example-map/mapnik.xml HOST=0.0.0.0 TILESIZE=256

[example-map] URI=/tiles/renderd-example XML=/usr/share/renderd/example-map/mapnik.xml

[example-map-jpg] TYPE=jpg image/jpeg jpeg URI=/tiles/renderd-example-jpg XML=/usr/share/renderd/example-map/mapnik.xml

[example-map-png256] TYPE=png image/png png256 URI=/tiles/renderd-example-png256 XML=/usr/share/renderd/example-map/mapnik.xml

[example-map-png32] TYPE=png image/png png32 URI=/tiles/renderd-example-png32 XML=/usr/share/renderd/example-map/mapnik.xml

[example-map-webp] TYPE=webp image/webp webp URI=/tiles/renderd-example-webp XML=/usr/share/renderd/example-map/mapnik.xml

3) this is info about geotiff file

Driver: GTiff/GeoTIFF Files: AQ.tiff Size is 7220, 2810 Coordinate System is: GEOGCRS["WGS 84", DATUM["World Geodetic System 1984", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1]]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433]], CS[ellipsoidal,2], AXIS["geodetic latitude (Lat)",north, ORDER[1], ANGLEUNIT["degree",0.0174532925199433]], AXIS["geodetic longitude (Lon)",east, ORDER[2], ANGLEUNIT["degree",0.0174532925199433]], ID["EPSG",4326]] Data axis to CRS axis mapping: 2,1 Origin = (-180.500000000000000,84.099607528087063) Pixel Size = (0.050000000000000,-0.050000000000000) Metadata: AREA_OR_POINT=Area Image Structure Metadata: INTERLEAVE=BAND Corner Coordinates: Upper Left (-180.5000000, 84.0996075) (180d30' 0.00"W, 84d 5'58.59"N) Lower Left (-180.5000000, -56.4003925) (180d30' 0.00"W, 56d24' 1.41"S) Upper Right ( 180.5000000, 84.0996075) (180d30' 0.00"E, 84d 5'58.59"N) Lower Right ( 180.5000000, -56.4003925) (180d30' 0.00"E, 56d24' 1.41"S) Center ( 0.0000000, 13.8496075) ( 0d 0' 0.01"E, 13d50'58.59"N) Band 1 Block=7220x1 Type=Int32, ColorInterp=Gray NoData Value=-255

hummeltech commented 2 months ago

Hello @pdpsinghr, It looks like your mapnik.xml file may be mal-formed, can you provide your renderd --foreground output?

Here's an example of our valid example mapnik.xml file: https://github.com/openstreetmap/mod_tile/blob/c3453bc1e19247c145b0e87742710d5e076e338e/utils/example-map/mapnik.xml

pdpsinghr commented 2 months ago

Hi @hummeltech

I'm exploring ways to dynamically serve GeoTIFF files with mod_tile, where the hour parameter is provided via an API URL. I tried using a custom script in renderd.conf (ModTileXMLConfigEndpoint /usr/renderd/custom_script.py), but encountered issues. Do you know of any alternative methods or approaches?

i keep last 48 hours geotiff so the url will be dynamic along with the mapnik.xml.

hummeltech commented 2 months ago

@pdpsinghr, I would recommend you look into writing a "parameterization" function for this, here's a comment I wrote recently explaining it a little bit: https://github.com/openstreetmap/mod_tile/issues/396#issuecomment-1979130089

In your case, you might add a new function which would change the source GeoTIFF based on the URL path.

pdpsinghr commented 2 months ago

@hummeltech I am new to this one , so... one another questions is do i have to handle all the changes in src/parameterize_style.cpp, like on basis of url change the geotiff url in mapnik in parameterize_map_language function only? or is there any plugin i can add?

hummeltech commented 2 months ago

@pdpsinghr, you would just need to create the function and add a configuration to your renderd.conf file. The value in the request will be passed via the parameter function parameter. E.g.: Create your new function in /src/parameterize_style.cpp:

 static void parameterize_geotiff_by_date(mapnik::Map &m, char *parameter) 
 {
    char *geotiff_date = strdup(parameter);
    # modify `mapnik::Map &m` to use `geotiff_date` in the `DataSource` file name
 }

Add a reference to it in init_parameterization_function in /src/parameterize_style.cpp:

parameterize_function_ptr init_parameterization_function(const char *function_name)
{
    if (strcmp(function_name, "") == 0) {
        g_logger(G_LOG_LEVEL_DEBUG, "Parameterize_style not specified (or empty string specified)");
        return NULL;
    } else if (strcmp(function_name, "language") == 0) {
        g_logger(G_LOG_LEVEL_DEBUG, "Loading parameterization function for '%s'", function_name);
        return parameterize_map_language;
    } else if (strcmp(function_name, "geotiff_by_date") == 0) {
        g_logger(G_LOG_LEVEL_DEBUG, "Loading parameterization function for '%s'", function_name);
        return parameterize_geotiff_by_date;
    } else {
        g_logger(G_LOG_LEVEL_WARNING, "unknown parameterization function for '%s'", function_name);
    }

    return NULL;
}

Add a configuration to renderd.conf:

[geotiff_by_date]
PARAMETERIZE_STYLE=geotiff_by_date
TILEDIR=/var/lib/mod_tile
XML=/usr/share/renderd/example-map/mapnik.xml
pdpsinghr commented 2 months ago

if i define renderd.conf file like this

[ats_tile] URI=/tiles/ats_tile/2024_05_20_08 XML=/usr/share/renderd/example-map/ats_tile/2024_05_20_08_ats_tile.xml

URI=/tiles/ats_tile/2024_05_20_09 XML=/usr/share/renderd/example-map/ats_tile/2024_05_20_09_ats_tile.xml

URI=/tiles/ats_tile/2024_05_20_10 XML=/usr/share/renderd/example-map/ats_tile/2024_05_20_10_ats_tile.xml

URI=/tiles/ats_tile/2024_05_20_11 XML=/usr/share/renderd/example-map/ats_tile/2024_05_20_11_ats_tile.xml

then from cache i getting wrong tile mostly from different hour not for the hour specified and in cache directory also it is on basis of x,y,z not on basis of hour

can we store cache according to hour and then go by x, y, z?

hummeltech commented 2 months ago

If you are going to create multiple map sections in your renderd.conf file, you will need to add the section headers:

[ats_tile_2024_05_20_08]

URI=/tiles/ats_tile/2024_05_20_08 XML=/usr/share/renderd/example-map/ats_tile/2024_05_20_08_ats_tile.xml

[ats_tile_2024_05_20_09] URI=/tiles/ats_tile/2024_05_20_09 XML=/usr/share/renderd/example-map/ats_tile/2024_05_20_09_ats_tile.xml

[ats_tile_2024_05_20_10] URI=/tiles/ats_tile/2024_05_20_10 XML=/usr/share/renderd/example-map/ats_tile/2024_05_20_10_ats_tile.xml

[ats_tile_2024_05_20_11] URI=/tiles/ats_tile/2024_05_20_11 XML=/usr/share/renderd/example-map/ats_tile/2024_05_20_11_ats_tile.xml

then from cache i getting wrong tile mostly from different hour not for the hour specified and in cache directory also it is on basis of x,y,z not on basis of hour

can we store cache according to hour and then go by x, y, z?