segasai / q3c

PostgreSQL extension for spatial indexing on a sphere
GNU General Public License v2.0
76 stars 27 forks source link

q3c_poly_query does not select objects inside a reasonably sized polygon #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Create a simple two column table with two double precision fields: ra and 
dec. Populate the table with uniformly spaced values of ra and dec, centered at 
(ra = 45.0, dec = 35.5), and a total width of 1 degree on a side. Create a q3c 
index on the table with q3c_ang2ipix.

2. Define a four-sided polygon whose vertices lie outside the range of ra and 
dec values in the table, e.g. {40,30,40,40,50,40,50,30}.  

3. Select objects from the table using q3c_poly_query and the polygon defined 
in step 2.

What is the expected output? What do you see instead?

I expect the query will select all rows in the table. However, the query only 
select a subset of the rows. 

The attached .png files illustrate the problem. 

Fig1.png shows the ra (x-axis) and dec (y-axis) of the rows returned by a 
'SELECT *' from the table. 

Fig2.png shows the ra and dec of the rows returned when filtering with 
q3c_poly_query, e.g. "SELECT * FROM table WHERE 
q3c_poly_query(ra,dec,'{40.0,30,40,40,50,40,50,30}');". 

Comparing the two figures, you can see that the polygon query is missing  rows 
that are inside the polygon.

The missing data problem persists if I change the vertices to be larger or 
smaller. 

After playing around with the vertices, the problem seems to occur whenever the 
point (45.0, 35.26) lies inside the polygon.  The problem goes away if the 
polygon does not contain that point.

Curiously, this same problem appears if either of two other points are inside 
the specified polygon: (135.0, 35.26) and (225.0, 35.26) (and provided the 
table has rows inside the polygon). 

I'd appreciate it if you have look into this.

What version of the product are you using? On what operating system?

I'm using:

* q3c-1.4.12-rev-ac0bf1cf8393
* Postgresql v9.2.1
* Linux (2.6.18-308.4.1.el5)

 - Greg Madsen

Original issue reported on code.google.com by greg.j.m...@gmail.com on 14 Dec 2012 at 3:28

Attachments:

GoogleCodeExporter commented 9 years ago
Hi Greg, 

Thank you for the reporting the bug, I've fixed it here:
http://code.google.com/p/q3c/source/detail?r=45b60299df0dc9a044241f87a6307b3c97c
6cde1
Could you please double check that it works for you now.

S 

Original comment by koposov on 14 Dec 2012 at 7:34

GoogleCodeExporter commented 9 years ago

Yep, that fixed the problem described above. Thanks for the quick fix!

I haven't tested q3c_radial_query() or q3_ellipse_query(); I assume these 
wouldn't suffer from this same kind of problem?

Original comment by greg.j.m...@gmail.com on 15 Dec 2012 at 2:52

GoogleCodeExporter commented 9 years ago
No, ellipse query and radial query had this bug fixed years ago.
The problem with the polygon query was also that I never had a
regression test suite for them, that's why the bug was there for a while.
Now I'm committing a test suite, so this should.

Original comment by koposov on 15 Dec 2012 at 3:03

GoogleCodeExporter commented 9 years ago
Hi Greg, 

I've released the new version of Q3C which includes the bug fix that you 
already tested, as well as another tiny polygon query bug fix, so I would 
recommend to download the version of Q3C
http://code.google.com/p/q3c/downloads/list

Sergey 

Original comment by koposov on 17 Dec 2012 at 6:09