0 votes
137 views
Is there a way to execute a query with a box that is not aligned with the coordinate system but has some position angle?

I'm basically hoping there is a simple way to do a query at a position, with a width, length, and angle ...

Thanks
asked Mar 16 by Nicolas | 137 views

1 Answer

0 votes
Using the q3c_poly_query(ra, dec, poly) function we support,  see here and the example https://github.com/segasai/q3c, you could query within a polygon once you know the vertices.

By rotating your bounding box by an angle you should be able to determine the new vertices (using trig ratios)  required by q3c_poly_query...


answered Mar 16 by ascottdemo (680 points)
Thanks! I've tried that:

query = """
SELECT ra, dec, l, b, phot_g_mean_mag
FROM gaia_dr1.gaia_source
WHERE q3c_poly_query(ra, dec, '{0, 0, 0.2, 0, 0.2, 0.1, 0, 0.1}');
"""

but got some error back:

queryClientError: Error: function q3c_poly_query(double precision, double precision, unknown) is not unique
LINE 4: WHERE 't'=q3c_poly_query(ra, dec, '{0, 0, 0.2, 0, 0.2, 0.1, ...
                  ^
HINT:  Could not choose a best candidate function. You might need to add explicit type casts.

But then this query:
query = """
SELECT ra, dec, l, b, phot_g_mean_mag
FROM gaia_dr1.gaia_source
WHERE q3c_poly_query(cast(ra as double precision), cast(dec as double precision), '{0, 0, 0.2, 0, 0.2, 0.1, 0, 0.1}');
"""

returned the same error ...

Any idea what I am doing wrong?
This is a newish feature so we only support it using sync queries not ADQL unfortunately.  

Below is an example test of the q3c_in_poly query.

Notice the additional RA and Dec constraints slightly outside the range at the bottom; this is to speed up the search.

 select ra,dec from smash_dr2.object where q3c_in_poly(ra,dec,
 '{103.049994318506,-37.9621648388989, 103.055631230088,-37.9621648388989,
   103.049994318506,-37.9651915104376, 103.055631230088,-37.9651915104376}'::double precision[])
  and
ra >= 103.048 and ra <=103.056 and
  dec >= -37.966 and dec <= -37.961
 ;
        ra        |        dec
------------------+-------------------
 103.049994318506 | -37.9651915104376
 103.052963758628 | -37.9644048637405
 103.053451197365 | -37.9621655881433
(3 rows)

Hope this helps
Thanks for your replies to my question!
I was just wondering if you could explain what that means:
"This is a newish feature so we only support it using sync queries not ADQL unfortunately."
Can't I use q3c_poly in AstroLab?

192 questions

189 answers

176 comments

1,335 users

Welcome to Data Lab Help Desk, where you can ask questions and receive answers from other members of the community.