'"name 'pygeos' is not defined"

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



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zazoupile