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

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.

Related

Can't extract geo keys when inserting large polygon

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.

Calculate distance between two coordinates using postgres?

I´ve got a job offer to work with postgres and I have not much idea of it. The guy told me to build a simple data base which automatically calculates the distance to my house from a list of some other places (bars, pharmacies, museums, whatever...) everything given in geocoordinates.
I have already installed postgres, also postgis and create a data base. May you give me some hints about how I should do this task? Is there any tutorial or resource I could use to make this tasks easier? Should I use postgis?
Thank you.
PostGIS will do this easily. Boundless Geo have an excellent PostGIS tutorial. I also recommend you are familiar with Ch3 & 4 of the PostGIS manual.
I strongly advise you to learn & understand the difference between projected and unprojected coordinates if you're going to be working with spatial data. Projected means the coordinates have been taken from a 'round earth' and adjusted or projected onto to a flat map page (with coordinates normally given in feet or metres depending on the properties of the projection used). This enables computationally efficient normal cartesian calculations to be done for distance, area, direction, intersection, contains etc. There are trade offs for using projections- You can't preserve all of area, distance, shape, direction when you project a curved line or surface onto a flat map. Different projections are optimised for different trade-offs. Calculations on projected data are only accurate over a relatively small portion of the earth's surface. There are many map projections available to suit various needs and localities. If you are going to be working with projected data, you need to pick a projection that suits your purposes and location. If you don't understand projections, your queries can easily produce garbage without realising it.
Unprojected data (ie, raw Lat/Lon coordinates which is what you have) involve much more complicated calculations as they are done on the curved surface of the spheroid representing the earth. There are a number of reference coordinate systems that are used to express Lat/Lon, however the most common is "WGS84" (which is what "GPS" coordinates are expressed in).
PostGIS objects (in the form of "simple features" as defined by the OGC) can be stored as either "geometry" types (projected coordinates) or "geography" types (unprojected Lon/Lat in WGS84: note the order, a common source of confusion!). As a bit of a wrinkle, Lon/Lat (order again!) can also be stored as a "pseudo projected" geometry type (typically with a projection SRID of '4326' for WGS84 Lon/Lat).
The method you use to calculate distance will depend on how you choose to store your points ('geometry' or 'geography').
See ST_Distance from the PostGIS docs for excellent examples of measuring distance using both geometry and geography points. Note, if you wish to calculate projected map distances you will need to pick an appropriate map projection and use ST_Transform to project your points to the appropriate spatial reference system (currently in SRID 4326- "GPS" coordinates). For only a few points the difference won't be at all noticeable, but once you start doing lots of more complex spatial queries, the difference can be significant. PostGIS has a lot more functions for geometry types than for geography types which may influence your decision. Also see ST_DistanceSpheroid for another possibility for calculating distance from Lon/Lat coordinates.
To start with, I'd store your points as 'geography' to simplify your experiments. Your distances will then be 'great circle' calcs in metres and you won't have to worry about projections initially.

Creating Postgis Polygon using ST_ConcaveHull from Geometry Points

I have a postgis 2.2 table with 20 columns of type geometry(Point,4326)
I'd like to generate a polygon which covers the outer boundary of the points - it seems like ST_ConcaveHull is a good option, but I can't see how to do it without first converting my points back to text (which seems to be missing the point).
Is st_concavehull the right option, and how do I go about constructing the query?
Thanks!
You first need to collect your points, then pass this collection to ST_ConcaveHull:
ST_ConcaveHull(ST_Collect(geom), 1)
Per the ST_ConcaveHull documentation:
Although it is not an aggregate - you can use it in conjunction with ST_Collect or ST_Union to get the concave hull of a set of points/linestring/polygons ST_ConcaveHull(ST_Collect(somepointfield), 0.80).

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 a point(x,y) inside a irregular polygon using Oracle10g Spatial function or any other API

I am very new in working with GIS or geometry data. I have geometry data (polygon) in oracle10g database. Is there any Spatial function to find a point inside that polygon. If not then any tool like geotools for .Net or any other API can help me. The polygon can have hole inside it. So point must be in a polygon area.
Thanks in advance for your help
Naym
Have you looked at Oracle Locator? The query syntax is awful to read, but it is capable of doing "is point in polygon" queries. You'll need to create a spatial index column on any table that you want to run a spatial query against. Reading the documentation is a must, because it is a pain to get working initially.