0

I'm trying to create network for a place where I want to check accessibility of my friends to me.

Importing libraries(all latest versions)

import warnings
warnings.filterwarnings("ignore")
import pandas as pd
from pandana.loaders import osm
import pandana
%pylab inline
from pyproj.crs import CRS
import numpy as np
import osmnx as ox
import networkx as nx
import peartree
import sys, os
import geopandas as gpd
import folium
import rasterio
from pandana.loaders import osm
from shapely.geometry import Point
import mplleaflet as mpll
from osgeo import ogr
from math import ceil, cos, pi
import geocoder
from shapely.geometry import mapping, Polygon, box
import fiona

Creating GeoDataFrame with point geometery and defining CRS

df = pd.DataFrame(
  {'Name': ['Neil', 'Nitin', 'Mukesh'],
   'Area': ['Valsad', 'Silvasa', 'Daman'],
   'lat': [12.994270, 12.976576, 12.900404],
   'lon': [77.536782, 77.653850, 77.575158]})
friends= gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.lon, df.lat))
friends.crs  =  "EPSG:4326"

Defining methods to create network using pandana

def get_bounds(place_gdf, buffer_fraction):
    bounds = emp_place_gdf.unary_union.bounds
    x_width = abs(bounds[2] - bounds[0])
    y_height = abs(bounds[3] - bounds[1])
    minx = bounds[0] - (x_width * buffer_fraction)
    miny = bounds[1] + (y_height * buffer_fraction)
    maxx = bounds[2] - (x_width * buffer_fraction)
    maxy = bounds[3] + (y_height * buffer_fraction)
    return(minx, miny, maxx, maxy)

def create_network(frnd_gdf, bounding_increment):
    coords = get_bounds(emp_gdf, bounding_increment)
    coords = (coords[1],coords[0],coords[3],coords[2])
    return(osm.pdna_network_from_bbox(*coords))

Creating network over friends gdf

G_BOIS = create_network(friends, 0.2)

Error I get Error I'm receiving

Please help me with the error and please comment If needed more information

  • Does it work if you use `friends['crs'] = "EPSG:4326"` rather than `friends.crs`? You're currently simply setting an attribute rather than defining a new column – TayTay Jul 06 '20 at 17:57
  • @Tgsmith61591 No, its not working for the way you shared instead my way works, its even mentioned in the geopandas documentation. – Lucky Verma Jul 06 '20 at 18:08
  • 2
    It seems that `osmnet` has not been updated to work with GeoPandas 0.7+ and expects that `gdf.crs` is a dict, which is not true anymore. To use it, you'll have to downgrade GeoPandas to 0.6.3 to make it work I am afraid, until devs of `osmnet` will release a fix. – martinfleis Jul 06 '20 at 18:15
  • 2
    See https://github.com/UDST/osmnet/issues/19 – martinfleis Jul 06 '20 at 18:17
  • Thanks @martinfleis for the information but, I'm afraid that osmnx has made geopandas>=0.7.0 for all its previous versions. I believe these things get fixed by devs soon. – Lucky Verma Jul 06 '20 at 20:53
  • What version of OSMnx are you using? It may still work if you downgrade geopandas in your environment. Or you could possibly downgrade OSMnx too. – gboeing Jul 07 '20 at 03:35
  • @gboeing OSMnx==0.15.0, I wanted to use newer version of osmnx with newer version of geopandas but, newer version is having some issues. – Lucky Verma Jul 07 '20 at 05:18

0 Answers0