GithubHelp home page GithubHelp logo

Comments (1)

loreabad6 avatar loreabad6 commented on September 25, 2024

Hi @swaheera,

After reviewing your code I see a couple of issues.

  1. The way you define your start and end points is not entirely correct. When you set the CRS, you are basically telling sf to assign a EPSG:3347 to coordinates that actually are in EPSG:4326 as given above. To correct this you should do something like:
q1 <- st_transform(st_sfc(q1, crs = st_crs(4326)) , st_crs(a))
q2 <- st_transform(st_sfc(q2, crs = st_crs(4326)) , st_crs(a))
  1. When you create the network as_sfnetwork() defaults to directed networks. This usually is a tricky setting knowing that many road networks are not correctly digitized. The algorithm doesnot find a path between your points because of the direction of the edges. To avoid this you can use:
net <- as_sfnetwork(a, directed = FALSE)
  1. In your original code you were getting a result already stored on the paths object. This is where all the nodes and edges of you resulting path are located as list objects. If you are only looking for the distance however, I would recommend you to call st_network_cost(net, q1, q2). This will directly give you the shortest network distance in meters between your two points.

If hope you don't mind that I convert this issue to a discussion. If you have any question we can discuss there 😄

from sfnetworks.

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.