How do I get the distance between multipolygon and point? How do I check if point is inside multipolygon?

92 views
Skip to first unread message

Stenver Jerkku

unread,
Apr 6, 2017, 7:15:46 PM4/6/17
to RGeo-Users
I'm struggling to understand this. Can somebody please give me any tips on how to do these operations on geodata?


(byebug) field_rgeo = RGeo::GeoJSON.decode(field_area.as_json, json_parser: :json)
#<RGeo::Cartesian::MultiPolygonImpl:0x3ff918a27aa0 "MULTIPOLYGON (((26.90379372036799 58.43030272463889, 26.905523701857298 58.430250466611746, 26.90554793827585 58.43017676297873, 26.90379372036799 58.43030272463889)))">

(byebug) g = RGeo::GeoJSON.decode(soil_sample.geojson.as_json, json_parser: :json)
#<RGeo::Cartesian::PointImpl:0x3ff91987088c "POINT (638670.1717082587 6499485.679810431)">

(byebug) field_rgeo.distance(g)
*** RGeo::Error::UnsupportedOperation Exception: Method Geometry#distance not defined.

nil
(byebug) g.within?(field_rgeo)
*** RGeo::Error::UnsupportedOperation Exception: Method Geometry#within? not defined.

nil

I can't seem to get any methods to work, as Geomtery always has the method undefined, even though it's listed in the documentation and when checking with #public_methods(true)

Stenver Jerkku

unread,
Apr 14, 2017, 2:03:23 PM4/14/17
to RGeo-Users
Turned out the problem was that I didn't have GEOS and Proj 4 installed

Installing those and recompiling the gems fixed the problems. I got the distances to be correct by learning a bit about projections:

factory = RGeo::Geographic.projected_factory(projection_proj4: "+proj=utm +datum=WGS84 +zone=32T")
field_geocoded = RGeo::GeoJSON.decode(field_area.as_json, geo_factory: factory)
soil_sample_geocoded = RGeo::GeoJSON.decode(soil_sample.geojson.as_json, geo_factory: factory)


Reply all
Reply to author
Forward
0 new messages