PatBall1 / detectree2

Python package for automatic tree crown delineation based on the Detectron2 implementation of Mask R-CNN
https://patball1.github.io/detectree2/
MIT License
148 stars 35 forks source link

clean.to_file Error - strange 0/NaN column in cleaned output #106

Closed LiamTrees closed 1 year ago

LiamTrees commented 1 year ago

Experiencing this error with clean.to_file after using the clean_crowns function:

AttributeError Traceback (most recent call last) in <cell line: 1>() ----> 1 clean.to_file(site_path + "/crowns_out.gpkg")

5 frames /usr/local/lib/python3.10/dist-packages/geopandas/geodataframe.py in to_file(self, filename, driver, schema, index, kwargs) 1261 from geopandas.io.file import _to_file 1262 -> 1263 _to_file(self, filename, driver, schema, index, kwargs) 1264 1265 def set_crs(self, crs=None, epsg=None, inplace=False, allow_override=False):

/usr/local/lib/python3.10/dist-packages/geopandas/io/file.py in _to_file(df, filename, driver, schema, index, mode, crs, engine, kwargs) 570 571 if engine == "fiona": --> 572 _to_file_fiona(df, filename, driver, schema, crs, mode, kwargs) 573 elif engine == "pyogrio": 574 _to_file_pyogrio(df, filename, driver, schema, crs, mode, **kwargs)

/usr/local/lib/python3.10/dist-packages/geopandas/io/file.py in _to_file_fiona(df, filename, driver, schema, crs, mode, kwargs) 596 elif crs: 597 crs_wkt = crs.to_wkt("WKT1_GDAL") --> 598 with fiona.open( 599 filename, mode=mode, driver=driver, crs_wkt=crs_wkt, schema=schema, kwargs 600 ) as colxn:

/usr/local/lib/python3.10/dist-packages/fiona/env.py in wrapper(*args, *kwds) 455 456 with env_ctor(session=session): --> 457 return f(args, **kwds) 458 459 return wrapper

/usr/local/lib/python3.10/dist-packages/fiona/init.py in open(fp, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt, allow_unsupported_drivers, **kwargs) 301 ) 302 elif mode == "w": --> 303 colxn = Collection( 304 path, 305 mode,

/usr/local/lib/python3.10/dist-packages/fiona/collection.py in init(self, path, mode, driver, schema, crs, encoding, layer, vsi, archive, enabled_drivers, crs_wkt, ignore_fields, ignore_geometry, include_fields, wkt_version, allow_unsupported_drivers, kwargs) 244 elif self.mode in ("a", "w"): 245 self.session = WritingSession() --> 246 self.session.start(self, kwargs) 247 except OSError: 248 self.session = None

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

AttributeError: 'int' object has no attribute 'encode'

PatBall1 commented 1 year ago

Thanks @LiamTrees for raising this issue - I am looking into it! Would you mind posting a screen grab of how the geopandas df looked (with the strange 0 column)?

The behaviour comes from a recent update I made to the clean_crowns function.