OpenGeoscience / geonotebook

A Jupyter notebook extension for geospatial visualization and analysis
Apache License 2.0
1.08k stars 141 forks source link

Change projection of rasters overlaid on Mapnik #158

Open corinat opened 6 years ago

corinat commented 6 years ago

Hello, I am new to GeoNotebook, I am at the stage where I try to understand how GeoNotebook works, or more precisely what each of the python libraries that are used in GeoNotebook do.

What I didn't understand is how I can change the projection of the rasters overplayed in Mapnik? What is the library that does this, is it Mapnik or Rasterio? For the vectors, is Shapely, if I am not mistaken.

jbeezley commented 6 years ago

At a low level, raster reprojection is handled by GDAL. Rasterio has functions that wrap GDAL and make it more palatable to use. To reproject a raster, you can either do it offline with a command-line tool like gdalwarp, or you can do it by generating a vrt file. gdalwarp can help in generating a vrt file by specifying the output format as "VRT".

For vectors, shapely has a function called transform that can perform an arbitrary transforms on all coordinates. See this stackoverflow answer for how it can be used with pyproj to reproject geometries. GDAL can also reproject vector files using the commandline tool ogr2ogr.

corinat commented 6 years ago

Actually my question is, changing the projection will change the aspect of the raster too? I can only see the raster from a side, not actually a rectangle, more like a diamond shape. If the shape is preserved (no matter the projection), that it is actually how Mapnik displays images?

jbeezley commented 6 years ago

Mapnik (via GDAL) transparently reprojects the image while tiling if the projection is set correctly in the source image. Is the image actually projected correctly when you see it? I'm guessing the "diamond shape" is a result of reprojecting from a source image provided in a sinusoidal projection common among satellite imagery.

corinat commented 6 years ago

Probably it would have been better if I had said I am trying to reproject the images from the examples that come by default with GeoNotebook. But I had a closer look and I think the way images are displayed on Mapnik has nothing to do with the projection in this case, but more with the image itself, because the projection is 4326.

jbeezley commented 6 years ago

I see, you want to set the projection of the map on the client. It's possible to get mapnik to output tiles in other projections, but there isn't any code in geonotebook to handle this. In principle it could be done, but there are a lot of places in the code base that assume that the display projection is in web mercator.

corinat commented 6 years ago

Ah, I see. So it is necessarily a Mapnik issue, it is how GeoNotebook is set to display images. It would be nice to be able to change projection, at least for the most common ones. :)

aashish24 commented 6 years ago

@corinat what projection you are hoping to use inside GeoNotebook?

corinat commented 6 years ago

Hi @aashish24. I apologies for the late response. EPSG 4326 would be great.

philnugent commented 6 years ago

I've been looking for 4326 support in interactive map widgets and would like to see 4326 included as well. Of the three modules I've looked at (ipyleaflet, folium, GeoNotebook) only folium supports 4326.

jbeezley commented 6 years ago

What is your motivation for displaying the map in 4326? In terms of visual distortion, it is worse than 3857 in every way. If you are just looking to display gridded that is given on a regular lat/lon grid, mapnik can seemlessly reproject them while generating the tiles for display. Many if not all of the examples that we have created use datasets given in 4326.

While displaying the map in an alternate projection is certainly something we can consider implementing, I want to make sure there isn't an easier option available for your use case. Also note that if the map were displayed in an alternate projection, you would have to find (or create) a base layer tile server that supports it. I don't know of any publicly accessible tile servers that provide 4326.

philnugent commented 6 years ago

@jbeezley Thanks for your response. We have large stores of imagery that are served only in 4326. I was working on a proof of concept/demonstration that would allow a user to search and display imagery from this source for which they could train and run ML models. We have moved on to another phase, but I would still be interested in any plans to add support for 4326 as I think this project is really valuable.