检查多边形是否有形状地接壤不能始终如一地工作

Checking if polygons are bordering in shapely not working consistently

我正在写一些东西,需要一个函数来查看两个多边形是否在多个点处接壤。 从 this question 我找到了这个解决方案:isinstance(poly1.intersection(poly2), MultiLineString).

这在佛蒙特州的选区地图上无法始终如一地工作,您可以通过下载和解压缩 this file 获得该地图。辖区地图在 geodata.json。以下是未检测到的成对边界区域的几个示例。 ("GEOID10" 属性):

在这两个例子中,边界都很细,因此我认为这是 GEOS 中精度的问题。我有一个朋友在用 C++ 做这件事,他们告诉我尝试将所有坐标乘以 2^18。那并没有解决问题。

可能是什么原因造成的,我该如何解决?提前致谢。

这是第一对区域的坐标(我不能做第二对,因为它超过了 SO 最大体型):

50003VD24:

[[[-73.140484,43.025853],[-73.140489,43.025760999999996],[-73.143985,43.025862],[-73.155616,43.026199],[-73.15767199999999,43.026258999999996],[-73.1657,43.026483999999996],[-73.166195,43.026506999999995],[-73.16712799999999,43.026548999999996],[-73.168528,43.026633],[-73.179712,43.027173],[-73.185087,43.027432],[-73.215159,43.028815],[-73.22040799999999,43.029001],[-73.220833,43.029012],[-73.23498599999999,43.029317999999996],[-73.24955299999999,43.029632],[-73.27004099999999,43.030716],[-73.26977699999999,43.035976],[-73.269027,43.046808],[-73.268898,43.04866],[-73.268776,43.050466],[-73.268743,43.05094],[-73.268051,43.060764],[-73.266774,43.079485],[-73.26675,43.079834],[-73.26668,43.080805],[-73.26644399999999,43.084084999999995],[-73.266223,43.087157999999995],[-73.266171,43.087877],[-73.26617,43.087907],[-73.266168,43.087938],[-73.266164,43.087998],[-73.26612999999999,43.088468999999996],[-73.26559499999999,43.095926],[-73.265044,43.106100000000005],[-73.265041,43.106154],[-73.265031,43.106237],[-73.265029,43.106401],[-73.265025,43.106435],[-73.26491299999999,43.10859],[-73.26491299999999,43.108599],[-73.264546,43.115429999999996],[-73.264449,43.11653],[-73.26441299999999,43.117079],[-73.264062,43.123394999999995],[-73.258454,43.123340999999996],[-73.258014,43.123337],[-73.21382799999999,43.122195999999995],[-73.209248,43.121984],[-73.207358,43.122074],[-73.203341,43.122046],[-73.20006699999999,43.122022],[-73.186044,43.121634],[-73.183497,43.121604],[-73.13494899999999,43.120509999999996],[-73.135813,43.106108],[-73.135848,43.105492999999996],[-73.135859,43.105362],[-73.135854,43.105275999999996],[-73.135876,43.105050999999996],[-73.13596299999999,43.103215999999996],[-73.135986,43.102734999999996],[-73.136039,43.102275],[-73.13605,43.102117],[-73.136132,43.100569],[-73.136123,43.100184999999996],[-73.13612599999999,43.100017],[-73.136164,43.099171999999996],[-73.13618799999999,43.098577999999996],[-73.136186,43.098506],[-73.136185,43.098448999999995],[-73.136214,43.097862],[-73.136279,43.096447999999995],[-73.136956,43.08052],[-73.137168,43.078382],[-73.137579,43.074222999999996],[-73.138,43.069474],[-73.138119,43.068101999999996],[-73.13820199999999,43.068023],[-73.13829799999999,43.059404],[-73.138311,43.059095],[-73.138323,43.058820999999995],[-73.138469,43.05741],[-73.138881,43.053228999999995],[-73.138865,43.052948],[-73.13887299999999,43.052364],[-73.13974499999999,43.043381],[-73.139755,43.04314],[-73.13991,43.039459],[-73.140484,43.025853]]]

50003VDBEN1:

