geopandas/geopandas — pull request #158 by jwass (2014-08-17 05:05:35+00:00)
Title: ENH: Don't build the spatial index until it's requested

Before this commit, a new rtree is generated with each new GeoPandas object even though it might not be needed. For example:

```
df = gpd.read_file(...)
df.to_crs(epsg=4326, inplace=True)
df_filtered = df[df['column'] == 'value']
```
The above code would re-create the rtree 3 times even though we never use it. This can be fairly expensive. Instead, don't compute it until it's first requested, then cache it and re-use.

We'll have to be careful to call `_reset_sindex()` on any inplace geometry updates (only implemented with `set_geometry` for now). See also #128.

The downside of this approach is that it could seem like inconsistent runtime performance since it may not be obvious where/when the index is created. Another option would be to decide whether a spatial index should be generated on a per-GeoSeries/GeoDataFrame level. This would be more like PostGIS where we can default to off and then create the index only when explicitly told.