Can't get polygon to work, always returns nil

98 views
Skip to first unread message

Spencer Renosis

unread,
Apr 30, 2013, 1:10:00 PM4/30/13
to rgeo-...@googlegroups.com
I have been following Daniel Azuma's excellent tutorial at http://blog.daniel-azuma.com/archives/88. I am on part 3. I am certain Geos and proj is working. I follow the tutorial exactly, when I try to convert line_string1 into a polygon it returns nil. I have also tried several of my own variations (including polygons from linestrings with more than 3 points and I tried passing an array of points). I can get the intersects to work from the example before the polygon, although I had to add a ? otherwise it wasn't recognizing the method. Has something changed with polygon since this tutorial was written, or am I missing something?

Code:

    1.9.3-p385 :069 > line_string1
     => #<RGeo::Geos::CAPILineStringImpl:0x1740260 "LINESTRING (1.0 0.0, 1.0 4.0, -2.0 0.0)"> 
    1.9.3-p385 :070 > large_triangle = factory.polygon(line_string1)
     => nil 
    1.9.3-p385 :071 > large_triangle
     => nil 
    1.9.3-p385 :072 > 
   

As you can see Ruby version 1.9.3-p385. RGeo Version says "0.3.20". Rails version "3.2.12". RGeo::Geos.version = "3.3.3". 

Any help would be appreciated.

Thanks,

Spencer Renosis

Tyler DeWitt

unread,
May 20, 2013, 2:34:28 PM5/20/13
to rgeo-...@googlegroups.com
I found I had to turn the line_string into a linear_ring and then pass the linear_ring into the polygon.  

Something along the lines of: 

linear_ring = factory.linear_ring(line_string1)
large_triangle = factory.polygon(linear_ring)

I found that I could create polygons from line_strings if I used a different factory (like the spherical one).

There's an open github issue about this right now: https://github.com/dazuma/rgeo/issues/47.
Reply all
Reply to author
Forward
0 new messages