rgeo / rgeo Goto Github PK
View Code? Open in Web Editor NEWGeospatial data library for Ruby
Home Page: https://rgeo.info
License: Other
Geospatial data library for Ruby
Home Page: https://rgeo.info
License: Other
I'm sure this is something easy but I've been struggling for hours and can't figure it out.
Basically, I've followed the instructions on your blog. With everything seemingly installed properly, in irb:
ruby-1.9.2-p290 :001 > require 'rgeo'
=> true
ruby-1.9.2-p290 :002 > RGeo::Geos.supported?
=> true
ruby-1.9.2-p290 :003 > RGeo::CoordSys::Proj4.supported?
=> true
ruby-1.9.2-p290 :004 > factory = RGeo::Cartesian.factory
=> #<RGeo::Geos::CAPIFactory:0x3ff801ea97d0 srid=0 bufres=1 flags=8>
ruby-1.9.2-p290 :005 > point1 = factory.point(1, 0)
=> #<RGeo::Geos::CAPIPointImpl:0x3ff801ea62ec "POINT (1.0 0.0)">
ruby-1.9.2-p290 :006 > point2 = factory.point(1, 4)
=> #<RGeo::Geos::CAPIPointImpl:0x3ff801e9fdc0 "POINT (1.0 4.0)">
ruby-1.9.2-p290 :007 > point3 = factory.point(-2, 0)
=> #<RGeo::Geos::CAPIPointImpl:0x3ff801e990b0 "POINT (-2.0 0.0)">
ruby-1.9.2-p290 :008 > point4 = factory.point(-2, 4)
=> #<RGeo::Geos::CAPIPointImpl:0x3ff801e93714 "POINT (-2.0 4.0)">
ruby-1.9.2-p290 :009 > line_string1 = factory.line_string([point1, point2, point3])
=> #<RGeo::Geos::CAPILineStringImpl:0x3ff801e8f04c "LINESTRING (1.0 0.0, 1.0 4.0, -2.0 0.0)">
ruby-1.9.2-p290 :010 > point5 = factory.point(0, 1)
=> #<RGeo::Geos::CAPIPointImpl:0x3ff801e8b85c "POINT (0.0 1.0)">
ruby-1.9.2-p290 :011 > line_string2 = factory.line_string([point4, point5])
=> #<RGeo::Geos::CAPILineStringImpl:0x3ff801e878ec "LINESTRING (-2.0 4.0, 0.0 1.0)">
ruby-1.9.2-p290 :012 > large_triangle = factory.polygon(line_string1)
=> nil
I'm unable to create polygons like this, which I figured should be the easiest way to do it. I was able to create polygons in my rails app by following your instructions in the second tutorial, but then many of the functions don't work. In rails console:
ruby-1.9.2-p290 :001 > loc = Location.last.latlon
(1.5ms) SELECT * FROM geometry_columns WHERE f_table_name='locations'
Location Load (2.5ms) SELECT "locations".* FROM "locations" ORDER BY "locations"."id" DESC LIMIT 1
=> #<RGeo::Geographic::SphericalPointImpl:0x3fc0cd5764e4 "POINT (-122.193963 47.675086)">
ruby-1.9.2-p290 :002 > area = Area.first.loc
(0.4ms) SELECT * FROM geometry_columns WHERE f_table_name='areas'
Area Load (0.5ms) SELECT "areas".* FROM "areas" LIMIT 1
=> #<RGeo::Geographic::SphericalPolygonImpl:0x3fc0cee61954 "POLYGON ((30.0 10.0, 10.0 20.0, 20.0 40.0, 40.0 40.0, 30.0 10.0))">
ruby-1.9.2-p290 :004 > area.contains?(loc)
RGeo::Error::UnsupportedOperation: Method Geometry#contains? not defined.
from /Users/jeff/.rvm/gems/ruby-1.9.2-p290/gems/rgeo-0.3.14/lib/rgeo/feature/geometry.rb:409:in contains?' from (irb):4 from /Users/jeff/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in
start'
from /Users/jeff/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in start' from /Users/jeff/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.6/lib/rails/commands.rb:41:in
<top (required)>'
from script/rails:6:in require' from script/rails:6:in
I get RGeo::Error::UnsupportedOperation: Method Geometry#contains? not defined errors for many different methods, but not all. Any ideas?
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
-- control frame ----------
c:0024 p:---- s:0086 b:0086 l:000085 d:000085 CFUNC :geometry_n
c:0023 p:0013 s:0082 b:0082 l:002398 d:000081 EVAL (irb):50
c:0022 p:---- s:0080 b:0080 l:000079 d:000079 FINISH
c:0021 p:---- s:0078 b:0078 l:000077 d:000077 CFUNC :eval
c:0020 p:0028 s:0071 b:0071 l:000070 d:000070 METHOD ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/workspace.rb:80
c:0019 p:0033 s:0064 b:0063 l:000062 d:000062 METHOD ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/context.rb:254
c:0018 p:0031 s:0058 b:0058 l:000dc8 d:000057 BLOCK ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:159
c:0017 p:0042 s:0050 b:0050 l:000049 d:000049 METHOD ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:273
c:0016 p:0011 s:0045 b:0045 l:000dc8 d:000044 BLOCK ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:156
c:0015 p:0144 s:0041 b:0041 l:000024 d:000040 BLOCK ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:243
c:0014 p:---- s:0038 b:0038 l:000037 d:000037 FINISH
c:0013 p:---- s:0036 b:0036 l:000035 d:000035 CFUNC :loop
c:0012 p:0009 s:0033 b:0033 l:000024 d:000032 BLOCK ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:229
c:0011 p:---- s:0031 b:0031 l:000030 d:000030 FINISH
c:0010 p:---- s:0029 b:0029 l:000028 d:000028 CFUNC :catch
c:0009 p:0023 s:0025 b:0025 l:000024 d:000024 METHOD ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:228
c:0008 p:0046 s:0022 b:0022 l:000dc8 d:000dc8 METHOD ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:155
c:0007 p:0011 s:0019 b:0019 l:002378 d:000018 BLOCK ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:70
c:0006 p:---- s:0017 b:0017 l:000016 d:000016 FINISH
c:0005 p:---- s:0015 b:0015 l:000014 d:000014 CFUNC :catch
c:0004 p:0183 s:0011 b:0011 l:002378 d:002378 METHOD ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:69
c:0003 p:0142 s:0006 b:0006 l:001df8 d:0011e8 EVAL ~/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
-- Ruby level backtrace information ----------------------------------------
~/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in <main>' ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:69:in
start'
~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:69:in catch' ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:70:in
block in start'
~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:155:in eval_input' ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in
each_top_level_statement'
~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in catch' ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in
block in each_top_level_statement'
~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in loop' ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:243:in
block (2 levels) in each_top_level_statement'
~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:156:in block in eval_input' ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:273:in
signal_status'
~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:159:in block (2 levels) in eval_input' ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/context.rb:254:in
evaluate'
~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/workspace.rb:80:in evaluate' ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/workspace.rb:80:in
eval'
(irb):50:in irb_binding' (irb):50:in
geometry_n'
-- C level backtrace information -------------------------------------------
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(rb_vm_bugreport+0x5f) [0x7f504933b88f]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x603f6) [0x7f50492243f6]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(rb_bug+0xb3) [0x7f5049224593]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x109d45) [0x7f50492cdd45]
/lib/libpthread.so.0(+0xfb40) [0x7f5048fb6b40]
/usr/lib/libgeos_c.so.1(GEOSGeom_clone_r+0x2f) [0x7f5045e0ecaf]
~/.rvm/gems/ruby-1.9.2-p180/gems/rgeo-0.2.6/lib/rgeo/geos/geos_c_impl.so(rgeo_wrap_geos_geometry_clone+0x26) [0x7f504638a806]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x172cf0) [0x7f5049336cf0]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x165d49) [0x7f5049329d49]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x16c51a) [0x7f504933051a]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x16cfc0) [0x7f5049330fc0]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(rb_f_eval+0xd9) [0x7f5049331539]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x172cf0) [0x7f5049336cf0]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x165d49) [0x7f5049329d49]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x16c51a) [0x7f504933051a]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x16fe01) [0x7f5049333e01]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(rb_rescue2+0x16b) [0x7f504922882b]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x162d7e) [0x7f5049326d7e]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x172cf0) [0x7f5049336cf0]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x165d49) [0x7f5049329d49]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x16c51a) [0x7f504933051a]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x17698b) [0x7f504933a98b]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(rb_catch_obj+0xc6) [0x7f50493257f6]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x162c2e) [0x7f5049326c2e]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x172cf0) [0x7f5049336cf0]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x165d49) [0x7f5049329d49]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x16c51a) [0x7f504933051a]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x17698b) [0x7f504933a98b]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(rb_catch_obj+0xc6) [0x7f50493257f6]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x162c2e) [0x7f5049326c2e]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x172cf0) [0x7f5049336cf0]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x165d49) [0x7f5049329d49]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x16c51a) [0x7f504933051a]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(rb_iseq_eval_main+0x290) [0x7f5049330950]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(+0x64bb2) [0x7f5049228bb2]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(ruby_exec_node+0x1d) [0x7f5049228bdd]
~/.rvm/rubies/ruby-1.9.2-p180/lib/libruby.so.1.9(ruby_run_node+0x1e) [0x7f504922a65e]
irb(main+0x4b) [0x40095b]
/lib/libc.so.6(__libc_start_main+0xfe) [0x7f504837ad8e]
irb() [0x400849]
[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html
Aborted
Using libgeos and postgis from ppa:ubuntugis/ubuntugis-unstable or building libgeos myself at 3.3, i cannot start a rake task after the upgrade from 3.2 and postgis2 SVN.
When running a rake task i get:
"/usr/local/rvm/gems/ruby-1.9.3-p194-perf@global/bin/rake: symbol lookup error: /usr/local/rvm/gems/ruby-1.9.3-p194-perf@rails_app/bundler/gems/rgeo-2a9e1f1d948f/lib/rgeo/geos/geos_c_impl.so: undefined symbol: initGEOS_r"
The gem and geos sources build fine, but this seems to indicate that its not looking properly on start. Best part is that in irb "require 'rgeo'; RGeo::Geos.supported? == true"
Is this an RGeo bug or a problem with the Geos code at 3.3.2
Trying to use a prepared polygon, but the "prepared?" method always returns false even after calling "prepare!". Is my thinking wrong?
irb(main):002:0> factory = RGeo::Cartesian.factory
=> #<RGeo::Geos::Factory:0x3fe9d79da7f0 srid=0 bufres=1 flags=0>
irb(main):002:0> p1 = factory.point(1, 2)
=> #<RGeo::Geos::PointImpl:0x3fe9d79c5c24 "POINT (1.0 2.0)">
irb(main):003:0> p2 = factory.point(3, 4)
=> #<RGeo::Geos::PointImpl:0x3fe9d79bfa68 "POINT (3.0 4.0)">
irb(main):004:0> p3 = factory.point(5, 2)
=> #<RGeo::Geos::PointImpl:0x3fe9d79b56e4 "POINT (5.0 2.0)">
irb(main):005:0> polygon = factory.polygon(factory.linear_ring([p1, p2, p3, p1]))
=> #<RGeo::Geos::PolygonImpl:0x3fe9d79aa94c "POLYGON ((1.0 2.0, 3.0 4.0, 5.0 2.0, 1.0 2.0))">
irb(main):006:0> polygon.prepared?
=> false
irb(main):007:0> polygon.prepare!
=> #<RGeo::Geos::PolygonImpl:0x3fe9d79aa94c "POLYGON ((1.0 2.0, 3.0 4.0, 5.0 2.0, 1.0 2.0))">
irb(main):008:0> polygon.prepared?
=> false
Hi all,
I've a problem with the code below:
wkt = "POLYGON((-53.36 -65.98, -49.49 -67.09, -45.27 -68.10, -45.27 -68.10, -46.09 -68.62, -53.36 -65.98))"
factory = RGeo::Geographic.spherical_factory(:srid => 4326)
feature = factory.parse_wkt(wkt)
feature.should_not be nil #FAIL
This test fails, because in the polygon (which I extracted from third party source) there are to identical vertexes (perhaps this is what I understood after several trials in a file with thousands of polygons).
Eliminating one of the two vertexes, everything works well
wkt = "POLYGON((-53.36 -65.98, -49.49 -67.09, -45.27 -68.10, -46.09 -68.62, -53.36 -65.98))"
factory = RGeo::Geographic.spherical_factory(:srid => 4326)
feature = factory.parse_wkt(wkt)
feature.should_not be nil #PASSED
What I'm missing? Is this the normal behaviour?
Thanks in advance,
best regards
Roberto
Hi,
I've been using RGeo for several months on a project without any problems. Recently we've had the need to make a direct ffi-geos call for a calculation so have added that gem to the project. Unfortunately this results in rails crashing whenever I try and load a geometry object from the database. The error is:
dyld: lazy symbol binding failed: Symbol not found: _initGEOS_r
Referenced from: /Users/george/.rvm/gems/ruby-1.9.3-p327@propertydetective/gems/rgeo-0.3.19/lib/rgeo/geos/geos_c_impl.bundle
Expected in: flat namespace
dyld: Symbol not found: _initGEOS_r
Referenced from: /Users/george/.rvm/gems/ruby-1.9.3-p327@propertydetective/gems/rgeo-0.3.19/lib/rgeo/geos/geos_c_impl.bundle
Expected in: flat namespace
/Users/george/.rvm/gems/ruby-1.9.3-p327@propertydetective/gems/rgeo-0.3.19/lib/rgeo/geos/capi_factory.rb:120: [BUG] Segmentation fault
My ruby version is bang up to date (ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]) and I've tried this with the latest rgeo & ffi-geos too. So any ideas what's causing this? My initial thoughts are it's library related but then I'm confused as to why it would install in the first place if that were the case. Just to be sure I wiped the gems and geos library and did a clean install but that didn't help.
I originally raised this against ffs-geos but after tracking it down I don't believe it ever uses that gem - although frustratingly it's presence in the bundle file does cause the crash. That is if I remove it the gem then everything returns to normal.
George
Hello i want to know what is the metric for the method distance? i mean the result is in meters, kilometers, miles???
Hi, I have a table with a geographic polygon column.
add_column :mytable, :area, :polygon, :geographic=>true, :srid=>4326
That me describe the problem a bit:
So, I'm trying to import some polygon data into the column above. The data is in WKT format (which are collected from a KML file, i think it doesn't matter here). Most of the data is imported well, but just one polygon data wont be imported, the area kept return nil. The wkt is as below:
"POLYGON((144.953500981593265 -37.755336568377764,144.979974380619751 -37.758248642270679,144.9871221983569 -37.765131726017557,145.027891232857655 -37.767514331929945,145.022596553052352 -37.778633159521064,145.012801395412566 -37.78233943538477,145.017037139256814 -37.784722041297151,145.019155011178924 -37.803518154605946,145.011742459451511 -37.817019588109446,145.016242937285995 -37.827079479739503,145.027626498867392 -37.832903627525333,145.006183045655945 -37.832903627525333,144.994270016094049 -37.832374159544806,144.984739592444498 -37.826814745749246,144.982886454512652 -37.83343309550586,144.976532838746294 -37.832638893535069,144.969120287018882 -37.81913746003157,144.971502892931255 -37.801400282683829,144.915114553004884 -37.800606080713038,144.902672055462432 -37.79028145509271,144.911408277141135 -37.780221563462646,144.933116464342874 -37.780486297452917,144.948471035778226 -37.777044755579475,144.950588907700336 -37.757189706309617,144.950588907700336 -37.757189706309617,144.953500981593265 -37.755336568377764))"
The other polygons are in exactly same format. And the kml file is working properly on google earth including this polygon.
Is there anyway to validate the format of the string? Or how am i suppose to find out what is going wrong?
Thanks a lot!
The CAPI segfaults when accessing the result of calculating the centroid for multipolygons like "MULTIPOLYGON EMPTY" and "MULTIPOLYGON (( EMPTY, ((-97.68491886050731 30.35776444685369, -97.71787784488231 30.30146103366149, -97.70517490298778 30.401222526730834, -97.68491886050731 30.35776444685369)))"
I think this relates to the fact that the centroid of an empty geometry is a null geometry collection (therefore not having an x or a y).
The FFI interface just throws an exception for an invalid field.
It seems when using ruby 2.1, rgeo can't work with geos and proj4 (it says it did not find them, yet they are fine and working when installing with ruby 2.0.0)
I can confirm everything works fine when doing this: rvm use 2.0.0
but when doing this: rvm use 2.1.0, I get:
RGeo::Geos.supported? => false
RGeo::CoordSys::Proj4.supported? => false
and I did reinstall everything on both ruby versions...
i find the within command not working, and found than even in the simpler examples like the first one in
http://www.daniel-azuma.com/blog/archives/28 don´t work.
line3 = polygon.intersection(line2)
throws the error
RGeo::Error::UnsupportedOperation: Method Geometry#intersection not defined.
from lib/ruby/gems/1.9.1/gems/rgeo-0.3.14/lib/rgeo/feature/geometry.rb:532:in intersection' from (irb):19 from bin/irb:12:in
Hi, First off, thanks for a GREAT gem! And thanks for fixing the last issue I encountered.
We uncovered what seems to be a classic floating point rounding error when a cartesian factory uses the GEOS extensions. Not an overly significant rounding error, but there none the less. Here is an example on the ruby console:
--pure ruby is correct--
ruby-1.8.7-p160 :002 > f = RGeo::Cartesian.simple_factory
=> #<RGeo::Cartesian::Factory:0x7f47b7a70890 @srid=0, @proj4=nil, @has_m=false, @coord_sys=nil, @has_z=false>
ruby-1.8.7-p160 :003 > f.point(111.99, -40.37)
=> #<RGeo::Cartesian::PointImpl:0x3fa3dbd31724 "Point(111.99 -40.37)">
--ruby with c extension is not--
ruby-1.8.7-p160 :004 > f = RGeo::Cartesian.preferred_factory
=> #<RGeo::Geos::Factory:0x3fa3dbcf7cb8 srid=0 bufres=1 flags=0>
ruby-1.8.7-p160 :005 > f.point(111.99, -40.37)
=> #<RGeo::Geos::PointImpl:0x3fa3dbcf1520 "POINT (111.9899999999999949 -40.3699999999999974)">
I have not tested this with other rubies yet, as this is what we are currently running in prod (unfortunately) for the time being. Again, thanks for a great gem, and let me know if I can provide any other information, or if i'm wrong about this being an error.
Currently, serialization fails for most RGeo objects, including geometry objects.
We should at least have Marshal working. Ideally, we would also support YAML and JSON.
This work is currently in progress.
Just for context I am attempting to get RGeo operational on heroku.
I wasn't able find in the code where the lookup occurs to simply add another default lookup.
If I create my class as:
class Location < ActiveRecord::Base
GEOM_FACTORY ||= RGeo::Geographic.projected_factory(projection_srid: 21781, srid: 4326, projection_proj4: '+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs', has_z_coordinate: false)
set_rgeo_factory_for_column(:coords, GEOM_FACTORY.projection_factory)
attr_reader :latlng
...
def latlng
GEOM_FACTORY.unproject(coords)
end
end
The latlng
method fails if it gets called from a worker process in a production environment with the error:
RGeo::Error::InvalidGeometry (You can unproject only features that are in the projected coordinate space.):
app/models/location.rb:15:in `latlng'
...
The reason seems to be the following line:
https://github.com/dazuma/rgeo/blob/master/lib/rgeo/geographic/factory.rb#L304 where @projector
is nil
.
BTW:
$ uname -a
Linux box 3.2.0-23-virtual #36-Ubuntu SMP Tue Apr 10 22:29:03 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
$ ruby -v
ruby 1.9.3p429 (2013-05-15) [x86_64-linux] Brightbox
$ bundle exec rails c production
Loading production environment (Rails 4.0.0.rc2)
irb(main):004:0> RGeo::Geos.supported?
=> true
irb(main):005:0> RGeo::CoordSys::Proj4.supported?
=> true
I am using Apache with passenger and the issue goes away when I set the PassengerSpawnMethod
to conservative
(direct
). See here: http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerSpawnMethod
Although the OGC spec itself [1] appears to require that Points in a MultiPoint are surrounded by parentheses, actual implementations in the wild seem to make them optional. The following are both parsed successfully by GEOS and PostGIS for instance:
select ST_AsText('MULTIPOINT (0 0, 2 3)');
-- => MULTIPOINT(0 0,2 3)
select ST_AsText('MULTIPOINT ((0 0), (2 3))');
-- => MULTIPOINT(0 0,2 3)
ST_AsText
and ST_AsEWKT
also output MultiPoints without parentheses. SQL Server apparently accepts both formats as well [2], although I can't confirm that directly.
RGeo appears to require the parentheses and will throw an exception without them:
RGeo::Cartesian.factory.parse_wkt('MULTIPOINT (0 0, 2 3)')
# => RGeo::Error::ParseError: :begin expected but 0.0 found.
While it might not be strictly kosher according to the OGC specs, the fact is that these parentheses are used in the wild, so it might be prudent to have RGeo recognize both formats as well.
[1] http://www.opengeospatial.org/standards/sfa
[2] http://postgis.refractions.net/pipermail/postgis-users/2011-January/028586.html
I'm reading geojson from a file and doing a point in polygon query.
require 'rubygems'
require 'rgeo'
require 'rgeo/geo_json'
File.foreach("feature.geojson") do |line|
row =line.split("\t")
factory = ::RGeo::Cartesian.preferred_factory()
point = factory.point(row[12],row[13])
features = RGeo::GeoJSON.decode(row[14].chomp, :json_parser => :json)
features.each do |feature|
ering = feature.geometry().exterior_ring()
the_polygon = factory.polygon(ering)
puts the_polygon.contains?(point)
end
end
returns this error:
find_poly.rb:14: [BUG] Segmentation fault
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.6.0]
-- control frame ----------
c:0011 p:---- s:0038 b:0038 l:000037 d:000037 CFUNC :contains?
c:0010 p:0052 s:0034 b:0033 l:0014e8 d:000032 BLOCK find_poly.rb:14
c:0009 p:---- s:0028 b:0028 l:000027 d:000027 FINISH
c:0008 p:---- s:0026 b:0026 l:000025 d:000025 CFUNC :each
c:0007 p:0015 s:0023 b:0023 l:000022 d:000022 METHOD /usr/local/lib/ruby/gems/1.9.1/gems/rgeo-geojson-0.2.1/lib/rgeo/geo_json/entities.rb:198
c:0006 p:0117 s:0019 b:0019 l:0014e8 d:001cc0 BLOCK find_poly.rb:11
c:0005 p:---- s:0012 b:0012 l:000011 d:000011 FINISH
c:0004 p:---- s:0010 b:0010 l:000009 d:000009 CFUNC :foreach
c:0003 p:0065 s:0006 b:0006 l:0014e8 d:0024d8 EVAL find_poly.rb:6
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
-- Ruby level backtrace information ----------------------------------------
find_poly.rb:6:in <main>' find_poly.rb:6:in
foreach'
find_poly.rb:11:in block in <main>' /usr/local/lib/ruby/gems/1.9.1/gems/rgeo-geojson-0.2.1/lib/rgeo/geo_json/entities.rb:198:in
each'
/usr/local/lib/ruby/gems/1.9.1/gems/rgeo-geojson-0.2.1/lib/rgeo/geo_json/entities.rb:198:in each' find_poly.rb:14:in
block (2 levels) in
-- C level backtrace information -------------------------------------------
[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html
Abort trap
if I instantiate the same feature geometry in the code, contains? works as expected.
require 'rubygems'
require 'rgeo'
require 'rgeo/geo_json'
factory = ::RGeo::Cartesian.preferred_factory()
point = factory.point(-97.60528,30.433372)
geojson = '{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-110.93994140625,32.2119140625],[-110.91796875,32.2119140625],[-110.91796875,32.200927734375],[-110.93994140625,32.200927734375],[-110.93994140625,32.2119140625]]]},"properties":{"dpsf0020003":"38.7","dpsf0020001":"36.1"}}]}'
features = RGeo::GeoJSON.decode(geojson.to_s, :json_parser => :json)
features.each do |feature|
ering = feature.geometry().exterior_ring()
the_polygon = factory.polygon(ering)
puts the_polygon.contains?(point)
end
Some of the each methods don't return an Enumerator if called without a block.
Setting a spatial column on a new Model works fine, but subsequent updates to that column fail in Rails with the exception:
RGeo::Error::UnsupportedOperation: Method Geometry#equals? not defined
I assume equals? should be defined in sub-classes of Feature::Geometry, but I can't find how/where to fix it.
See http://pastie.org/private/z9b0ofbmev3kffdfervzq
Is this a bug, or am I doing something wrong?
PostGIS 1.5/PostgreSQL 9.1/Rails 3.1.3
Getting UnsupportedOperation errors on all distance calculations. I am attempting to use in a Sinatra app. Have tried in 1.9.2 and 1.9.3
Configuration looks like this...
require 'sinatra'
require 'active_record'
require 'rgeo'
require 'pg'
ActiveRecord::Base.establish_connection(
:adapter => :postgis,
:database => "xxxx",
:username => "xxxx",
:password => "xxxx",
:host => "xxxx",
:schema_search_path => "public"
)
class Cable < ActiveRecord::Base
set_primary_key :sw_id
set_rgeo_factory_for_column(:wkb_geometry,
RGeo::Geographic.spherical_factory(:srid => 4326))
end
in irb....
1.9.2p318 :001 > require "./app.rb"
=> true
1.9.2p318 :002 > Cable.first.wkb_geometry.length
RGeo::Error::UnsupportedOperation: Method Curve#length not defined.
from /home/cfrugard/.rvm/gems/ruby-1.9.2-p318/gems/rgeo-0.3.8/lib/rgeo/feature/curve.rb:90:in length' from (irb):2 from /home/cfrugard/.rvm/rubies/ruby-1.9.2-p318/bin/irb:16:in
Using multi_json (1.2.0)
Using activesupport (3.1.1)
Using builder (3.0.0)
Using i18n (0.6.0)
Using activemodel (3.1.1)
Using arel (2.2.3)
Using tzinfo (0.3.32)
Using activerecord (3.1.1)
Using pg (0.13.2)
Using rgeo (0.3.8)
Using rgeo-activerecord (0.4.3)
Using activerecord-postgis-adapter (0.4.1)
Using json (1.6.6)
Using rack (1.4.1)
Using rack-protection (1.2.0)
Using tilt (1.3.3)
Using sinatra (1.3.2)
Using bundler (1.1.3)
Received and verified a report that, when installing rgeo on the built-in ruby on Mac OS X 10.6 (Snow Leopard), GEOS doesn't get recognized even if it is installed.
Some of my methodologies are failing because of a bunch of superfluous M & Z coordinates in my shape file data. How do I downgrade these polygons to simply X,Y objects?
I have previously used rgeo successfully, but I can't get anyhting but nil objects now. Anything obvious I'm doing wrong? Any ideas? Using 0.3.19
$ irb
1.9.3-p194 :001 > require 'rgeo'
=> true
1.9.3-p194 :002 > factory = RGeo::Cartesian.factory
=> #<RGeo::Geos::CAPIFactory:0x3fc71cef2a18 srid=0 bufres=1 flags=8>
1.9.3-p194 :003 > factory.point(1,2,3)
=> nil
1.9.3-p194 :004 >
Jeff
Hi!
I tried to convert a lat/lon geographic geometry to MTM8 (SRID 32188) and I get a 20km shift (almost 20000 meters too high) for the y, but the x is correct.
If I use directly the postgis function ST_Transform, there is no shift.
Here is the rgeo command I use to transform (the one that shifts 20km):
RGeo::Feature.cast(geometry_attribute, :factory => RGeo::Cartesian.factory(:srs_database => RGeo::CoordSys::SRSDatabase::ActiveRecordTable.new, :srid => 32188), :project => true)
Thanks for any cue!
rails_admin is a Rails engine, distributed as a gem, that creates a pretty interface to models and provides some stats about the data. Some people use it internally, straight out of the box, as a way to manage their data. Others integrate it into their app, or tweak their app so that it merges into the rails_admin look; we've done that at my company. Combined with cancan, models can be exposed in different ways to different roles and one can get productive with this setup quite quickly.
https://github.com/sferik/rails_admin
It doesn't know jack about the spatial field type and blows up when it encounters one, so enabling RGeo and PostGIS will cause problems when rails_admin tries to do its thing with any model that has spatial fields.
I wrote a pair of simple rake tasks to enable and disable the spatial type. The enable task looks to see if the database adapter is 'PostGIS', and adds a line to a file to register that type. The disable task removes that line if it finds it. I made a pull request--
railsadminteam/rails_admin#881
--and the project lead suggested it be made a separate gem.
Seems overly complex to me, but thought I'd ask here to see what people think. One argument might be that rails_admin will eventually need to be able to work with other spatial databases, e.g., Oracle or MS SQL, and, if that's complex, that complexity should be handled apart from rails_admin.
I'd appreciate any feedback. My immediate goals are 1) to make it easy for my team to geo-enable dev, test, and prod environments and 2) to do this in a way that works for others so that 3) we don't have another forked project to maintain.
Find by id hangs both for spatial and non-spatial tables.
Stack trace:
from /usr/lib/ruby/1.8/irb.rb:89:in irb_abort' from /usr/lib/ruby/1.8/irb.rb:255:in
signal_handle'
from /usr/lib/ruby/1.8/irb.rb:66
from /usr/lib/ruby/gems/1.8/gems/rgeo-activerecord-0.2.3/lib/rgeo/active_record/common.rb:75:in call' from /usr/lib/ruby/gems/1.8/gems/rgeo-activerecord-0.2.3/lib/rgeo/active_record/common.rb:75:in
node_has_spatial_type?'
from /usr/lib/ruby/gems/1.8/gems/rgeo-activerecord-0.2.3/lib/rgeo/active_record/common.rb:99:in visit_Arel_Nodes_Equality' from /usr/lib/ruby/gems/1.8/gems/arel-2.0.6/lib/arel/visitors/visitor.rb:15:in
send'
from /usr/lib/ruby/gems/1.8/gems/arel-2.0.6/lib/arel/visitors/visitor.rb:15:in visit' from /usr/lib/ruby/gems/1.8/gems/arel-2.0.6/lib/arel/visitors/to_sql.rb:109:in
visit_Arel_Nodes_Grouping'
from /usr/lib/ruby/gems/1.8/gems/arel-2.0.6/lib/arel/visitors/visitor.rb:15:in send' from /usr/lib/ruby/gems/1.8/gems/arel-2.0.6/lib/arel/visitors/visitor.rb:15:in
visit'
from /usr/lib/ruby/gems/1.8/gems/arel-2.0.6/lib/arel/visitors/to_sql.rb:89:in visit_Arel_Nodes_SelectCore' from /usr/lib/ruby/gems/1.8/gems/arel-2.0.6/lib/arel/visitors/to_sql.rb:89:in
map'
from /usr/lib/ruby/gems/1.8/gems/arel-2.0.6/lib/arel/visitors/to_sql.rb:89:in visit_Arel_Nodes_SelectCore' from /usr/lib/ruby/gems/1.8/gems/arel-2.0.6/lib/arel/visitors/to_sql.rb:77:in
visit_Arel_Nodes_SelectStatement'
from /usr/lib/ruby/gems/1.8/gems/arel-2.0.6/lib/arel/visitors/to_sql.rb:77:in map' ... 2 levels... from /usr/lib/ruby/gems/1.8/gems/arel-2.0.6/lib/arel/visitors/visitor.rb:15:in
send'
from /usr/lib/ruby/gems/1.8/gems/arel-2.0.6/lib/arel/visitors/visitor.rb:15:in visit' from /usr/lib/ruby/gems/1.8/gems/arel-2.0.6/lib/arel/visitors/visitor.rb:5:in
accept'
from /usr/lib/ruby/gems/1.8/gems/arel-2.0.6/lib/arel/visitors/to_sql.rb:19:in accept' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:110:in
with_connection'
from /usr/lib/ruby/gems/1.8/gems/arel-2.0.6/lib/arel/visitors/to_sql.rb:17:in accept' from /usr/lib/ruby/gems/1.8/gems/arel-2.0.6/lib/arel/tree_manager.rb:19:in
to_sql'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/relation.rb:64:in to_a' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/relation/finder_methods.rb:333:in
find_first'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/relation/finder_methods.rb:122:in first' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/relation/finder_methods.rb:291:in
find_one'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/relation/finder_methods.rb:281:in find_with_ids' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/relation/finder_methods.rb:107:in
find'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:439:in __send__' from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:439:in
find'
Gems included by the bundle:
Same behaviour with postgis.
My current workaround is replacing
@query = Query.find(params[:id])
with
@query = Query.where(['id=?', params[:id]]).first
i have a problem:
I have two tables:
migration:
create_table :inegis, :options=>"ENGINE=MyISAM", :force => true do |t|
t.point :point
end
model:
class Inegi < ActiveRecord::Base
self.rgeo_factory_generator = RGeo::Geos.method(:factory)
set_rgeo_factory_for_column(:point, RGeo::Geographic.spherical_factory)
end
When i write this in the console:
Inegi.first.point
works perfectly!!!!
but in my other migration and model:
migration:
def self.up
create_table :polygons, :options=>"ENGINE=MyISAM", :force => true do |t|
t.string :name
t.polygon :polygon
end
end
model:
class Polygon < ActiveRecord::Base
#self.rgeo_factory_generator = RGeo::Geos.method(:factory)
#set_rgeo_factory_for_column(:polygon, RGeo::Geographic.spherical_factory)
end
When i write this in the console:
Polygon.first.polygon
the console return nil
whats wrong with that??
The links to the RDoc documentation have been updated (to point at dazuma.github.com/rgeo/rdoc ), but the rdoc directory is missing on the gh-pages branch. The equivalent link in rgeo-geojson is working fine, so it's possibly an oversight for the rgeo repository?
Guessing this might be something with my configuration. At a loss though. Same configuration I have in Issue #24. I am using Ubuntu Server 10.04 Application faults out immediately.
1.9.3p125 :001 > Cable.first
(7.8ms) SELECT * FROM geometry_columns WHERE f_table_name='cables'
Cable Load (9.0ms) SELECT "cables".* FROM "cables" LIMIT 1
/home/cfrugard/.rvm/rubies/ruby-1.9.3-p125/bin/ruby: symbol lookup error: /home/cfrugard/.rvm/gems/ruby-1.9.3-p125/gems/rgeo-0.3.8/lib/rgeo/geos/geos_c_impl.so: undefined symbol: GEOSSetSRID_r
cfrugard@mapping1:~/applications/testrgeo$
Below is my rake task code. RGeo::Geos.supported? returns false. When I run the same code in irb, I don't receive the same error, and the shapefile loads just fine.
namespace :read_shp do
task :read_shapefile => :environment do
puts RGeo::Geos.supported?
RGeo::Shapefile::Reader.open("myshapefile.shp") do |file|
puts "File contains #{file.num_records} records."
file.each do |record|
puts "Record number #{record.index}:"
puts " Geometry: #{record.geometry.as_text}"
puts " Attributes: #{record.attributes.inspect}"
end
file.rewind
record = file.next
puts "First record geometry was: #{record.geometry.as_text}"
end
end
end
$ irb
1.9.3p286 :001 > require 'rgeo'
=> true
1.9.3p286 :002 > RGeo::Geographic.simple_mercator_factory
TypeError: wrong argument type String (expected Array)
from /home/user/.rvm/gems/ruby-1.9.3-p286/gems/rgeo-0.3.19/lib/rgeo/coord_sys/proj4.rb:250:in `_create'
from /home/user/.rvm/gems/ruby-1.9.3-p286/gems/rgeo-0.3.19/lib/rgeo/coord_sys/proj4.rb:250:in `create'
from /home/user/.rvm/gems/ruby-1.9.3-p286/gems/rgeo-0.3.19/lib/rgeo/geographic/interface.rb:515:in `_proj4_4326'
from /home/user/.rvm/gems/ruby-1.9.3-p286/gems/rgeo-0.3.19/lib/rgeo/geographic/interface.rb:250:in `simple_mercator_factory'
from (irb):2
from /home/user/.rvm/rubies/ruby-1.9.3-p286/bin/irb:16:in `<main>'
1.9.3p286 :003 >
$ proj
Rel. 4.7.1, 23 September 2009
usage: proj [ -beEfiIlormsStTvVwW [args] ] [ +opts[=arg] ] [ files ]
Hi, I'm having a devil of a time getting GEOS support under Ubuntu (version 5/lenny). It's working great on my OSX dev machine but the production environment won't have it. Geos and proj4 are installed locally, I send the prefixes to gem install, the native extensions are compiled and linked to both, and yet rgeo doesn't see it! Here's a log:
https://gist.github.com/2564023
I thought it might be a gem caching issue but have tried clearing caches, uninstalling & rebuilding several times. Any ideas where to look? Thanks!
I installed libgeos-dev from Synaptic package manager. This installs to /usr/lib/libgeos-3.3.3.so, which rgeo apparently can't find. After running
sudo ln -s /usr/lib/libgeos-3.3.3.so /usr/lib/libgeos.so
and removing and reinstalling geos, things work.
Is this rgeo's problem, or is it GEOS's, or Ubuntu's, or mine? I don't know.
Looks like buffer is not implemented for a spherical factory:
factory = RGeo::Geographic.spherical_factory(buffer_resolution: 8)
p1 = RGeo::WKRep::WKTParser.new(factory, support_ewkt: true).parse('POINT(-93.2636 44.9800)')
p2 = RGeo::WKRep::WKTParser.new(factory, support_ewkt: true).parse('POINT(-93.246160 44.969690)')
p2.buffer 50
# RGeo::Error::UnsupportedOperation: Method Geometry#buffer not defined.
# from /Users/kyledrake/.rvm/gems/ruby-1.9.3-p125/gems/rgeo-0.3.12/lib/rgeo/feature/geometry.rb:499:in `buffer'
This could also be me using it wrong, which I apologize if that is the case. It does work for the Mercador factory, so I wanted to double check incase this was a bug.
I know the projection is mismatched, but a segfault seems extreme:
require 'rgeo'
f = RGeo::Geographic.simple_mercator_factory
loc = f.line_string([f.point(-123, 37), f.point(-122, 38)])
f2 = f.projection_factory
loc2 = f2.line_string([f2.point(-123, 37), f2.point(-122, 38)])
p loc.envelope.intersection(loc2.envelope)
p loc2.envelope.intersection(loc.envelope)
produces:
#<RGeo::Geographic::ProjectedPolygonImpl:0x-2447e002 "POLYGON ((-122.0 37.0, -123.0 37.0, -123.0 38.0, -122.0 38.0, -122.0 37.0))">
rgeo_bug.rb:7: [BUG] Segmentation fault
ruby 1.8.7 (2011-06-30 patchlevel 352) [i386-linux]
Aborted
gdb says:
(gdb) bt
#0 0x004e5f20 in rgeo_convert_to_geos_geometry (factory=3085063400, obj=3085036880, type=4) at factory.c:361
#1 0x004e4b46 in method_geometry_intersection (self=3085062080, rhs=3085036880) at geometry.c:660
#2 0x00159a6c in call_cfunc (func=0x4e4b05 <method_geometry_intersection>, recv=<value optimized out>, len=1, argc=1, argv=0xbfffeb10) at eval.c:5784
#3 0x00164850 in rb_call0 (klass=3086034680, recv=3085062080, id=20161, oid=20161, argc=1, argv=0xbfffeb10, body=0xb7f1176c, flags=0) at eval.c:5928
#4 0x001649e5 in rb_call (klass=3086034680, recv=3085062080, mid=20161, argc=1, argv=0xbfffeb10, scope=0, self=<value optimized out>) at eval.c:6176
#5 0x00161e23 in rb_eval (self=3086960980, n=0xb7ea1408) at eval.c:3506
#6 0x0015f5cb in rb_eval (self=3086960980, n=0xb7ea13e0) at eval.c:3516
#7 0x00170214 in ruby_exec_internal () at eval.c:1654
#8 0x00170254 in ruby_exec () at eval.c:1674
#9 0x00170289 in ruby_run () at eval.c:1684
#10 0x08048655 in main (argc=2, argv=0xbffff614, envp=0xbffff620) at main.c:48
rgeo-0.3.2, libgeos-3.3.1
The title says it all. Anytime I try to create a POLYHEDRALSURFACE the attribute is nil when i read it back.
Here's one of the failing ones
"POLYHEDRALSURFACE(((-122.11829337775245 37.38069297281639 54.58596039, -122.11780138990547 37.38069297281639 54.58596039, -122.11780138990547 37.38027158034676 54.58596039, -122.11829337775245 37.38027158034676 54.58596039, -122.11829337775245 37.38069297281639 54.58596039 )),((-122.11829337775245 37.38069297281639 66.94806331, -122.11780138990547 37.38069297281639 66.94806331, -122.11780138990547 37.38027158034676 66.94806331, -122.11829337775245 37.38027158034676 66.94806331, -122.11829337775245 37.38069297281639 66.94806331 )),((-122.11829337775245 37.38069297281639 66.94806331, -122.11780138990547 37.38069297281639 66.94806331, -122.11780138990547 37.38069297281639 54.58596039, -122.11829337775245 37.38069297281639 54.58596039, -122.11829337775245 37.38069297281639 66.94806331 )),((-122.11780138990547 37.38069297281639 66.94806331, -122.11780138990547 37.38069297281639 54.58596039, -122.11780138990547 37.38027158034676 54.58596039, -122.11780138990547 37.38027158034676 66.94806331, -122.11780138990547 37.38069297281639 66.94806331 )),((-122.11780138990547 37.38027158034676 66.94806331, -122.11780138990547 37.38027158034676 54.58596039, -122.11829337775245 37.38027158034676 54.58596039, -122.11829337775245 37.38027158034676 66.94806331, -122.11780138990547 37.38027158034676 66.94806331 )),((-122.11829337775245 37.38027158034676 66.94806331, -122.11829337775245 37.38069297281639 66.94806331, -122.11829337775245 37.38069297281639 54.58596039, -122.11829337775245 37.38027158034676 54.58596039, -122.11829337775245 37.38027158034676 66.94806331)))"
Spherical_factory distances become wrong after half the possible Earth distance.
So I do this on a new Rails application with Rgeo gem used:
>> factory = RGeo::Geographic.spherical_factory(:srid => 4326)
In fact I tried different srids and coord_sys but the result was always the same. I'll compare each rgeo request with the same georuby request. All georuby requests are right.
This one is ok:
>> factory.point(-45, 0).distance(factory.point(0,0))
5009377.08569731
>> GeoRuby::SimpleFeatures::Point.xy(-45,0).spherical_distance(GeoRuby::SimpleFeatures::Point.xy(0,0))
5003769.342810653
This one is still ok:
>> factory.point(-90, 0).distance(factory.point(0,0))
10018754.171394622
>> GeoRuby::SimpleFeatures::Point.xy(-90,0).spherical_distance(GeoRuby::SimpleFeatures::Point.xy(0,0))
10007538.685621308
But now the distance starts to decrease instead of further increasing:
>> factory.point(-91, 0).distance(factory.point(0,0))
9907434.680601358
>> GeoRuby::SimpleFeatures::Point.xy(-91,0).spherical_distance(GeoRuby::SimpleFeatures::Point.xy(0,0))
10118733.55990599
So it decreases until becoming nearly zero:
>> factory.point(-180, 0).distance(factory.point(0,0))
7.810965061573302e-10
>> GeoRuby::SimpleFeatures::Point.xy(-180,0).spherical_distance(GeoRuby::SimpleFeatures::Point.xy(0,0))
20015077.371242613
The same problem is with latitude:
>> factory.point(0, 0).distance(factory.point(0,90))
10018754.171394622
>> GeoRuby::SimpleFeatures::Point.xy(0,0).spherical_distance(GeoRuby::SimpleFeatures::Point.xy(0,90))
10007538.685621308
>> factory.point(0, -45).distance(factory.point(0,90))
5009377.085697311
>> GeoRuby::SimpleFeatures::Point.xy(0,-45).spherical_distance(GeoRuby::SimpleFeatures::Point.xy(0,90))
15011308.028431961
>> factory.point(0, 45).distance(factory.point(0,90))
5009377.085697311
>> GeoRuby::SimpleFeatures::Point.xy(0,45).spherical_distance(GeoRuby::SimpleFeatures::Point.xy(0,90))
5003769.342810653
>> factory.point(0, -90).distance(factory.point(0,90))
7.810965061573302e-10
>> GeoRuby::SimpleFeatures::Point.xy(0,-90).spherical_distance(GeoRuby::SimpleFeatures::Point.xy(0,90))
20015077.371242613
May be I'm using a wrong factory for such type of calculations? If so, then which one is the right?
When i query a pointset for intersection with 3 polygons (which should be adjacent and disjoint) i get the following
boxes.map {|box| Address.where { projected_latlon.op('&&', box) } }.map(&:size)
> [46, 18, 32]
ok... but when i do the following:
bigbox = boxes.inject &:union
Address.where { projected_latlon.op('&&', bigbox) }.size
> 117
here is my migration for the address
add_column :addresses, :projected_latlon, :point, srid: 3785
add_index :addresses, :projected_latlon, spatial: true
oh and my migration for the boxes column
add_column :maponics_neighborhoods_1124_s12991, :projected_geom, :geometry, srid: 3785
here is an example box:
#<RGeo::Geos::CAPIPolygonImpl:0x57f8f64 "POLYGON ((-8574094.383298062 4694406.755065906, etc...
everything is done in projected coordinates... I've painstakingly converted all of my data to projection thinking it would fix this problem, but whether i do the union in ruby with rgeo, or via squeel with st_union, i get the same terrible results
to make things even more fun... consider this third case
Address.where { projected_latlon.op('&&', boxes[0]) | projected_latlon.op('&&', boxes[1]) | projected_latlon.op('&&', boxes[2]) }.size
> 68
assuming these are disjoint i should get 96 for SURE... :(
if i use & (and) instead of | (or) i get 0 results...
clues?
:(
Hi,
I want to use rgeo to manipulate spatial object with jruby (1.7.1) and ffi-geos. I try this :
rgeo_factory = RGeo::Geos.factory(:srid => 4326, :wkt_parser => {:support_ewkt => true})
puts rgeo_factory.point(2, 0).inspect
puts rgeo_factory.point(2.0, 0).inspect
And the result is :
<RGeo::Geos::FFIPointImpl:0x7d0 "POINT (1.0E-323 0.0)">
<RGeo::Geos::FFIPointImpl:0x7d0 "POINT (2.0 0.0)">
I suppose there is a problem to convert int in double. I havn't this bug with ruby. Do you know is it a problem with ffi or ffi-geos?
Thanks for your help
Hello,
I am using your project, and i find it very useful and nice, however i have got a small problem :
Rgeo is making useless Select statement with non-geographic object. For example, if i type sth like
a = Some_Class.new, Rails will issue a Select to the DB : 'SELECT * FROM geometry_columns where f_table_name = 'some_class',
is there a way to disable this behaviour ?
Hi,
I'm pretty new to GIS so please excuse me if this is a n00b error but .. I see weird results trying to parse WKT in rgeo. For instance, this wkt generated by postgis (FYI this is a snap to grid for a country):
ruby-1.9.3-preview1 :068 > t => "MULTIPOLYGON(((75 37,74 37,75 37,74 37,73 37,72 37,72 36,71 36,72 36,72 35,71 35,71 34,70 34,70 33,69 33,69 32,68 32,68 31,67 31,66 31,66 30,65 30,64 30,64 29,62 29,62 30,61 30,62 31,61 31,61 32,61 33,61 34,60 34,61 34,60 34,61 34,61 35,61 36,62 35,63 35,63 36,64 36,65 36,65 37,66 37,66 38,66 37,67 37,68 37,69 37,69 38,70 38,71 38,72 38,71 37,72 37,73 37,74 37,75 37)))" ruby-1.9.3-preview1 :069 > f = RGeo::WKRep::WKTParser.new => #<RGeo::WKRep::WKTParser:0x007f9f4e83f118 @factory_generator=#<Method: RGeo::Cartesian.preferred_factory>, @exact_factory=nil, @support_ewkt=false, @support_wkt12=false, @strict_wkt11=false, @ignore_extra_tokens=false, @default_srid=nil> ruby-1.9.3-preview1 :070 > f.parse t => nil
Needless to say this is not the expected result. Am I doing something horrible wrong, is this data somehow invalid, or is this a bug?
thanks very much
James
In trying to get fixtures working with the activerecord spatial adapters, I ran into the problem that part of Rails' fixture.rb
does the following (line 595 in rails 3.0.7):
row[key] = label if value == "$LABEL"
If value
is an RGeo type, such as a Point
, the comparison against the string "$LABEL"
raises an error, since String
doesn't have a method factory
. A simple (and hack-ish) fix is to change the equals?
method on ProjectedGeometryMethods
to:
def equals?(rhs_)
projection.equals?(Feature.cast(rhs_, factory).projection) if rhs_.respond_to?(:factory)
end
making sure that rhs_
responds to factory()
before trying to cast it. This is obviously not ideal, but I don't know how you would prefer to handle such cases.
I attempted to build a simple polygon with geographic data with the following code:
factory = RGeo::Geographic.spherical_factory(:srid => 4326)
# This satisfies a linear ring requirement: to be a closed linear string
a=[factory.point(-92.272935049926986,15.831411705496032)]
a << factory.point(-92.273079163754431,15.830847348631419)
a << factory.point(-92.272935049926986,15.831411705496032)
# Then when trying to build a linear ring I get nil. Am I missing an additional requirement?
linear_ring = factory.linear_ring(a)
>> nil
# Then tried building a line string
linestring = factory.line_string(a)
>> Worked as expected
# Attempted to build a polygon, failed
factory.polygon(linestring)
>> nil
´´´
Also, from the extended documentation on: http://blog.daniel-azuma.com/archives/88
I found out that executing the code for creating a cartesian polygon as in the example also yields a nil object.
Is this a bug or am I missing something? Thanks
On line 245 in bounding_box.rb
@factory.polygon(@factory.linear_ring(point_min_, @factory.point(@max_x, @min_y, *extras_), point_max_, @factory.point(@min_x, @max_y, *extras_), point_min_))
The factory#linear_ring accepts an array of points, not multiple point as arguments.
rgeo-0.3.14 and geos-3.3.5 (using geos-3.2.2, it does not crash)
require 'rgeo'
f = RGeo::Geographic.simple_mercator_factory
loc = f.line_string([f.point(-123, 37), f.point(-122, 38)])
f2 = f.projection_factory
loc2 = f2.line_string([f2.point(-123, 37), f2.point(-122, 38)])
p loc.envelope.intersection(loc2.envelope)
p loc2.envelope.intersection(loc.envelope)
gdb says:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff54948df in GEOSGeomTypeId_r (extHandle=0x9671a0, g1=0x96a0b0) at geos_ts_c.cpp:1541
1541 return g1->getGeometryTypeId();
Missing separate debuginfos, use: debuginfo-install libgcc-4.4.6-3.45.amzn1.x86_64 libstdc++-4.4.6-3.45.amzn1.x86_64 nss-softokn-freebl-3.12.9-11.13.amzn1.x86_64
(gdb) bt
#0 0x00007ffff54948df in GEOSGeomTypeId_r (extHandle=0x9671a0, g1=0x96a0b0) at geos_ts_c.cpp:1541
#1 0x00007ffff5a19012 in method_geometry_envelope (self=<value optimized out>) at geometry.c:260
#2 0x00007ffff7b14f1e in rb_call0 (klass=140737318785160, recv=140737317291840, id=13561, oid=<value optimized out>, argc=0, argv=0x0, body=0x7ffff5e533a8,
flags=0) at eval.c:5928
#3 0x00007ffff7b150f7 in rb_call (klass=140737318785160, recv=140737317291840, mid=13561, argc=0, argv=0x0, scope=0, self=<value optimized out>)
at eval.c:6176
#4 0x00007ffff7b11e2d in rb_eval (self=140737317297360, n=0x7ffff5d05c08) at eval.c:3506
#5 0x00007ffff7b0f4e4 in rb_eval (self=140737317297360, n=0x7ffff5d05bb8) at eval.c:3501
#6 0x00007ffff7b14dd0 in rb_call0 (klass=140737317386840, recv=140737317297360, id=13561, oid=<value optimized out>, argc=<value optimized out>,
argv=<value optimized out>, body=0x7ffff5d05b18, flags=0) at eval.c:6079
#7 0x00007ffff7b150f7 in rb_call (klass=140737317386840, recv=140737317297360, mid=13561, argc=0, argv=0x0, scope=0, self=<value optimized out>)
at eval.c:6176
#8 0x00007ffff7b11e2d in rb_eval (self=140737354044080, n=0x7ffff7f63a48) at eval.c:3506
#9 0x00007ffff7b0f450 in rb_eval (self=140737354044080, n=0x7ffff7f639a8) at eval.c:3500
#10 0x00007ffff7b0f5d6 in rb_eval (self=140737354044080, n=0x7ffff7f63958) at eval.c:3516
#11 0x00007ffff7b21b45 in ruby_exec_internal () at eval.c:1654
#12 0x00007ffff7b21b85 in ruby_exec () at eval.c:1674
#13 0x00007ffff7b21bb5 in ruby_run () at eval.c:1684
#14 0x0000000000400831 in main (argc=2, argv=0x7fffffffe548, envp=<value optimized out>) at main.c:48
Based on the documentation of what the buffer method does, shouldn't the buffers around a point be circular, not square? Exterior ring of the buffer shape is definitely farther away at the points that it is in the middle, flat areas...
We are using PostGIS 2.0, PostgreSQL 9.1, JRuby 1.7.3, Rails 3.2.13 and the latest version of activerecord-postgis-adapter gem.
We are using a column of type "point". If there is a value in the DB, the value is not loaded, when reading the record.
I have created a sample Rails project at https://github.com/mariszin/postgis_point_sample .
To recreate the "bug" described, in console execute
$ psql postgis_point rails
psql (9.1.9)
Type "help" for help.
postgis_point=# create extension postgis schema public;
CREATE EXTENSION
postgis_point=# create extension postgis_topology;
CREATE EXTENSION
Then, in Rails console:
Point.create!
ActiveRecord::Base.connection.execute 'update points set point=point(50000,50000)'
Point.first
The result:
jruby-1.7.3 :003 > Point.first
Point Load (4.0ms) SELECT "points".* FROM "points" LIMIT 1
=> #<Point id: 1, point: nil>
Is this really a bug or is it made like this by design and we need to update our schema to use geometry column w/ type Point?
I'm working with:
--Rails 3.1
--activerecord-postgis-adapter 0.4.0
--rgeo 0.3.3 (I also tried 0.3.2)
#In 'class Post < ActiveRecord::Base'
set_rgeo_factory_for_column(:location,
RGeo::Geographic.spherical_factory(:srid => 4326))
post = Post.create(:location => "POINT(45,45)")
post.location #returns nil
post.location = "POINT(45,45)" #returns "POINT(45,45)"
post.location #returns nil
factory = RGeo::Geographic.spherical_factory(:srid => 4326)
post.location = factory.point(45,45) #returns #<RGeo::Geographic::SphericalPointImpl:0x3fd00fab3e88 "POINT (45.0 45.0)">
post.location #returns #<RGeo::Geographic::SphericalPointImpl:0x3fd00fab3e88 "POINT (45.0 45.0)">
So, it seems like my location point will silently not accept the WKT string as a point. I am forced to create a point and store it manually. I believe this is the exact functionality that set_rgeo_factory_for_column is supposed to take care of.
(Here is the exact code irb session. http://pastebin.com/Rc5Uf9Xg )
http://alastaira.wordpress.com/2011/01/23/the-google-maps-bing-maps-spherical-mercator-projection/
rgeo's "simple mercator" seems to use a set of parameters that don't fully match 3857 or 3785:
PROJCS["Popular Visualisation CRS / Mercator",
GEOGCS["Popular Visualisation CRS",
DATUM["Popular_Visualisation_Datum",
SPHEROID["Popular Visualisation Sphere",6378137,0,AUTHORITY["EPSG","7059"]],
TOWGS84[0,0,0,0,0,0,0],
AUTHORITY["EPSG","6055"]],
PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],
UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4055"]],
UNIT["metre",1,AUTHORITY["EPSG","9001"]],
PROJECTION["Mercator_1SP"],
PARAMETER["central_meridian",0],
PARAMETER["scale_factor",1],
PARAMETER["false_easting",0],
PARAMETER["false_northing",0],
AUTHORITY["EPSG","3785"],
AXIS["X",EAST],
AXIS["Y",NORTH]]
In 4b972c3 the SRID was changed from one to the other, but I'm not sure either are quite correct.
In the Section 3.5 of the rdoc :
p00 = factory.point(0, 0)
p20 = factory.point(2, 0)
p11 = factory.point(1, 1)
p00.distance(p11) # returns 1.41421356...
line = factory.line(p00, p20)
line.length # returns 2
line.distance(p11) # returns 1
ring = factory.linear_ring([p00, p11, p20, p00])
ring.length # returns 4.82842712...
ring.distance(p11) # returns 0
poly = factory.polygon(ring)
poly.area # returns 1
poly.area is not implemented and raise :
RGeo::Error::UnsupportedOperation: Method Surface#area not defined.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.