[SERVER-31412] Edges cross error for near edges Created: 05/Oct/17  Updated: 27/Oct/23  Resolved: 06/Oct/17

Status: Closed
Project: Core Server
Component/s: Geo
Affects Version/s: 3.4.9
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: George Stepanov Assignee: Mark Agarunov
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File polygon-fixed.png     File polygon.geojson     PNG File polygon.png    
Operating System: ALL
Steps To Reproduce:

> db.createCollection('polygon_test')
{ "ok" : 1 }
> db.polygon_test.createIndex({geometry: '2dsphere'})
{
	"createdCollectionAutomatically" : false,
	"numIndexesBefore" : 1,
	"numIndexesAfter" : 2,
	"ok" : 1
}
> db.polygon_test.insert({
...   "type": "Feature",
...   "properties": {},
...   "geometry": {
...     "type": "Polygon",
...     "coordinates": [
...       [
...         [
...           -92.3262,
...           29.5319
...         ],
...         [
...           -92.3236,
...           29.5314
...         ],
...         [
...           -92.1092,
...           29.5311
...         ],
...         [
...           -92.8126,
...           29.53115
...         ],
...         [
...           -92.3262,
...           29.5319
...         ]
...       ]
...     ]
...   }
... })
WriteResult({
	"nInserted" : 0,
	"writeError" : {
		"code" : 16755,
		"errmsg" : "Can't extract geo keys: { _id: ObjectId('59d65ac8452ead2f11d5af10'), type: \"Feature\", properties: {}, geometry: { type: \"Polygon\", coordinates: [ [ [ -92.3262, 29.5319 ], [ -92.3236, 29.5314 ], [ -92.1092, 29.5311 ], [ -92.8126, 29.53115 ], [ -92.3262, 29.5319 ] ] ] } }  Loop is not valid: [ [ -92.3262, 29.5319 ], [ -92.3236, 29.5314 ], [ -92.1092, 29.5311 ], [ -92.8126, 29.53115 ], [ -92.3262, 29.5319 ] ] Edges 0 and 2 cross. Edge locations in degrees: [-92.3262000, 29.5319000]-[-92.3236000, 29.5314000] and [-92.1092000, 29.5311000]-[-92.8126000, 29.5311500]"
	}
})
> 

Participants:

 Description   

Cannot insert a polygon with near edges. Edges are very close to each other, but not crossing actually.



 Comments   
Comment by Mark Agarunov [ 06/Oct/17 ]

Hello gstepanov,

Thank you for the report. While the polygon you provided does not intersect if it is on a flat surface, the lines do appear to intersect when on the surface of a sphere due to the distortion of mapping a flat object to a spherical surface. When plotted on a map which uses Geodesic (spherical) projection, you can see this intersection:

If this polygon is slightly modified as follows:

{
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [
       [
         -92.1092,
         29.5300
       ],
       [
         -92.3236,
         29.5314
       ],
       [
         -92.3262,
         29.5319
       ],
       [
         -92.8126,
         29.53115
       ],
       [
         -92.1092,
         29.5300
       ]
      ]
    ]
  }
}

The lines of the polygon no longer intersect when mapped on a sphere:

This polygon can be inserted to mongod without error.

Thanks,
Mark

Generated at Thu Feb 08 04:26:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.