question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Serializing to RasterField()

See original GitHub issue

Hello 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:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
nemesisdesigncommented, Aug 26, 2021

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

0reactions
simon-tarrcommented, Sep 3, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django RasterField deserialization bug with pixeltype flags
After inserting some raster data with raster2pgsql into a Django model table with a RasterField column, I get a list index out of...
Read more >
Serializing a model in GeoDjango where the geo_field is in a ...
I am trying to serialize this model, but am getting extra fields in my geojson file: Models.py class Historicalfile(models.
Read more >
Field (ArcGIS_Runtime_Java 10.1.1 API) - ArcGIS Resources
public class Field; extends Object; implements Serializable ... define an esri Raster field. static int, esriFieldTypeSingle ... int, getFieldType()
Read more >
GeoJSON Serializer Django 1.10官方教程 _w3cschool - 编程狮
GeoDjango provides a specific serializer for the GeoJSON format. See Serializing Django objects for more information on serialization.
Read more >
GeoDjango - GeoDjango Model API - 《Django v4.1 Documentation ...
PolygonField(); class Elevation(models.Model): name = models. ... Stores a GDALRaster. RasterField is currently only implemented for the PostGIS backend.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found