OSRM wrong waypoint index? - osrm

I'm trying to use OSRM to get a list of locations ordered by the distance between them. For that I'm using the Trip service (https://github.com/Project-OSRM/osrm-backend/blob/master/docs/http.md#trip-service).
Given the encoded polyline:
omq~Fji_vOg#sHQcnAjCtrAkCs|AvHpcBwCeeB
I receive the following:
"waypoints": [
{
"waypoint_index": 0,
"trips_index": 0,
"hint": "RzfEg1U3xIPaAAAAJgAAAAAAAAAAAAAANgAAAAoAAAAAAAAAAAAAAHM6AACFecb6__B-AoR5xvoQ8X4CAACPBd_PZ4A=",
"name": "",
"location": [
-87.656059,
41.873663
]
},
{
"waypoint_index": 2,
"trips_index": 0,
"hint": "OTfEg5M4xINDAwAAnwEAAAAAAAAAAAAA0AAAAGgAAAAAAAAAAAAAAHM6AACJf8b6xvF-Aoh_xvrY8X4CAADPEN_PZ4A=",
"name": "",
"location": [
-87.654519,
41.873862
]
},
{
"waypoint_index": 5,
"trips_index": 0,
"hint": "WuVchFzlXIQ6AwAAbwUAAAAAAAAAAAAAzgAAAFwBAAAAAAAAAAAAAHM6AAD3sMb6EPN-Avywxvoy8n4CAACfBd_PZ4A=",
"name": "",
"location": [
-87.641865,
41.874192
]
},
{
"waypoint_index": 1,
"trips_index": 0,
"hint": "PDfEg343xIOuAQAAggQAAAAAAAAAAAAAawAAACEBAAAAAAAAAAAAAHM6AACsfMb6su9-Aq58xvp2734CAADPEN_PZ4A=",
"name": "",
"location": [
-87.655252,
41.87333
]
},
{
"waypoint_index": 3,
"trips_index": 0,
"hint": "VuVchFjlXITqAQAA0QEAAAAAAAC1BAAAegAAAHUAAAAAAAAALQEAAHM6AACYtsb6L_J-AjK3xvoy8n4CAABvFt_PZ4A=",
"name": "",
"location": [
-87.640424,
41.873967
]
},
{
"waypoint_index": 6,
"trips_index": 0,
"hint": "6WJUhBgEhoTTBAAAdgQAAAAAAAAAAAAANAEAAB4BAAAAAAAAAAAAAHM6AAAJesb6H-x-Alh4xvoa7H4CAAB_Ft_PZ4A=",
"name": "",
"location": [
-87.655927,
41.872415
]
},
{
"waypoint_index": 4,
"trips_index": 0,
"hint": "TOVchFDlXIRTAgAAhQEAACoAAADuAAAAlAAAAGIAAAAKAAAAPAAAAHM6AAAtuMb6FvB-Aja4xvoS734CAQCPBd_PZ4A=",
"name": "",
"location": [
-87.640019,
41.87343
]
}
]
URL for testing: http://router.project-osrm.org/trip/v1/driving/polyline(omq~Fji_vOg#sHQcnAjCtrAkCs|AvHpcBwCeeB)?overview=false
This is how they were plotted (for better understanding):
If I understood the docs correctly, waypoint_index was supposed to provide the order of the locations by distance. If so, it doesn't seem to be working given the result. Check it here:
Wanted
Group 1
lat: 41.87368, lon: -87.65606
lat: 41.87388, lon: -87.65452
lat: 41.87327, lon: -87.65525
lat: 41.87241, lon: -87.65636
Group 2
lat: 41.87317, lon: -87.64001
lat: 41.87397, lon: -87.64186
lat: 41.87397, lon: -87.64027
Actual
Group 1
lat: 41.873663, lon: -87.656059
lat: 41.87333, lon: -87.655252
lat: 41.873862, lon: -87.654519
Group 2
lat: 41.873967, lon: -87.640424
lat: 41.87343, lon: -87.640019
lat: 41.874192, lon: -87.641865
Group 1
lat: 41.872415, lon: -87.655927
As you can see the order provided by waypoint_index under Actual does exclude the last item from its supposed group (1). I think this might be related to the roundtrip option, is this the case? If so, is there an option I can set on the trip service that will provide me with the result I need?
Or, is there another service that will receive a list of locations and return them ordered by the distance between them? Given that I can't provide the start/end.
I'd like to just send a list of locations and receive them ordered by proximity, not using roundtrip (if that's what's breaking the previous request).
Thanks!

ordered by the distance between them
What the trip service does is order them in a way that minimizes the total drive-time if you need to visit all waypoints, not cluster them by straight-line distance.
If you look at the route that was actually generated, the order makes sense: It is a circular trip that includes all provides locations (and at least looks optimal)

Related

OpenStreetMap distances between source and destination(s)

I'm trying to get the distances between one source point and one or more destination points, I'm using the OSRM API to accomplish this. However, the distances being returned are way off.
Source coordinates:
-2.2314725 | 53.4832925
Destination
-2.2315072 | 53.483238
Performing the following request:
http://router.project-osrm.org/table/v1/driving/-2.2314725,53.4832925;-2.2315072,53.483238?sources=0
The distance between the two points should be around 41km, but the result doesn't match at all.
Am I missing something blatantly obvious?
Below is the output from the above request:
{
"durations": [
[
0,
1.3
]
],
"destinations": [
{
"hint": "DBhtiw0YbYteAAAASwAAAAwAAAARAAAAQMh8QZccSEFqRAFARVYzQF4AAABLAAAADAAAABEAAABqpgAAg_Pd_0MXMANP893_HRcwAwEAXxOHnFES",
"distance": 5.459720867300434,
"name": "",
"location": [
-2.231421,
53.483331
]
},
{
"hint": "DBhtiw0YbYtRAAAAWAAAAAwAAAARAAAA27FaQUMzakFqRAFARVYzQFEAAABYAAAADAAAABEAAABqpgAAnPPd_zcXMAMt893_5hYwAwEAXxOHnFES",
"distance": 11.644459328154321,
"name": "",
"location": [
-2.231396,
53.483319
]
}
],
"sources": [
{
"hint": "DBhtiw0YbYteAAAASwAAAAwAAAARAAAAQMh8QZccSEFqRAFARVYzQF4AAABLAAAADAAAABEAAABqpgAAg_Pd_0MXMANP893_HRcwAwEAXxOHnFES",
"distance": 5.459720867300434,
"name": "",
"location": [
-2.231421,
53.483331
]
}
],
"code": "Ok"
}
There are two issues:
You probably mixed latitude and longitude. -2.2314725, 53.4832925 is somewhere in the ocean whereas 53.4832925,-2.2314725 is in Manchester. Sorry, I was wrong. OSRM expects lon,lat.
The two locations are almost identical. They are only 7 meters apart.

Filtering by Gender on targeting_spec

How to set the gender in Facebook Marketing API targetting spec?
I've tried setting the gender but i'm getting gender is not a valid target spec field error.
targeting_spec = {"geo_locations":
{
"location_types": ["recent"],
"custom_locations": [
{
"latitude": 14.5764,
"longitude": 121.0851,
"radius": 17
}
]
},
"age_min": 18,
"age_max": 35,
"gender": "male", // Setting gender, doesn't work
"flexible_spec": [
{
"interests": [
{"id": "6002998074973", "name": "BTS"}
]
},
{
"interests": [
{"id": "6005882720291", "name": "Data Science"}
]
}
]
}
Found it! It should be genders.
The values are:
gender: [0] # All
gender: [1] # Men
gender: [2] # Women
From https://developers.facebook.com/docs/marketing-api/buying-api/targeting/:
genders: array
1=male
2=female.
Defaults to all.
For example:
targeting: {
genders: [1]
...

Analytical map: how to display data of each region state wise

I want to divide the country state wise as per latitude and longitude, plot a circle in each state, and also provide JSON-file accordingly.
I have used the below code:
this.oData = {
regionProperties: [
{
"code": "DE",
"region": "Germany",
"Revenue": 428214.13,
"Cost": 94383.52,
"color": "rgb(92,186,230)",
},
{
"code": "FR",
// ...
},
// ...
]
};
In above code, is it possible to add sub region e.g. my country "code": "IN" sub region like "IN-AP", "IN-KA", etc..?

Can't extract geo keys, longitude/latitude is out of bounds

Working with MongoDB 2dsphere to store GEOJSON and on certain stores of lat/lng I keep getting the following error:
{
"code": 16755,
"index": 0,
"errmsg": "Can't extract geo keys: { _id: ObjectId('586ff135b79aa00b84181bfb'), name: \"Austin\", slug: \"Austin\", description: \"\", twitter: \"\", facebook: \"\", instagram: \"\", author: ObjectId('57b60fed8620b56af460d5c5'), tags: [], created: new Date(1483731253640), location: { address: \"Austin, TX, United States\", coordinates: [ 30.267153, -97.74306079999997 ], type: \"Point\" }, __v: 0 } longitude/latitude is out of bounds, lng: 30.2672 lat: -97.7431",
"op": {
"name": "Austin",
"slug": "Austin",
"description": "",
"twitter": "",
"facebook": "",
"instagram": "",
"author": "57b60fed8620b56af460d5c5",
"_id": "586ff135b79aa00b84181bfb",
"tags": [
],
"created": "2017-01-06T19:34:13.640Z",
"location": {
"address": "Austin, TX, United States",
"coordinates": [
30.267153,
-97.74306079999997
],
"type": "Point"
},
"__v": 0
}
}
I can't seem to figure out why it doesn't like some lat/lng coordinates.
Here is my schema for the location field:
location: {
type: { type: String, default: 'Point' },
coordinates: [Number],
address: String
},
and it's indexed as 2dsphere:
storeSchema.index({ location: '2dsphere' });
The only weird thing I can see is that the error message:
longitude/latitude is out of bounds, lng: 30.2672 lat: -97.7431",
the lat/lng are shortened from what I inputted - not sure if that has anything to do with it.
Oh wow - I'm not sure who decided this but Mongodb expects you to store as [lng, lat], not [lat,lng] like everything else in this world.
:|
Here is how I fixed the issue without having to swap the [lat,lng] sequence.
Somewhere in your code you are making a call to ensureIndex. Instead of calling (as I was previously doing) ...
collection.ensureIndex({ "location": "2dsphere" });
Use the following instead ...
collection.ensureIndex({ "location.coordinates":"2d"});
This completely got rid of the error at runtime and no massive refactor of data was needed.

How to post data to a mapquest table

I'm trying to post data to a mapquest table and I've done everything according to their API
Here is my json:
{
"tableName": "mqap.jZ3uoAVablablabla_reported_points",
"append": true,
"returnResults": true,
"rows": [
[
{
"mqap_geography": "POINT (-123.3141509 48.4647675)",
"date": "2016-03-13T02:19:09.674Z",
"email": "anna#gmail.com",
"latitude": "48.47542496514236",
"longitude": "-123.37663650512695",
"message": "ss",
"user": "a"
}
]
]
}
Here is a screenshot of the table
And this is the response I get in Postman
{
"failures": [
{
"reason": "Either no latitude/longitude was provided, or the other information was insufficient for geocoding at or near line #0 of input.",
"row": ""
}
],
"append": true,
"returnResults": true,
"totalRows": 1,
"tableName": "mqap.jblablabla_reported_points",
"tableSize": {
"raw": 8192,
"readable": "8 KB"
},
"data": {
"rows": []
},
"failureCount": 1,
"rowCount": 0,
"info": {
"statusCode": 0,
"copyright": {
"text": "© 2015 MapQuest, Inc.",
"imageUrl": "http://api.mqcdn.com/res/mqlogo.gif",
"imageAltText": "© 2015 MapQuest, Inc."
},
"messages": []
}
}
What am I doing wrong?
The geography column should be in the table by default when the table is created: mqap_geography. This column is populated depending on information in other columns depending on their data type: Geography, [Latitude, Longitude], [Street, City, StateProvince, PostalCode, County, Country], and FullAddress. The Latitude, Longitude columns in the table above are type String so they won't populate the Geography column.
Two things I was missing:
The database NEEDS to have a geography object. So I added a latlong Geography object that I didn't end up using.
The format of the JSON should've been the following:
{
"tableName": "mqap.jZ3uoAVablablabla_reported_points",
"append": true,
"returnResults": true,
"rows": [
[
{"name":"user","value":user},
{"name":"email","value":email},
{"name":"date","value":date},
{"name":"message","value":message},
{"name":"latitude","value":latitude},
{"name":"longitude","value"longitude},
{"name":"latlong","value":"POINT(" + parseFloat(longitude) + " " + parseFloat(latitude) +")"}
]
]
}