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)
- Adding other highway types to street_widths dict in osmnx.plot.plot_figure_ground, not appearing in map HOT 1
- Tests on Windows fail with [WinError 6] The handle is invalid HOT 4
- Adding type hints to the function signatures HOT 4
- Dictionaries attributes not handled in io.load_graphml() HOT 5
- Feature Request: Adding Buffer Zone Function to OSMnx HOT 1
- 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
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.