RGeo::Geos::CAPIPolygonImpl#intersects? true while intersection is nil

119 views
Skip to first unread message

Stuart Johnson

unread,
Jul 9, 2014, 1:02:17 AM7/9/14
to rgeo-...@googlegroups.com
Hi I've recently been working with RGeo to do some simple geometry involving polygons. unfortunately I've encountered an issue where two large but similar and overlapping polygons will return nil for an intersection but will return true for intersects? Is this a known issue? Is there some sort of workaround or common problem I'm missing? I can provide code to reproduce if necessary but be warned it's somewhat long.

Thanks in advance
Message has been deleted

Stuart Johnson

unread,
Jul 9, 2014, 1:43:21 AM7/9/14
to rgeo-...@googlegroups.com
I should say that RGeo::Geos.supported? returns true so it appears that I do have the GEOS library installed. geos-3.4.2 installed via homebrew if that's relevant

tyler.scott.dewitt

unread,
Jul 10, 2014, 11:11:47 AM7/10/14
to rgeo-...@googlegroups.com
Could you post the code? 

I just did a quick test and intersection worked for me (cartesian factory, square with triangle)

Thanks,
Tyler

On Jul 9, 2014, at 12:43 AM, Stuart Johnson <stuart.hen...@gmail.com> wrote:

I should say that RGeo::Geos.supported? returns true so it appears that I do have the GEOS library installed. geos-3.4.2 installed via homebrew if that's relevant

--
You received this message because you are subscribed to the Google Groups "RGeo-Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rgeo-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stuart Johnson

unread,
Jul 10, 2014, 11:19:38 PM7/10/14
to rgeo-...@googlegroups.com
Sure here's a example:

factory = RGeo::Cartesian.factory

points = [[13.47252793455753, 290.4766485546728],
  [15.54073426239082, 276.35055725990753],
  [21.90820951900018, 303.537522515156],
  [8.213611305931236, 296.67601244677155],
  [15.856670355018885, 288.5390965152138],
  [5.203107005628723, 282.8149364819326],
  [11.645108176884317, 293.92931144857505],
  [21.47576740464814, 270.17134399422736],
  [29.567834075055067, 295.4682035260122],
  [48.068092286949536, 270.3459504624785],
  [43.03794739858885, 258.13815141284425],
  [55.64874297500046, 280.60030199869936],
  [32.032323591078075, 280.0517447031193],
  [49.87548537467882, 258.4676114262518],
  [59.63260599700384, 277.04500320083656],
  [31.614857616326788, 258.431620967041],
  [53.87189907349915, 265.80523647228813],
  [52.316443015244246, 261.3094217374252],
  [30.37850602489661, 243.96629767610517],
  [37.08920720717105, 252.6877424786614],
  [37.67156320109957, 256.0991612787459],
  [49.7584728112775, 268.3759102823432],
  [59.74319735148887, 264.2208658108574],
  [60.54396507940886, 245.38971341527755],
  [57.564649888497605, 250.08403853549206],
  [39.682138626675425, 259.0749883694973],
  [62.00527379837224, 263.58136799797455],
  [65.05145753546759, 272.02541066609746],
  [83.31572356144625, 254.90296245666315],
  [92.25465895580949, 263.29479945303524],
  [100.81651519586794, 244.4781415919933],
  [97.38250503130493, 243.78791706757247],
  [87.49444190296876, 243.9105261298119],
  [81.82798724390774, 269.6598019646186],
  [80.71955318698129, 260.49555506489577],
  [85.00768677074382, 276.00048670421893],
  [80.10443410251679, 268.8426712207494],
  [91.08764526469497, 271.26692548675146],
  [85.8450963377431, 248.78985255565703],
  [106.03331426082401, 285.6862023617447],
  [81.48185571652127, 276.64182698469585],
  [92.13991556203014, 271.2485875583364],
  [98.38365036214643, 281.45797323863655],
  [102.14553720914083, 278.80697248987985],
  [95.79149025730165, 279.82358453431533],
  [95.38236405117578, 278.8826046839788],
  [79.84595372109368, 285.0388151062105],
  [109.71787571959159, 283.02108741182485],
  [112.05321670679596, 301.5399519356833],
  [96.82862362239786, 272.33343670783256],
  [112.54061379482926, 284.36252505248075],
  [109.06903277165821, 297.19078942883584],
  [75.13325825094185, 308.9704604638807],
  [83.55187277360703, 295.0546419466594],
  [88.84790298938569, 292.9639477216925],
  [75.29244966532377, 295.0210099208458],
  [75.23335443874339, 282.4739464327858],
  [67.91530620904584, 323.50955164491853],
  [63.296053254751605, 298.995544235466],
  [71.80246436883493, 324.3318894704985],
  [64.48794851576415, 309.1294987323138],
  [69.62609875481044, 292.7394221824507],
  [48.95124034776636, 301.7575544233305],
  [84.55514650058575, 303.92593114667574],
  [43.235417508838566, 306.80206762714073],
  [34.73892220880614, 329.1907286303983],
  [52.281451303202594, 301.6084275695357],
  [28.5553253406923, 313.78687528227863],
  [42.59416401736963, 314.44364573586654],
  [33.96574556983046, 331.63047327518854],
  [37.38616713845671, 329.6824866871678],
  [23.131715778639652, 311.4013991985247],
  [15.828757564139648, 323.0965255455127],
  [21.96675393525481, 328.47311769889797],
  [2.9080724237548132, 328.7687465564651],
  [10.505827766014386, 318.71044965218437],
  [21.19898160178375, 333.79701722368725],
  [-1.2563038057836753, 308.56001944644083],
  [16.032524269458786, 313.86497375252344],
  [10.364272681542873, 289.536695054825],
  [12.05479520856448, 297.99725674515264],
  [21.14666849486861, 309.9853339832766],
  [1.3061680539270597, 322.6074468000856],
  [7.3768561576888025, 309.9450393773967],
  [-11.97992962187135, 308.21316177663465]]

