# Open just a subset of shapefile with VectorSource

**URL:** <https://openradar.discourse.group/t/open-just-a-subset-of-shapefile-with-vectorsource/225>\
**Category:** General\
**Created:** [April 24, 2023, 8:03am UTC](https://openradar.discourse.group/t/open-just-a-subset-of-shapefile-with-vectorsource/225 "2023-04-24T08:03:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![plvoit](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/plvoit/32/62_2.png) [@plvoit](https://openradar.discourse.group/u/plvoit)\
**Post date:** [April 24, 2023, 8:03am UTC](https://openradar.discourse.group/t/open-just-a-subset-of-shapefile-with-vectorsource/225/1 "2023-04-24T08:03:03Z")

</div>

Hello,  
I’m using wradlib for zonal statistics. I extract mean rainfall data from a radar image for a polygons (subbasins). Because my shapefile is quite large and not fully covered by the radar image, I would like to just open a subset of the shapefile, (defined by bounding box or shape) to save resources and time (I’m running thousands of cases on a HPC ).  
I know that this partial opening of large shapefile is possible with geopandas/fiona ([Reading and Writing Files — GeoPandas 0.12.2+0.gefcb367.dirty documentation](https://geopandas.org/en/stable/docs/user_guide/io.html)) but is it also possible with wradlib Vector Source (gdal/ogr)?

wradlib.VectorSource can also take iterables as input: _"sequence of source points (shape Nx2) or polygons (shape NxMx2) "_

So another option would be to open the subset with geopandas and then convert it somehow to an iterable which is accepted by VectorSource as input.  
I played around with this a little bit but I am not sure how exactly I can convert a geopandas Dataframe to the desired input format to create a VectorSource object with it.

Here, finally, my two questions:

1. Can I open a subset of a large shapefile with VectorSource?
2. How can I convert a geopandas Dataframe into a _"sequence of source points (shape Nx2) or polygons (shape NxMx2) "_ as input to create a VectorSource object?

Looking forward for your ideas, thanks,  
Paul

---

<div class="post-metadata">

**Author:** ![kmuehlbauer](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/kmuehlbauer/32/439_2.png) [@kmuehlbauer](https://openradar.discourse.group/u/kmuehlbauer)\
**Post date:** [April 26, 2023, 10:24am UTC](https://openradar.discourse.group/t/open-just-a-subset-of-shapefile-with-vectorsource/225/2 "2023-04-26T10:24:17Z")

</div>

@plvoit Great question and nice to see what `VectorSource` is used for.

You might check the `.geo`-property of `VectorSource` this will just open that file using `geopandas`. This will not help you for your use case, but just to note it.

There is also the `.get_data_by_geom`-method, which will use geopandas or GDAL to retrieve data which is inside some `geometry`.

You can also apply GDAL’s `Layer.SetSpatialFilter(geom)` directly to the `VectorSource` `.ds`, but it would be better to add some method (eg. `.clip()`) which would clip the `VectorSource` by bounding box/geometry. It would be great if you open an issue on the wradlib github issue tracker with that request.

---

<div class="post-metadata">

**Author:** ![plvoit](https://yyz2.discourse-cdn.com/free1/user_avatar/openradar.discourse.group/plvoit/32/62_2.png) [@plvoit](https://openradar.discourse.group/u/plvoit)\
**Post date:** [April 28, 2023, 7:24am UTC](https://openradar.discourse.group/t/open-just-a-subset-of-shapefile-with-vectorsource/225/4 "2023-04-28T07:24:33Z")

</div>

Hello @kmuehlbauer,  
thank you for your reply. I submitted an issue at github with some more ideas and suggestions.  
Thank you!
