I am writing a simple python code to perform sjoin on two geodataframe.

    gdf1 = gpd.read_file(polygon1.geojson)
    gdf2 = gpd.read_file(polygon2.geojson)
    gdf = gpd.sjoin(gdf1, gdf2, how="left", op='intersects')
    gdf.to_file(filename= 'myfile.geojson', driver='GeoJSON')

However, I encounter this error when writing the result to geojson.

I can avoid this error by writing to a shapefile then convert the shapefile to geojson. But this sounds too odd.

Is there anyone know the root cause of such an error?

C:\ProgramData\Anaconda3\lib\site-packages\geopandas\geodataframe.py in to_file(self, filename, driver, schema, index, **kwargs) 531 from geopandas.io.file import to_file 532 --> 533 to_file(self, filename, driver, schema, index, **kwargs) 534 535 def to_crs(self, crs=None, epsg=None, inplace=False):

C:\ProgramData\Anaconda3\lib\site-packages\geopandas\io\file.py in to_file(df, filename, driver, schema, index, **kwargs) 191 filename, "w", driver=driver, crs_wkt=crs_wkt, schema=schema, **kwargs 192 ) as colxn: --> 193 colxn.writerecords(df.iterfeatures()) 194 195

C:\ProgramData\Anaconda3\lib\site-packages\fiona\collection.py in writerecords(self, records) 347 if self.mode not in ('a', 'w'): 348 raise IOError("collection not open for writing") --> 349 self.session.writerecs(records, self) 350 self._len = self.session.get_length() 351 self._bounds = self.session.get_extent()

fiona/ogrext.pyx in fiona.ogrext.WritingSession.writerecs()

fiona/ogrext.pyx in fiona.ogrext.OGRFeatureBuilder.build()

1 Answer 1


I found the error was caused by duplicated column name.

There were two columns in my dataset having the same name and the geopandas seemed to be not case sensitive.

After renaming one of the columns, I can write to geojson without any issue~

  • You can accept your own answer with the checkbox
    – Bera
    Commented Dec 3, 2020 at 9:03

Your Answer

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

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