python - 我在 Spyder 中使用 pyproj 时出错,但在同一 conda 环境中的 Jupiter 实验室中没有
问题描述
这是我的功能:
def geographics2proyected(crsg, crsp, lat_lon):
"""
Transforms a list of geographic coordinates xyg from geographic
coordinate reference system crsg to a proyected crsp one
Parameters
----------
crsg : int
geographic coordinate reference system
crsp : int
proyected coordinate reference system
lat_lon : List of lists of str (latitude, longitude)
latitude is a str with the format DDMMSSC
longitude is a str with the format DDMMSSC
where DD degres, MM minutes, SS seconds and C is a cardinal direction:
N, S, E, W
Returns
-------
xyp List of list of [x, y] in the projected crsp
"""
import pyproj as proj
import numpy as np
if proj.crs.CRS(crsg).is_projected:
raise ValueError(f'crs {crsg:d} is not geographic')
if proj.crs.CRS(crsp).is_geographic:
raise ValueError(f'crs {crsp:d} is not projected')
transformer = proj.Transformer.from_crs(crsg, crsp)
xyp = np.empty((len(lat_lon), 2), np.float32)
for i, lat_lon1 in enumerate(lat_lon):
for j, item in enumerate(lat_lon1):
dg = float(item[0:2])
mn = float(item[2:4])
sc = float(item[4:6])
d = item[6:7]
if j == 0:
if d not in 'NS':
raise ValueError (f'{item} is not a longiude')
lat_deg = dg + (mn/60) + (sc/3600)
if d == 'S':
lat_deg = -1. * lat_deg
else:
if d not in 'WE':
raise ValueError (f'{item} is not a latitude')
lon_deg = dg + mn/60 + sc/3600
if d == 'W':
lon_deg = -1. * lon_deg
xp1, yp1 = transformer.transform(lat_deg, lon_deg)
xyp[i,:] = [xp1, yp1]
return xyp.tolist()
在同一个 conda 环境中,如果我在 Jupyter 实验室中运行该函数,它会正确运行,但如果我在 Syper 中尝试,它会在使用 pyproj 的行中引发错误。第一个引发的错误是:
文件“C:\Users...\gis_utils\gis_utils.py”,第 31 行,geographics2proyected if proj.crs.CRS(crsg).is_projected:文件“C:\Users\solis\miniconda3\envs\env01\lib \site-packages\pyproj\crs\crs.py",第 296 行,在init super() 中。init (projstring) 文件“pyproj_crs.pyx”,第 2309 行,在 pyproj._crs._CRS 中。在里面 pyproj.exceptions.CRSError: Invalid projection: epsg:4258: (Internal Proj Error: proj_create: cannot build geodeticCRS 4258: SQLite error on SELECT extent.description, extent.south_lat, extent.north_lat, extent.west_lon, extent.east_lon, scope .scope, (CASE WHEN scope.scope LIKE '%large scale%' THEN 0 ELSE 1 END) AS score FROM usage JOIN extent ON usage.extent_auth_name = extent.auth_name AND usage.extent_code = extent.code JOIN scope ON usage.scope_auth_name = scope.auth_name AND usage.scope_code = scope.code WHERE object_table_name = ? AND object_auth_name = ? AND object_code = ? ORDER BY score, usage.auth_name, usage.code: no such table: usage)
所以 Windows 10。Python 3.8、conda 4.9.2、spyder 4.2.0、pyproj 3.0.1。我也有 QGIS 3.16.6
非常感谢您的帮助
解决方案
推荐阅读
- session - XCTest 断言失败:请求自动化会话失败
- javascript - i18next 后端加载资源取决于检测到的语言 js
- java - 如何解决 org.glassfish.jersey.server.ContainerException: java.lang.NoSuchMethodError: org.jvnet.mimepull.MIMEMessage.close()V
- node.js - 从“快递”进口快递;SyntaxError:意外的标识符
- javascript - 如何使用 jQuery 在多选下拉列表中设置值?
- python - 彭博 API 安装
- cluster-analysis - BIRCH 聚类后 Cluster Size 太大
- angular - 无法使用 Angular cli 在 Angular 中注册服务人员
- angular - 如何使用@agm-core 在角度谷歌地图上绘制多边形?
- sql - SQL TO MDX 转换(SUM 和大小写)