1

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.

2

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)]
print(get_patt("to_crs",geopandas))
[] # nothing at this level
# but
from geopandas import GeoDataFrame, GeoSerie
print(get_patt("to_crs",GeoDataFrame))
['to_crs']
print(get_patt("to_crs",GeoSeries))
['to_crs']

Thus, at the GeoDataFrame level:

shapef =  geopandas.read_file("a_shape.shp")
type(shapef)
<class 'geopandas.geodataframe.GeoDataFrame'>
print(get_patt("to_crs",shapef))
['to_crs']

And you can use shapef.to_crs()

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

from see import see
see(shapef).filter('*to_crs*')
.to_crs()

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.