Comments (3)
truncate_graph_polygon
is an under-the-hood function that I ended up exposing. It uses intersect_index_quadrats
but doesn't expose some of its arguments. Thus, it works fine when you're using lat-long geometries, but chokes on projected geometries. The fix is to expose those arguments, which I just did in ba1d1b3. Thus your code should work in the latest GitHub version of OSMnx. Here's a small working example:
import osmnx as ox
ox.config(use_cache=True, log_console=True)
G = ox.graph_from_place('Piedmont, CA, USA', network_type='drive')
G = ox.project_graph(G)
gdf = ox.gdf_from_place('Piedmont, CA, USA')
poly = gdf['geometry'].iloc[0]
poly, crs = ox.project_geometry(poly)
poly = poly.buffer(-500)
G_truncated = ox.truncate_graph_polygon(G, poly, retain_all=False, truncate_by_edge=False,
quadrat_width=1000, buffer_amount=0.01)
fig, ax = ox.plot_graph(G_truncated)
The quadrat_width
and buffer_amount
arguments are in the polygon's units. So, here, we projected the polygon to UTM and thus the units are in meters.
In the meantime (pending these commits getting packaged and released), you can still make this work using OSMnx versions < 0.5. The trick is to work in all lat-long, and only project at the end:
import osmnx as ox
ox.config(use_cache=True, log_console=True)
G = ox.graph_from_place('Merced County, California, USA', network_type='drive_service')
place_names = ['Merced, California, USA',
'Atwater, California, USA',
'Livingston, California, USA']
merced_cities = ox.gdf_from_places(place_names)
merced_polygon = merced_cities['geometry'].iloc[0]
g_sample = ox.truncate_graph_polygon(G, merced_polygon, retain_all=False, truncate_by_edge=False)
g_sample_projected = ox.project_graph(g_sample)
fig, ax = ox.plot_graph(g_sample_projected)
Note that as of OSMnx v0.15.0, the gdf_from_place
and gdf_from_places
functions have been deprecated and replaced by the geocode_to_gdf
function. See the docs for details.
from osmnx.
Just wanted to chime in and ask a short follow up question/s.
So osmnx.project_gdf()
's functionality is to: "Project a GeoDataFrame to the UTM zone appropriate for its geometries' centroid."
Is the purpose of this step purely for rendering purposes? That is, is the intent to prepare the geometries to be rendered in a manner that is less distorted?
In @kelanstoy's example, there is no advantage necessarily in that process to re-projecting the data at that step, right? One could simply work in web mercator/latlng until one is ready to plot the results and then use the project_gdf
function. Otherwise, one would be fine leaving it "as is" during their analysis.
from osmnx.
There are various reasons to project spatial data from an (approximately) spheroidal coordinate system like lat-long to a planar coordinate system like UTM. Like you mentioned, you might want to display it in two dimensions, such as on a sheet of paper or on a computer screen. Or you might want to have your geometries in units that are more meaningful than degrees -- typically meters.
from osmnx.
Related Issues (20)
- [Meta] Enable Discussions tab on this GitHub repo HOT 2
- Further API streamlining for v2 HOT 2
- _bearings_distribution: apply weight during histogram HOT 2
- Conditional tolerance for intersection consolidation HOT 16
- Add edge_attrs_differ argument to each graph.graph_from_* method HOT 2
- Add support for implicit maxspeed values
- `ox.shortest_path` returns `None` HOT 3
- Add function to merge parallel roads HOT 4
- Publish v2 pre-releases HOT 1
- Issues with plotting and basic stats when using DiGraphs HOT 1
- AttributeError: module 'osmnx' has no attribute 'convert' HOT 1
- InsufficientResponseError while HOT 1
- FutureWarning: The 'unary_union' attribute is deprecated HOT 4
- Issue with graph_from_bbox on Visual Studio code. HOT 5
- plot_graph raises an MPL error while running in a remote Linux machine HOT 1
- Change bounding box coordinates' order for v2.0.0? HOT 2
- Graph route animations HOT 3
- `consolidate_intersections` crashes with dictionary for tolerances HOT 4
- Bounding Box doesn't work in ox.features_from_bbox(bbox, tags) HOT 1
- We need a fucntion that can generate gdf_nodes and gdf_edges from locallly downloaded road network loaded using geopandas as gdf HOT 3
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.