Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storing polygons as array is messing with $geoIntersects #44

Open
wa0x6e opened this issue Jan 26, 2016 · 2 comments
Open

Storing polygons as array is messing with $geoIntersects #44

wa0x6e opened this issue Jan 26, 2016 · 2 comments

Comments

@wa0x6e
Copy link

wa0x6e commented Jan 26, 2016

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 ?

@nofxx
Copy link
Collaborator

nofxx commented Jan 26, 2016

@wa0x6e yup, my bad! Let/s geoJSON em.
If you fixed, please pull request, I'll merge and release.

@cgriego
Copy link

cgriego commented Oct 12, 2017

How do the maintainers see this working? Would the gem just switch the classes in place to use GeoJSON and leave the migration up to users? Include a rake task to migrate? Or add new field classes that read/write as GeoJSON?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants