How to set the fare on the km based in the fare_attributes.txt file - gtfs

I am new to the GTFS. I need to set the fare for the route based on the km.
For example
1 km = 2USD
2 km = 4USD
3 km = 6USD
and so on.
How to set this on the fare_attribute.txt? I have to set each km fare on the fare_attribute.txt manually?

There is currently no simple way to set distance-based fares in GTFS. You will have to do it manually by explicitly setting the fare between every pair of stops.
Example 6 on this Google Code page gives some of the flavor. To summarize that example, you will have to
define each stop as its own "zone" in stops.txt,
add a record in fare_rules.txt with a unique fare_id for every pair of stops specifying the origin_id and the destination_id of that stop pair, and
add a corresponding record with the same fare_id to fare_attributes.txt that specifies the exact price between that pair of stops.
This will of course result in very large fare_rules.txt and fare_attributes.txt files, which is pretty unpleasant. This might be a nice feature request for future GTFS schema changes.

Related

Is this gas fee calculation correct?

An address consumes 20,000 gas via SSTORE.
Given is a gas price of 35 Gwei.
If I store 10,000 addresses in a map, it will cost me:
20,000 gas * 10,000 = 200,000,000 gas
200,000,000 Gas * 35 Gwei = 7 Ether.
Is the calculation correct?
If I do the same on a layer2 chain, does the whole thing cost me 7 matic for example, or is there something else I need to consider?
Your calculation is correct.
I'm assuming you want to store the values in an array instead of 10k separate storage variables. If it's a dynamic-length array, you should also consider the cost of sstore while updating a (non-zero to non-zero) value of the slot holding the array length (currently 2900 gas for each .push() function resizing the array).
You should also consider the block gas limit - a transaction costing 200M gas is not going to fit into a block on probably any network, so any miner won't mine it.
So based on your use case, you might want to change the approach. For example, if the addresses are used for validation, you might be able to store just the merkle tree root (1 value instead of the 10k) and then validate against it using the address and its merkle proof.

Google maps sum of unique road distance in given area

I would like to calculate the number of unique kilometers of roadways in my city. More generally, I wish to sum the distance of every road within a bound, for simplicity a rectangle will do.
Is this possible using the Google Maps suite of APIs? If so, how would you go about doing it? If anyone has any resources related to this type of problem, I would be interested in reading them regardless of language (or even solutions with other mapping tools).
Bonus points: A general solution to this problem that can be applied to the pre set "cities" (example) that appear in Google Maps with well defined city limits.
You can use OpenStreetMap to calculate the total road length of a specific country or geographic area. There are multiple solutions available, based on multiple similar questions already asked.
Approach 1 from Total road length in Kilometers for a country at help.openstreetmap.org:
Use the Perl script osm-length-2.pl. There is an example at a mailing list post.
Approach 2 from Actual road length of exported map at help.openstreetmap.org:
Import your data (the planet or an country or area extract) into a PostGIS database, then use the following queries proposed by Frederik Ramm:
SELECT way AS clip
INTO clipping_polygon
FROM planet_osm_polygon
WHERE boundary='administrative' AND admin_level='8' and name='My City';
SELECT name, highway, ST_INTERSECTION(way, clip)
INTO clipped_roads
FROM planet_osm_line, clipping_polygon
WHERE ST_INTERSECTS(way, clip) AND highway IS NOT NULL;
SELECT highway, SUM(ST_LENGTH(way::geography))
FROM clipped_roads
GROUP BY highway;

Filter POIs that are close to a route

I have a list of Points-of-Interest (e.g. car rest areas).
The user selects the Starting Point and the Ending Point.
This generates a route.
How can I programmatically filter the POIs that are close (e.g. 50 meters distance from the road) that route?
Can Google Maps SDK or OSRM offer this functionality?
Thank you,
Nick
1. You have to find the distance from one POI to the road.
In order to accomplish this, you have to store your road in a mathematical fashion:
You can sample equidistant points of your road and store them in an array (more practical, less precise) and then calculate the distance of the POI from every point in the array, then save the minor result and repeat the whole process for every POIs.
You can store a road in a function (more and more complex, but more precise). Now that you have this function, you can calculate same distance from your POI, take the minimum value and repeat for all POIs.
2. Google Distance Matrix can actually do this
With this Api you can calculate distance till 2500 origins * destinations points.
The result will give you an array of rows, with each row corresponding
to an origin, and each element within that row corresponds to a pairing of the origin with a destination value.
Example of a request:
https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=32.777211,35.021250&destinations=32.778663,35.015757&key=YOURAPIKEY
This is very useful to your goal, because lets you specify more than one points of which calculates distance.

Using google maps API to find average speed at a location

I am trying to get the current traffic conditions at a particular location. The GTrafficOverlay object mentioned here only provides an overlay on an existing map.
Does anyone know how I can get this data from Google using their API?
It is only theorical, but there is perhaps a way to extract those data using the distancematrix api.
Method
1)
Make a topological road network, with node and edge, something like this:
Each edge will have four attributes: [EDGE_NUMBER;EDGE_SPEED;EDGE_TIME,EDGE_LENGTH]
You can use the openstreetmap data to create this network.
At the begining each edge will have the same road speed, for example 50km/h.
You need to use only the drivelink and delete the other edges. Take also into account that some roads are oneway.
2)
Randomly chose two nodes that are not closer than 5 or 10km
Use the dijsktra shortest path algorithm to calculate the shortest path between this two nodes (the cost = EDGE_TIME). Use your topological network to do that. The output will look like:
NODE = [NODE_23,NODE_44] PATH = [EDGE_3,EDGE_130,EDGE_49,EDGE_39]
Calculate the time needed to drive between the two nodes with the distance matrix api.
Preallocate a matrix A of size N X number_of_edge filled with zero value
Preallocate a matrix B of size 1 X number_of_edge filled with zero value
In the first row of matrix A fill each column (corresponding to each edge) with the length of the edge if the corresponding edge is in the path.
[col_1,col_2,col_3,...,col_39,...,col_49,...,col_130]
[0, 0, len_3,...,len_39,...,len_49,...,len_130] %row 1
In the first row of matrix B put the time calculated with the distance matrix api.
Then select two news node that were not used in the first path and repeat the operation until that there is no node left. (so you will fill the row 2, the row 3...)
Now you can solve the linear equation system: Ax = B where speed = 1/x
Assign the new calculated speed to each edge.
3)
Iterate the point 2) until your calculated speed start to converge.
Comment
I'm not sure that the calculated speed will converge, it will be interesting to test the method.I will try to do that if I got some time.
The distance matrix api don't provide a traveling time more precise than 1 minute, that's why the distance between the pair of node need to be at least 5 or 10 or more km.
Also this method fails to respect the Google's terms of service.
Google does not make available public API for this data.
Yahoo has a feed (example) with traffic conditions -- construction, accidents, and such. A write-up on how to access it is here.
If you want actual road speeds, you will probably need to work with a commercial provider.

Question about tracking user in a map application using cellid

I am trying to understand the concept of cellid (http://www.opencellid.org/api)
As per that, if we send a request
http://www.opencellid.org/cell/get?key=myapikey&mnc=1&mcc=2&lac=200&cellid=234
it will respond with the latitude and longitude.
I was wondering if this can be used from within a google map application for tracking a user or it needs to be used from within a mobile device?
If it can be used from within a web app, what parameters should it use for
mcc: mobile country code (decimal)
mnc: mobile network code (decimal)
lac: locale area code (decimal)
cellid: value of the cell id
E.g., will it work if we know the cell number of the person(e.g., 281 222 6700)
The request is just a lookup in the opencellid database.
It doesn't matter where the information is coming from.
If you know the MMC, MNC, LAC and CellID of a user/mobile device,
the request will return latitude and longitude if the cellID has been found in the DB.
There is no additional information transfered by using the request from within a J2ME app.
MCC+MNC+LAC+CELLID should be a unique identifier of a cell. (afaik those values can change over time,
but they still should be unique.)
More often than not, knowing just the LAC and CellID is sufficient.
However, you can't use this to track based on a number, only by cell tower parameters. Number tracking is a whole different ball game with VRL & HRL lookups which are hard to come by, very expensive ($100+ per lookup) and sometimes even illegal.
Google Maps also uses cell ID lookups to approximate the user's location before GPS kicks in (the translucent circle around a dot is actually data from Cell IDs).
That being said, opencellid has very minimal coverage and little or no updates to the project. Check out some paid players who offer wider coverages:
LocationAPI
Combian