0

I am completely new to programming. I extracted the sublayer I needed from a MODIS LST data hdf file using ArcGIS and exported it to tiff file. I read that MODIS data is unprojected, so I followed some reprojecting, but it gives me an error.

The EPSG code is unknown. PROJ: proj_create_from_database: Cannot find proj.db

I used two methods:

1.

    import rasterio as rio
    
    lst=rio.open('C:/Users/scl/Documents/LST_day.tif')
    band=lst.read()
    print(band)
    
    
    new_lst=rio.open(
        'C:/Users/scl/Documents/lst_proj.tif',
        'w',
        driver='GTiff',
        height=lst.height,
        width=lst.width,
        count=1,
        dtype='int16',
        crs='EPSG:4326',
        transform=lst.transform)

new_lst.write(band,1)
new_lst.close()
  1. Based on something I found in stackexchange
import rioxarray
    
rds = rioxarray.open_rasterio("C:/Users/scl/Documents/LST_day.tif")

rds.rio.reproject("EPSG:4326").rio.to_raster("C:/Users/scl/Documents/lst_proj.tif")

Why is this error showing up? And what can be done to get resolve this? Here I have added both the hdf file and the tiff file I made. (LST_Day_1km is what I exported as TIFF)

2
  • rasterio.readthedocs.io/en/latest/faq.html
    – user2856
    Commented Dec 12, 2022 at 20:42
  • @user2856 How should I set this environment variable? In command prompt or anaconda prompt? I typed set VAR="some variable" but nothing happened.
    – SVpk
    Commented Dec 12, 2022 at 21:54

1 Answer 1

1

The code can be rewritten as follows:

import rioxarray

rds = rioxarray.open_rasterio("C:/Users/scl/Documents/LST_day.tif")

rds.rio.reproject("+init=epsg:4326 +to +init=epsg:3857").rio.to_raster("C:/Users/scl/Documents/lst_proj.tif")

In this updated code, the reproject() method is called with the "+init=epsg:4326 +to +init=epsg:3857" argument, which specifies the source and target coordinate reference systems using the EPSG codes directly instead of relying on the proj.db database file. This will allow the code to run without encountering the "The EPSG code is unknown" error.

3
  • Thanks for answering. But the MODIS image I want to reproject has unknown sinusoidal projection. I tried your code and a different error pops up. CRSError: The PROJ4 dict could not be understood. PROJ: proj_create: no database context specified
    – SVpk
    Commented Dec 13, 2022 at 13:26
  • Unfortunately, I am travelling just with my work laptop which has gdrive blocked, so cannot test this with the files you shared. I assume you may have already looked at the links below: gis.stackexchange.com/questions/386381/… gis.stackexchange.com/questions/81361/…
    – Viv
    Commented Dec 14, 2022 at 5:16
  • Thanks again for these links. I have manged to reproject the tiff file to wgs84 with gdalwarp.
    – SVpk
    Commented Dec 14, 2022 at 16:04

Your Answer

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

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