1

The dataset I want to use have some special characters like ü, õ, ö, ä. which cause encoding issue.

The below example runs totally fine and doesnt mess up those characters.

gdf_local = gpd.read_file(r'my-local-machine-path\maakond_shp.zip', encoding = 'iso-8859-15')

However the problem is that I want to create multiple geo data frames, plus have to share script only, so its not feasible to download all of those shapefiles to my machine first and hence I want to create geodataframes directly from the URL. one of the example below works but messes up the special characters.

url = 'https://geoportaal.maaamet.ee/docs/haldus_asustus/maakond_shp.zip?t=20220501011007'
gdf_url = gpd.read_file(url) # it works but messes up those special characters

Next I tried the following

gdf_url = gpd.read_file(url , encoding = 'iso-8859-15') # it gives error

But it threw this error: TypeError: init() got multiple values for keyword argument 'encoding'

Apparently geopandas try utf-8 by default which is causing issue in my case but doesn't let me use different encoding.

Is there any workaround or solution for this?

Broken attempts:

gdf['mycol'] = gdf.mycol.str.encode('iso-8859-15') # messed it way more. tried using different encodings etc but no help

tried requests method to make file first then gdf but didnt worked.

finally tried the following solution Reading raw data into geopandas but it also messed up those characters.

url = 'https://geoportaal.maaamet.ee/docs/haldus_asustus/maakond_shp.zip?t=20220501011007'
request = requests.get(url)
b = bytes(request.content)

with fiona.BytesCollection(b) as f:
    crs = f.crs
    gdf = gpd.GeoDataFrame.from_features(f, crs=crs)
    print(gdf.head())
2
  • try the Windows-1257 i.e. encoding = 'cp1252'
    – Taras
    May 17, 2022 at 12:14
  • issue is not using wrong encoder. even 'iso-8859-15' is also working . Main prob is that whilst trying to make df using URL when i try to add encoding attribute it throws the error which is strange. as it shud not throw error and it doesnt throw error when i try making df from local path. any idea why its behaving this way? thx May 17, 2022 at 12:24

1 Answer 1

1

This seems to be a bug in a dependency of geopandas, the fiona package. It was discussed on github here and should be fixed on a newer release (>=1.8.21).

So try updating the fiona package and see if it works.

1
  • it worked with the following. gpd ver: 0.10.2 fiona ver: 1.8.21 May 17, 2022 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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