geocube icon indicating copy to clipboard operation
geocube copied to clipboard

[Feature] Is it possible to add the funcitonability of polygonizing

Open CWen001 opened this issue 3 years ago • 3 comments

First, thank you very much for this package, which helps solve the pain point of converting Geopandas vector data to tif through xarray. May I ask if the package can also facilitate converting an Xarray dataset to Geopandas vectors (polygonizing). That would be much convenient than using gdal functions. Thank you very much.

CWen001 avatar Apr 05 '21 07:04 CWen001

@Meresmata Did you ever end up building any raster->vector functionality? I found this issue while searching for similar functionality, and ended up creating my own implementation to build a geodataframe using rasterio.features.shapes on an xarray dataset. It's highly application specific (loops through only one variable based on the time dimension) and the code still needs some cleanup, but I wanted to share in case it's helpful. Where the variable data fit into memory it was as simple as adding the transform input to shapes(). The trickier part was when the variable data was a dask array that didn't all fit into memory, so a geotransform needed to be constructed per-chunk and then fed into shapes() within a dask.delayed function call.

Originally posted by @JessicaS11 in https://github.com/corteva/rioxarray/issues/159#issuecomment-801210867

snowman2 avatar Apr 05 '21 13:04 snowman2

This is something that I think would make sense to add to geocube if someone wanted to take a stab at it.

snowman2 avatar Apr 05 '21 13:04 snowman2

Raster->Vector? I normally rasterstats for it, but this is probably something completely different, from what you intended!

I never had problems that a raster fits into the memory! The think is a) perhaps you have invoke the garbage collector? That's what helps me normally, when processing several rasters after another or with multiprocessing. I never had to deal with a single raster, that was larger than my RAM!

sehHeiden avatar Jul 02 '21 12:07 sehHeiden

Related: https://github.com/xarray-contrib/xvec

snowman2 avatar Mar 02 '23 19:03 snowman2