'How can I retrieve my raster data from PostGIS database in Django project and calculate my value of the raster at Given location
I have the raster data stored in my database. I want to get that raster data back in my Django and try to find the value at that certain pixel. My code
class dataviewView(views.View):
def post(self, request):
data = json.loads(request.body)
name = data['name']
lat = data['lat']
long = data['long']
point = ogr.Geometry(ogr.wkbPoint)
point.AddPoint(lat,long)
if ndvimodel.objects.filter(name = name).exists():
p1 = ndvimodel.objects.all()
for raster_data in p1:
rasterdata = raster_data.rast
print(type(rasterdata))
But I am unable to get that raster content. How can I solve these issues
Solution 1:[1]
Access to raster.bands[0].data() will return numpy array from the first band, then access to raster.geotransform. After yo can use
mx, my = geom.GetX(), geom.GetY()
px = int((mx - gt[0]) / gt[1])
py = int((my - gt[3]) / gt[5])
intval = raster.bands[0].data()[px, py]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ?????? ??????? |
