segasai / q3c

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

Getting a 'polygon is too large' error. #31

Closed demitri closed 3 years ago

demitri commented 3 years ago

Hi,

I have the following query using a polygon generated as the boundary of a region (from a FITS header):

SELECT * FROM my_catalog WHERE q3c_poly_query(ra, dec, '((255.3121984665786, 18.92312700639222), (255.3143170639072, 18.9386188738895), (255.3164420501668, 18.95411450130444), (255.3185734189125, 18.9696136942468), (255.3207111629718, 18.98511625949686), (255.3228552744448, 19.00062200500532), (255.3250057447032, 19.01613073989319), (255.3271625643902, 19.03164227445179), (255.3293257234205, 19.04715642014253), (255.3314952109791, 19.06267298959681), (255.3336710155218, 19.07819179661602), (255.335853124774, 19.09371265617135), (255.3380415257311, 19.10923538440376), (255.3402362046577, 19.12475979862382), (255.3424371470873, 19.14028571731165), (255.3446443378217, 19.15581296011687), (255.3468577609312, 19.17134134785842), (255.3490773997538, 19.18687070252457), (255.3513032368947, 19.20240084727275), (255.3535352542262, 19.21793160642952), (255.3557734328875, 19.23346280549046), (255.3580177532839, 19.24899427112011), (255.3602681950864, 19.26452583115187), (255.3625247372319, 19.28005731458791), (255.3647873579223, 19.29558855159914), (255.3670560346244, 19.31111937352509), (255.3693307440691, 19.32664961287385), (255.3716114622518, 19.34217910332202), (255.3738981644311, 19.3577076797146), (255.3761908251292, 19.37323517806494), (255.3784894181313, 19.38876143555468), (255.3807939164848, 19.4042862905337), (255.3831042924995, 19.41980958252001), (255.3854205177471, 19.43533115219972), (255.3877425630606, 19.45085084142696), (255.390070398534, 19.46636849322387), (255.3924039935222, 19.48188395178047), (255.3947433166403, 19.49739706245466), (255.3970883357634, 19.51290767177215), (255.3994390180261, 19.5284156274264), (255.4017953298224, 19.54392077827858), (255.4041572368051, 19.5594229743575), (255.4065247038853, 19.5749220668596), (255.4088976952324, 19.59041790814889), (255.4112761742737, 19.60591035175687), (255.4136601036936, 19.62139925238256), (255.4160494454337, 19.63688446589239), (255.4184441606922, 19.65236584932019), (255.4208442099237, 19.66784326086715), (255.4232495528387, 19.68331655990185), (255.4256601484031, 19.69878560696005), (255.4092289742708, 19.7009057247165), (255.392798380428, 19.70302314707616), (255.376368427323, 19.70513794574351), (255.3599391705132, 19.70725019083826), (255.343510660665, 19.70935995089326), (255.3270829435549, 19.71146729285232), (255.3106560600697, 19.71357228206791), (255.2942300462075, 19.71567498229921), (255.2778049330776, 19.71777545570963), (255.2613807469016, 19.71987376286484), (255.2449575090137, 19.72196996273055), (255.2285352358611, 19.72406411267019), (255.212113939005, 19.72615626844291), (255.1956936251207, 19.72824648420131), (255.1792742959982, 19.73033481248926), (255.162855948543, 19.7324213042397), (255.1464385747763, 19.73450600877251), (255.1300221618355, 19.73658897379226), (255.1136066919751, 19.73867024538615), (255.0971921425669, 19.74074986802171), (255.0807784861005, 19.74282788454463), (255.0643656901839, 19.74490433617666), (255.0479537175441, 19.7469792625134), (255.0315425260274, 19.74905270152208), (255.0151320685998, 19.75112468953943), (254.998722293348, 19.75319526126952), (254.9823131434793, 19.75526444978149), (254.9659045573223, 19.75733228650748), (254.9494964683277, 19.75939880124043), (254.9330888050682, 19.76146402213181), (254.9166814912392, 19.76352797568963), (254.9002744456597, 19.76559068677609), (254.8838675822719, 19.76765217860547), (254.8674608101425, 19.76971247274198), (254.8510540334626, 19.77177158909756), (254.8346471515484, 19.7738295459297), (254.8182400588416, 19.77588635983929), (254.8018326449098, 19.77794204576836), (254.785424794447, 19.77999661699806), (254.769016387274, 19.7820500851463), (254.7526072983387, 19.78410246016575), (254.7361973977169, 19.78615375034146), (254.7197865506125, 19.78820396228892), (254.7033746173576, 19.79025310095163), (254.6869614534134, 19.7923011695991), (254.6705469093705, 19.7943481698246), (254.6541308309492, 19.79639410154296), (254.6377130589998, 19.79843896298841), (254.6212934295035, 19.80048275071235), (254.6048717735721, 19.80252545958125), (254.6025497945791, 19.78709200433929), (254.6002326510131, 19.77165530716474), (254.5979203780645, 19.75621546518594), (254.5956130101798, 19.7407725766955), (254.593310581062, 19.7253267411503), (254.5910131236713, 19.70987805917137), (254.5887206702246, 19.69442663254415), (254.586433252197, 19.6789725642182), (254.5841509003213, 19.66351595830749), (254.5818736445888, 19.64805692009019), (254.5796015142492, 19.63259555600884), (254.5773345378118, 19.61713197367024), (254.5750727430448, 19.60166628184558), (254.5728161569763, 19.58619859047039), (254.5705648058949, 19.57072901064459), (254.5683187153492, 19.55525765463247), (254.5660779101492, 19.53978463586278), (254.5638424143656, 19.52431006892868), (254.5616122513312, 19.50883406958784), (254.5593874436402, 19.49335675476241), (254.5571680131497, 19.47787824253908), (254.5549539809791, 19.46239865216912), (254.5527453675111, 19.44691810406836), (254.5505421923913, 19.43143671981731), (254.5483444745297, 19.41595462216112), (254.5461522321001, 19.40047193500964), (254.5439654825408, 19.38498878343748), (254.5417842425552, 19.36950529368406), (254.5396085281115, 19.35402159315358), (254.5374383544438, 19.33853781041515), (254.5352737360521, 19.3230540752028), (254.5331146867027, 19.30757051841551), (254.5309612194283, 19.29208727211729), (254.5288133465292, 19.27660446953724), (254.5266710795726, 19.26112224506953), (254.5245344293936, 19.24564073427355), (254.5224034060955, 19.23016007387389), (254.5202780190501, 19.21468040176045), (254.5181582768979, 19.19920185698847), (254.5160441875487, 19.18372457977859), (254.513935758182, 19.16824871151692), (254.5118329952468, 19.1527743947551), (254.5097359044629, 19.13730177321036), (254.5076444908206, 19.12183099176564), (254.5055587585809, 19.10636219646954), (254.5034787112767, 19.0908955345365), (254.501404351712, 19.07543115434682), (254.4993356819635, 19.05996920544674), (254.4972727033801, 19.04450983854854), (254.4952154165833, 19.02905320553058), (254.5116030592, 19.02697688253724), (254.5279844649522, 19.02489841535069), (254.5443599581396, 19.02281785058198), (254.560729858222, 19.02073523309787), (254.5770944798202, 19.0186506060232), (254.5934541327146, 19.0165640107432), (254.6098091218452, 19.01447548690559), (254.6261597473117, 19.01238507242291), (254.6425063043725, 19.01029280347468), (254.6588490834452, 19.00819871450985), (254.6751883701054, 19.00610283824868), (254.6915244450871, 19.00400520568525), (254.707857584282, 19.00190584608953), (254.7241880587393, 18.9998047870096), (254.7405161346652, 18.99770205427386), (254.7568420734229, 18.99559767199324), (254.773166131532, 18.9934916625634), (254.7894885606684, 18.99138404666685), (254.8058096076635, 18.98927484327523), (254.8221295145044, 18.98716406965136), (254.8384485183333, 18.98505174135158), (254.8547668514472, 18.98293787222778), (254.8710847412977, 18.98082247442959), (254.88740241049, 18.97870555840663), (254.9037200767835, 18.97658713291062), (254.9200379530909, 18.97446720499746), (254.9363562474778, 18.97234578002953), (254.9526751631624, 18.97022286167776), (254.9689948985156, 18.96809845192376), (254.9853156470596, 18.96597255106203), (255.0016375974687, 18.96384515770214), (255.017960933568, 18.96171626877076), (255.0342858343337, 18.95958587951385), (255.0506124738921, 18.95745398349891), (255.0669410215196, 18.95532057261696), (255.0832716416424, 18.95318563708483), (255.0996044938357, 18.95104916544713), (255.1159397328236, 18.94891114457863), (255.1322775084786, 18.94677155968623), (255.1486179658213, 18.94463039431107), (255.1649612450199, 18.94248763033083), (255.1813074813896, 18.94034324796172), (255.1976568053925, 18.93819722576072), (255.214009342637, 18.93604954062771), (255.2303652138774, 18.93390016780755), (255.2467245350136, 18.93174908089231), (255.2630874170904, 18.92959625182332), (255.2794539662971, 18.92744165089341), (255.2958242839675, 18.92528524674899))'::polygon);

