无法打开EPSG支持文件gcs.csv。\设置GDAL_DATA环境变量

时间:2019-07-31 10:38:33

标签: python conda gdal

我尝试使用GDAL库并收到此错误:

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.

我创建了这些解决方案     How to set the GDAL_DATA environment variable to point to the directory containing EPSG csv files?

所以我更改了工作环境,GDAL-DATA文件夹的路径,没有任何帮助。

然后,我看到了这个:How to fix the enviroment variable GDAL_DATA path set?
现在就可以了,但是现在我必须每次都定义GDAL_DATA文件夹的路径。

import os
import ospybook as pb
from ospybook.vectorplotter import VectorPlotter

#Theese two lines are the new solution from the 2nd link that I want to stop adding at the begining of each code
# os.environ['GDAL_DATA'] = r'C:\Users\royanc\Anaconda3\Library\share\gdal'
# os.environ['proj'] = r'C:\Users\royanc\Anaconda3\Library\share'

os.chdir(r'C:\Users\royanc\Desktop\ospybook\osgeopy-data\global')

# Plot populated places on top of countries from an interactive session.
vp = VectorPlotter(True)
vp.plot('ne_50m_admin_0_countries.shp', fill=False)
vp.plot('ne_50m_populated_places.shp', 'bo')

我在Win 8.1上使用pycharm 3.6,conda版本4.7.10,python 3.7

1 个答案:

答案 0 :(得分:1)

由于您正在使用PyCharm,因此可以在“运行配置”中设置环境变量

转到Run -> Edit Configurations并在此处设置GDAL_DATA变量

how to set gdal data

这仍然需要您为每个项目设置配置,但是它将系统特定的配置保留在代码之外。