[SERVER-9764] Save Google Map Polygon cordinates in MongoDB 2dsphere Index Created: 23/May/13 Updated: 09/Jul/16 Resolved: 25/May/13 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Geo |
| Affects Version/s: | 2.4.3 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Prabath Kumarasinghe | Assignee: | hari.khalsa@10gen.com |
| Resolution: | Done | Votes: | 0 |
| Labels: | indexing | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Ubuntu 12.04 32bit version with MongoDB 2.4.3 |
||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Participants: | |||||||||
| Description |
|
Hi All, I had generated Polygon coordinates from Google map and try to save it to mongodb GEO spatial index with 2dsphere and I'm getting following error. "Can't extract geo keys from object, malformed geometry." My coordinates are as follow and I had validated it with http://geojsonlint.com/ {"type":"Polygon","coordinates":[[[79.6728515625,8.189742344383703],[80.15625,10.09867012060338],[82.265625,6.926426847059551],[80.5078125,5.528510525692801]]]}Cheers Prabath |
| Comments |
| Comment by Prabath Kumarasinghe [ 30/May/13 ] |
|
Finally, it worked in the following way, thanks to one of my colleagues and you, add an extra coordinate at the end which equal to first coordinate to Google Map polygon. {"type":"Polygon","coordinates":[[[79.6728515625,8.189742344383703],[80.15625,10.09867012060338],[82.265625,6.926426847059551],[80.5078125,5.528510525692801],[79.6728515625,8.189742344383703]]]}What I did was wrong dropping the last coordinate rather than increasing. Thanks for the help. |
| Comment by Prabath Kumarasinghe [ 30/May/13 ] |
|
Following data is shown in Google Map as a Polygon. {"type":"Polygon","coordinates":[[[79.6728515625,8.189742344383703],[80.15625,10.09867012060338],[82.265625,6.926426847059551],[80.5078125,5.528510525692801]]]}Once I connect the first point to last point then it shows in Google Map as a triangle. But I can save this in MongoDB, because first and last coordinates are same. {"type":"Polygon","coordinates":[[[79.6728515625,8.189742344383703],[80.15625,10.09867012060338],[82.265625,6.926426847059551],[79.6728515625,8.189742344383703]]]} |
| Comment by hari.khalsa@10gen.com [ 29/May/13 ] |
|
I'm not sure what you mean exactly by it not looking the same in Google Maps. Can you provide a set of links or images? |
| Comment by Prabath Kumarasinghe [ 25/May/13 ] |
|
Above data is in longitude, latitude combination. Then at the client side I use following library which is recommend in Google map v3 doc, in that code also latitude, longitude swapping is maintained. https://github.com/JasonSanford/GeoJSON-to-Google-Maps It says GeoJSON->"Google Maps", do we need vise-versa "Google Maps"->GeoJSON. |
| Comment by hari.khalsa@10gen.com [ 25/May/13 ] |
|
Google Maps uses latitude, longitude. GeoJSON is longitude, latitude. Does it work if you swap the coordinates? |
| Comment by Prabath Kumarasinghe [ 25/May/13 ] |
|
Once first and last points are same then it gives different shape in google map. Is there is any algorithm to convert google map coordinates into GeoJSON LinearRing. |
| Comment by hari.khalsa@10gen.com [ 25/May/13 ] |
|
geojsonlint.com doesn't do a very good job "A LinearRing is closed LineString with 4 or more positions. The first and last positions are equivalent (they represent equivalent points). Though a LinearRing is not explicitly represented as a GeoJSON geometry type, it is referred to in the Polygon geometry type definition." Your first and last points have to be the same. |