1

I have satellite image that I want to convert into numpy array (and then to Pandas). I already know how to do that, but the problem 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 always get this error:

NameError: name 'gdal_array' is not defined

which does not allow me to open the image.

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

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Oct 30, 2020 at 10:50
1

2 Answers 2

3

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

answered Oct 31, 2020 at 19:02
1

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

answered Nov 1, 2020 at 2:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.