Serializing to RasterField()
See original GitHub issueHello django-rest-framework-gis
team, thanks for your work on this package, it’s been super helpful for me recently.
I have a quick question that I’m hoping someone can help me with. I have read through the ReadMe and also searched issues, but I can’t see a mention of ‘raster’ so I hope it’s okay to post a quick question here.
** Question**
Is it possible to easily serialize a raster (.tif) image so that it can be saved to a geodjango
RasterField()
?
Use Case
I have an app which grabs some Corine landcover data via the API. With the .tif file in memory, I wish to save the data to a RasterField
:
# bbox = <add_bbox_coords_here>
corine_lc = requests.get("https://image.discomap.eea.europa.eu/arcgis/rest/services/Corine/CLC2018_WM/MapServer/export?bbox="+bbox+"&bboxSR=4326&layers=&layerDefs=&size=800%2C800&imageSR=&historicMoment=&format=tif&transparent=true&dpi=300&time=&layerTimeOptions=&dynamicLayers=&gdbVersion=&mapScale=&rotation=&datumTransformations=&layerParameterValues=&mapRangeValues=&layerRangeValues=&clipping=&spatialFilter=&f=json")
corine_lc = corine_lc.json()
file = rasterio.open(corine_lc['href'])
# Use 'file' to save to a RasterField
If this is a ridiculous way to approach the problem, does anyone know a better way of doing this? Perhaps some sort of ByteIO
way, saving the .tif as raw data into a different model field type?
Thanks!
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
I honestly have no idea, nor I know if this is on-topic for this project or not. In this org we maintain a lot of packages we use in OpenWISP and we are generally overloaded with work to do and have very little time available to answer questions like this one.
I am closing this because it’s not a bug report nor an explicit feature request. If you find an answer to your question and you think this can become a feature request please reopen and add the necessary deatails and motivations.
I wish you good luck with your search!
Best regards Federico
Hi @henriod thanks for the detective work in DRF’s
ImageField
.Unfortunately I’m a bit rookie to fully understand how to implement this within
djang-rest-framework-gis
. I’d have to do some research to see how this would be possible.