Giter VIP home page Giter VIP logo

Comments (4)

Robinlovelace avatar Robinlovelace commented on August 22, 2024

This would slow down line2route. It already fails well and indicates so in the data. I suggest creating a function that can re-route straight lines generated by line2route using a snap to route algorithm. Note that I tested CycleStreets.net's 'snap to route' algorithm and found it is already used internally so instead we should use another one, e.g. Google's or OSRM's, both of which are documented in stplanr I believe.

from stplanr.

richardellison avatar richardellison commented on August 22, 2024

I would suggest a wrapper script around line2route that runs the process you suggest. You would then get a function that does:

  1. Call line2route normally
  2. Select a subset of the SpatialLinesDataFrame that contains only the routes that failed in the initial call.
  3. Snap each of the coordinates to the nearest point on the route network using another algorithm
  4. Run line2route with the subset with updated coordinates
  5. Replace the failed routes with the new ones.

from stplanr.

Robinlovelace avatar Robinlovelace commented on August 22, 2024

Sounds like a good suggestion @richardellison I'm up for giving it a bash. We need it anyway for our work. (Context: @nikolai-b is working on the development of the Propensity to Cycle Tool for which line2route was originally written.)

from stplanr.

nikolai-b avatar nikolai-b commented on August 22, 2024

First I wanted to check if this has been fixed upstream
Here is a csv file (github wanted me to rename it as a text file...) with the points that were failing and now Cyclestreets seems able to route them.

Looks like it has been fixed upstream!

Ruby code used to check the newer nearest point api:

require 'httparty'
require 'rgeo/geo_json'

class CycleStreetNearest
  include HTTParty
  base_uri 'https://api.cyclestreets.net/'
  attr_reader :token, :dir

  def initialize(token = ENV['CYCLESTREET'], dir = 'data-sources')
    @token, @dir = token, dir
  end

  def query
    file = File.read(File.join(dir, "failing-points.geojson"))
    unsnappable = RGeo::GeoJSON.decode(file, json_parser: :json)
    nearestpoints = unsnappable.map do |feature|
      lng = feature.geometry.x
      lat = feature.geometry.y
      [feature.properties['geo_code'], lng, lat] + api_call(lng, lat)
    end
    CSV.open(File.join(dir, "snapped.csv"), "wb") do |csv|
      nearestpoints.each { |point| csv << point }
    end
  end

  private

  def api_call(lng, lat)
    self.class.get('/v2/nearestpoint', query: {
      key: token,
      lonlat: "#{lng},#{lat}"
    })['features'][0]['geometry']['coordinates']
  end
end

from stplanr.

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.