2

The error pops up when I try to run GeoPandas to_file. The error message is:

Traceback (most recent call last):
  File "<pyshell#88>", line 1, in <module>
    df.to_file('psuedo.shp')
  File "C:\Python27\ArcGIS10.5\lib\site-packages\geopandas\geodataframe.py", 
    line 365, in to_file
    to_file(self, filename, driver, schema, **kwargs)
  File "C:\Python27\ArcGIS10.5\lib\site-packages\geopandas\io\file.py", line 
    64, in to_file
    schema=schema, **kwargs) as colxn:
  File "C:\Python27\ArcGIS10.5\lib\site-packages\fiona\__init__.py", line 
    183, in open
    enabled_drivers=enabled_drivers, crs_wkt=crs_wkt)
  File "C:\Python27\ArcGIS10.5\lib\site-packages\fiona\collection.py", line 
    156, in __init__
    self.session.start(self, **kwargs)
  File "fiona\ogrext.pyx", line 948, in fiona.ogrext.WritingSession.start
DriverIOError: 'utf8' codec can't decode byte 0xb9 in position 41: invalid 
start byte

I've checked related questions and learned that this type of error is usually solved by convert the encoding of the related file. But I can't even find ogrext.pyx... Could anyone help me out? I'm new in python, using python2.7

1 Answers1

0

Try using wborrb argument while writing or reading files.

Like this:

with open("path to file", 'rb') as f:
  contents = f.read()
  • Thanks Agile. Since I'm new in python, could you write out the code for me? The error happens when I'm running street.to_file("osm.shp"), 'street' is the name of my geodataframe, "osm.shp" is the output file name. I tried to add 'wb' and write the code as street.to_file("osm.shp", 'wb'), but 'wb' is not a supported argument. – Samantha Leo May 27 '18 at 03:52
  • @SamanthaLeo use rb when reading files(or opening them). This will most probably resolve the error –  May 27 '18 at 09:27
  • apology for keep asking. I adapted your code to my need, which is to write Geodataframe 'street' to 'osm.shp', and tried with open(street,'wb') as input: input.to_file("osm.shp") The error message is "TypeError: coercing to Unicode: need string or buffer, GeoDataFrame found". What should I do? Apology for being naive in python. – Samantha Leo May 28 '18 at 03:58
  • well, it still doesn't.. do you have other idea? – Samantha Leo Jun 01 '18 at 05:25