{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Compute distance to power substation\n", "For each exit, compute the distance to the nearest power substation...\n", "\n", "1. Fetch exit data, using arcgis package\n", "2. Fetch power substation data, using arcgis package\n", "3. Convert data to geopandas dataframes\n", "4. Compute nearest distance between exits and substations, using arcgis [find_nearest()](https://developers.arcgis.com/python/api-reference/arcgis.features.analysis.html#find-nearest) function" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Import packages\n", "from arcgis import GIS\n", "from arcgis.features import FeatureLayer, analysis\n", "import pandas as pd\n", "import geopandas as gpd\n", "import os" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Fetch exit data into a spatially enabled dataframe\n", "data_url = 'https://services7.arcgis.com/fqNd6NEGNf5qzQdv/arcgis/rest/services/TCI_NC_exits_2019_06_11_v1/FeatureServer/1'\n", "lyr_exits = FeatureLayer(data_url)\n", "sdf_exits = lyr_exits.query(\"State = 'NC'\").sdf" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Save\n", "if not os.path.exists('./Data/MJBA'): os.mkdir('./Data/MJBA')\n", "sdf_exits.spatial.to_featureclass(location='/Data/MJBA/Exits.shp')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Fetch power substation data\n", "data_url = 'https://services1.arcgis.com/Hp6G80Pky0om7QvQ/ArcGIS/rest/services/Electric_Substations_1/FeatureServer/0'\n", "sdf_substations = FeatureLayer(data_url).query(\"State = 'NC'\").sdf" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Save\n", "if not os.path.exists('./Data/HILFD'): os.mkdir('./Data/HILFD')\n", "sdf_exits.spatial.to_featureclass(location='/Data/HILFD/Substations.shp')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sdfLyr = sdf_exits.spatial.to_featurelayer(\"Exits\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Find the nearest substation to each exit\n", "foo = analysis.find_nearest(sdf_exits.to_featurelayer(\"Exits\"))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }