1

I have at my dispositions a JSON list with all the bike stations called Velib in Paris with their latitude, longitude, number of bikes and capacity.

I am trying to calculate proportion averages(number_of_bikes/bike_capacity) of the number of bikes for the bike stations in different districts of Paris. I would like to create a mapping/function of a city that differentiates different districts(= so that when i put coordinates it sends me back the number or the district ) so that when i try to calculate an average per part of the city i can insert coordinates of the bike stations and it goes directly into the average of the number of bikes of the district it is in.

I can do it when the districts are parallel one to each other delimited by horizontal/ vertical strait lines.

for k in range(len(bike_station_list): if lat(bike_station_k)<lat_district_1 and lng(bike_station_k <lng_disctrict_1 ... and so on 

However in reality Paris districts are far more complex.

How can I create a mapping of the city that can tell me in which district I am.

My first idea was to create a huge matrix with all longitudinal and latitudinal coordinates with the number of the district it is in but it looks a bit exaggerated.

Thanks for helping !

4
  • Would the operative question be closest (in terms of time to get to) vs what district am I in? Closest is also far easier to calculate... Commented Oct 15, 2016 at 17:38
  • well i am trying to do a precise representation so i'd rather have the exact district - but i might as well try closest if it is too consuming Commented Oct 15, 2016 at 21:23
  • But suppose the closest is 100 meters across a district boarder and the district station is on the other side of the district? Commented Oct 15, 2016 at 21:25
  • well the thing is that i am trying to evaluate the influence of certain factors in a big area - but in order to do that i am starting with smaller areas which are in my case districts Commented Oct 16, 2016 at 10:40

3 Answers 3

2

You can do get the district information by coordinate using Google's geocoding API

https://maps.googleapis.com/maps/api/geocode/json?latlng=48.874809,2.396988

In the response:

{ long_name: "20th arrondissement", short_name: "20th arrondissement", types: [ "political", "sublocality", "sublocality_level_1" ] } 

See here. You'll be limited to 2500 free requests per day however (more if you pay) and you'll need to register an API key.

Sign up to request clarification or add additional context in comments.

Comments

1

If you can find the coordinates for the vertices of a polygon that approximates Paris' districts, then this reduces to a point-in-polygon problem. You can use the ray-casting or the winding number algorithm to solve it, as mentioned in that article.

Comments

1

You'll need an approximate contour map of your districts, so the boundaries of the districts as a number of e.g. straight line segments. And then you need a way to find out if you're inside such a closed contour.

You'll find how to do that here

Given the complexity of this algorithm, your large matrix isn't too bad an idea, if you're satisfied with a resolution of say 10 * 10 m. If you want to cover an area of say 30 * 30 km that would be 3000 * 3000 == 9,000,000 squares. Nothing a PC can't easily handle, including the searches involved.

2 Comments

do you know where i can find such matrixes or do i have to make it by hand ?
If you have a colored (by district) paper map of Paris, some preprocessing would get you in business. Take a picture, read it in memory using PIL or Pillow, compute average colors from a number of adjacent pixels and reduce the size by spatially sampling it (taking one out of every x * y pixels, so 1 pixel per 10m x 10m area.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.