Can't extract geo keys when inserting large polygon - mongodb

I have been battling this for the past 2 days and can't seem to get it working.
I have the polygon in this gist, which I'm trying to insert into collection with '2dsphere' index on the polygon field. I've gone through quite a few itterations, removing some points from the polygon, trying to sort it so that it's 100% counter-clockwise (which resulted in malformed polygon) and mongo still won't let me insert it. The error I'm seeing is just Can't extract geo keys: without any extra information at the end.
I went for help to geo json validator, which told me, that I need to have the first point at the end of the polygon, but that results in a Edges 0 and 395 cross.. I'm kinda getting hopeless, as I have about 1000 of these polygons from external API and can't go through them 1 by 1. Also the wierd thing is, if I swap latitude with longitude, mongo is able to insert them, but that's not a solution, even the documentation says longitude first. And as can be observed in the gist, pretty much every map I tried can display the polygon and I wasn't able to observe any kind of "disruption" or wierd edges.
I would love if someone could point out what's wrong with the polygon or gime me a nudge in the right direction.
Also this probably shouldn't change anything, but I'm using mongoose and I did try to insert this polygon manualy via the mongo shell.

Related

Why ST_Intersection from Postgis returns multilinestring for self-intersecting linestrings?

I am trying on PostgreSQL with the extension Postgis to get the geometry of a gps_trace that intersects a box, then i want to get one linestring for each distinct part of the trace in the box. In the following example with 1 trace and 1 box , that would mean ST_intersection returns me a multilinestring with 2 linestrings inside, so that i can extract each of them with ST_Dump()
The geometries are in epsg 4326, I use the request SELECT ST_Intersection(gps_traces.geom, grid.box)
FROM gps_traces, grid
But as a result, i get a multilestring with 34 geometries inside. After zooming a little, i discovered that when the line self-intersects, it seems to consider and register each part as a separate linestring although at the beginning, the trace was a linestring in one go.
I am extremely surprised of this behavior, and didn't find any documentation on the subject nor topics that talked about it, so i'm asking here how is build the geometry resulting from an intersection and why I get this behavior ?
This is the first time i get to use stackoverflow, so I apologize if some elements are missing

Circular data entry in MongoDB

I am new to mongoDB and am interested in the geospatial data feature.
I know that it's possible to create data points and then use circular queries to see if the point is inside.
I don't want to do this though. I want to experiment by making a little game where the user has a 1-d point position on the earth and there are circular (2-d) data entries that are like explosion radius' or infection radius'. Then I want to be able to compute which explosions/infections (2-d) the user (1-d point) is being affected by.
Sorry if this sounds crazy. Let me know if this is even possible. I have seen that rethinkdb can do something like it, but I was hoping mongodb would too.

A geo polygon does not let Mongo create the 2dsphere index

I am using the geospacial feature of MongoDB.
I follow these directions to create a 2dsphere index
http://docs.mongodb.org/manual/tutorial/build-a-2dsphere-index/
However, when this polygon is in the collection, the index creation fails.
https://gist.github.com/anonymous/56345a0a96dd1e2c030e
The error is:
Can't extract geo keys from object, malformed geometry?:...
What is wrong with the polygon ?
There is nothing wrong with the polygon itself. The problem is that 2dsphere indexes, and related queries like $geoIntersects and $near only operate on polygons within one hemisphere, see the jira bug. It seems that the resolution to this bug was to update the documentation, see hemisphere restriction comments. There is a comment to this effect in the $geoIntersects documentation though not in the 2dsphere docs, it would seem.
Basically, the problem is that if you have a rectangle with longitude coordinates of, eg, -90, -90, 90 and 90 it is impossible to tell if this rectangle crosses in an East/West direction at 0 or 180/-180 (ie, the date line), so the results of any spatial operation would be indeterminate. In this case of your polygon, it could be inferred, and is obvious from visual inspection, but in general this is not the case, and hence the error.
You may also find this comparison from Boston GIS of spatial databases interesting. Note that Postgis, SQL Server and Oracle also have various restrictions on geometries/geographies that cross hemispheres.

MongoDB storing a circle

Is it possible to store a circle on MongoDB? I want to store circles as collections, and be able to index them for searching. I know that the $geoWithin query is possible where one specifies a circle and retrieves points or now GeoJSON objects, but I want to be able to do the opposite. Somehow drawing a giant polygon with multiple points on a plane doesn't seem very attractive as a workaround, so I'm hoping that someone has something better.
I've searched on Google, but can't find anything. I know about storing polygons and linestring, which were introduced in MongoDB 2.3>, there are also some suggestions on the GeoJSON spec for defining circles.
I have also seen this question on SO,but the OP never came back to link to jira, or to update the answer if they found a solution.

How to find all points away from some polygon?

What I need is to find all points away from rectangle for 10km. Points geometry is the_geom1, rectangles (polygon) geometry is the_geom2. SRID of them is 4258.
I tried:
SELECT *
FROM table1,table2
WHERE ST_DWithin(table1.the_geom1,table2.the_geom2,10000)
and table1.gid=2;
But the result is not Ok. I get way too many results (everything is returned).
What am I doing wrong?
Your query should work. The big issue may be as described in https://gis.stackexchange.com/questions/32711/how-do-i-use-st-dwithin-with-meters which discusses unit conversion issues.
You may have an issue with unit selection or configuration.
If you are telling it, for example, that the geometries must be within 10000 miles, you would get just about everywhere. Even 10000km would likely return everything on the same continent.