Open mrmarcondes opened 8 years ago
Alou quase xará! 'Marcos' aqui... Vou testar essa parada!
O new seria Polygon.new()
Tenta spatial: true
invés de sphere tb... sphre acho q é só pra ponto no mongo, ñ?
Tva vendo o findshop teu, manero! Se tu quiser ligar por cidades da uma olhada na gem geopolitical
...
Dá pra popular com todas as cidades/estados e por drop nos forms. Bom tb pra procura depois.
Olá @nofxx, obrigado pelo seu email!
Legal saber que brasileiro toca essa gem. Parabéns!
Ontem eu fiz um fork, e mudando o demongoize acabou quebrando alguns testes, mas para minha necessidade não tem problemas.
Vou alterar para spatial. Havia tentado inicialmente assim, mas por algum motivo que não me lembro agora, mudei para sphere.
Quanto ao findshop, é uma idéia antiga, que não estou mais mexendo, mas obrigado pela dica.
Vi seu repo e tem bastante coisa interessante. Depois vou dar uma fuçada.
Se puder contribuir com alguma coisa ai, por favor, avise-me, ok?
Abraços e obrigado, Marco(s)
Alou Marco,
Cara, fui ver os docs, agora ñ entendi se mudou ou se sempre teve errado,,.
Eu nao to convertendo pra geojson, achei q passar point, polygon era no index...
Mais: ponto funcionando normal soh array: [x,y]
inves de {type: Point, coordinates: [x,y]}
E agora José? hehe, amanhã vejo com calma. Sono... Souber mais avisa, abraço.
Just cleaning up old issues. What should we do with this?
I need to review this, did mongodb changed or the implementation was never correct?
Point(x,y) -> [x,y] or { type: Point, coordinates: [x,y] }
Polygon([[..]]) -> [[]] or {type: Polygon, coordinates: [[]] }
... so on
Having the same issue with a different error, because type
was saved before coordinates
in the hash.
Reverse the order in the hash and you get the error from above
Same setup
class Area
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Geospatial
field :area_profile, type: Polygon, sphere: true
end
creating an area
> hash = {type: "Polygon", coordinates: [[[0, 0], [3, 6], [6, 1], [0, 0]]]}
> area = Area.new(area_profile: hash)
> area.save # => true
> area.area_profile
TypeError: no implicit conversion of Hash into Integer
from /Users/tedmartinez/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mongoid-geospatial-5.0.0/lib/mongoid/geospatial/geometry_field.rb:86:in `initialize'
removing && new(obj)
fixes the problem
> Area.last.area_profile
{"type"=>"Polygon", "coordinates"=>[[[0, 0], [3, 6], [6, 1], [0, 0]]]}
@tedma4 you should never have to write the full hash:
> hash = {type: "Polygon", coordinates: [[[0, 0], [3, 6], [6, 1], [0, 0]]]}
> area = Area.new(area_profile: hash)
Should be:
> area = Area.new(area_profile: [[[0, 0], [3, 6], [6, 1], [0, 0]]])
To my understanding, the polygon is only a index thing, field should be Array, not Hash. I need to confirm this with mongodb. (And if so if geospatial is generating the index correctly) If mongodb expects the Hash, need some code changing...so you aways just work with the Array.
@nofxx Why are you using three level of arrays? why not use this instead:
area = Area.new(area_profile: [[0, 0], [3, 6], [6, 1], [0, 0]])
for me works fine if I use one array and inside arrays with coordinates
The thing here is if I use two level of array the Polygon methods works fine for example area.area_profile.center works well, but if I use three level of arrays this throws the exception TypeError: no implicit conversion of Hash into Integer.
But if we use two level of arrays then if I try to query something using polygons this throws Mongo::Error::OperationFailure: GeoJSON coordinates must be an array (2) for example using :loc.within_polygon
the model
creating an area
On MongoDB
Executing on rails c
I changed the line 86 of geometry_field.rb from:
to
And apparently worked. Question: Why we have the '&& new(obj)'? Thank you, Marco.