Friday 24 June 2022

Extract Lat/Long/Value data from TIF without Rasterio

Edit: I made a mistake with the bounty selection

Hi I would like to extract Lat/Long/Value Data from a Tif document. Unfortunately I cannot install Rasterio and only use GDAL for this. So far I have written the following code:

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
from osgeo import gdal
from numpy import linspace
from numpy import meshgrid
import pandas as pd 

Basemap = Basemap(projection='tmerc', 
              lat_0=0, lon_0=3,
              llcrnrlon=1.819757266426611, 
              llcrnrlat=41.583851612359275, 
              urcrnrlon=1.841589961763497, 
              urcrnrlat=41.598674173123)

ds = gdal.Open('Tif_file_path')
data = ds.ReadAsArray()
x = linspace(0, Basemap.urcrnrx, data.shape[1])
y = linspace(0, Basemap.urcrnry, data.shape[0])
xx, yy = meshgrid(x, y)
xx, yy = Basemap(xx, yy)
xx, yy = Basemap(xx,yy,inverse=True)

dfl = pd.DataFrame({
    'Latitude': yy.reshape(-1),
    'Longitude': xx.reshape(-1),
    'Altitude': data.reshape(-1)
    })

dfl.to_csv('C:/Users/Oliver Weisser/Desktop/Bachelor/Programm/Daten/Daten/elevation.csv')

my data: https://wetransfer.com/downloads/924bb5b5a9686c042d33a556ae94c9c020220621143611/6c3e64

Is there a good way to extract the data without using Rasterio or creating the data incorrectly?

But now I want to extract the Lat/Long data with the lines:

xx, yy = meshgrid(x, y)
xx, yy = Basemap(xx, yy)
xx, yy = Basemap(xx,yy,inverse=True)
...

However, I get quite strange results (see below) as well as a csv. File with 2.4 GB which I cannot open.

>>> print(xx)
[[1.81975727 1.81975778 1.81975829 ... 1.84184992 1.84185043 1.84185094]
 [1.81975725 1.81975777 1.81975828 ... 1.84184991 1.84185042 1.84185093]
 [1.81975724 1.81975775 1.81975826 ... 1.8418499  1.84185041 1.84185092]

Is there a good way to extract the data without using Rasterio or creating the data incorrectly?



from Extract Lat/Long/Value data from TIF without Rasterio

No comments:

Post a Comment