Skip to content

Storing polygons as array is messing with $geoIntersects #44

@wa0x6e

Description

@wa0x6e

When storing a polygon field as array, searching all points within the polygon, as well as intersecting 2 polygons works.

But finding all polygons including a particular point does not work when the polygon field is an array, and seems to works only when the polygon is store as GeoJSON object.

To reproduce:

db.geom.insert({"polygons":
  {"type":"Polygon",
     coordinates:
      [[[ 17.60083012593064, 78.18557739257812], 
        [ 17.16834652544664, 78.19381713867188], 
        [ 17.17490690610013, 78.739013671875], 
        [ 17.613919673106714, 78.73489379882812],
        [ 17.60083012593064, 78.18557739257812]
      ]]
  }, "coo": [[ 17.60083012593064, 78.18557739257812], 
        [ 17.16834652544664, 78.19381713867188], 
        [ 17.17490690610013, 78.739013671875], 
        [ 17.613919673106714, 78.73489379882812],
        [ 17.60083012593064, 78.18557739257812]
      ]
}); 

This works

db.geom.find({polygons:
  {$geoIntersects:
     {$geometry:{ "type" : "Point",
          "coordinates" : [ 17.3734, 78.4738 ] }
      }
  }
});

This does not work

db.geom.find({coo:
  {$geoIntersects:
     {$geometry:{ "type" : "Point",
          "coordinates" : [ 17.3734, 78.4738 ] }
      }
  }
});

A solution is to store the polygon as a geoJSON object.
Is there any reason it's stored as a plain array, or is it safe to migrate all the geo field to GeoJSON object ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions