Coder Social home page Coder Social logo

Comments (6)

fscottfoti avatar fscottfoti commented on June 23, 2024 2

from pandana.

smmaurer avatar smmaurer commented on June 23, 2024 1

Hi @majdal,

My guess is that the brute force approach of calculating the distance from every building to every school -- and then selecting the closest one -- would actually work pretty well here.

Since the recent v0.5 update, point-to-point network distances are super fast to calculate. Section 2 of this notebook has some code examples: Pandana-demo.ipynb

It's on our wish list to expose direct functionality like you're describing, but right now I think it's buried deep inside the graph traversal algorithms.

Something here might be helpful too: shortest-paths.ipynb. This notebook uses NetworkX instead of Pandana to calculate distances, which guarantees you're getting exactly the shortest path but is much slower. The last cell has an example of selecting the closest destination for each origin.

One final suggestion -- if there are so many buildings (millions, say) that the pure brute-force approach is too slow, you could add a preprocessing step where you use euclidean distances to identify a handful of candidate schools for each building, and then use Pandana to figure out which has the shortest network distance.

Hope this helps, and best of luck!

from pandana.

smmaurer avatar smmaurer commented on June 23, 2024 1

Actually, it might be easier and/or faster to just calculate the closest school to each network node, and then match the buildings that you're interested in to the relevant nodes.

The function you linked to is actually in the underlying C++ code -- here's the corresponding Python function: http://udst.github.io/pandana/network.html#pandana.network.Network.nearest_pois

from pandana.

majdal avatar majdal commented on June 23, 2024

Thanks @smmaurer and @fscottfoti for your very quick replies!

I like Sam's suggestion, of finding the nearest school to each node, then matching the buildings with nodes. I'm still not sure what would be the best way of connecting the building to a node.

One (awkward) way of doing so would be to also run the nearest_pois but with category = buildings, then joining the two two dataframes by node, and removing duplicate buildings. But this seems overly cumbersome.

from pandana.

fillipefeitosa avatar fillipefeitosa commented on June 23, 2024

@majdal

Hey friend, I got a similar problem and solved using OSMnx to get the "real distances" based on the street network and got the nearest using KDtree.

I had to find the nearest schools to a set of polygons centroids. To understand better check this notebook maps .

basically the algorithm will stretch the graph of the urban network.

nA = np.array(list(zip(polygon.geometry.x, polygon.geometry.y)) )
nB = np.array(list(zip(schools_preEscolar.geometry.x, schools_preEscolar.geometry.y)) )
btree = cKDTree(nB)
dist, idx = btree.query(nA, k=1)
polygon['place'] = idx
polygon['dist'] = dist

from pandana.

CWen001 avatar CWen001 commented on June 23, 2024

Hello. Is this feature on a development roadmap, please?

from pandana.

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.