简体   繁体   English

pyproj“找不到crs”(GDAL/Docker)-Python

[英]pyproj "crs not found" (GDAL/Docker) - Python

I am attempting to run a Docker container which contains several Python scripts to be executed in sequence, including one that converts UTM coordinates to their latitude/longitude equivalent.我正在尝试运行一个 Docker 容器,该容器包含几个要按顺序执行的 Python 脚本,其中包括一个将 UTM 坐标转换为其纬度/经度等效值的脚本。 The script works when run as a standalone script (eg in the Spyder environment), but I am getting errors when execute the same script inside my docker container.该脚本在作为独立脚本运行时工作(例如在 Spyder 环境中),但是在我的 docker 容器中执行相同的脚本时出现错误。 Here is the segment of the script that retrieves the projections for EPSG 3857 and EPSG 4326:下面是检索 EPSG 3857 和 EPSG 4326 投影的脚本段:

import glob
from osgeo import gdal, osr, ogr
from pyproj import Proj, transform

for file in glob.glob("*.tif"):
    dem = gdal.Open(file)
    epsg_zone='EPSG:'+ osr.SpatialReference(dem.GetProjection()).GetAttrValue("PROJCS|AUTHORITY", 1))
    P3857 = Proj(init=epsg_zone)
    P4326 = Proj(init='epsg:4326')

My docker container was built by installing GDAL v3.0.2 and pyproj v.3.0.0.post1 among other libraries.我的 docker 容器是通过在其他库中安装 GDAL v3.0.2 和 pyproj v.3.0.0.post1 构建的。 However, when this specific script is launched I am encountering an error when the processing gets to the line segment that reads "P3857 = Proj(init=epsg_zone)":但是,当启动此特定脚本时,当处理到达读取“P3857 = Proj(init=epsg_zone)”的线段时遇到错误:

File "pyproj/_crs.pyx", line 2302, in pyproj._crs._CRS.__init__
pyproj.exceptions.CRSError: Invalid projection: +init=epsg:None +type=crs: (Internal Proj 
Error: proj_create: crs not found)

I further identified another issue regarding how the GeoTIFF is being read.我进一步确定了有关如何读取 GeoTIFF 的另一个问题。 When I run a print statement for "dem.GetProjection()" for running the script in my docker container, it returns an empty string while it returns the full projection and coordinate reference system information when run as a standalone tool.当我为“dem.GetProjection()”运行打印语句以在我的 docker 容器中运行脚本时,它返回一个空字符串,而它在作为独立工具运行时返回完整的投影和坐标参考系统信息。 It specifically reads the dem object (print(dem)) as follows:它具体读取dem object (print(dem)) 如下:

osgeo.gdal.Dataset; proxy of <Swig Object of type 'GDALDatasetShadow *' at 0x7f5e48651120>

I am confused as to why the script runs fine as a standalone from the Spyder environment, but I get these errors from within the Docker container.我很困惑为什么脚本在 Spyder 环境中作为独立的运行良好,但我从 Docker 容器中得到这些错误。 Any assistance is most appreciated!非常感谢任何帮助!

GDAL relies on a directory full of data files to do its job. GDAL 依赖于一个充满数据文件的目录来完成它的工作。 It is likely that either this data directory was not copied into the container, or the GDAL search path inside the container does not match the installation location.可能是这个数据目录没有复制到容器中,或者容器内的 GDAL 搜索路径与安装位置不匹配。

The GDAL library will use the environment variable GDAL_DATA to find the data directory. GDAL 库将使用环境变量 GDAL_DATA 来查找数据目录。 First, find the data (one possible file to search for is epsg.wkt ) in the container.首先,在容器中找到数据(要搜索的一个可能文件是epsg.wkt )。 Copy it in if it's not present.如果它不存在,请复制它。 Then set GDAL_DATA somewhere in the environment before launching your software然后在启动软件之前在环境中的某处设置 GDAL_DATA

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM