Mapbox directions matrix returns null only if there are several coordinates - mapbox

I have these two requests :
https://api.mapbox.com/directions-matrix/v1/mapbox/driving-traffic/173.9543384136836,-41.52476038734238;172.62594150748157,-43.53247945583633?approaches=curb;&access_token=token
https://api.mapbox.com/directions-matrix/v1/mapbox/driving-traffic/173.9543384136836,-41.52476038734238;1.4455293705867536,43.614261693278266;-1.4940893252308407,47.20258004614798;172.62594150748157,-43.53247945583633?approaches=curb;curb;curb;&access_token=token
Basically, it calculates a matrix of directions between a position in New Zealand, and :
for the first, another position in New Zealand;
for the second, three different positions (one in New Zealand, and two in France)
The first request works well and returns this :
"durations": [
[
0,
15402
],
[
15593,
0
]
],
My issue is that the second request returns a matrix as such :
"durations": [
[
null,
null,
null,
null
],
[
null,
0,
21949.4,
null
],
[
null,
22376.6,
0,
null
],
[
null,
null,
null,
null
]
],
As the documentation specifies, the duration matrix is built as such :
durations[i][j] gives the travel time from the ith source to the jth
destination.
I really don't understand how and why the second request returns null. I have had some success with others requests before but this one I can't get around.

Related

Can I use other coordinate types to create a 2d index in MongoDB?

I am building a MongoDB database of property data in the Netherlands. I want to be able to perform geospatial queries on my dataset. Each document does not have longitude and latitude coordinates, but something called "Rijksdriehoeks" coordinates. These Rijksdriehoeks coordinates do not conform to MongoDB's requirements for 2d coordinate pairs, in that they can exceed values of 600.000 (this system uses meters for units). This is a problem, because creating a 2d index requires all coordinate pairs to use longitude and latitude and thus to have values between [-180, 180] and [-90, 90], respectively.
I need to create a geo index for this dataset to reduce query time to acceptable levels, but creating a "legacy" 2d index will give this error because of the issue described above:
> db.Bag3DMembers.createIndex( { "properties.bbox" : "2d" })
{
"ok" : 0,
"errmsg" : "point not in interval of [ -180, 180 ] :: caused by :: { _id: ObjectId('5dfa7596cc0b7324e5331509'), type: \"Feature\", properties: { identificatie: \"0003100000117485\", aanduidingrecordinactief: false, aanduidingrecordcorrectie: 0, officieel: false, inonderzoek: false, documentnummer: \"FB 2010/PANDEN001\", documentdatum: \"2010-07-20\", bouwjaar: \"1991-01-01\", begindatumtijdvakgeldigheid: null, einddatumtijdvakgeldigheid: null, gemeentecode: \"0003\", ground-000: -0.43, ground-010: -0.34, ground-020: -0.31, ground-030: -0.3, ground-040: -0.27, ground-050: -0.25, roof-025: 10.58, rmse-025: 1.5, roof-050: 13.43, rmse-050: 1.28, roof-075: 13.46, rmse-075: 1.28, roof-090: 13.52, rmse-090: 1.27, roof-095: 13.87, rmse-095: 1.27, roof-099: 14.35, rmse-099: 1.27, roof_flat: false, nr_ground_pts: 220, nr_roof_pts: 6816, ahn_file_date: null, ahn_version: 2, height_valid: true, tile_id: \"07fz1\", gid: \"1\", bbox: [ [ 254052.046875, 593486.3125 ], [ 254076.625, 593504.6875 ] ] }, geometry: { type: \"Polygon\", coordinates: [ [ [ 254059.737, 593504.637, 0.0 ], [ 254059.227, 593500.0, 0.0 ], [ 254059.216, 593499.899, 0.0 ], [ 254058.242, 593500.0, 0.0 ], [ 254057.914, 593500.034, 0.0 ], [ 254057.893, 593500.0, 0.0 ], [ 254057.807, 593499.863, 0.0 ], [ 254052.074, 593490.692, 0.0 ], [ 254052.182, 593490.639, 0.0 ], [ 254058.138, 593490.002, 0.0 ], [ 254057.932, 593488.165, 0.0 ], [ 254074.487, 593486.4129999999, 0.0 ], [ 254075.981, 593500.0, 0.0 ], [ 254076.265, 593502.583, 0.0 ], [ 254076.561, 593502.55, 0.0 ], [ 254076.594, 593502.847, 0.0 ], [ 254059.737, 593504.637, 0.0 ] ] ] } }",
"code" : 13027,
"codeName" : "Location13027"
}
Is there any way I can persuade MongoDB to accept my "Rijksdriehoeks" coordinates or will I need to convert them to longitude and latitude values?
Check documentation Create a 2d Index:
On 2d indexes you can change the location range.
You can build a 2d geospatial index with a location range other than
the default. Use the min and max options when creating the index.
Would be
db.Bag3DMembers.createIndex(
{ "properties.bbox" : "2d" },
{ min: -10000, max: 630000, bits: 24 }
)

Editing nested values in mongodb

This is my structure and i want to, given both an user id and an item id (the first element in each entry inside the havelist - 5d2807a1eba04543f914d9da in the first entry), change the last value in the array (1 in the first case, 2 in the second case) by either increasing it in one or decreasing it in one.
these fields have no name, so when I browse to them, they are referred to as [0],[1],... [7] (the last one, the one i want to edit)
{
"_id" : "david",
"havelist" : [
[
"5d2807a1eba04543f914d9da",
"aaaa",
"cccc",
null,
"bbbb",
"2",
"",
1
],
[
"5d28079eeba04543f914d62f",
"dddd",
"zzzz",
null,
"bbbb",
"3",
"",
2
],
[
"5d2807bdeba04543f914eb25",
"eeee",
"cccc",
null,
"zzzz",
"3",
"",
1
],
],
"email" : "w#w.com",
}
i tried this
k=USERS_COLLECTION.updateOne({'$and':[{'_id':'david'},{'havelist':{'$elemMatch':{'0':"5d2807a1eba04543f914d9da"}}}]},{'$set':{'havelist.$.7':0}})
in order to attribute 0 to the value
but it didn't work
COLLECTION.find_one_and_update({'$and':[{'_id':'david'},{'havelist':{'$elemMatch':{'0':'5d2807a1eba04543f914d9da'}}}]},{'$set':{'havelist.$.7':0}})
this will succesfully change the value to 0. i'm still searching for an answer on how to increase or decrease by 1 the value.

How do I query a GeometryCollection in Mongodb?

I am trying to run a mongoldb query on a GEOjson collection of points and polygons but I'm struggling. I am new to GEOjson and Mongodb and haven't been able to find any examples on how to do this via google search and S.O. search so I'm hoping someone can shed some light on my issue.
I have created a 2DSphere index on geometry.coordinates - not sure if that's correct or not.
My overall objective is to return all points within the current map view and add both the point and the polygon associated to the map. I am using Leaflet.js and understand how to add to the map, but I can't figure out the query on Mongodb to get the results.
Just looking to find out if my GEOjson is correct and maybe an example on how I would perform the search on my GeometryCollection and get the point using $geowithin and then get the associated polygon.
Here's an example of my GEOjson-
{
"_id" : ObjectId("5709722f4044ccc4b8291651"),
"type" : "Feature",
"geometry" : {
"type" : "GeometryCollection",
"geometries" : [
{
"type" : "Point",
"coordinates" : [
-105.960805584616,
39.4671896545181
]
},
{
"type" : "Polygon",
"coordinates" : [
[
[
-105.96110187372227,
39.463449804295806
],
[
-105.96602244670311,
39.462956063632134
],
[
-105.96577627486317,
39.46671592928652
],
[
-105.96553007974012,
39.470475771657675
],
[
-105.96047434857059,
39.47089761421853
],
[
-105.95541854755197,
39.471319247231634
],
[
-105.95579990086372,
39.46763141937862
],
[
-105.95618125417559,
39.463943568242485
],
[
-105.96110187372227,
39.463449804295806
]
]
]
}
]
},
"properties" : {
"processed" : "Yes"
}
}

Why am I getting values outside polygon with geoIntersect

I am using mongodb with polygons stored with geometry in this format
"geometry" : { "type" : "Polygon", "coordinates" : [ [ [ 2.0315, 85.8546219515 ], [ 2.0315, 86.1673780485 ], [ 1.7185, 86.1673780485 ], [ 1.7185, 85.8546219515 ], [ 2.0315, 85.8546219515 ] ] ] }
I am trying to use geoIntersect and query a rectangle polygon using something like this:
find({geometry:{$geoIntersects:{$geometry:{"type": "Polygon", "coordinates":[ [[12,20], [13,20], [13,18], [12,18], [12,20]]]}}}})
When I do small queries like that, the results are fine, but when I expand to really large boxes:
find({geometry:{$geoIntersects:{$geometry:{"type": "Polygon", "coordinates":[ [[-166.2890625,46.55886030311719], [-166.2890625,47.39834920035926], [12.12890625,47.39834920035926], [12.12890625,46.55886030311719], [-166.2890625,46.55886030311719]]]}}}})
then I start getting really odd results like
"geometry" : { "type" : "Polygon", "coordinates" : [ [ [ 2.9684999999999997, 85.54162195149999 ], [ 2.9684999999999997, 85.8543780485 ], [ 2.6555, 85.8543780485 ], [ 2.6555, 85.54162195149999 ], [ 2.9684999999999997, 85.54162195149999 ] ] ] }
I am only returned a few polygons (4 total) from the db that are actually inside my input polygon:
"geometry":{"type":"Polygon","coordinates":[[[12.343499999999999,47.1416219515],[12.343499999999999,47.454378048500004],[12.0305,47.454378048500004],[12.0305,47.1416219515],[12.343499999999999,47.1416219515]]]}}
"geometry":{"type":"Polygon","coordinates":[[[12.343499999999999,46.829621951499995],[12.343499999999999,47.1423780485],[12.0305,47.1423780485],[12.0305,46.829621951499995],[12.343499999999999,46.829621951499995]]]}}
"geometry":{"type":"Polygon","coordinates":[[[-166.0935,46.5166219515],[-166.0935,46.829378048500004],[-166.4065,46.829378048500004],[-166.4065,46.5166219515],[-166.0935,46.5166219515]]]}}
"geometry":{"type":"Polygon","coordinates":[[[-166.0935,46.829621951499995],[-166.0935,47.1423780485],[-166.4065,47.1423780485],[-166.4065,46.829621951499995],[-166.0935,46.829621951499995]]]}}
I shouldn't have any latitudes in the 80's with my input. I don't know where these are coming from. They make up the majority of what is returned. (847/851 results)
I don't think the polygon fits in one hemisphere. From the $geoIntersects docs,
Any geometry specified with GeoJSON to $geoIntersects queries, must fit within a single hemisphere.

Mongodb Sphere index rejects my object

Hi i have an COllection with an 2d sphere index
wayCollection.createIndex(new BasicDBObject("poly", "2dsphere"));
i when i try to insert a certain object i get an error:
Exception in thread "main" com.mongodb.WriteConcernException: { "serverUsed" : "localhost:27017" , "ok" : 1 , "n" : 0 , "err" : "insertDocument :: caused by :: 16755 Can't extract geo keys from object, malformed geometry?: { _id: ObjectId('53a89dc6a0042baf54050037'), id: 24837452, version: \"64\", changeset: \"13731788\", uid: \"362915\", user: \"micha555\", timestamp: \"2012-11-03T09:11:23Z\", poly: { type: \"Polygon\", coordinates: [ [ [ 9.1244131, 50.0109503 ], [ 9.120464800000001, 50.0099731 ], [ 9.116641, 50.0077
although the multipolygon ring is closed (first and last coordinate is the same)
any ideas?
Here is another polygon which is rejected:
{
"type":"Polygon",
"coordinates":[
[
[
9.0496053,
51.3255584
],
[
9.0492235,
51.32532
],
[
9.0495831,
51.3251321
],
[
9.049917199999999,
51.3253429
],
[
9.0496053,
51.3255584
],
[
9.049984500000001,
51.3258463
],
[
9.0505795,
51.3262127
],
[
9.050045600000001,
51.326574
],
[
9.0496432,
51.3263928
],
[
9.049625300000001,
51.3262806
],
[
9.0495628,
51.3261244
],
[
9.0495316,
51.3259341
],
[
9.0495471,
51.3257127
],
[
9.0496053,
51.3255584
]
]
]
}
when i paste it here it seems to be ok: http://geojsonlint.com/
maybe mongo db does not like when a point is used twice
The polygon is self-intersecting:
MongoDB prohibits such polygons.
First thing I would do is check your polygon at http://geojsonlint.com/ . If it does not pass then you know you have an issue with your data points (which has caused this error for many people previously).
If it does pass then I would check this bug that was recently reported and submitted to MongoDB: https://jira.mongodb.org/browse/SERVER-13735 . Basically a valid MultiPolygon is causing an error with the 2dsphere index on MongoDB 2.6.X. Others have reported similar issues so my bet is that it's a bug, or some undocumented limitation.
I'd vote up the issue on JIRA and add your voice to the comments - the more people let MongoDB know that this bug exists and is impacting them the faster it will get fixed.