[[[-73.146357,42.932266],[-73.144481,42.959395],[-73.143258,42.976157],[-73.142329,42.988892],[-73.142322,42.989081],[-73.142403,42.990328],[-73.142372,42.992087999999995],[-73.141539,42.999627],[-73.141468,43.000265],[-73.14147299999999,43.000689],[-73.141065,43.002837],[-73.141364,43.012769],[-73.14133799999999,43.013380999999995],[-73.141291,43.01392],[-73.141273,43.014632],[-73.141155,43.015859999999996],[-73.140908,43.018293],[-73.14066199999999,43.02267],[-73.140489,43.025760999999996],[-73.140484,43.025853],[-73.13993599999999,43.025833],[-73.12487999999999,43.025358],[-73.100184,43.024569],[-73.08112899999999,43.023982],[-73.071707,43.023663],[-73.07143599999999,43.023657],[-73.065962,43.023468],[-73.048707,43.022887999999995],[-73.038615,43.02254],[-73.035809,43.022452],[-73.026265,43.022611999999995],[-73.01920299999999,43.022731],[-73.00832,43.022914],[-73.003005,43.023002999999996],[-73.00278899999999,43.023007],[-73.002796,43.022881999999996],[-73.00280699999999,43.022703],[-73.002859,43.021826],[-73.002883,43.021429],[-73.00358899999999,43.009718],[-73.004119,43.000077999999995],[-73.004389,42.99474],[-73.004865,42.986444],[-73.005386,42.97793],[-73.00561499999999,42.973275],[-73.00565399999999,42.973034999999996],[-73.00565499999999,42.973029],[-73.005656,42.973019],[-73.00565999999999,42.972995999999995],[-73.005678,42.972888],[-73.005681,42.972868999999996],[-73.005682,42.972863],[-73.00568799999999,42.972826999999995],[-73.005551,42.972705999999995],[-73.00544599999999,42.972577],[-73.00538499999999,42.972437],[-73.005378,42.972356],[-73.005376,42.972151],[-73.005388,42.971914999999996],[-73.005432,42.971804],[-73.00547999999999,42.971264999999995],[-73.005558,42.971101],[-73.00561499999999,42.970889],[-73.005628,42.970808999999996],[-73.005633,42.970698999999996],[-73.00562599999999,42.970593],[-73.005605,42.970476999999995],[-73.005552,42.970391],[-73.005473,42.970313999999995],[-73.00546,42.970304999999996],[-73.005347,42.970233],[-73.005307,42.970222],[-73.005287,42.970174],[-73.005281,42.97016],[-73.005269,42.970133],[-73.005253,42.970096],[-73.005254,42.970085],[-73.005263,42.970008],[-73.005348,42.969296],[-73.005361,42.969184],[-73.005617,42.96702],[-73.005641,42.966814],[-73.005663,42.966629999999995],[-73.005687,42.966423],[-73.006373,42.960622],[-73.006948,42.949627],[-73.00695999999999,42.949373],[-73.00698899999999,42.948778999999995],[-73.00699,42.948758999999995],[-73.006991,42.948754],[-73.006991,42.948747999999995],[-73.007058,42.947385],[-73.007082,42.946884],[-73.007088,42.946768999999996],[-73.00708999999999,42.946735],[-73.007091,42.946715],[-73.007091,42.946709999999996],[-73.007094,42.946641],[-73.00710699999999,42.946366],[-73.007172,42.945042],[-73.007182,42.944842],[-73.00733799999999,42.941679],[-73.007339,42.941659],[-73.007365,42.94113],[-73.007453,42.939357],[-73.007458,42.939276],[-73.00806299999999,42.930087],[-73.019301,42.93044],[-73.025137,42.930695],[-73.033309,42.930808],[-73.04326499999999,42.931058],[-73.057132,42.931433],[-73.066409,42.931664],[-73.074163,42.931908],[-73.07642,42.931926999999995],[-73.08343099999999,42.932072999999995],[-73.085196,42.932117999999996],[-73.087768,42.932182999999995],[-73.090474,42.932234],[-73.09658499999999,42.932401999999996],[-73.097189,42.932421],[-73.098923,42.932480999999996],[-73.099963,42.932513],[-73.102952,42.93253],[-73.106768,42.932646999999996],[-73.10946299999999,42.932693],[-73.110698,42.932682],[-73.114735,42.932662],[-73.12025299999999,42.932635999999995],[-73.120717,42.932632999999996],[-73.12468,42.93243],[-73.146357,42.932266]]]

您应该检查交叉点是 LineString 还是 MultiLineString