Skip to content

Commit

Permalink
Merge pull request #21 from alexanderquispe/osrm_feature
Browse files Browse the repository at this point in the history
osrm
  • Loading branch information
TJhon authored Jul 7, 2023
2 parents 28937e9 + 42da25e commit 0dd2209
Show file tree
Hide file tree
Showing 5 changed files with 683 additions and 876 deletions.
591 changes: 591 additions & 0 deletions examples/osrmareas.ipynb

Large diffs are not rendered by default.

116 changes: 90 additions & 26 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Pre requirements
# OSRM - AREAS

## Windows
## Pre requirements

### Windows

- Please download the [release archive](https://github.com/christophrust/osrmtime/releases/download/v1.3.3/osrmtime_release1.3.3.zip) and unpack it at a location of your choice.
- Recommended:
Expand Down Expand Up @@ -65,49 +67,111 @@
![](figs/01-path.png)
![](figs/02-path.png)

# Work with `osrm` localy:

- Download a `pbf` file: [Link](https://download.geofabrik.de/)
- Move the file to your working environment.
- Recomend -> Make a data directory `osrmdata`
- Open the terminal and change the directory to your working environment.

Done!
## Features

# Python library
- Allows downloading PBF files from `geofabrik.de`.
- Prepares all necessary files for route generation.
- Initializes the OSRM server in the background.
- Generates a route between 2 coordinate points.
- Generates all routes from a coordinate within a radius.
- Creates a shapefile with the endpoint coordinates of the destinations.

## Installation

github
From Github

```
pip install git+https://github.com/alexanderquispe/osrm_python
```

Specific branch

```
pip install git+https://github.com/alexanderquispe/osrm_python@{branch}
```

## Usage

Chile Example, [dbf]()
### Download a file

```py
from osrmareas.osrm import Server
from osrmareas import areas
all = areas.get_routes([-20.2015383, -70.1575468], radius_km=20)
from osrmareas.downloader import GetPBF
download = GetPBF()
```

Connection
Methods, `GetPBF().continent()`, `GetPBF().country()` and `GetPBF().su_region()`, the methods
receive an array of continents, countries, and subregions,
which can be downloaded to a custom folder using the `.get('save\in\this\path')`
method. The path can be relative or absolute.
If not specified, it will create a `data_pbf` folder by default in the current execution folder.
You can force the download with the `get(force_download=True)` parameter.

```py
download.country(['peru', 'pakistan']).get(save_dir='country_pbf')
download.sub_region(['alberta']).get(save_dir='country_pbf')
```

The database can be called as follows:

```py
import osrmareas.downloader as dwnl
dwnl.cnt # continent
dnwl.cntry # continent, countries
dnwl.region # continent, countries, regions
```

### OSRM Connection

We define the file name and the directory path where the .pbf file is located.

```python
pbf_file = 'chile-latest.osm'
pbf_file_path = 'D:\Workflow\work\osrm-backend\data'
client = Server(pbf_file, pbf_file_path)
client.prepare_server()
client.run_server()
pbf_file = 'alberta-latest.osm' #{country, subregion}-latest.osm
pbf_file_path = 'path/to/dir/with/pbf/file'
```

Areas
- We use `Server` to generate routes for the execution files.

```python
all = areas.get_routes([-20.2015383, -70.1575468], radius_km=10)
all.plot()
areas.get_ameba(all, 5, alpha = 80).plot()
from osrmareas.osrm import Server
cnd_alb = Server(pbf_file, pbf_file_path)
```

- We generate the necessary files with the following command lines.
- If these files already exist, it will prompt for confirmation to execute them again.
- These processes may consume 100% of the CPU.

```python
cnd_alb.gen_osrm_1()
cnd_alb.prepare_server_2()
```

- And we initialize the server in the background.

```python
cnd_alb.run_server()
```

### OSRM ROUTES

We can make route queries using `areas.get_osrm_routes(from, to)`.

```py
from osrmareas import areas
from_ = [53.550905, -113.268436]
to_ = [53.548449, -113.258648]
rt = areas.get_osrm_route(from_, to_)
rt.plot()
```

We can also obtain all routes within a default radius (in kilometers).

```python
all_rt=areas.get_routes(from_, 5)
all_rt
```

Finally, we can see a difference between the radius we defined in the area radius parameter.

```py
ameba = areas.get_ameba(all_rt, max_km = 5, alpha = 80, km_col='dist_driving_km')
```
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pandas
geopandas
alphashape
shapely
tqdm
tqdm
twine
Loading

0 comments on commit 0dd2209

Please sign in to comment.