ring = factory.linear_ring( points.map { |point| factory.point(point[0], point[1])})

polygon = factory.polygon(ring)

polygon.intersects?(polygon) #=> true

polygon.intersection(polygon) #=> should be the same polygon but is nil instead

Sorry that it can't be shorter there appears to be little rime or reason as to why it fails as the exact same machine/gem/ruby interpreter works correctly on many simpler polygons.

Also it should be noted that the same behaviour occurs even when the two polygons are not the same.

Tyler DeWitt

unread,
Aug 27, 2014, 3:03:13 PM8/27/14
to rgeo-...@googlegroups.com
I totally forgot about this, sorry.

Did you get it working or still running into issues?

Sent from Mailbox

Stuart Johnson

unread,
Oct 19, 2014, 5:23:21 PM10/19/14
to rgeo-...@googlegroups.com
Ohh man sorry I totally forgot about this. Unfortunately I haven't been able to get it working. 

Stuart Johnson

unread,
Oct 19, 2014, 5:38:31 PM10/19/14
to rgeo-...@googlegroups.com
Just to confirm I just updated everything and my test case still doesn't work. Any ideas about how I could resolve this? 

tyler.scott.dewitt

unread,
Oct 21, 2014, 3:07:09 PM10/21/14
to rgeo-...@googlegroups.com
I was able to get it to work like this:

points = [[13.47252793455753, 290.4766485546728],
  [15.54073426239082, 276.35055725990753],
  [21.90820951900018, 303.537522515156],
  [8.213611305931236, 296.67601244677155],
  [15.856670355018885, 288.5390965152138]]
  

ring = factory.linear_ring( points.map { |point| factory.point(point[0], point[1])})

polygon = factory.polygon(ring)
polygon.intersects?(polygon) 

polygon.intersection(polygon) 

I only used the first 5 points.

Something about that 6th point was no bueno. I tested to make sure the polygon is_simple? and both reported true, so there must be something we are missing, or is_simple? is broken….

tyler.scott.dewitt

unread,
Oct 21, 2014, 3:54:19 PM10/21/14
to rgeo-...@googlegroups.com
Now that there is a new maintainer of the library, I’ve posted this to GitHub: https://github.com/rgeo/rgeo/issues/80
Reply all
Reply to author
Forward
0 new messages