VectorShapesDataset for loading geometries from vector files #458
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current VectorDataset in torchgeo v0.2.0 returns an image mask, but people might want the actual geometries instead (e.g. for object detection tasks which uses bounding boxes).
This PR moves the geometry loading logic in VectorDataset (handled by
fiona
) into a_load_shapes
method. A newVectorShapesDataset
class is then created (subclassed from this modified VectorDataset), which returns a sample like so:Note that the geometries returned are raw geometries like
[(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0)]
(in the case of a polygon), and the user would need to write their own code to convert it into a bounding box tuple like(minx, miny, maxx, maxy)
or(x, y, width, height)
. I've got some code to do this, but want to know whether this VectorShapesDataset should be generic, or actually output those bounding boxes.Happy to add more tests and/or change this draft implementation. I've just been working on an object detection project that has the bounding box labels in a shapefile/geopackage, and thought it might be useful to have this in torchgeo 😃
May help with the object detection related feature requests at #442 and #454.