diff --git a/.gitignore b/.gitignore index a10f2ca..8b373ea 100644 --- a/.gitignore +++ b/.gitignore @@ -105,12 +105,17 @@ venv.bak/ .DS_Store -tutorial/tutorial_outputs/* -Tutorial/tutorial_data/rek_grid_pop_gravity.cpg -Tutorial/tutorial_data/rek_grid_pop_gravity.dbf -Tutorial/tutorial_data/rek_grid_pop_gravity.prj -Tutorial/tutorial_data/rek_grid_pop_gravity.shp -Tutorial/tutorial_data/rek_grid_pop_gravity.shx +Tutorials/tutorial_outputs/* +Tutorials/tutorial_data/rek_grid_pop_gravity.cpg +Tutorials/tutorial_data/rek_grid_pop_gravity.dbf +Tutorials/tutorial_data/rek_grid_pop_gravity.prj +Tutorials/tutorial_data/rek_grid_pop_gravity.shp +Tutorials/tutorial_data/rek_grid_pop_gravity.shx +Tutorials/tutorial_data/rek_grid_pop_gravity2.cpg +Tutorials/tutorial_data/rek_grid_pop_gravity2.dbf +Tutorials/tutorial_data/rek_grid_pop_gravity2.prj +Tutorials/tutorial_data/rek_grid_pop_gravity2.shp +Tutorials/tutorial_data/rek_grid_pop_gravity2.shx # ignore the version file *_version.py* diff --git a/Tutorials/EXAMPLE_Finding_links_between_pairs.ipynb b/Tutorials/EXAMPLE_Finding_links_between_pairs.ipynb index d750181..35531ca 100644 --- a/Tutorials/EXAMPLE_Finding_links_between_pairs.ipynb +++ b/Tutorials/EXAMPLE_Finding_links_between_pairs.ipynb @@ -16,8 +16,7 @@ "outputs": [], "source": [ "import os\n", - "import sys\n", - "\n", + "import pickle as pkl\n", "import networkx as nx\n", "import geopandas as gpd\n", "import pandas as pd\n", @@ -31,8 +30,7 @@ "metadata": {}, "outputs": [], "source": [ - "# add to your system path the location of the LoadOSM.py and GOSTnet.py scripts\n", - "sys.path.append(\"../\")\n", + "# import the GOSTnet library\n", "import GOSTnets as gn" ] }, @@ -45,8 +43,8 @@ "# Define input data\n", "pth = \"./\"\n", "# Read in cleaned pickle from earlier analysis and convert to time\n", - "G = nx.read_gpickle(\n", - " os.path.join(pth, \"tutorial_outputs\", r\"iceland_network_clean.pickle\")\n", + "G = pkl.load(\n", + " open(os.path.join(pth, \"tutorial_outputs\", r\"iceland_network_clean.pickle\"), \"rb\")\n", ")\n", "G_time = gn.convert_network_to_time(\n", " G, distance_tag=\"length\", road_col=\"infra_type\", factor=1000\n", @@ -117,6 +115,18 @@ "## Calculate line strings connecting all origins to all destinations" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# for the sake of the example we truncate the number of origins and destinations\n", + "# to make the computation faster. We will only use the first 10 of each\n", + "origins = origins[:10]\n", + "destinations = destinations[:10]" + ] + }, { "cell_type": "code", "execution_count": null, @@ -153,7 +163,7 @@ "source": [ "# Write all connections to file\n", "all_results = pd.DataFrame(all_res, columns=[\"O\", \"D\", \"geometry\"])\n", - "all_results.to_csv(os.path.join(pth, \"tutorial_data\", \"all_OD_links.csv\"))" + "all_results.to_csv(os.path.join(pth, \"tutorial_outputs\", \"all_OD_links.csv\"))" ] }, { @@ -177,7 +187,9 @@ "metadata": {}, "outputs": [], "source": [ - "all_connections_first.to_csv(os.path.join(pth, \"tutorial_data\", \"OD_links_usage.csv\"))" + "all_connections_first.to_csv(\n", + " os.path.join(pth, \"tutorial_outputs\", \"OD_links_usage.csv\")\n", + ")" ] }, { diff --git a/Tutorials/EXAMPLE_Fixing_your_road_network.ipynb b/Tutorials/EXAMPLE_Fixing_your_road_network.ipynb index 1ecb186..a7993a4 100644 --- a/Tutorials/EXAMPLE_Fixing_your_road_network.ipynb +++ b/Tutorials/EXAMPLE_Fixing_your_road_network.ipynb @@ -16,9 +16,9 @@ "outputs": [], "source": [ "import os\n", - "import sys\n", "import networkx as nx\n", - "import osmnx as ox" + "import osmnx as ox\n", + "import pickle as pkl" ] }, { @@ -27,8 +27,7 @@ "metadata": {}, "outputs": [], "source": [ - "# add to your system path the location of the LoadOSM.py and GOSTnet.py scripts\n", - "sys.path.append(\"../\")\n", + "# import the GOSTnets library\n", "import GOSTnets as gn" ] }, @@ -41,8 +40,8 @@ "pth = \"./\" # change this path to your working folder\n", "data_pth = os.path.join(pth, \"tutorial_outputs\")\n", "\n", - "# read back your graph from step 1 from you saved pickle\n", - "G = nx.read_gpickle(os.path.join(data_pth, \"iceland_network_clean.pickle\"))" + "# read back your graph from step 2 from you saved pickle\n", + "G = pkl.load(open(os.path.join(data_pth, \"iceland_network_clean.pickle\"), \"rb\"))" ] }, { @@ -64,8 +63,7 @@ "metadata": {}, "outputs": [], "source": [ - "G_largest = list_of_subgraphs[0]\n", - "G_second_largest = list_of_subgraphs[1]" + "G_largest = list_of_subgraphs[0]" ] }, { @@ -74,25 +72,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(nx.info(G_largest))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(nx.info(G_second_largest))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(nx.info(list_of_subgraphs[2]))" + "print(G_largest)" ] }, { @@ -106,20 +86,7 @@ "G_largest.graph[\"name\"] = \"Iceland\"\n", "\n", "# largest connected subgraph\n", - "ox.plot_graph(G_largest, fig_width=10, edge_linewidth=1, node_size=7)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "G_second_largest.graph[\"crs\"] = \"epsg:32646\"\n", - "G_second_largest.graph[\"name\"] = \"Iceland\"\n", - "\n", - "# second largest connected subgraph\n", - "ox.plot_graph(G_second_largest, fig_width=10, edge_linewidth=1, node_size=7)" + "ox.plot_graph(G_largest, figsize=(10, 14), edge_linewidth=1, node_size=7)" ] }, { @@ -132,16 +99,6 @@ "edges_largest.to_csv(os.path.join(data_pth, \"edges_largest.csv\"))" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "edges_second = gn.edge_gdf_from_graph(G_second_largest)\n", - "edges_second.to_csv(os.path.join(data_pth, \"edges_second.csv\"))" - ] - }, { "cell_type": "markdown", "metadata": {}, diff --git a/Tutorials/EXAMPLE_Gravity_Calculations.ipynb b/Tutorials/EXAMPLE_Gravity_Calculations.ipynb index c67016a..ff09ee1 100644 --- a/Tutorials/EXAMPLE_Gravity_Calculations.ipynb +++ b/Tutorials/EXAMPLE_Gravity_Calculations.ipynb @@ -7,12 +7,11 @@ "outputs": [], "source": [ "import os\n", - "import sys\n", "import rasterio\n", "\n", - "import networkx as nx\n", "import geopandas as gpd\n", - "import pandas as pd" + "import pandas as pd\n", + "import pickle as pkl" ] }, { @@ -21,8 +20,7 @@ "metadata": {}, "outputs": [], "source": [ - "# add to your system path the location of the LoadOSM.py and GOSTnet.py scripts\n", - "sys.path.append(\"../\")\n", + "# import the GOSTnets library\n", "import GOSTnets as gn" ] }, @@ -35,8 +33,11 @@ "# Define input data\n", "pth = \"./\"\n", "# Read in cleaned pickle from earlier analysis and convert to time\n", - "G = nx.read_gpickle(\n", - " os.path.join(pth, \"tutorial_outputs\", r\"iceland_network_clean.pickle\")\n", + "G = pkl.load(\n", + " open(\n", + " os.path.join(pth, \"tutorial_outputs\", r\"iceland_network_clean.pickle\"),\n", + " \"rb\",\n", + " )\n", ")\n", "G_time = gn.convert_network_to_time(\n", " G, distance_tag=\"length\", road_col=\"infra_type\", factor=1000\n", @@ -177,9 +178,15 @@ "OD = gn.calculate_OD(G_time, origins, destinations, fail_value=9999999)\n", "gravity = calcOD.calculate_gravity(\n", " OD, oWeight=origins_df[\"Pop\"], dWeight=destinations_df[\"Pop\"]\n", - ")" + ")\n", + "gravity[\"NN\"] = origins" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, { "cell_type": "code", "execution_count": null, diff --git a/Tutorials/Step_1-Extract_From_OSM.ipynb b/Tutorials/Step_1-Extract_From_OSM.ipynb index dfc5483..a7a8546 100644 --- a/Tutorials/Step_1-Extract_From_OSM.ipynb +++ b/Tutorials/Step_1-Extract_From_OSM.ipynb @@ -1,12 +1,5 @@ { "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## note: As of Jan 21, 2020 This tutorial is using the GOSTnets version from this repo's master branch. Make sure that the GOSTnets version from PyPi is uninstalled and that you are pointing your path to the correct location of the library." - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -23,8 +16,7 @@ "outputs": [], "source": [ "import geopandas as gpd\n", - "import os\n", - "import sys" + "import os" ] }, { @@ -43,8 +35,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Add to your system path the location of the LoadOSM.py and GOSTnet.py scripts. \n", - "In this case, we use relative paths (\"..\") to locate the parent directory (one level up). One dot (\".\") means current directory." + "Import the GOSTnets library as gn." ] }, { @@ -53,7 +44,6 @@ "metadata": {}, "outputs": [], "source": [ - "sys.path.append(\"../\")\n", "import GOSTnets as gn" ] }, @@ -216,7 +206,7 @@ "outputs": [], "source": [ "clip_shp = gpd.read_file(os.path.join(pth, \"tutorial_data\", \"rek2.shp\"))\n", - "clip_shp = clip_shp.to_crs({\"init\": \"epsg:4326\"})\n", + "clip_shp = clip_shp.to_crs(\"epsg:4326\")\n", "clip_shp_obj = clip_shp.geometry.iloc[0]" ] }, @@ -271,7 +261,7 @@ "outputs": [], "source": [ "iceland.roads_raw = iceland.roads_raw.loc[\n", - " iceland.roads_raw.geometry.intersects(clip_shp_obj) is True\n", + " iceland.roads_raw.geometry.intersects(clip_shp_obj) == True # noqa: E712\n", "]" ] }, @@ -291,6 +281,16 @@ "iceland.generateRoadsGDF(verbose=False)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# view the first 5 rows of the newly created roads GeoDataFrame\n", + "iceland.roadsGPD.head()" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/Tutorials/Step_2-Clean_Network.ipynb b/Tutorials/Step_2-Clean_Network.ipynb index d2a09ad..a7b7164 100644 --- a/Tutorials/Step_2-Clean_Network.ipynb +++ b/Tutorials/Step_2-Clean_Network.ipynb @@ -18,9 +18,9 @@ "outputs": [], "source": [ "import os\n", - "import sys\n", "import time\n", - "import networkx as nx" + "import networkx as nx\n", + "import pickle" ] }, { @@ -29,8 +29,7 @@ "metadata": {}, "outputs": [], "source": [ - "# add to your system path the location of the LoadOSM.py and GOSTnet.py scripts\n", - "sys.path.append(\"../\")\n", + "# import the GOSTnets library\n", "import GOSTnets as gn" ] }, @@ -44,7 +43,7 @@ "data_pth = os.path.join(pth, \"tutorial_outputs\")\n", "\n", "# read back your graph from step 1 from you saved pickle\n", - "G = nx.read_gpickle(os.path.join(data_pth, \"iceland_unclean.pickle\"))" + "G = pickle.load(open(os.path.join(data_pth, \"iceland_unclean.pickle\"), \"rb\"))" ] }, { @@ -69,7 +68,7 @@ "outputs": [], "source": [ "# you can also print general graph information with networkx\n", - "print(nx.info(G))" + "print(G)" ] }, { @@ -95,9 +94,9 @@ "metadata": {}, "outputs": [], "source": [ - "Iceland_UTMZ = {\"init\": \"epsg:32627\"}\n", + "Iceland_UTMZ = \"epsg:32627\"\n", "\n", - "WGS = {\"init\": \"epsg:4326\"} # do not adjust. OSM natively comes in ESPG 4326" + "WGS = \"epsg:4326\" # do not adjust. OSM natively comes in ESPG 4326" ] }, { @@ -116,7 +115,7 @@ "source": [ "print(\"start: %s\\n\" % time.ctime())\n", "G_clean = gn.clean_network(\n", - " G, UTM=Iceland_UTMZ, WGS={\"init\": \"epsg:4326\"}, junctdist=10, verbose=False\n", + " G, UTM=Iceland_UTMZ, WGS=\"epsg:4326\", junctdist=10, verbose=False\n", ")\n", "\n", "# using verbose = True:\n", @@ -132,7 +131,7 @@ "outputs": [], "source": [ "# let's print info on our clean version\n", - "print(nx.info(G_clean))" + "print(G_clean)" ] }, { @@ -182,7 +181,7 @@ "outputs": [], "source": [ "# print info about the largest sub-graph\n", - "print(nx.info(G_largest))" + "print(G_largest)" ] }, { @@ -260,7 +259,7 @@ "G.graph[\"name\"] = \"Iceland\"\n", "\n", "# original graph\n", - "ox.plot_graph(G, fig_width=10, edge_linewidth=1, node_size=7)" + "ox.plot_graph(G, figsize=(10, 14), edge_linewidth=1, node_size=7)" ] }, { @@ -273,7 +272,7 @@ "G_clean.graph[\"name\"] = \"Iceland\"\n", "\n", "# cleaned graph\n", - "ox.plot_graph(G_clean, fig_width=10, edge_linewidth=1, node_size=7)" + "ox.plot_graph(G_clean, figsize=(10, 14), edge_linewidth=1, node_size=7)" ] }, { @@ -286,7 +285,7 @@ "G_largest.graph[\"name\"] = \"Iceland\"\n", "\n", "# largest subgraph\n", - "ox.plot_graph(G_largest, fig_width=10, edge_linewidth=1, node_size=7)" + "ox.plot_graph(G_largest, figsize=(10, 14), edge_linewidth=1, node_size=7)" ] } ], diff --git a/Tutorials/Step_3-Using_your_Graph.ipynb b/Tutorials/Step_3-Using_your_Graph.ipynb index c904f10..408a9d2 100644 --- a/Tutorials/Step_3-Using_your_Graph.ipynb +++ b/Tutorials/Step_3-Using_your_Graph.ipynb @@ -28,10 +28,10 @@ "outputs": [], "source": [ "import os\n", - "import sys\n", "import networkx as nx\n", "import geopandas as gpd\n", - "import pandas as pd" + "import pandas as pd\n", + "import pickle as pkl" ] }, { @@ -40,8 +40,7 @@ "metadata": {}, "outputs": [], "source": [ - "# add to your system path the location of the LoadOSM.py and GOSTnet.py scripts\n", - "sys.path.append(\"../\")\n", + "# import GOSTnet library\n", "import GOSTnets as gn" ] }, @@ -68,8 +67,8 @@ "outputs": [], "source": [ "pth = \"./\" # change this path to your working folder\n", - "G = nx.read_gpickle(\n", - " os.path.join(pth, \"tutorial_outputs\", r\"iceland_network_clean.pickle\")\n", + "G = pkl.load(\n", + " open(os.path.join(pth, \"tutorial_outputs\", r\"iceland_network_clean.pickle\"), \"rb\")\n", ")" ] }, @@ -363,7 +362,7 @@ "outputs": [], "source": [ "mini_gdf = gpd.GeoDataFrame(\n", - " {\"geometry\": my_house}, crs={\"init\": \"epsg:4326\"}, geometry=\"geometry\", index=[1]\n", + " {\"geometry\": my_house}, crs=\"epsg:4326\", geometry=\"geometry\", index=[1]\n", ")" ] }, diff --git a/Tutorials/tutorial_data/OD_links_usage.csv b/Tutorials/tutorial_data/OD_links_usage.csv deleted file mode 100644 index 69a0ac0..0000000 --- a/Tutorials/tutorial_data/OD_links_usage.csv +++ /dev/null @@ -1 +0,0 @@ -,start,node,geometry,count diff --git a/Tutorials/tutorial_data/all_OD_links.csv b/Tutorials/tutorial_data/all_OD_links.csv deleted file mode 100644 index 2037447..0000000 --- a/Tutorials/tutorial_data/all_OD_links.csv +++ /dev/null @@ -1 +0,0 @@ -,O,D,geometry diff --git a/Tutorials/tutorial_outputs/iceland_network_clean.pickle b/Tutorials/tutorial_outputs/iceland_network_clean.pickle index 62502f2..81da747 100644 Binary files a/Tutorials/tutorial_outputs/iceland_network_clean.pickle and b/Tutorials/tutorial_outputs/iceland_network_clean.pickle differ diff --git a/docs/_config.yml b/docs/_config.yml index 1d45609..b087b8a 100755 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -8,6 +8,7 @@ logo: images/logo.png # Force re-execution of notebooks on each build. # See https://jupyterbook.org/content/execute.html execute: + timeout: 600 # 10 minutes execute_notebooks: force allow_errors: true diff --git a/src/GOSTnets/calculate_od_raw.py b/src/GOSTnets/calculate_od_raw.py index aafeaa3..66dc7c9 100644 --- a/src/GOSTnets/calculate_od_raw.py +++ b/src/GOSTnets/calculate_od_raw.py @@ -14,7 +14,7 @@ def calculateOD_gdf( fail_value=-1, weight="time", calculate_snap=False, - wgs84={"init": "epsg:4326"}, + wgs84="epsg:4326", ): """Calculate Origin destination matrix from GeoDataframes @@ -76,7 +76,7 @@ def calculateOD_csv( oLon="Lon", dLat="Lat", dLon="Lon", - crs={"init": "epsg:4326"}, + crs="epsg:4326", fail_value=-1, weight="time", calculate_snap=False, @@ -100,8 +100,8 @@ def calculateOD_csv( Destination latitude field dLon : str Destination longitude field - crs : dict - crs of input origins and destinations, defaults to {'init':'epsg:4326'} + crs : str + crs of input origins and destinations, defaults to 'epsg:4326' fail-value : int value to put in OD matrix if no route found, defaults to -1 weight : str diff --git a/src/GOSTnets/core.py b/src/GOSTnets/core.py index 2c46ca9..b847c0c 100644 --- a/src/GOSTnets/core.py +++ b/src/GOSTnets/core.py @@ -2,6 +2,7 @@ import logging import warnings import time +import pickle as pkl import pyproj import networkx as nx @@ -379,7 +380,7 @@ def node_gdf_from_graph( G : nx.Graph a graph object G crs : str - projection of format {'init' :'epsg:4326'}. Defaults to WGS84. note: here we are defining the crs of the input geometry - we do NOT reproject to this crs. To reproject, consider using geopandas' to_crs method on the returned gdf. + projection of format 'epsg:4326'. Defaults to WGS84. note: here we are defining the crs of the input geometry - we do NOT reproject to this crs. To reproject, consider using geopandas' to_crs method on the returned gdf. attr_list : list list of the keys which you want to be moved over to the GeoDataFrame, if not all. Defaults to None, which will move all. geometry_tag : str @@ -490,7 +491,7 @@ def edge_gdf_from_graph( G : nx.Graph (required) a graph object G crs : str - (optional) projection of format {'init' :'epsg:4326'}. Defaults to WGS84. Note: here we are defining the crs of the input geometry -we do NOT reproject to this crs. To reproject, consider using geopandas' to_crs method on the returned gdf. + (optional) projection of format 'epsg:4326'. Defaults to WGS84. Note: here we are defining the crs of the input geometry -we do NOT reproject to this crs. To reproject, consider using geopandas' to_crs method on the returned gdf. attr_list : list (optional) list of the keys which you want to be moved over to the GeoDataFrame. geometry_tag : str @@ -635,8 +636,8 @@ def graph_nodes_intersecting_polygon(G, polygons, crs=None): ---------- G : nx.Graph or gpd.GeoDataFrame a Graph object OR node geodataframe - crs : dict - a crs object of form {'init':'epsg:XXXX'}. If passed, matches both inputs to this crs. + crs : str + a crs object of form 'epsg:XXXX'. If passed, matches both inputs to this crs. Returns ------- @@ -930,7 +931,7 @@ def make_iso_polys( weight : str The edge weight to use when appraising travel times. measure_crs : str - measurement crs, object of form {'init':'epsg:XXXX'} + measurement crs, object of form 'epsg:XXXX' edge_filters : dict you can optionally add a dictionary with key values, where the key is the attribute and the value you want to ignore from creating isochrones. An example might be an underground subway line. @@ -1086,7 +1087,7 @@ def make_iso_polys_original( weight : str The edge weight to use when appraising travel times. measure_crs : str - measurement crs, object of form {'init':'epsg:XXXX'} + measurement crs, object of form 'epsg:XXXX' Returns ------- @@ -1891,7 +1892,7 @@ def save(G, savename, wpath, pickle=True, edges=True, nodes=True): new_edge_gdf = edge_gdf_from_graph(G) new_edge_gdf.to_csv(os.path.join(wpath, "%s_edges.csv" % savename)) if pickle is True: - nx.write_gpickle(G, os.path.join(wpath, "%s.pickle" % savename)) + pkl.dump(G, open(os.path.join(wpath, "%s.pickle" % savename), "wb")) def add_missing_reflected_edges(G, one_way_tag=None, verbose=False): @@ -2071,9 +2072,7 @@ def convert_to_MultiDiGraph(G): #### NETWORK SIMPLIFICATION #### -def simplify_junctions( - G, measure_crs, in_crs={"init": "epsg:4326"}, thresh=25, verbose=False -): +def simplify_junctions(G, measure_crs, in_crs="epsg:4326", thresh=25, verbose=False): """ simplifies topology of networks by simplifying node clusters into single nodes. @@ -2128,7 +2127,7 @@ def simplify_junctions( juncs_gdf_unproj, gdfnodes, how="left", - op="intersects", + predicate="intersects", lsuffix="left", rsuffix="right", ) diff --git a/src/GOSTnets/fetch_pois.py b/src/GOSTnets/fetch_pois.py index d9bb06b..e99f5a4 100644 --- a/src/GOSTnets/fetch_pois.py +++ b/src/GOSTnets/fetch_pois.py @@ -37,7 +37,7 @@ class OsmObject: -------- >>> education = {'amenity':['school', 'kindergarten','university', 'college']} >>> health = {'amenity':['clinic', 'pharmacy', 'hospital', 'health']} - >>> crs = {'init' :'epsg:4326'} + >>> crs = 'epsg:4326' >>> buf_width = 0.0005 >>> for a in amenities: ... curr_amenity = amenities[a] diff --git a/src/GOSTnets/load_osm.py b/src/GOSTnets/load_osm.py index 23f9575..fb7c07b 100644 --- a/src/GOSTnets/load_osm.py +++ b/src/GOSTnets/load_osm.py @@ -207,7 +207,7 @@ def fetch_roads(self, data_path): road_gdf = gpd.GeoDataFrame( roads, columns=["osm_id", "infra_type", "one_way", "geometry"], - crs={"init": "epsg:4326"}, + crs="epsg:4326", ) return road_gdf @@ -291,7 +291,7 @@ def fetch_roads_and_ferries(self, data_path): road_gdf = gpd.GeoDataFrame( roads, columns=["osm_id", "infra_type", "geometry"], - crs={"init": "epsg:4326"}, + crs="epsg:4326", ) return road_gdf @@ -319,7 +319,7 @@ def line_length(self, line, ellipsoid="WGS-84"): Length of line in kilometers """ - if line.geometryType() == "MultiLineString": + if line.geom_type == "MultiLineString": return sum(self.line_length(segment) for segment in line) return sum( @@ -398,9 +398,9 @@ def get_all_intersections( # Save intersecting point # updating to be compatible with Shapely ver 2 # if "Point" == inter.type: - if "Point" == inter.type: + if "Point" == inter.geom_type: idx_inters.insert(0, inter.bounds, inter) - elif "MultiPoint" == inter.type: + elif "MultiPoint" == inter.geom_type: # updating to be compatible with Shapely ver 2 # for pt in inter: for pt in inter.geoms: @@ -455,7 +455,7 @@ def get_all_intersections( # Transform into geodataframe and add coordinate system full_gpd = gpd.GeoDataFrame(flat_list, geometry="geometry") - full_gpd.crs = {"init": "epsg:4326"} + full_gpd.crs = "epsg:4326" return full_gpd diff --git a/src/GOSTnets/network_clean.py b/src/GOSTnets/network_clean.py index 83b8775..2e300ff 100644 --- a/src/GOSTnets/network_clean.py +++ b/src/GOSTnets/network_clean.py @@ -13,8 +13,8 @@ def clean_network( G, wpath="", output_file_name="", - UTM={"init": "epsg:3857"}, - WGS={"init": "epsg:4326"}, + UTM="epsg:3857", + WGS="epsg:4326", junctdist=50, verbose=False, ): diff --git a/src/GOSTnets/osm_parser.py b/src/GOSTnets/osm_parser.py index 6c8626e..695f291 100644 --- a/src/GOSTnets/osm_parser.py +++ b/src/GOSTnets/osm_parser.py @@ -500,7 +500,7 @@ def fetch_roads_OSM( road_gdf = gpd.GeoDataFrame( roads, columns=["osm_id", "infra_type", "geometry"], - crs={"init": "epsg:4326"}, + crs="epsg:4326", ) return road_gdf else: