Comments (12)
FWIW, you can also get the network within n meters of the center_point along the network (rather than by constructing a bounding box around your center_point), like this:
G = ox.graph_from_point(center_point, distance=1000, distance_type='network', network_type='drive')
from osmnx.
This is working correctly. If you get the geometry for Povo, Italy:
ox.gdf_from_place('Povo, Italy')
OpenStreetMap returns a point:
POINT (11.154962 46.0654207)
If you have logging turned on, it issues a warning: "OSM returned a Point as the geometry."
You can see this directly from the API -- looks like OSM doesn't have a polygon for this place, only a centroid point. The geocoder warns you that it got a point back, and when graph_from_polygon receives the point geometry, it throws the exception you saw: the geometry has to be a Polygon or MultiPolygon to run graph_from_polygon.
See also: #16
from osmnx.
A related query: I can get a point gdf for a city without a polygon (like "Povo, Italy" in the example above), but this doesn't seem to work as an input to "graph_from_point" for either "distance_type
= 'network'" or "distance_type = 'bbox'". What is a better way to achieve this?
import osmnx as ox
gdf = ox.gdf_from_place('Povo, Italy')
G = ox.graph_from_point(gdf, distance = 3000)
TypeError: __new__() takes at most 4 arguments (5 given)
from osmnx.
Your code snippet is almost there. If you check out the docstring for graph_from_point
, you'll see the first argument is center_point
. The docstring defines it as center_point : tuple, the (lat, lon) central point around which to construct the graph
So, you just need to extract the point as a (lat, lon) tuple from the GeoDataFrame, like this:
import osmnx as ox
gdf = ox.gdf_from_place('Povo, Italy')
point_geometry = gdf['geometry'].iloc[0]
center_point = (point_geometry.y, point_geometry.x)
G = ox.graph_from_point(center_point, distance=3000)
from osmnx.
import osmnx as ox
gdf = ox.gdf_from_place('Povo, Italy')
point_geometry = gdf['geometry'].iloc[0]
center_point = (point_geometry.y, point_geometry.x)
G = ox.graph_from_point(center_point, distance=3000)
this is giving me an error of LinearRing
from osmnx.
I'd check your operations and rerun it again, it's working for me:
from osmnx.
@yujinh this is likewise all working fine in my test environments. Can you provide your full package list and environment info (ie, what OS, what python version, etc)?
from osmnx.
macOS Sierra version 10.12.6
python 3.6
#
_nb_ext_conf 0.4.0 py36_1
altair 1.2.1 py_0 conda-forge
anaconda-client 1.6.5 py36h04cfe59_0
appnope 0.1.0 py36_0 conda-forge
asn1crypto 0.22.0 py36_0 conda-forge
backports 1.0 py36_1 conda-forge
backports.functools_lru_cache 1.4 py36_1 conda-forge
bleach 2.0.0 py36_0 conda-forge
branca 0.2.0 py_1 conda-forge
ca-certificates 2017.08.26 ha1e5d58_0
certifi 2017.7.27.1 py36hd973bb6_0
cffi 1.10.0 py36_0 conda-forge
chardet 3.0.4 py36_0 conda-forge
click 6.7 py36_0 conda-forge
click-plugins 1.0.3 py36_0 conda-forge
cligj 0.4.0 py36_0 conda-forge
clyent 1.2.2 py36hae3ad88_0
cryptography 2.0.3 py36_0 conda-forge
curl 7.54.1 0 conda-forge
cycler 0.10.0 py36_0 conda-forge
decorator 4.1.2 py36_0 conda-forge
descartes 1.1.0 py36_0 conda-forge
entrypoints 0.2.3 py36_1 conda-forge
expat 2.2.1 0 conda-forge
fiona 1.7.9 py36_1 conda-forge
folium 0.5.0 py_0 conda-forge
freetype 2.7 1 conda-forge
freexl 1.0.2 2 conda-forge
gdal 2.1.3 np112py36_2 conda-forge
geopandas 0.3.0 py36_0 conda-forge
geopy 1.11.0 py36_0 conda-forge
geos 3.5.1 1 conda-forge
giflib 5.1.4 0 conda-forge
hdf4 4.2.12 0 conda-forge
hdf5 1.8.17 11 conda-forge
html5lib 0.999999999 py36_0 conda-forge
icu 58.1 1 conda-forge
idna 2.6 py36_1 conda-forge
ipykernel 4.6.1 py36_0 conda-forge
ipython 6.2.1 py36_0 conda-forge
ipython_genutils 0.2.0 py36_0 conda-forge
ipywidgets 7.0.0 py36h24d3910_0
jedi 0.10.2 py36_0 conda-forge
jinja2 2.9.6 py36_0 conda-forge
jpeg 9b 1 conda-forge
json-c 0.12.1 0 conda-forge
jsonschema 2.6.0 py36_0 conda-forge
jupyter_client 5.1.0 py36_0 conda-forge
jupyter_core 4.3.0 py36_0 conda-forge
kealib 1.4.6 3 conda-forge
krb5 1.14.2 0 conda-forge
libcxx 4.0.1 h579ed51_0
libcxxabi 4.0.1 hebd6815_0
libdap4 3.18.3 2 conda-forge
libedit 3.1 hb4e282d_0
libffi 3.2.1 hd939716_3
libgfortran 3.0.0 0 conda-forge
libiconv 1.14 4 conda-forge
libnetcdf 4.4.1.1 4 conda-forge
libpng 1.6.28 0 conda-forge
libpq 9.6.3 0 conda-forge
libsodium 1.0.10 0 conda-forge
libspatialindex 1.8.5 1 conda-forge
libspatialite 4.3.0a 15 conda-forge
libssh2 1.8.0 1 conda-forge
libtiff 4.0.6 7 conda-forge
libxml2 2.9.5 0 conda-forge
markupsafe 1.0 py36_0 conda-forge
matplotlib 2.1.0 py36_0 conda-forge
mistune 0.7.4 py36_0 conda-forge
mkl 2017.0.3 0
munch 2.2.0 py36_0 conda-forge
nb_anacondacloud 1.4.0 py36_0
nb_conda 2.2.1 py36h349edbb_0
nb_conda_kernels 2.1.0 py36_0
nbconvert 5.3.1 py_1 conda-forge
nbformat 4.4.0 py36_0 conda-forge
nbpresent 3.0.2 py36hef4c988_1
ncurses 6.0 ha932d30_1
networkx 2.0 py36_0 conda-forge
notebook 5.2.0 py36_1 conda-forge
numpy 1.13.3 <pip>
numpy 1.12.1 py36_0
openjpeg 2.1.2 2 conda-forge
openssl 1.0.2l h57f3a61_2
osmnx 0.6 py36_0 conda-forge
pandas 0.20.3 py36_1 conda-forge
pandoc 1.19.2 0 conda-forge
pandocfilters 1.4.1 py36_0 conda-forge
pcre 8.39 0 conda-forge
pexpect 4.2.1 py36_0 conda-forge
pickleshare 0.7.4 py36_0 conda-forge
pip 9.0.1 py36hbd95645_3
proj4 4.9.3 4 conda-forge
prompt_toolkit 1.0.15 py36_0 conda-forge
psycopg2 2.7.3.1 py36_0 conda-forge
ptyprocess 0.5.2 py36_0 conda-forge
pycparser 2.18 py36_0 conda-forge
pygments 2.2.0 py36_0 conda-forge
pyopenssl 17.2.0 py36_0 conda-forge
pyparsing 2.2.0 py36_0 conda-forge
pyproj 1.9.5.1 py36_0 conda-forge
pysal 1.14.2 py36_1 conda-forge
pysocks 1.6.7 py36_0 conda-forge
python 3.6.2 0 conda-forge
python-dateutil 2.6.1 py36_0 conda-forge
pytz 2017.2 py36_0 conda-forge
pyyaml 3.12 py36h2ba1e63_1
pyzmq 16.0.2 py36_2 conda-forge
readline 6.2 2
requests 2.18.4 py36_1 conda-forge
rtree 0.8.3 py36_0 conda-forge
scipy 0.19.1 np112py36_0
setuptools 36.5.0 py36h2134326_0
shapely 1.6.1 py36_1 conda-forge
simplegeneric 0.8.1 py36_0 conda-forge
six 1.11.0 py36_1 conda-forge
sqlalchemy 1.1.13 py36_0 conda-forge
sqlite 3.13.0 1 conda-forge
terminado 0.6 py36_0 conda-forge
testpath 0.3.1 py36_0 conda-forge
tk 8.5.19 2 conda-forge
tornado 4.5.2 py36_0 conda-forge
traitlets 4.3.2 py36_0 conda-forge
urllib3 1.22 py36_0 conda-forge
vega 0.4.4 py36_1 conda-forge
vincent 0.4.4 py36_0 conda-forge
wcwidth 0.1.7 py36_0 conda-forge
webencodings 0.5 py36_0 conda-forge
wheel 0.29.0 py36h3597b6d_1
widgetsnbextension 3.0.2 py36h91f43ea_1
xerces-c 3.1.4 3 conda-forge
xz 5.2.3 ha24016e_1
yaml 0.1.7 hff548bb_1
zeromq 4.2.1 1 conda-forge
zlib 1.2.11 h60db283_1
from osmnx.
Hello!
I had an error with shapely polygon or multipolygon, but it worked when I changed from place to address. In a next step, it failed when I put the address, so I changed to the place and it worked. However, coming to the next step, it showed another error:
#Calculate basic street network measures (topological and metric)
get the network for Piedmont, calculate its basic stats, then show the average circuity
stats = ox.basic_stats(ox.graph_from_address('11.568271,104.9224426'))
stats['circuity_avg']
1.036148445103483
get the street network for a place, and its area in square meters
place = 'Phnom Penh, Cambodia'
gdf = ox.gdf_from_place(place)
area = ox.project_gdf(gdf).unary_union.area
G = ox.graph_from_place(place, which_result=2, network_type='drive_service')
calculate basic and extended network stats, merge them together, and display
stats = ox.basic_stats(G, area=area)
extended_stats = ox.extended_stats(G, ecc=True, bc=True, cc=True)
for key, value in extended_stats.items():
stats[key] = value
pd.Series(stats)
ZeroDivisionError Traceback (most recent call last)
in
1 # calculate basic and extended network stats, merge them together, and display
----> 2 stats = ox.basic_stats(G, area=area)
3 extended_stats = ox.extended_stats(G, ecc=True, bc=True, cc=True)
4 for key, value in extended_stats.items():
5 stats[key] = value
c:\anaconda3\envs\osmnx\lib\site-packages\osmnx\stats.py in basic_stats(G, area, clean_intersects, tolerance, circuity_dist)
154
155 # calculate node density as nodes per sq km
--> 156 node_density_km = n / area_km
157
158 # calculate intersection density as nodes with >1 street emanating from
ZeroDivisionError: float division by zero
I am a beginner of python and osmnx. Any advice, please? I really appreciate!
from osmnx.
Hi, @gboeing
thank you for osmnx package! It is really good to use it.
I had similar issue arising from "non-polygons" objects, e.g. "Povo, Italy".
So, I tried to overcome this error by giving coordinates for Polygon:
Create Polygon from coordinates
coords = [(24.950899, 60.169158), (24.953492, 60.169158), (24.953510, 60.170104), (24.950958, 60.169990)] #working example
But then I cannot search for amenities in the Polygon for some reason.
Is it because of the same reason that this is no Polygon on openstreetmaps for this region in these coordinates?
e.g. I try
hosp= ox.pois.osm_poi_download(polygon=poly, amenities=['hospitals'])
Thank you!
from osmnx.
@Liyubov if you provide a minimal, complete, reproducible example I will take a look.
from osmnx.
Yes, tnx, sure, here it is @gboeing
The problem is that when I create polygon and search for amenities in the area bounded by coordinates I cannot get the right dataframe of amenities with properties.
Hope this is clear. Thank you!
`import networkx as nx
import osmnx as ox
import requests
from matplotlib import pyplot as plt
import matplotlib.cm as cm
import matplotlib.colors as colors
ox.config(use_cache=True, log_console=True)
ox.version
import numpy as np
from shapely.geometry import Point, Polygon
Create a Polygon
coords = [(24.950899, 60.169158), (24.953492, 60.169158), (24.953510, 60.170104), (24.950958, 60.169990)]
poly = Polygon(coords)
hospitals = ox.pois.osm_poi_download(polygon=poly, amenities=['hospital'])
How many hospitals do we have in this district?
print('number of hospitals',len(hospitals))
`
from osmnx.
Related Issues (20)
- Node Identification within Buffer Zone (if buffer was to be implemented) HOT 1
- PermissionError [ErrNo 13] when connecting to localhost using the latest docker image HOT 2
- Contributing guidelines link nowhere HOT 2
- Document usage limitations HOT 10
- UnicodeDecodeError in graph_from_xml on Windows Installations HOT 4
- Calling graph_from_place("Alaska", network_type="drive") throws GEOSException: TopologyException HOT 4
- Vasu HOT 1
- Unable to plot superimposed image HOT 1
- street networks graphs not working HOT 3
- AttributeError: module 'osmnx' has no attribute 'clean_intersections' HOT 2
- Removal of inner_polygons from outer_polygons (creation of holes), creates maximum one hole. HOT 5
- Include parking space data in nodes HOT 7
- Fill missing values with most common value on similar roads HOT 4
- OSMnx 2.0 Migration Guide HOT 3
- Add junction/intersection types to nodes HOT 6
- Support directed bearing/orientation distributions and plots HOT 5
- Support loading and/or merging multiple networks HOT 5
- [Meta] Enable Discussions tab on this GitHub repo HOT 1
- Further API streamlining for v2 HOT 2
- _bearings_distribution: apply weight during histogram HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from osmnx.