This is a plot of the polygon in question:

ploygon_plot

The error I am getting is:

ERROR:  The polygon is too large. Polygons having diameter >~23 degrees are unsupported
CONTEXT:  SQL function "q3c_poly_query" during inlining

I have code where the function does work. Can you suggest what might be the problem?

segasai commented 3 years ago

Hi,

It looks like I have an internal assumption that the polygon has less than 100 vertices (which I never properly check and error on) and this assumption is not satisfied here. I'll fix this but probably keep the limit on 100 vertices or so.

segasai commented 3 years ago

Fixed in 26c936868708c0ce1fb21566cd36c8acd0cf9983 Now it will return an error saying that the polygon has more than 100 vertices which is not suported. If it's important for you to work with so many vertices, I can consider bumping up that number to say 300, but those will be quite slow anyway , so I'm not thrilled about doing that.

demitri commented 3 years ago

Thanks for the quick reply. I think the 100 vertex limit is a reasonable limitation (certainly for the simple polygon above). Can you mention the limit in the documentation? If I end up needing more at least I know I can go into the code and recompile.

segasai commented 3 years ago

I've added a limitation section to the README. But also now the corresponding functions will complain with a clear message if the polygon has too many vertices.

Closing.

demitri commented 3 years ago

Perfect, thank you.