Giter Club home page Giter Club logo

Comments (7)

gboeing avatar gboeing commented on May 24, 2024 1

I'll have some time to take a considered look at this soon.

from osmnx.

gboeing avatar gboeing commented on May 24, 2024

@EwoutH thanks and sorry for the delay. I'm still reflecting on this proposal. One thing I'm thinking about is if this could be generalized to a attach_features_to_nodes function that would take arbitrary OSM features and add them to the nearest nodes. If it could be generalized in such a way, this could be a broadly useful enhancement.

from osmnx.

EwoutH avatar EwoutH commented on May 24, 2024

Thanks! That's an excellent idea, it might also be useful to see what stores, parks, public transport stops, bodies of water or anything else is close to certain nodes.

On thing that might be difficult is how to generalize. For example, in the case of parking spots I might want to know how many there are, so I want to take the sum of capacity. But simultaneously I want to keep bike and car parking separate. Maybe we can make some aggregation function for if there are multiple, for example.

from osmnx.

EwoutH avatar EwoutH commented on May 24, 2024

Simplest way is just to start with adding the feature data and doing aggregation manually.

So if I want to add parking spaces to a node:

# Proposed function enhancement
G = ox.add_parking_to_nodes(G, max_radius=500, parking_types=['car', 'motorcycle', 'bicycle'], only_public=True, include_distances=False) 

You might get something like this:

# Example representation of parking spaces at a node
print(G.edges[0][1].feature_data)
[
    {
        'feature_type': 'Parking Lot',
        'capacity': 20,
        'fee': True,
        'accessible': True,  # Whether the parking lot is accessible to all
        'security_level': 'High',  # Security level of the parking lot
        'electric_charging': False  # Whether electric vehicle charging is available
    },
    {
        'feature_type': 'Bicycle Rack',
        'capacity': 10,
        'covered': False,  # Whether the bicycle rack is covered
        'secured': True  # Whether the bicycle rack is secured
    },
    {
        'feature_type': 'Motorcycle Parking',
        'capacity': 5,
        'fee': False,
        'covered': True,  # Whether the motorcycle parking is covered
        'security_level': 'Medium'  # Security level of the motorcycle parking
    }
]

And then users can aggerate the data however they like, and maybe in the future we could support some simple functions for it.

from osmnx.

gboeing avatar gboeing commented on May 24, 2024

Ok, I've had some time to reflect on this. In general, the OSMnx project follows 3 principles when adding new functionality: 1) it is useful to a broad set of users, 2) it generalizes well, and 3) it is not trivially easy for users to implement themselves. Your proposal satisfies point 1 but I don't think it satisfies points 2 and 3. Let me explain my thinking...

Let's say you create a street network graph and a GeoDataFrame of features, like this:

import osmnx as ox
import pandas as pd
place = "Piedmont, CA, USA"
G = ox.graph.graph_from_place(place, network_type="drive")
features = ox.features.features_from_place(place, {"amenity": "parking"})

It is trivially easy to attach your features to your graph's nearest nodes as attributes:

nn = ox.distance.nearest_nodes(G, features.centroid.x, features.centroid.y)
useful_tags = ["access", "parking", "surface", "capacity", "fee"]
for node, feature in zip(nn, features[useful_tags].to_dict(orient="records")):
    feature = {k: v for k, v in feature.items() if pd.notna(v)}
    G.nodes[node].update({"parking": feature})

I didn't initially consider how simple it would be to implement a basic version of this when I first read your proposal. Furthermore, I can imagine nearly infinite variation in how users would proceed from here with aggregation or customized attachment for their specific analytical goals. Because it's trivially easy to implement in just a few lines of code and it needs extreme flexibility to proceed from there for various analyses, this seems like the ideal use case to demonstrate in the examples gallery rather than building into the codebase itself.

Long story short: I think it's a great use case for OSMnx but is best served in the examples gallery rather than as a new feature in the codebase. A basic implementation is trivially simple, and a sufficiently flexible implementation to capture all use cases would be overly complex.

from osmnx.

gboeing avatar gboeing commented on May 24, 2024

See gboeing/osmnx-examples#83

from osmnx.

EwoutH avatar EwoutH commented on May 24, 2024

Thanks for getting back! I also didn't realise it would be this simple, in that case I agree an example is more than sufficient.

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.