28

I want to wrap(re-project) one variable in this netcdf file.

D:\ gdalwarp -t_srs EPSG:4326 NETCDF:"C:\fie.nc":var "C:\Desktop\SM.img"

But I get this error:

ERROR 4: Unable to open EPSG support file gcs.csv. Try setting the GDAL_DATA environment variable to point to the directory containing EPSG csv files.

ERROR 1: Translating source or target SRS failed: EPSG:4326

I am using GDAL 1.9.0, released 2011/12/29. I will be grateful for any help.

Community
  • 1
  • 1
sacvf
  • 2,463
  • 5
  • 36
  • 54

5 Answers5

35

You can edit the environment variables graphically in Windows (e.g., this, or this).

Add a System variable with name GDAL_DATA and value of the path to the shared GDAL data (a folder with a several files, like coordinate_axis.csv, gcs.csv, pcs.csv, and other files).

To make the environment variable effective, you need to run cmd.exe, or log-out, or other method.

See also: http://trac.osgeo.org/gdal/wiki/FAQInstallationAndBuilding#HowtosetGDAL_DATAvariable


Anaconda / Miniconda users

GDAL library and command-line tools are available via (e.g.) conda install gdal

The GDAL_DATA variable is properly set when the environment is activated. This is done for you if you start an Anaconda Prompt, otherwise you can activate the environment as documented.

Mike T
  • 41,085
  • 18
  • 152
  • 203
  • @DPSSpatial thanks, replace with an alternative resource. – Mike T Apr 23 '18 at 22:11
  • I fixed my problem based on your solution but I got new error message, "ERROR 1: Failed to process SRS definition: ESPG:3857" How fix this problem now? – Navid Jul 29 '18 at 16:53
  • @PredatorX can you find/open `%GDAL_DATA%\pcs.csv`? Does the folder have any special file permissions that may limit it's access? – Mike T Jul 30 '18 at 01:52
  • Yes, I checked that GDAL_DATA folder had read-only permission, I unchecked read-only permission moreover I changed security level for users also, and I'll check again as soon as possible if it fixed I'll write here fixed, thank you @MikeT – Navid Jul 30 '18 at 03:49
  • it fixed that previous error but I got new error message "Unable to find driver `PostgreSQL'." this new problems is annoying I did upgrade GDAL to latest version 2.3.1 but it didn't fix, My PostgreSQL is 9.5.3 64 and latest version of OsGeo4W64 – Navid Jul 30 '18 at 03:59
  • My GDAL is saved under the Home directory. Do I still need to use a system variable or can I use a User variable? It doesn't seem to be working as a user variable – Steve Scott Jun 23 '23 at 18:03
11

You can also use the --config switch:

D:\ gdalwarp --config GDAL_DATA "D:/my/gdal/data" -t_srs EPSG:4326 NETCDF:"path":Soil_Moisture "C:\Desktop\SM.img"

See: http://trac.osgeo.org/gdal/wiki/ConfigOptions

for information on config options.

sacvf
  • 2,463
  • 5
  • 36
  • 54
5

I tried to set the GDAL_DATA variable programmatically (C#) and @turgay's solution didn't work for me. here I found the working way:

OSGeo.GDAL.Gdal.SetConfigOption("GDAL_DATA", path+@"\gdal\data");
Kaz
  • 1,047
  • 8
  • 18
null.point3r
  • 1,053
  • 2
  • 9
  • 17
2

You can also use for making programmatically (with C# API). Sample code:

string path = @"C:\abc\";
_SetValueNewVariable("GDAL_DATA", path + "\\data");
_SetValueNewVariable("GEOTIFF_CSV", path + "\\data");
_SetValueNewVariable("GDAL_DRIVER_PATH", path + "\\gdalplugins");

private static void _SetValueNewVariable(string sVar, string sValue)
{
    if (System.Environment.GetEnvironmentVariable(sVar) == null)
    {
        System.Environment.SetEnvironmentVariable(sVar, sValue);
    }
}
Kaz
  • 1,047
  • 8
  • 18
turgay
  • 438
  • 4
  • 7
2

On the command prompt, I used to set the GDAL_DATA path by pointing to where (and which gdal-data) to use:

set GDAL_DATA=C:\Program Files\PostgreSQL\9.3\gdal-data

I learned it from http://clhenrick.github.io/thesis-blog/procrastination/portfolio-work/2014/09/27/procrastinating/ I always needed to do the above even though I already set it up in my environment variables. My problem seemed to be an installation issue but I didn't want to reinstall anything...yet.

As a temporary solution, while I did not have time for a more permanent one, I deleted the existing GDAL_DATA path in my environment variables, shut down the computer, turned it on, created a new one, shut down the computer, turned it on again. FIXED!

Complete shut-down not restart due to the quirky behaviour of my system.

curiousCat
  • 41
  • 7