Skip to content

Commit

Permalink
osmnxelevation package update
Browse files Browse the repository at this point in the history
[Major Update]: osmnxelevation Python packaging boiler plate update.

[osmnxelevation Update]:
Created methods under the module NetworkDataset:
 - _save_geopackage()
 - _read_geopackage()
 - _extract_raster_bounds()
 - _append_raster_fname()
 - bind_elevation_to_nodes()
 - bind_elevation_to_edges()

pyproject.toml update
environment.yml update
requirements.txt update
  • Loading branch information
Sidrcs committed Dec 10, 2023
1 parent bbea308 commit 5b346e0
Show file tree
Hide file tree
Showing 34 changed files with 1,444 additions and 32 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
6 changes: 6 additions & 0 deletions .ipynb_checkpoints/Demo-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
165 changes: 149 additions & 16 deletions .ipynb_checkpoints/Elevation_Evaluation-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,6 @@
"def bind_elevation_to_edges(node_gdf, edge_gdf):\n",
" # Perform a join operation on the 'osmid' column\n",
" merged_gdf = node_gdf.merge(edge_gdf, left_on='from', right_on='osmid', how='left')\n",
"\n",
" # Assuming 'elev_1_arc' is the elevation column in midland_nodes\n",
" merged_gdf['from_elev'] = merged_gdf['elev_1_arc'] \n",
"\n",
Expand Down Expand Up @@ -2130,33 +2129,32 @@
},
{
"cell_type": "code",
"execution_count": 72,
"execution_count": 98,
"id": "2040c200-214a-48c0-9115-5ca57c31f2bc",
"metadata": {},
"outputs": [],
"source": [
"def bind_elevation_to_nodes(node_gdf, col_name):\n",
" # node_gdf = gpd.read_file(node_shapefile)\n",
" # node_gdf = node_gdf.to_crs(3857)\n",
" # dem = rio.open(dem_raster)\n",
" # dem_data = dem.read(1)\n",
"def bind_elevation_to_nodes(node_gdf):\n",
" node_gdf[col_name] = None\n",
" # if node_gdf.crs.to_epsg() == dem.crs.to_epsg():\n",
" unq_list = list(midland_nodes[\"file_name\"].unique())\n",
" raster_dict = {}\n",
" for raster_file in unq_list:\n",
" dst = rxr.open_rasterio(raster_file)\n",
" reproj_dst = dst.rio.reproject(3857)\n",
" raster_dict[raster_file] = reproj_dst\n",
" for index, row in node_gdf.iterrows():\n",
" osmid = row['osmid']\n",
" lon, lat = row['geometry'].x, row['geometry'].y\n",
" dst = rxr.open_rasterio(row['file_name'])\n",
" raster = dst.rio.reproject(3857)\n",
"\n",
" node_gdf.at[index, col_name] = elevation\n",
" # else:\n",
" # print(f\"Raster CRS: {dem.crs.to_epsg()} does not match. Reproject raster using reproj_raster function\")\n",
" filename = row['file_name']\n",
" raster = raster_dict[filename]\n",
" elevation = raster.sel(x=lon, y=lat, method=\"nearest\").values\n",
" node_gdf.at[index, col_name] = elevation[0]\n",
" return node_gdf"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 96,
"id": "eef8ac4c-f688-4b89-9e26-b992453867f7",
"metadata": {},
"outputs": [],
Expand All @@ -2172,6 +2170,141 @@
"Below code is found on StackOverFlow (<a href=\"https://gis.stackexchange.com/questions/358036/extracting-data-from-a-raster\">link</a>)"
]
},
{
"cell_type": "code",
"execution_count": 97,
"id": "9d448bdf-b719-46b5-89b9-164ec41a24c7",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>osmid</th>\n",
" <th>y</th>\n",
" <th>x</th>\n",
" <th>street_cou</th>\n",
" <th>highway</th>\n",
" <th>ref</th>\n",
" <th>geometry</th>\n",
" <th>file_name</th>\n",
" <th>elev</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>227119561</td>\n",
" <td>32.051585</td>\n",
" <td>-102.097694</td>\n",
" <td>3</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>POINT (-11365463.307 3770083.866)</td>\n",
" <td>Midland_DEM\\USGS_13_n33w103_20211124.tif</td>\n",
" <td>852.853882</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>227119675</td>\n",
" <td>32.051125</td>\n",
" <td>-102.098976</td>\n",
" <td>1</td>\n",
" <td>turning_circle</td>\n",
" <td>NaN</td>\n",
" <td>POINT (-11365606.019 3770023.450)</td>\n",
" <td>Midland_DEM\\USGS_13_n33w103_20211124.tif</td>\n",
" <td>852.403992</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>227119691</td>\n",
" <td>31.994311</td>\n",
" <td>-102.121742</td>\n",
" <td>3</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>POINT (-11368140.318 3762563.881)</td>\n",
" <td>Midland_DEM\\USGS_13_n32w103_20211124.tif</td>\n",
" <td>866.695679</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>227119696</td>\n",
" <td>31.995644</td>\n",
" <td>-102.122176</td>\n",
" <td>3</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>POINT (-11368188.631 3762738.848)</td>\n",
" <td>Midland_DEM\\USGS_13_n32w103_20211124.tif</td>\n",
" <td>865.980286</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>227119719</td>\n",
" <td>32.010517</td>\n",
" <td>-102.146385</td>\n",
" <td>3</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>POINT (-11370883.565 3764691.226)</td>\n",
" <td>Midland_DEM\\USGS_13_n33w103_20211124.tif</td>\n",
" <td>866.202637</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" osmid y x street_cou highway ref \\\n",
"0 227119561 32.051585 -102.097694 3 NaN NaN \n",
"1 227119675 32.051125 -102.098976 1 turning_circle NaN \n",
"2 227119691 31.994311 -102.121742 3 NaN NaN \n",
"3 227119696 31.995644 -102.122176 3 NaN NaN \n",
"4 227119719 32.010517 -102.146385 3 NaN NaN \n",
"\n",
" geometry \\\n",
"0 POINT (-11365463.307 3770083.866) \n",
"1 POINT (-11365606.019 3770023.450) \n",
"2 POINT (-11368140.318 3762563.881) \n",
"3 POINT (-11368188.631 3762738.848) \n",
"4 POINT (-11370883.565 3764691.226) \n",
"\n",
" file_name elev \n",
"0 Midland_DEM\\USGS_13_n33w103_20211124.tif 852.853882 \n",
"1 Midland_DEM\\USGS_13_n33w103_20211124.tif 852.403992 \n",
"2 Midland_DEM\\USGS_13_n32w103_20211124.tif 866.695679 \n",
"3 Midland_DEM\\USGS_13_n32w103_20211124.tif 865.980286 \n",
"4 Midland_DEM\\USGS_13_n33w103_20211124.tif 866.202637 "
]
},
"execution_count": 97,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gdf.head()"
]
},
{
"cell_type": "code",
"execution_count": 79,
Expand Down Expand Up @@ -2255,7 +2388,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "5eec79ba-3a0b-4b50-a7e5-9e845e01871e",
"id": "f987b8da-57af-4e7a-bded-b65495cf4736",
"metadata": {},
"outputs": [],
"source": []
Expand Down
260 changes: 260 additions & 0 deletions .ipynb_checkpoints/VIA_Demo-checkpoint.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 5b346e0

Please sign in to comment.