0

I have satellite image that I want to convert into numy array (and then to Pandas). I already know how to do that thanks to Stefan, but th eproblem is that it does not preserve the coordinate data.

This is how I do it now:

import xarray
src=rasterio.open('14072020.tif')
array = src.read()

pd.DataFrame(array.reshape([13,-1]).T)

I have also tried to follow this answer (keeping the coordinate system of raster files in the resulting raster file after operation with numpy) but I get all the time error

NameError: name 'gdal_array' is not defined

which doest allow me to open the image.

My end goal is to have Pandas table that contains the bands values toegther with the coordinate values.

1

You can use the open_rasterio and to_dataframe methods to accomplish that.

import rioxarray

rds = rioxarray.open_rasterio("file.tif")
rds.to_dataframe()

See also: https://gis.stackexchange.com/a/358057/144357

| improve this answer | |
0

I would read with gdal and dump that to a numpy array. ReadAsArray().

Coordinates and projection are obtained using the GetGeotransform() SetGeotransform() and the GetProjection() and SetProjection() applied to the data set.

Example here. https://pcjericks.github.io/py-gdalogr-cookbook/raster_layers.html

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.