Giter Club home page Giter Club logo

Comments (3)

gboeing avatar gboeing commented on May 14, 2024 2

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.

kuanb avatar kuanb commented on May 14, 2024

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.

gboeing avatar gboeing commented on May 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.