SQL Server STIntersects 返回错误结果

问题描述 投票:0回答:1

问题

我正在使用 Azure SQL 数据库来存储具有地理数据类型的表。在其中一张表中,我有多边形和多重多边形类型的地理。我已经使用几何图形的 wkt 然后

geography::STGeomFromText(?, 4326))
从 pandas DataFrame 插入了数据。我已经验证我可以查询我的数据并在 python 中正确绘制它。

但是,我现在尝试从一个点创建一个缓冲区,并找到该缓冲区与表中的几何图形之间的交集:

BEGIN
    DECLARE @location GEOGRAPHY = GEOGRAPHY::Point(40.4168, -3.7038, 4326);
    DECLARE @buffer GEOGRAPHY = @location.STBuffer(500);

    SELECT column1, geom.STAsText() as geom
    FROM my_schema.my_table
    WHERE geom.STIntersects(@buffer) = 1;
END

结果始终为 1,即使对于距离原点非常远的几何图形也是如此。

我尝试过的事情

我尝试使用

MakeValid()
纠正一些几何形状,但结果没有改变。这种错误几何形状的一个例子是:

POLYGON ((-1.604360589999942 39.260269826000069, -1.6045030709999537 39.258929008000052, -1.605052293999961 39.253439263000075, -1.6051683319999484 39.250512273000027, -1.6052226829999654 39.250107472000025, -1.6052798829999801 39.249558507000074, -1.6062581329999261 39.246975258000077, -1.606406849999928 39.246490465000079, -1.6067534919999389 39.245368341000074, -1.6069688219999421 39.245028532000049, -1.6076113749999763 39.243008879000058, -1.6081279999999651 39.242077959000028, -1.6086371669999266 39.240939759000071, -1.6100061759999562 39.238505304000057, -1.6110338559999491 39.23692268700006, -1.6121469229999548 39.235710553000047, -1.61223049299997 39.235585413000081, -1.6125533799999516 39.235075661000053, -1.6126331959999334 39.232787967000036, -1.6127879199999597 39.231402235000076, -1.6130749519999767 39.228008744000078, -1.6133330939999269 39.227254937000055, -1.6137814699999353 39.226251139000055, -1.6145765289999758 39.224701781000078, -1.6154262389999303 39.223315268000079, -1.6159553849999497 39.222330398000054, -1.6167405669999653 39.221276531000058, -1.618945546999953 39.218707668000036, -1.6194574709999756 39.218001927000046, -1.6199186269999473 39.217520844000035, -1.6201586149999798 39.216505432000076, -1.6207249639999759 39.215385895000054, -1.6208004209999558 39.215299884000046, -1.6211396259999447 39.214913230000036, -1.6234468209999591 39.213021335000064, -1.625190378999946 39.212113874000067, -1.6262894039999765 39.211586194000063, -1.6264950229999613 39.211138103000053, -1.6273292979999496 39.209931545000074, -1.6279176979999761 39.209451878000039, -1.6289146149999283 39.208814862000054, -1.629584791999946 39.208300162000057, -1.62989515299995 39.207826290000071, -1.6305546209999306 39.207266363000031, -1.6309994929999334 39.206424653000056, -1.6315449969999349 39.204574867000076, -1.6323382589999369 39.20427778700008, -1.6350435199999538 39.20332742800008, -1.6383260099999575 39.202464761000044, -1.6391793599999573 39.202060269000071, -1.6447371089999478 39.199701235000077, -1.6471226949999505 39.198494538000034, -1.6492000959999586 39.19765366300004, -1.6570503329999724 39.200141199000029, -1.6570381609999458 39.201384492000045, -1.6573068879999369 39.203694263000045, -1.6572975709999582 39.204180742000062, -1.6568477549999443 39.205301848000033, -1.6549889539999754 39.208028594000041, -1.654841954999938 39.208450407000043, -1.6548447539999529 39.208909965000032, -1.6550083439999526 39.210047185000064, -1.6554889489999596 39.211566488000074, -1.6555766969999581 39.212432496000076, -1.6557042759999376 39.213028655000073, -1.6555966819999526 39.213811349000025, -1.65578170699996 39.216255278000062, -1.6561274999999682 39.218773216000045, -1.6564489689999391 39.220137493000038, -1.6570319369999424 39.221153359000027, -1.6592881189999389 39.223729304000074, -1.6612496159999637 39.226581148000037, -1.6618544929999644 39.227669334000041, -1.6624849809999773 39.228631685000039, -1.6631853329999444 39.22957682100008, -1.6636745059999498 39.230050961000074, -1.6648515129999737 39.230911392000053, -1.6648970139999619 39.230957034000028, -1.6659467369999561 39.231807007000043, -1.6668429959999571 39.234033864000025, -1.6676574359999563 39.235692043000029, -1.6691306219999547 39.238051622000057, -1.6703067619999388 39.239578798000025, -1.6723718389999362 39.241899975000081, -1.6732963229999314 39.242649381000035, -1.6766949149999277 39.244931652000048, -1.6778152289999753 39.245746300000064, -1.6782142539999541 39.246093212000062, -1.677474363999977 39.246616417000041, -1.6738745069999368 39.250089574000071, -1.6711598339999796 39.252698629000065, -1.6700101929999391 39.252820657000029, -1.6667474549999497 39.250089287000037, -1.6650017919999414 39.248645624000062, -1.6636584669999479 39.248594192000041, -1.65884469599996 39.248223495000047, -1.6567636699999753 39.249181630000066, -1.6552048979999654 39.250100699000029, -1.6548415639999803 39.250312773000076, -1.6529632569999535 39.251570536000031, -1.6501991509999243 39.253088365000053, -1.6491990229999374 39.253265952000049, -1.6476436789999411 39.253392075000079, -1.6469294689999288 39.253771226000026, -1.6455649099999619 39.254818565000051, -1.6446250789999795 39.255474420000041, -1.6425155999999674 39.257287936000068, -1.640851146999978 39.258854316000054, -1.6405486389999737 39.258913895000035, -1.6392525589999423 39.258808689000034, -1.6373290459999339 39.258786198000053, -1.6356592329999557 39.258829683000044, -1.6337248409999461 39.258771001000071, -1.6322999829999389 39.259925629000065, -1.6319743509999398 39.26176887500003, -1.6305164939999486 39.267590452000036, -1.6283389639999655 39.268096405000051, -1.6203154709999694 39.26997489200005, -1.6156715159999635 39.270928910000066, -1.6147017309999683 39.270728160000033, -1.6133250759999669 39.27058562600007, -1.6098750719999657 39.270364271000062, -1.6078159329999266 39.270150449000027, -1.6063014679999696 39.269943114000057, -1.6052976909999757 39.269705854000051, -1.6020478649999745 39.268747799000039, -1.602369375999956 39.267733527000075, -1.6026627569999619 39.266385501000059, -1.6029213339999728 39.26562274500003, -1.6033150409999735 39.265059794000081, -1.6043328599999427 39.263999761000036, -1.6052175999999463 39.262055140000029, -1.6052022489999445 39.261658471000032, -1.6049266939999711 39.260943376000057, -1.604360589999942 39.260269826000069))

我感到很失落,我觉得我表格中的几何图形可能不正确,但如果您有任何见解,这确实会有帮助。

python pandas geometry azure-sql-database
1个回答
0
投票

解决了!我的多边形方向不正确,因此每个距离计算都关闭了。正如此评论中所解释的,解决方案是在计算距离之前重新调整多边形的方向。

© www.soinside.com 2019 - 2024. All rights reserved.