Code Monkey home page Code Monkey logo

distancematrix's Introduction

DistanceMatrix

Using Python, GDAL and Google Maps API to calculate travel times between pairs of regions, given an specific weekday and time.

What problem are we trying to solve?

Given a specific region, divided into administrative areas, we want to calculate the average time a person takes to go from an area to another, at 8 a.m. of a typical weekday, for each transportation mode available (e.g.: driving, taking public transport, walking, bicycling).

What is the result we expect?

After doing this for all possible pairs of regions, for each mode, we want to obtain a Distance Matrix, which presents the average trip duration for the pairs of origins and destinations.

Why do we want to do this?

This information is required as a feature for a machine learning model that predicts a person transportation behavior, as we can read from the article "Data-driven activity scheduler for agent-based mobility models", https://www.sciencedirect.com/science/article/pii/S0968090X18306417.

How do we do this?

The example we present here comprises the metropolitan area of Brasilia, Brazil, but may be replicated using diferent input files.

Input files

  • An ESRI Shapefile set of documents (.shp + .shx + .cpj + .dbf + .prj + .qpj), in which the polygon layer is formed by features representing the administrative areas, which names are presented in a field. In this example, we use a Shapefile with information about the Brasilia Metropolitan Area, composed by the 31 administrative areas (or neighborhoods) of Brasilia and 21 towns.
  • An "origins.csv" file and an "destinations.csv" file, which are lists with the name of the regions that must be included as origins and destinations on the Distance Matrix.

Algorithm design considerations

  • We define a randomPoint function that converts the Shapefile polygon into points and then returns one of the points' coordinates (it was based on the recipe as in https://pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html#convert-polygon-to-points);
  • We define a commuteTime function that returns the trip duration between to points, given a day and a transportation mode, using the Google Maps API;
  • Finally, we apply the randomPoint funcion to select origin and destination points for each pair of administrative regions and use them as input to the commuteTime function. We calculate the commuteTime for three pairs of points, for each pair of administrative regions, and fill in the Distance Matrix instance with the average of those values.

distancematrix's People

Contributors

danielefm avatar

Watchers

 avatar

distancematrix's Issues

question about matsim

Hey,

I am a researcher at the China Academy of Urban Planning and Design, first, thank you so much for ur effort in MatSIM, I have read your bachelor thesis about MatSIM, which is quite good, I have learned a lot from this paper.

Apologies first for my following question if it is too personal...

Since u r doing PhD(i read this info through your cover page in GitHub), I am wondering, r u still use MatSIM to simulate transportation. The most difficult question for me is how to generate population and daily plan. When I read ur thesis, I have noticed the population data in ur bachelor paper, the population data are generated by population census(but random in location). R you trying to use data in GoogleMAP API to solve this problem?

We are trying to combine urban planning and transportation simulation, we can have a further discussion if you are interested in this kind of question. But anyway, thank you so much for your paper.

Thx

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.