“名称‘pygeos’”未定义”

发布于 2025-01-09 08:51:38 字数 376 浏览 1 评论 0原文

执行 df = gpd.GeoDataFrame(df1, crs = 'EPSG:4326',ometry = geopandas.points_from_xy(df1.longitude,df1.latitude)) 时,我得到“名称 'pygeos' 未定义”,但我已经安装了 pygeos 目录中

在我 dev 和python3.9/site-packages/geopandas/_vectorized.py 的 来自 xy 的点(x,y,z) 第247章 第248章 -->第249章 250 其他: 251 out = _points_from_xy(x, y, z)

anf import pygeos 位于脚本中。有没有一种特定的方法可以很好地安装 pygeos 以避免此类错误?谢谢

When doing df = gpd.GeoDataFrame(df1, crs = 'EPSG:4326', geometry = geopandas.points_from_xy(df1.longitude,df1.latitude)) I get "name 'pygeos' is not defined", yet I have installed pygeos in the directory where I dev and

python3.9/site-packages/geopandas/_vectorized.py in points_from_xy(x, y, z)
247
248 if compat.USE_PYGEOS:
--> 249 return pygeos.points(x, y, z)
250 else:
251 out = _points_from_xy(x, y, z)

anf import pygeos is in the script. Is there a specific way to well install pygeos in order to avoid such error ? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小傻瓜 2025-01-16 08:51:38
USE_PYGEOS=1

import pyproj
import shapely
import pandas as pd
pd.options.display.max_rows = 100
import geopandas as gpd
import numpy as np
import sklearn
import matplotlib.pyplot as plt


gpd.show_versions()
print(gpd.options.use_pygeos)

location_df = pd.read_csv("location_01-03_01-04.csv", sep = ";")

import rtree
import pygeos

gpd.options.use_pygeos = True
#Point is (longitude, latitude)
# Function making geopandas points of latitude, longitude
location_geo = gpd.GeoDataFrame(location_df, crs = 'EPSG:4326', geometry = gpd.points_from_xy(location_df.longitude, location_df.latitude))

departments_df = gpd.read_file("departements.geojson", sep = ";")
print(departments_df)
import time
start = time.time()
print("hello")
import geopandas
import rtree

# Function to check wether a department contains a position - returns the department of the position. NaN values are probably in another country
dept_points = geopandas.sjoin(location_geo, departments_df)
end = time.time()
print(end-start, ' s')
print(dept_points)

不知怎的,这对我来说是这样的。
这是关于设置常量并按特定顺序导入包。

USE_PYGEOS=1

import pyproj
import shapely
import pandas as pd
pd.options.display.max_rows = 100
import geopandas as gpd
import numpy as np
import sklearn
import matplotlib.pyplot as plt


gpd.show_versions()
print(gpd.options.use_pygeos)

location_df = pd.read_csv("location_01-03_01-04.csv", sep = ";")

import rtree
import pygeos

gpd.options.use_pygeos = True
#Point is (longitude, latitude)
# Function making geopandas points of latitude, longitude
location_geo = gpd.GeoDataFrame(location_df, crs = 'EPSG:4326', geometry = gpd.points_from_xy(location_df.longitude, location_df.latitude))

departments_df = gpd.read_file("departements.geojson", sep = ";")
print(departments_df)
import time
start = time.time()
print("hello")
import geopandas
import rtree

# Function to check wether a department contains a position - returns the department of the position. NaN values are probably in another country
dept_points = geopandas.sjoin(location_geo, departments_df)
end = time.time()
print(end-start, ' s')
print(dept_points)

Somehow this did it for me.
It was about setting the constant and importing packages in a specific order.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文