Weiss
Weiss

Reputation: 303

Extract Lat/Long/Value data from TIF without Rasterio

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?

Upvotes: 1

Views: 293

Answers (1)

Weiss
Weiss

Reputation: 303

if you only need height data and don't want to use tiffs I would recommend using NetCDF data. Like the ones from the site: https://www.ngdc.noaa.gov/mgg/global/relief/ETOPO1/data/bedrock/grid_registered/netcdf/

These NetCDF data are well known and often used in geosciences! You can extract this data according to the example: https://earthscience.stackexchange.com/questions/23904/etopo1-region-selection-in-python/23924#23924

I know this doesn't quite answer your question but the result is the same without having to install rasterio or GDAL.

Upvotes: 0

Related Questions