does is_simple? work?

38 views
Skip to first unread message

ErnestoE

unread,
May 26, 2012, 3:31:14 PM5/26/12
to rgeo-...@googlegroups.com
Look at the following code:

f = RGeo::Cartesian.factory

p1 = f.point(-1,-1)
p2 = f.point(1,-1)
p3 = f.point(1,1)
p4 = f.point(-1,1)

lr1 = f.linear_ring([p1,p2,p3,p4])
lr2 = f.linear_ring([p1,p3,p4,p2])

pol1 = f.polygon(lr1)
pol2 = f.polygon(lr2)

lr1.is_simple?     # returns true, as expected
lr2.is_simple?     # returns true, but shouldn't it return false?

lr1.area 



I've been reading about Simple Feature Access, according to the documentation, lr1 is simple but lr2 is not. Running the previous code results in lr2 being simple

Daniel Azuma

unread,
May 27, 2012, 3:17:30 AM5/27/12
to RGeo-Users
Hi,

You're right-- I verified this behavior on my system as well.

I believe the issue is that GEOS doesn't guarantee results if the input is invalid. In the case of your "lr2", it's actually not a valid linear ring because a ring by definition must be simple. So for example, if you created an equivalent line_string and called is_simple?, it does return false.

RGeo could do better with error detection and reporting. That's number one on the enhancement list for RGeo 0.4. Until then, you just need to pre-validate your inputs.

Daniel

Jose Ernesto Echeverria

unread,
May 27, 2012, 8:06:54 AM5/27/12
to rgeo-...@googlegroups.com
ok good point then. That is precisely what I'm trying to do, validate information that has been given to me. So I'll build linear strings first before linear rings and polygons.

Thanks for the tip. My post got cut, I was also going to mention that measures such as area in the polygons returns values of zeros. So it is actually very important to care for data quality before using it.

Regards,
--
José Ernesto Echeverría
Tel +57 321 4900227 (Bogotá, Colombia)


Reply all
Reply to author
Forward
0 new messages