Skip to content
This repository has been archived by the owner on Jul 2, 2019. It is now read-only.

Remove osmnx instance in createBufferGeoPandas, updated readme #75

Open
wants to merge 3 commits into
base: spacenetV3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,25 @@ Further download instructions for the [SpaceNet Dataset](https://github.com/Spac


## Installation Instructions
Several packages require binaries to be installed before pip installing the other packages. Conda is a simple way to install everything and their dependencies
Several packages require binaries to be installed before pip installing spacenetutilities. Conda is a simple way to install everything and their dependencies and creating a dedicated conda environment is recommended. Python 3.5 is recommended as some packages run into issues in Python 2.7 and 3.6. If using another version proceed at your own risk!

* Install GDAL binaries and scripts
* Create a conda environment for python 3.5 and then enter it
```commandline
conda install -c conda-forge gdal
conda create -n spacenet_py35 python=3.5 anaconda
source activate spacenet_py35 #source deactivate to exit!
```
* Install [Rtree](http://toblerity.org/rtree/install.html)
* Install these packages via conda
```commandline
conda install -c conda-forge rtree
conda install -c conda-forge cython libgdal gdal numpy opencv pip pyproj matplotlib networkx=1.11 fiona scikit-image scikit-learn scipy geopandas tqdm shapely=1.5.16 rasterio affine pillow
```

* Install [pyproj](https://pypi.python.org/pypi/pyproj)
* Install these packages via pip
```commandline
conda install -c conda-forge pyproj
```
* Install [geopandas](https://pypi.python.org/pypi/geopandas)
```commandline
conda install -c conda-forge geopandas
```

* Install [shapely](https://pypi.python.org/pypi/shapely)
```commandline
conda install -c conda-forge shapely
pip install utm
pip install osmnx==0.5
```

* Install [rasterio](https://pypi.python.org/pypi/rasterio)
```commandline
conda install -c conda-forge rasterio
```


* Pip Install from github
* Pip install spacenetutilities from github
```commandline
git clone -b spacenetV3 https://github.com/SpaceNetChallenge/utilities.git
cd utilities
Expand All @@ -55,7 +42,7 @@ or
pip install --upgrade git+https://github.com/SpaceNetChallenge/utilities.git
```


If something breaks try checking your ~/.bash_profile or equivalent to ensure you are not pointing at other instances of gdal, etc...


## Evaluation Metric
Expand Down
33 changes: 21 additions & 12 deletions spacenetutilities/geoTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,34 +1017,43 @@ def explodeGeoPandasFrame(inGDF):
# return outGDF


def createBufferGeoPandas(inGDF, bufferDistanceMeters=5, bufferRoundness=1, projectToUTM=True):
def createBufferGeoPandas(inGDF, bufferDistanceMeters=5, bufferRoundness=1, projectToUTM=True, multiply=False):
# Calculate CenterLine
## Define Buffer Constraints


# Transform gdf Roadlines into UTM so that Buffer makes sense
if projectToUTM:
tmpGDF = osmnx.project_gdf(inGDF)
if inGDF.crs:
tmpGDF = projectGDFToUTM(inGDF, srcCrs=inGDF.crs)
else:
tmpGDF = projectGDFToUTM(inGDF, srcCrs="+proj=longlat +datum=WGS84 +no_defs")
else:
tmpGDF = inGDF

gdf_utm_buffer = tmpGDF

# perform Buffer to produce polygons from Line Segments
gdf_utm_buffer['geometry'] = tmpGDF.buffer(bufferDistanceMeters,
bufferRoundness)

gdf_utm_dissolve = gdf_utm_buffer.dissolve(by='class')
gdf_utm_dissolve.crs = gdf_utm_buffer.crs

#Buffer based on number of lanes
if multiply:
tmpGDF['buffval'] = pd.to_numeric(tmpGDF['lane_number'])*bufferDistanceMeters
gdf_utm_buffer['geometry']= tmpGDF.apply(lambda x: x.geometry.buffer(x.buffval,bufferRoundness), axis=1)
gdf_utm_dissolve = gdf_utm_buffer.dissolve(by='road_type')
gdf_utm_dissolve.crs = gdf_utm_buffer.crs

#Do not buffer based on number of lanes
else:
gdf_utm_buffer['geometry'] = tmpGDF.buffer(bufferDistanceMeters,bufferRoundness)
gdf_utm_dissolve = gdf_utm_buffer.dissolve(by='road_type')
gdf_utm_dissolve.crs = gdf_utm_buffer.crs


if projectToUTM:
gdf_buffer = gdf_utm_dissolve.to_crs(inGDF.crs)
else:
gdf_buffer = gdf_utm_dissolve


return gdf_buffer