1

I would like to know if there are any python libraries or tools to help convert raw data into a cloud optimized GeoTIFF. I have a lot of dat files with latitude, longitude, and a few other bits of metadata about an event that I would like to be able to render on a map.

1 Answer 1

2

GDAL can be used. I found these two links helped a lot:

https://geoexamples.com/other/2019/02/08/cog-tutorial.html

https://gdal.org/tutorials/raster_api_tut.html

In the end my code looked roughly like this. I'm sure you will need to adjust, customize, and add more (I came across your question while still searching for how to add a DateTime), but it's a start.

from osgeo import gdal
from osgeo import osr

# tutorial said we need to start with MEM driver
driver = gdal.GetDriverByName('MEM')

# create framework for the data
data_set = driver.Create('', x_size, y_size, num_bands, gdal.GDT_Float32)

# coordinates and spatial reference system
data_set.SetGeoTransform([UL_X, Xspace, 0, UL_Y, 0, -Yspace])
srs = osr.SpatialReference()
srs.ImportFromEPSG(4326)
data_set.SetProjection(srs.ExportToWkt())

# my data had only a single band to write
data_set.GetRasterBand(1).WriteArray(data_frame)

# I think this is for tiling in the COG
data_set.BuildOverviews("NEAREST", [2, 4, 8, 16, 32, 64])

# now we create the COG
driver = gdal.GetDriverByName('GTiff')
data_set2 = driver.CreateCopy(out_cog_filename, data_set, options=["COPY_SRC_OVERVIEWS=YES", "TILED=YES", "COMPRESS=LZW"])

# close the datasets
data_set = None
data_set2 = None
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.