我目前正在基于GeoDjango构建一个Web应用程序,我想检查多边形内是否存在许多点。为了形成多边形,我检查了选中的区域,然后使用以下查询将它们聚合为一个多边形:
area = Area.objects.filter(id__in = area_ids).aggregate(area=Union('geom'))['area']
print(area)
SRID=4326;MULTIPOLYGON (((5.014146 52.371687, 5.013973 52.371632, 5.013238 52.37166, 5.012505 52.372437, 5.01294 52.372787, 5.012977 52.373, 5.013142 52.373072, 5.014488 52.373032, 5.014564 52.372957, 5.014701 52.37272, 5.01461 52.372181, 5.014372 52.371786, 5.014146 52.371687)), ((5.014054 52.367988, 5.014448 52.368027, 5.014532 52.367978, 5.014079 52.367899, 5.014033 52.367822, 5.01398 52.367882, 5.012914 52.367781, 5.013032 52.367372, 5.012751 52.367294, 5.00198 52.366278, 5.001809 52.366739, 5.000036 52.366614, 5.000086 52.366682, 5.013941 52.367968, 5.013987 52.36805, 5.014054 52.367988)), ((4.997837 52.350827, 4.997581 52.350302, 4.996731 52.35072, 4.996493 52.350708, 4.991906 52.352949, 4.989279 52.354708, 4.990234 52.354938, 4.993064 52.353655, 4.997837 52.350827)), ((5.021518 52.384118, 5.018382 52.380388, 5.01628 52.377323, 5.014382 52.37417, 5.014296 52.374171, 5.014094 52.37425, 5.014288 52.374504, 5.014268 52.374785, 5.013763 52.374812, 5.013434 52.375018, 5.013673 52.375082, 5.01377 52.375441, 5.014177 52.375737, 5.014467 52.375531, 5.014801 52.375961, 5.014822 52.376498, 5.014295 52.376588, 5.014194 52.376725, 5.014413 52.377446, 5.015047 52.378, 5.015372 52.378016, 5.015413 52.377633, 5.01574 52.377412, 5.015965 52.377466, 5.015873 52.378071, 5.016008 52.378355, 5.015993 52.378669, 5.016702 52.380502, 5.016514 52.380922, 5.016989 52.381336, 5.017121 52.381644, 5.017756 52.381984, 5.017666 52.382471, 5.018341 52.383453, 5.018662 52.383813, 5.018769 52.383778, 5.019567 52.384011, 5.020317 52.383815, 5.02067 52.38387, 5.022685 52.386085, 5.022946 52.386199, 5.023521 52.386835, 5.023697 52.386851, 5.023905 52.386782, 5.021518 52.384118)), ((4.980684 52.330761, 4.982519 52.330804, 4.983355 52.330747, 4.984946 52.330428, 4.98604 52.329811, 4.987298 52.32893, 4.989045 52.327985, 4.989604 52.327548, 4.990891 52.326142, 4.991615 52.324538, 4.992109 52.323766, 4.995479 52.31931, 4.997103 52.317392, 4.997369 52.316672, 4.997147 52.315905, 4.997091 52.314456, 4.997298 52.314196, 4.997456 52.314246, 4.99786 52.313979, 5.001531 52.315911, 5.006523 52.319077, 5.016134 52.324512, 5.016323 52.324237, 5.016653 52.322987, 5.017933 52.323192, 5.018331 52.320249, 5.021543 52.302457, 5.019476 52.302498, 5.018104 52.302624, 5.016685 52.302881, 5.014265 52.303677, 5.014229 52.30359, 5.012989 52.303605, 5.012279 52.303522, 5.011623 52.303337, 5.011051 52.303029, 5.009933 52.302103, 5.008961 52.301726, 5.007892 52.301522, 5.007544 52.300868, 5.005265 52.298393, 5.003835 52.298509, 5.003233 52.297389, 5.003227 52.296065, 5.002484 52.296035, 5.001851 52.295879, 5.001789 52.292793, 4.998814 52.290239, 4.998551 52.290234, 4.998452 52.289839, 4.998298 52.289815, 4.997475 52.289118, 4.994117 52.289288, 4.990459 52.289603, 4.983506 52.290368, 4.982889 52.289642, 4.975148 52.286342, 4.973249 52.285236, 4.973072 52.285022, 4.972611 52.284846, 4.969726 52.283121, 4.969378 52.281789, 4.968815 52.280973, 4.968753 52.280726, 4.968328 52.280412, 4.967674 52.279582, 4.967576 52.279561, 4.966842 52.279878, 4.966491 52.280096, 4.966166 52.28098, 4.965709 52.280578, 4.965316 52.280448, 4.962548 52.280285, 4.962244 52.280207, 4.961054 52.278174, 4.959968 52.278346, 4.958664 52.278343, 4.957809 52.278612, 4.957144 52.278671, 4.956564 52.278641, 4.955241 52.278305, 4.95184 52.282443, 4.952091 52.282534, 4.946407 52.288562, 4.937142 52.29947, 4.934869 52.301943, 4.934936 52.301969, 4.933217 52.303553, 4.932721 52.304263, 4.931682 52.305025, 4.930256 52.30643, 4.929473 52.307414, 4.929825 52.307515, 4.929416 52.307829, 4.929909 52.308104, 4.929328 52.308532, 4.929615 52.308813, 4.930303 52.309182, 4.930065 52.30934, 4.931656 52.310267, 4.934138 52.311903, 4.936352 52.312663, 4.935229 52.313889, 4.938724 52.315091, 4.938738 52.315636, 4.938042 52.316505, 4.93983 52.31712, 4.940332 52.318302, 4.939585 52.31912, 4.941043 52.31962, 4.940205 52.320815, 4.939927 52.321936, 4.937619 52.323299, 4.937961 52.324122, 4.938612 52.324216, 4.940494 52.325678, 4.947659 52.328138, 4.952676 52.322644, 4.967541 52.327758, 4.970255 52.326169, 4.971101 52.326651, 4.971808 52.327473, 4.974025 52.328907, 4.974825 52.3297, 4.975307 52.330562, 4.977136 52.330643, 4.977946 52.33116, 4.978347 52.331077, 4.9798 52.331003, 4.980684 52.330761)), ((4.76656 52.427549, 4.767184 52.427468, 4.767538 52.428498, 4.82359 52.421255, 4.828585 52.420681, 4.833817 52.419911, 4.845285 52.418468, 4.848025 52.418073, 4.856078 52.416662, 4.859488 52.419785, 4.859858 52.420474, 4.859854 52.420991, 4.859724 52.42128, 4.857907 52.423729, 4.857811 52.42418, 4.857948 52.424717, 4.858388 52.425254, 4.862454 52.428776, 4.862706 52.429198, 4.862702 52.429599, 4.862805 52.429623, 4.862678 52.429941, 4.864187 52.430264, 4.864207 52.430375, 4.865014 52.430549, 4.865971 52.430679, 4.866691 52.430672, 4.867929 52.430524, 4.868743 52.430316, 4.869697 52.429746, 4.869934 52.429968, 4.870741 52.430395, 4.870958 52.430188, 4.872101 52.429918, 4.872737 52.429543, 4.873248 52.429543, 4.873337 52.429486, 4.874112 52.427964, 4.874221 52.427971, 4.875243 52.427059, 4.875967 52.426546, 4.876574 52.426228, 4.877666 52.425883, 4.878658 52.425721, 4.87952 52.42569, 4.880539 52.425781, 4.881808 52.426022, 4.882456 52.425888, 4.882977 52.425509, 4.88529 52.425612, 4.887047 52.425563, 4.889478 52.425636, 4.892458 52.425449, 4.895899 52.425034, 4.898406 52.424584, 4.898383 52.424521, 4.89961 52.424296, 4.901886 52.423623, 4.904127 52.422802, 4.907531 52.421247, 4.908082 52.421125, 4.907962 52.420874, 4.908677 52.420715, 4.910958 52.41968, 4.913594 52.418654, 4.914045 52.418495, 4.914646 52.418501, 4.914703 52.418675, 4.91569 52.418564, 4.919668 52.416844, 4.920265 52.416614, 4.920441 52.416613, 4.920891 52.416327, 4.923457 52.415244, 4.92554 52.414212, 4.930384 52.412081, 4.930716 52.411608, 4.93112 52.411693, 4.935142 52.41204, 4.93949 52.413183, 4.94257 52.413839, 4.944069 52.414342, 4.944555 52.41475, 4.944975 52.415315, 4.947789 52.421562, 4.948526 52.421425, 4.94971 52.421925, 4.949807 52.421861, 4.951481 52.42193, 4.951632 52.422649, 4.95152 52.423016, 4.951332 52.423226, 4.95277 52.423679, 4.952826 52.423621, 4.952494 52.423486, 4.95261 52.423256, 4.953602 52.422215, 4.954101 52.422218, 4.95495 52.422396, 4.955878 52.42244, 4.95595 52.421954, 4.956345 52.422054, 4.97332 52.422797, 4.982636 52.426762, 4.987102 52.422842, 4.987769 52.423268, 4.988834 52.423254, 4.989184 52.423372, 4.990406 52.424518, 4.990352 52.42517, 4.990445 52.425521, 4.990489 52.42543, 4.991372 52.425401, 4.991529 52.425456, 4.993459 52.425399, 4.995438 52.425492, 5.000157 52.425443, 5.018205 52.41906, 5.018513 52.419124, 5.020314 52.419899, 5.021155 52.421068, 5.021611 52.421222, 5.022373 52.420767, 5.023559 52.420266, 5.024288 52.420121, 5.024942 52.420083, 5.025624 52.420152, 5.026501 52.420064, 5.02726 52.419866, 5.028357 52.419416, 5.02898 52.418859, 5.029728 52.417707, 5.03005 52.416829, 5.030045 52.415643, 5.032489 52.416277, 5.033468 52.416685, 5.034064 52.417174, 5.034405 52.417814, 5.035047 52.418203, 5.03547 52.418274, 5.035869 52.418268, 5.036874 52.418089, 5.039389 52.417382, 5.04259 52.416985, 5.049177 52.415129, 5.050926 52.415279, 5.055089 52.415973, 5.057757 52.416538, 5.062556 52.416173, 5.063188 52.416258, 5.063683 52.416432, 5.065413 52.417239, 5.067935 52.416571, 5.068264 52.416558, 5.068413 52.415453, 5.067864 52.414638, 5.067495 52.413536, 5.06727 52.413422, 5.062511 52.414228, 5.057634 52.414816, 5.05659 52.414698, 5.055452 52.414374, 5.052211 52.413181, 5.051489 52.412816, 5.051109 52.412508, 5.04833 52.409345, 5.0481 52.408858, 5.04759 52.40842, 5.046255 52.406733, 5.044359 52.406341, 5.043648 52.406115, 5.04277 52.406022, 5.041961 52.405554, 5.041234 52.405273, 5.039083 52.405035, 5.038372 52.404872, 5.036112 52.403297, 5.035629 52.403076, 5.033962 52.402545, 5.032682 52.401199, 5.032027 52.401096, 5.031527 52.40092, 5.0312 52.400448, 5.029556 52.398883, 5.029061 52.398009, 5.028447 52.396409, 5.028532 52.395768, 5.027904 52.395225, 5.027646 52.394619, 5.027416 52.393565, 5.026593 52.392671, 5.026285 52.391378, 5.025874 52.390742, 5.025584 52.389864, 5.025337 52.389497, 5.025178 52.388718, 5.025239 52.388176, 5.024768 52.387941, 5.02353 52.387652, 5.023339 52.387548, 5.022491 52.387374, 5.021635 52.387394, 5.01998 52.386957, 5.019262 52.386688, 5.018888 52.386441, 5.018042 52.384975, 5.017645 52.38463, 5.017137 52.384374, 5.016163 52.384241, 5.014117 52.384561, 5.008455 52.382728, 5.009098 52.382802, 5.012712 52.384002, 5.013008 52.384048, 5.013136 52.383962, 5.013082 52.383483, 5.012062 52.383363, 5.01183 52.383406, 5.01129 52.383295, 5.010852 52.383061, 5.010915 52.382645, 5.011206 52.382171, 5.01146 52.382141, 5.012042 52.382302, 5.012459 52.382252, 5.012757 52.382355, 5.012973 52.382268, 5.013304 52.381991, 5.01301 52.381758, 5.0134 52.381839, 5.013562 52.381792, 5.013388 52.381329, 5.013783 52.380819, 5.013568 52.378745, 5.013238 52.378379, 5.012798 52.378167, 5.012634 52.377781, 5.012393 52.377526, 5.012791 52.377348, 5.013065 52.377124, 5.013039 52.377022, 5.012673 52.376617, 5.012404 52.376516, 5.012251 52.376117, 5.01174 52.375899, 5.011686 52.375765, 5.012096 52.374918, 5.011669 52.37463, 5.011947 52.374451, 5.011857 52.374253, 5.011516 52.374044, 5.01286 52.373219, 5.012809 52.373185, 5.011886 52.373706, 5.011508 52.373529, 5.009937 52.373108, 5.009547 52.372926, 5.009195 52.372981, 5.00836 52.372564, 5.007755 52.372707, 5.006538 52.373539, 5.00176 52.374918, 5.001307 52.375271, 5.000814 52.377085, 4.999904 52.378234, 4.998621 52.378781, 4.998115 52.378659, 4.997736 52.378324, 4.997495 52.378353, 4.997043 52.378222, 4.995957 52.378152, 4.994751 52.377718, 4.994272 52.377762, 4.993847 52.377945, 4.993671 52.378201, 4.994381 52.378533, 4.997897 52.379484, 4.998129 52.379381, 4.998486 52.379482, 4.998379 52.379757, 4.998226 52.379771, 4.993788 52.378575, 4.99128 52.377762, 4.991423 52.377615, 4.991247 52.377541, 4.991308 52.377487, 4.991539 52.377556, 4.991714 52.377449, 4.991767 52.3772, 4.991314 52.377222, 4.990749 52.377426, 4.990568 52.377386, 4.989741 52.377599, 4.989355 52.377525, 4.987859 52.376827, 4.987448 52.37635, 4.985317 52.375082, 4.984532 52.374763, 4.983763 52.374032, 4.983065 52.373896, 4.982348 52.373901, 4.982004 52.37377, 4.981801 52.373507, 4.981657 52.373461, 4.981071 52.373774, 4.980379 52.373668, 4.98012 52.373715, 4.978501 52.375766, 4.97698 52.376884, 4.973966 52.379442, 4.974107 52.378938, 4.974098 52.37807, 4.97432 52.376453, 4.97417 52.376366, 4.973923 52.376418, 4.973639 52.378086, 4.973488 52.37826, 4.97294 52.379825, 4.969685 52.379383, 4.969385 52.379267, 4.968595 52.379322, 4.968391 52.37948, 4.96481 52.376825, 4.97695 52.370367, 4.978998 52.369443, 4.982338 52.368275, 4.985751 52.367401, 4.989552 52.366771, 4.992988 52.366479, 4.997304 52.366443, 4.997288 52.366358, 4.996426 52.366326, 4.993466 52.366348, 4.990595 52.366562, 4.987866 52.366927, 4.985705 52.36732, 4.983671 52.367792, 4.982155 52.368217, 4.979676 52.369058, 4.978998 52.368785, 4.978627 52.368717, 4.973974 52.368672, 4.97366 52.368572, 4.973304 52.368008, 4.973288 52.367561, 4.975829 52.366076, 4.975757 52.365876, 4.976025 52.365728, 4.975906 52.365629, 4.977752 52.364646, 4.97788 52.364739, 4.978153 52.364593, 4.978276 52.36466, 4.978581 52.364548, 4.980912 52.363295, 4.983647 52.364427, 4.98354 52.364486, 4.983634 52.364507, 4.983603 52.364702, 4.98351 52.364718, 4.983707 52.364741, 4.983787 52.364202, 4.981267 52.363171, 4.985127 52.361166, 4.985508 52.361415, 4.985348 52.361604, 4.98702 52.36274, 4.984978 52.364603, 4.984792 52.364612, 4.983905 52.36425, 4.983825 52.364749, 4.983905 52.364532, 4.98474 52.364875, 4.984604 52.364997, 4.984493 52.364954, 4.984224 52.365218, 4.984692 52.365673, 4.988146 52.364699, 4.990777 52.363771, 4.990625 52.363651, 4.990229 52.363791, 4.989071 52.362971, 4.989427 52.362772, 4.986625 52.360809, 4.985802 52.361239, 4.985388 52.360923, 4.986292 52.360439, 4.986302 52.360376, 4.986058 52.360278, 4.986945 52.359806, 4.987392 52.359965, 4.987699 52.359786, 4.992078 52.361658, 4.996531 52.359691, 5.005736 52.354796, 5.00612 52.355064, 5.006466 52.354883, 5.005939 52.354508, 5.006008 52.354472, 5.006535 52.354847, 5.006244 52.354554, 5.00785 52.353677, 5.009262 52.353222, 5.009743 52.353274, 5.011093 52.353678, 5.015981 52.355316, 5.02009 52.356387, 5.020372 52.356345, 5.020516 52.355901, 5.021017 52.355244, 5.021235 52.354781, 5.021346 52.3543, 5.021262 52.354103, 5.019067 52.353908, 5.018187 52.353917, 5.017669 52.354432, 5.017247 52.354361, 5.014572 52.353524, 5.014578 52.353465, 5.01334 52.352837, 5.013069 52.352783, 5.012578 52.352532, 5.012584 52.352197, 5.01349 52.350794, 5.013856 52.350595, 5.014034 52.350575, 5.01421 52.35065, 5.014697 52.350475, 5.015256 52.350582, 5.016143 52.350608, 5.016668 52.350322, 5.016721 52.349919, 5.016206 52.349813, 5.015916 52.349236, 5.01547 52.34912, 5.015135 52.348728, 5.015514 52.347954, 5.015421 52.347834, 5.015128 52.347833, 5.015295 52.347634, 5.015119 52.347433, 5.014677 52.347961, 5.014573 52.347933, 5.014648 52.347844, 5.014183 52.347798, 5.014061 52.347719, 5.014572 52.34707, 5.009089 52.345037, 5.003628 52.347808, 4.998768 52.350814, 4.999165 52.351094, 4.999014 52.351173, 4.998702 52.350987, 4.990331 52.355456, 4.989356 52.355229, 4.986722 52.35664, 4.986525 52.358004, 4.987358 52.358171, 4.989029 52.3573, 4.989404 52.357393, 4.990006 52.357074, 4.990128 52.357162, 4.988123 52.358246, 4.988197 52.35864, 4.98645 52.359552, 4.986738 52.359719, 4.985837 52.360198, 4.985327 52.360045, 4.984775 52.360353, 4.980437 52.358556, 4.979415 52.359493, 4.979742 52.359633, 4.97842 52.360823, 4.977112 52.360291, 4.976214 52.361092, 4.975394 52.36077, 4.974513 52.361577, 4.97481 52.361703, 4.974462 52.362007, 4.977704 52.364254, 4.977448 52.364379, 4.977643 52.364567, 4.975807 52.365553, 4.975552 52.365378, 4.975258 52.365539, 4.974975 52.36548, 4.974346 52.365817, 4.973409 52.365305, 4.972628 52.365089, 4.972409 52.365231, 4.972065 52.365099, 4.971517 52.364805, 4.97103 52.364344, 4.968913 52.360785, 4.969172 52.36072, 4.973182 52.36069, 4.974059 52.360398, 4.974168 52.360219, 4.973997 52.359979, 4.974106 52.359932, 4.974217 52.358829, 4.974155 52.358039, 4.974063 52.357957, 4.974193 52.357765, 4.974713 52.357656, 4.975208 52.357177, 4.975658 52.357162, 4.976418 52.35732, 4.978204 52.357408, 4.979742 52.357668, 4.9811 52.357558, 4.982756 52.357836, 4.983287 52.358072, 4.984194 52.357938, 4.98429 52.358089, 4.984469 52.358103, 4.985358 52.357804, 4.985841 52.357519, 4.985969 52.357059, 4.985701 52.356551, 4.985048 52.356162, 4.985067 52.35597, 4.984858 52.355964, 4.984785 52.355876, 4.985158 52.355118, 4.985879 52.35474, 4.987016 52.354467, 4.987496 52.354072, 4.987454 52.353987, 4.98869 52.353827, 4.989096 52.353335, 4.989797 52.35293, 4.991362 52.352488, 4.992051 52.351711, 4.994208 52.350118, 4.994678 52.349962, 4.995271 52.34995, 4.995783 52.349819, 4.996954 52.348795, 4.997218 52.347998, 4.998007 52.347127, 4.998912 52.347277, 4.998413 52.348312, 4.998503 52.348389, 5.004966 52.346143, 5.005432 52.345916, 5.007528 52.34442, 5.005088 52.344183, 5.003609 52.34488, 4.999446 52.34619, 4.998935 52.347229, 4.998029 52.34708, 4.998395 52.346347, 5.000594 52.344828, 5.001295 52.344508, 5.002488 52.344121, 5.003602 52.344048, 5.005124 52.343642, 5.005814 52.343555, 5.007931 52.343661, 5.009204 52.34402, 5.009732 52.344077, 5.010949 52.344102, 5.0123 52.343941, 5.012052 52.34342, 5.011287 52.342829, 5.009698 52.342066, 5.008775 52.341847, 5.008092 52.341876, 5.005316 52.342487, 5.004162 52.342578, 5.002118 52.342424, 5.000718 52.342203, 4.999909 52.341933, 4.999321 52.341536, 4.993729 52.344422, 4.97449 52.354666, 4.973183 52.355219, 4.972179 52.355546, 4.970394 52.355957, 4.970425 52.356011, 4.969595 52.356102, 4.969314 52.35561, 4.969502 52.355577, 4.969522 52.355498, 4.96831 52.354927, 4.96624 52.354164, 4.965823 52.354697, 4.964957 52.353276, 4.961366 52.348853, 4.95993 52.347448, 4.959697 52.346929, 4.953053 52.34037, 4.951889 52.33967, 4.949701 52.338727, 4.94986 52.338528, 4.949548 52.338379, 4.946767 52.337658, 4.943798 52.336712, 4.941721 52.336407, 4.941706 52.335533, 4.939528 52.335593, 4.938148 52.335239, 4.937704 52.335003, 4.936512 52.334592, 4.935624 52.335514, 4.934221 52.335496, 4.928493 52.336555, 4.92677 52.335965, 4.926942 52.335777, 4.925773 52.335373, 4.923765 52.335443, 4.923727 52.334811, 4.923512 52.334257, 4.923083 52.333712, 4.922438 52.333216, 4.922551 52.333084, 4.920372 52.33236, 4.916902 52.331364, 4.914175 52.330678, 4.912932 52.33051, 4.913881 52.324552, 4.911288 52.324162, 4.910334 52.323566, 4.911351 52.322899, 4.91073 52.321914, 4.912488 52.321254, 4.912696 52.321062, 4.914282 52.320408, 4.912376 52.318248, 4.909135 52.318253, 4.909051 52.318826, 4.907841 52.319505, 4.904703 52.320394, 4.902532 52.321324, 4.901601 52.321528, 4.899347 52.32155, 4.898281 52.321644, 4.897146 52.321896, 4.896292 52.32242, 4.857863 52.321734, 4.857651 52.321689, 4.857614 52.321429, 4.856755 52.321413, 4.856747 52.321555, 4.856566 52.321562, 4.856569 52.321767, 4.856334 52.321762, 4.856422 52.328846, 4.855924 52.330318, 4.848007 52.33057, 4.847565 52.330046, 4.845237 52.329682, 4.843961 52.330218, 4.840517 52.329589, 4.839477 52.329146, 4.839631 52.327559, 4.839414 52.327546, 4.839405 52.327359, 4.826061 52.325928, 4.825179 52.325731, 4.819887 52.325759, 4.819469 52.325569, 4.818426 52.325557, 4.817711 52.326438, 4.817129 52.32692, 4.816404 52.327406, 4.815436 52.327893, 4.797766 52.335283, 4.797326 52.335596, 4.791782 52.341027, 4.790541 52.341842, 4.77174 52.349558, 4.75733 52.355203, 4.756106 52.355829, 4.755684 52.35615, 4.755104 52.356832, 4.754941 52.357219, 4.754837 52.357907, 4.754902 52.358384, 4.757984 52.369239, 4.758511 52.371241, 4.758596 52.372218, 4.75838 52.374015, 4.758047 52.375065, 4.75753 52.376189, 4.756434 52.377764, 4.757257 52.377979, 4.759125 52.379329, 4.758944 52.38442, 4.758513 52.387194, 4.758006 52.38955, 4.75801 52.394029, 4.757818 52.396663, 4.757448 52.396893, 4.756022 52.397103, 4.756053 52.397192, 4.728759 52.400711, 4.739208 52.431064, 4.76656 52.427549), (4.971393 52.365449, 4.970903 52.364523, 4.970873 52.364467, 4.971352 52.364883, 4.971786 52.365148, 4.97228 52.365326, 4.972021 52.365431, 4.971393 52.365449), (4.969986 52.365734, 4.970311 52.365281, 4.970388 52.364659, 4.970868 52.365611, 4.970338 52.365782, 4.969986 52.365734), (4.962275 52.368559, 4.958395 52.368523, 4.958009 52.368426, 4.957877 52.368182, 4.957959 52.367695, 4.957777 52.367662, 4.957813 52.36751, 4.958008 52.367525, 4.958161 52.366866, 4.959434 52.367113, 4.959483 52.366944, 4.959653 52.366866, 4.959554 52.366457, 4.958608 52.366263, 4.958552 52.366059, 4.95994 52.366299, 4.961104 52.366815, 4.961676 52.367273, 4.962008 52.367688, 4.962275 52.368559), (4.961478 52.381664, 4.961453 52.381605, 4.96132 52.381663, 4.961183 52.381563, 4.961623 52.381318, 4.96122 52.381485, 4.961083 52.38134, 4.961373 52.381151, 4.960883 52.381354, 4.960791 52.381157, 4.960297 52.38139, 4.960198 52.381311, 4.960376 52.381234, 4.959962 52.380967, 4.959547 52.380934, 4.958993 52.381069, 4.958858 52.380962, 4.959072 52.380816, 4.958757 52.380608, 4.95905 52.380587, 4.961618 52.379907, 4.961868 52.379783, 4.961743 52.379609, 4.958835 52.380378, 4.958706 52.380163, 4.961633 52.379388, 4.961389 52.379057, 4.961149 52.379127, 4.961254 52.379285, 4.959965 52.379644, 4.959861 52.37947, 4.961633 52.378504, 4.961752 52.378587, 4.961975 52.378459, 4.961861 52.378383, 4.964718 52.376878, 4.96829 52.379564, 4.965772 52.381865, 4.965209 52.382155, 4.964214 52.382979, 4.963296 52.383586, 4.961163 52.381801, 4.961478 52.381664), (4.962389 52.36857, 4.962069 52.367587, 4.961346 52.366878, 4.960143 52.366295, 4.959315 52.366087, 4.958518 52.365989, 4.958465 52.365789, 4.958937 52.365728, 4.960183 52.365997, 4.960842 52.366046, 4.961086 52.365991, 4.961461 52.365638, 4.961465 52.365193, 4.961621 52.365108, 4.962091 52.365119, 4.962206 52.364952, 4.96235 52.364497, 4.96227 52.3642, 4.961998 52.364025, 4.961582 52.363987, 4.961442 52.363703, 4.960745 52.36384, 4.95993 52.364242, 4.959395 52.365089, 4.959309 52.365074, 4.95945 52.364698, 4.959979 52.364051, 4.960805 52.363704, 4.962195 52.363312, 4.96517 52.36187, 4.968328 52.36092, 4.969895 52.363828, 4.97021 52.364597, 4.970193 52.365032, 4.96996 52.365509, 4.969789 52.365707, 4.969423 52.365668, 4.969227 52.365803, 4.968909 52.366187, 4.968728 52.366823, 4.968898 52.367287, 4.969888 52.368214, 4.969125 52.368628, 4.962389 52.36857)))
然后,我从 流 查询集中检索了所有点,这些点最初包含在这些点中,并注释它们到另一个 链 < / strong>使用新名称('producer_geom')的查询集:
subq = flows.filter(chains_id=OuterRef('pk'),
origin_role='producer')
chains = chains.annotate(pro_geom=
Subquery(subq.values('origin__administrative_location__geom'))
)
结果如下:
print(chains.values_list('id', 'pro_geom'))
<QuerySet [(10804, <Point object at 0x7f656e633de0>), (10803, <Point object at 0x7f656e649ab0>), (10802, <Point object at 0x7f656e649bc0>), '...(remaining elements truncated)...']>
但是当我尝试过滤链时,要收集生产者点与区域multipolygon所在的链的ID,
chains = chains.filter(pro_geom__within=area)
我收到以下错误消息:
Traceback (most recent call last):
File "/home/geofluxus/.local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/geofluxus/.local/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/geofluxus/.local/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/geofluxus/.local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/home/geofluxus/.local/lib/python3.6/site-packages/rest_framework/viewsets.py", line 116, in view
return self.dispatch(request, *args, **kwargs)
File "/home/geofluxus/.local/lib/python3.6/site-packages/reversion/views.py", line 35, in do_revision_view
response = func(request, *args, **kwargs)
File "/home/geofluxus/.local/lib/python3.6/site-packages/rest_framework/views.py", line 495, in dispatch
response = self.handle_exception(exc)
File "/home/geofluxus/.local/lib/python3.6/site-packages/rest_framework/views.py", line 455, in handle_exception
self.raise_uncaught_exception(exc)
File "/home/geofluxus/.local/lib/python3.6/site-packages/rest_framework/views.py", line 466, in raise_uncaught_exception
raise exc
File "/home/geofluxus/.local/lib/python3.6/site-packages/rest_framework/views.py", line 492, in dispatch
response = handler(request, *args, **kwargs)
File "/home/geofluxus/Desktop/geoFluxus/repair/apps/utils/views.py", line 36, in create
return self.post_get(request, **kwargs)
File "/home/geofluxus/Desktop/geoFluxus/repair/apps/asmfa/views/flowfilter.py", line 206, in post_get
queryset = self.filter_chain(queryset, filter_chains, keyflow)
File "/home/geofluxus/Desktop/geoFluxus/repair/apps/asmfa/views/flowfilter.py", line 356, in filter_chain
queryset = build_chain_filter(sub_filter, queryset, keyflow)
File "/home/geofluxus/Desktop/geoFluxus/repair/apps/asmfa/views/flowfilter.py", line 151, in build_chain_filter
chains = list(chains.values_list('id', flat=True))
File "/home/geofluxus/.local/lib/python3.6/site-packages/django/db/models/query.py", line 274, in __iter__
self._fetch_all()
File "/home/geofluxus/.local/lib/python3.6/site-packages/django/db/models/query.py", line 1242, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/home/geofluxus/.local/lib/python3.6/site-packages/django/db/models/query.py", line 182, in __iter__
for row in compiler.results_iter(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size):
File "/home/geofluxus/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1052, in results_iter
results = self.execute_sql(MULTI, chunked_fetch=chunked_fetch, chunk_size=chunk_size)
File "/home/geofluxus/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1087, in execute_sql
sql, params = self.as_sql()
File "/home/geofluxus/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 489, in as_sql
where, w_params = self.compile(self.where) if self.where is not None else ("", [])
File "/home/geofluxus/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 405, in compile
sql, params = node.as_sql(self, self.connection)
File "/home/geofluxus/.local/lib/python3.6/site-packages/django/db/models/sql/where.py", line 81, in as_sql
sql, params = compiler.compile(child)
File "/home/geofluxus/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 405, in compile
sql, params = node.as_sql(self, self.connection)
File "/home/geofluxus/.local/lib/python3.6/site-packages/django/db/models/sql/where.py", line 81, in as_sql
sql, params = compiler.compile(child)
File "/home/geofluxus/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 405, in compile
sql, params = node.as_sql(self, self.connection)
File "/home/geofluxus/.local/lib/python3.6/site-packages/django/db/models/sql/where.py", line 81, in as_sql
sql, params = compiler.compile(child)
File "/home/geofluxus/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 405, in compile
sql, params = node.as_sql(self, self.connection)
File "/home/geofluxus/.local/lib/python3.6/site-packages/django/contrib/gis/db/models/lookups.py", line 79, in as_sql
sql_params.extend(rhs_params)
AttributeError: 'tuple' object has no attribute 'extend'
从回溯中可以看到,问题出在Django GIS查找中,因为sql_params是一个元组对象,因此无法扩展。我可以添加以下检查,然后一切正常:
if isinstance(sql_params, tuple): sql_params = list[sql_params]
但是,我想弄清楚是不是搞砸了,还是真的是Django的错误。
PS。由于某种原因,此查询集似乎可以工作:
chains = chains.filter(pro_geom__isvalid=True)