I am trying to reproject data using GeoPandas' to_crs method but it seems to be missing. When I type hasattr(gpd, 'to_crs') I get FALSE. Also, when I type dir(geopandas) in the command prompt it doesn't appear in the list of attributes and methods.

>>> dir(geopandas)
['GeoDataFrame', 'GeoSeries', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package
__', '__path__', '__spec__', '__version__', '_version', 'base', 'datasets', 'geodataframe', 'geopandas', 'geoseries', '
gpd', 'io', 'np', 'overlay', 'pd', 'plotting', 'points_from_xy', 'read_file', 'read_postgis', 'sjoin', 'tools']

I have reinstalled GeoPandas several times, to no avail.


to_crs is a function at the GeoDataFrame level (def to_crs() in geodataframe.py) or the GeoSerie level (geoseries.py)

Using a function adapted from a script Script de Python para filtrar por patrón de texto los métodos de Clases en PyQGIS de José Guerrero (already used in Iterating over selected features in QGIS Processing)

import geopandas
import re
def get_patt(keyword, L):
    return [item for item in dir(L) if re.search(keyword,item)]
[] # nothing at this level
# but
from geopandas import GeoDataFrame, GeoSerie

Thus, at the GeoDataFrame level:

shapef =  geopandas.read_file("a_shape.shp")
<class 'geopandas.geodataframe.GeoDataFrame'>

And you can use shapef.to_crs()

You can also use the see module (dir for humans)

from see import see

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.