按多边形拆分折线并计算 Python 中的结果线长度
Splitting Polyline by Polygon and Calculating resultant line lengths in Python
我有一条 Google 编码多段线,我通过调用 Google 地图路线 API.
"apflIffec@lFgKdAfq@jQvo@f[||AzzAdmBx`@hsAfy@p\hwAkEv`Bhl@toA|s@ni@|sAnvAffDtOphAfvBdxAtd@htAhaCtsBzu@~bBt^Yrj@wT|U`T`NpuC~bAbeBtoAbeAfm@bTb`ArrA|~@d{Cxz@jwBth@xTne@r|@fp@vrClo@juArZpr@xq@|YngCyI|sE~lBfzBh`@~fAqFdu@TfR~WvThlA|Iv{An[jo@ht@vI|hBoAp|B}DrxAs}Ahp@gIdh@fb@lx@t}@jnAph@~cCoc@`|Buq@|gBdk@ls@`h@th@dfArTfgBkArwBdWjeBjt@n|@xiAdl@z|@iF`|Bk{Ah|B_y@~{Dqh@hzCt[t`DxfA|uAaGxaCkk@dwBsuAzpBas@fyBhJlyBrz@d{ApSlrAioAlmAk[p~A_@baCc{CphCmtCxfA}`E~bAwaGdq@mqBfi@kc@xaB{g@~cAkoAxzBu{BfsDpTdbBmHtpAcn@n_AjM`{@i`@vaAkPx}@j`@|l@vD~lAuVluAv@nrAtWv_CjvAhgAfZoDhwA~_@~uLtkBdcHfnBdgCjpCrs@tz@cAhvAyxAbV_\lHxPxd@~lDdbBrsDbd@t`C|m@z`D~q@z~E|lB`lH`d@`~DvbB`wGif@|oBnJpuBnfAzyCj_BteArx@|pAjk@hRzy@|}@rdBlpC|~@nfFkPvxAd\xjH~h@jhGwPvjJlw@pdK~|@dlBjwAre@zn@|hCjOpuH~|@lkF|dBl}D~fClbGbrAvhB|sA`b@jeB|pBla@tzAjDnrDcY|oBuG~oCp}@p|DfoAl|Cfd@`_D|nBx[nyCrgAtlBx|Cp}@xmAhuAzZdxBd_@nz@gRnaAu`@bvAn`@tdAp}@faA~AtlAyi@vx@`IzjCj~DptC~sDx`@duAhh@f`@daAbStzA`uApsB|uFlnCpzGf~A`gC|i@|_Cbd@t`Cvt@roAd_DnzC~vCr~DxcC|tBdmCbwDt{@jv@zw@sT`~@ePjdAjk@jyB|uDr{@vz@jhAfNl~CfPdcDb^teCzIzh@`r@nNtz@n_AbaB~zA`kDxmArbD~jAdmBleA~}EnaA~~Hfs@|fGvaAphDhgChkIp_AzzAr`B~yA`~AhpC~{@tZd`Agl@nqAud@rkAaNnnDic@rjBwEvrAy_@h`Adu@diB|`AjrCrsB`hAvh@fcAlBn`Btx@rsEpgDdnBfxBbrB`_BtgB|rA|pApNbv@k~Ad]cJ|a@xq@nkAgKjk@ji@kN~bAlNrqClKrpDlIr}BfIv^"
这条折线表示从北爱尔兰到爱尔兰共和国的行车路线。我需要计算北爱尔兰路线的距离(英里/公里)和爱尔兰共和国路线的距离。
我有一个北爱尔兰多边形边界的 GeoJSON 文件:
{
"type": "FeatureCollection",
"name": "northernIreland_5",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "featurecla": "Admin-0 country", "scalerank": 0, "LABELRANK": 2, "SOVEREIGNT": "United Kingdom", "SOV_A3": "GB1", "ADM0_DIF": 1, "LEVEL": 2, "TYPE": "Country", "ADMIN": "United Kingdom", "ADM0_A3": "GBR", "GEOU_DIF": 0, "GEOUNIT": "United Kingdom", "GU_A3": "GBR", "SU_DIF": 0, "SUBUNIT": "United Kingdom", "SU_A3": "GBR", "BRK_DIFF": 0, "NAME": "United Kingdom", "NAME_LONG": "United Kingdom", "BRK_A3": "GBR", "BRK_NAME": "United Kingdom", "BRK_GROUP": null, "ABBREV": "U.K.", "POSTAL": "GB", "FORMAL_EN": "United Kingdom of Great Britain and Northern Ireland", "FORMAL_FR": null, "NAME_CIAWF": "United Kingdom", "NOTE_ADM0": null, "NOTE_BRK": null, "NAME_SORT": "United Kingdom", "NAME_ALT": null, "MAPCOLOR7": 6, "MAPCOLOR8": 6, "MAPCOLOR9": 6, "MAPCOLOR13": 3, "POP_EST": 64769452, "POP_RANK": 16, "GDP_MD_EST": 2788000.0, "POP_YEAR": 2017, "LASTCENSUS": 2011, "GDP_YEAR": 2016, "ECONOMY": "1. Developed region: G7", "INCOME_GRP": "1. High income: OECD", "WIKIPEDIA": -99, "FIPS_10_": "UK", "ISO_A2": "GB", "ISO_A3": "GBR", "ISO_A3_EH": "GBR", "ISO_N3": "826", "UN_A3": "826", "WB_A2": "GB", "WB_A3": "GBR", "WOE_ID": -90, "WOE_ID_EH": 23424975, "WOE_NOTE": "Eh ID includes Channel Islands and Isle of Man. UK constituent countries of England (24554868), Wales (12578049), Scotland (12578048), and Northern Ireland (20070563).", "ADM0_A3_IS": "GBR", "ADM0_A3_US": "GBR", "ADM0_A3_UN": -99, "ADM0_A3_WB": -99, "CONTINENT": "Europe", "REGION_UN": "Europe", "SUBREGION": "Northern Europe", "REGION_WB": "Europe & Central Asia", "NAME_LEN": 14, "LONG_LEN": 14, "ABBREV_LEN": 4, "TINY": -99, "HOMEPART": 1, "MIN_ZOOM": 0.0, "MIN_LABEL": 1.7, "MAX_LABEL": 6.7, "NE_ID": 1159320713, "WIKIDATAID": "Q145", "NAME_AR": "المملكة المتحدة", "NAME_BN": "যুক্তরাজ্য", "NAME_DE": "Vereinigtes Königreich", "NAME_EN": "United Kingdom", "NAME_ES": "Reino Unido", "NAME_FR": "Royaume-Uni", "NAME_EL": "Ηνωμένο Βασίλειο", "NAME_HI": "यूनाइटेड किंगडम", "NAME_HU": "Egyesült Királyság", "NAME_ID": "Britania Raya", "NAME_IT": "Regno Unito", "NAME_JA": "イギリス", "NAME_KO": "영국", "NAME_NL": "Verenigd Koninkrijk", "NAME_PL": "Wielka Brytania", "NAME_PT": "Reino Unido", "NAME_RU": "Великобритания", "NAME_SV": "Storbritannien", "NAME_TR": "Birleşik Krallık", "NAME_VI": "Vương quốc Liên hiệp Anh và Bắc Ireland", "NAME_ZH": "英国" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -7.2471, 55.06932 ], [ -7.25674, 55.05069 ], [ -7.24096, 55.05028 ], [ -7.19542, 55.05805 ], [ -7.17748, 55.05695 ], [ -7.1339, 55.04385 ], [ -7.09948, 55.04096 ], [ -7.06505, 55.04385 ], [ -7.0537, 55.04873 ], [ -7.03189, 55.06493 ], [ -7.0172, 55.07111 ], [ -7.01781, 55.08397 ], [ -7.00992, 55.10224 ], [ -6.99795, 55.11864 ], [ -6.98648, 55.12572 ], [ -6.97492, 55.13544 ], [ -6.96866, 55.18065 ], [ -6.96255, 55.19465 ], [ -6.94669, 55.19538 ], [ -6.90355, 55.17866 ], [ -6.88378, 55.17414 ], [ -6.75451, 55.1778 ], [ -6.64045, 55.20832 ], [ -6.57128, 55.21125 ], [ -6.55451, 55.21857 ], [ -6.53917, 55.23066 ], [ -6.51985, 55.24067 ], [ -6.49812, 55.24714 ], [ -6.47594, 55.24868 ], [ -6.44001, 55.23603 ], [ -6.41592, 55.23188 ], [ -6.37816, 55.24624 ], [ -6.35289, 55.24262 ], [ -6.25585, 55.21088 ], [ -6.23982, 55.20832 ], [ -6.21764, 55.21039 ], [ -6.17955, 55.21971 ], [ -6.16002, 55.22191 ], [ -6.12084, 55.21784 ], [ -6.10098, 55.21239 ], [ -6.0924, 55.2049 ], [ -6.08422, 55.20222 ], [ -6.04723, 55.17853 ], [ -6.0371, 55.16791 ], [ -6.04064, 55.11205 ], [ -6.04743, 55.09565 ], [ -6.06208, 55.07412 ], [ -6.05435, 55.06513 ], [ -6.03539, 55.06363 ], [ -6.01667, 55.06428 ], [ -6.00353, 55.06318 ], [ -5.98868, 55.05948 ], [ -5.97574, 55.05305 ], [ -5.96825, 55.04385 ], [ -5.9702, 55.02582 ], [ -5.98827, 54.98867 ], [ -5.98624, 54.98176 ], [ -5.95714, 54.97895 ], [ -5.93033, 54.97089 ], [ -5.90661, 54.95795 ], [ -5.88634, 54.94082 ], [ -5.88199, 54.93403 ], [ -5.87523, 54.91791 ], [ -5.86925, 54.91039 ], [ -5.86278, 54.90595 ], [ -5.84704, 54.89814 ], [ -5.83918, 54.89301 ], [ -5.82999, 54.88516 ], [ -5.82095, 54.87507 ], [ -5.81395, 54.86278 ], [ -5.81119, 54.84833 ], [ -5.80053, 54.82075 ], [ -5.77526, 54.81151 ], [ -5.74559, 54.80459 ], [ -5.72183, 54.78376 ], [ -5.71565, 54.78376 ], [ -5.73375, 54.80524 ], [ -5.7976, 54.84455 ], [ -5.78173, 54.86172 ], [ -5.75162, 54.85688 ], [ -5.72061, 54.84101 ], [ -5.70198, 54.82469 ], [ -5.68985, 54.79312 ], [ -5.69262, 54.7652 ], [ -5.7069, 54.74299 ], [ -5.72932, 54.7285 ], [ -5.7589, 54.71992 ], [ -5.81843, 54.70962 ], [ -5.84537, 54.70124 ], [ -5.87149, 54.68732 ], [ -5.89074, 54.67231 ], [ -5.91434, 54.64684 ], [ -5.92724, 54.63296 ], [ -5.91515, 54.62824 ], [ -5.91096, 54.61945 ], [ -5.90998, 54.61054 ], [ -5.90738, 54.60562 ], [ -5.89489, 54.6048 ], [ -5.88728, 54.60981 ], [ -5.88199, 54.61616 ], [ -5.871, 54.6223 ], [ -5.84878, 54.64322 ], [ -5.83902, 54.64973 ], [ -5.80382, 54.65961 ], [ -5.76952, 54.67463 ], [ -5.74795, 54.68041 ], [ -5.73241, 54.67699 ], [ -5.71662, 54.66987 ], [ -5.69469, 54.66869 ], [ -5.5747, 54.68008 ], [ -5.569, 54.67695 ], [ -5.55671, 54.66279 ], [ -5.54711, 54.65961 ], [ -5.53661, 54.65746 ], [ -5.53327, 54.65168 ], [ -5.53279, 54.64322 ], [ -5.5301, 54.63296 ], [ -5.51439, 54.59789 ], [ -5.50255, 54.58348 ], [ -5.48571, 54.5777 ], [ -5.47891, 54.56948 ], [ -5.47289, 54.5301 ], [ -5.46862, 54.51626 ], [ -5.43708, 54.48786 ], [ -5.43078, 54.48517 ], [ -5.43757, 54.47565 ], [ -5.43651, 54.4702 ], [ -5.43346, 54.46625 ], [ -5.43383, 54.461 ], [ -5.43883, 54.4549 ], [ -5.45812, 54.4374 ], [ -5.46426, 54.42524 ], [ -5.45739, 54.40868 ], [ -5.46117, 54.39208 ], [ -5.47086, 54.38434 ], [ -5.484, 54.37759 ], [ -5.48913, 54.36957 ], [ -5.47484, 54.35859 ], [ -5.48957, 54.35371 ], [ -5.50202, 54.33967 ], [ -5.51578, 54.33808 ], [ -5.52766, 54.34528 ], [ -5.53698, 54.35928 ], [ -5.54711, 54.3791 ], [ -5.55899, 54.38264 ], [ -5.56949, 54.39151 ], [ -5.57665, 54.40278 ], [ -5.57844, 54.4138 ], [ -5.57169, 54.4256 ], [ -5.5487, 54.44282 ], [ -5.54369, 54.45783 ], [ -5.54735, 54.48908 ], [ -5.55801, 54.51191 ], [ -5.57531, 54.529 ], [ -5.64489, 54.56778 ], [ -5.67186, 54.57681 ], [ -5.70198, 54.5777 ], [ -5.70198, 54.57079 ], [ -5.69465, 54.5611 ], [ -5.69742, 54.55121 ], [ -5.70604, 54.54267 ], [ -5.71565, 54.53669 ], [ -5.70153, 54.53632 ], [ -5.69042, 54.53205 ], [ -5.68151, 54.52684 ], [ -5.67406, 54.52367 ], [ -5.63695, 54.52204 ], [ -5.6256, 54.51626 ], [ -5.64192, 54.51264 ], [ -5.66393, 54.5102 ], [ -5.67032, 54.50568 ], [ -5.63996, 54.49575 ], [ -5.64476, 54.48371 ], [ -5.6446, 54.47211 ], [ -5.6385, 54.46357 ], [ -5.6256, 54.461 ], [ -5.6267, 54.45669 ], [ -5.628, 54.4538 ], [ -5.63313, 54.44733 ], [ -5.6256, 54.44111 ], [ -5.65355, 54.38898 ], [ -5.66145, 54.37958 ], [ -5.69791, 54.36229 ], [ -5.70885, 54.35175 ], [ -5.66832, 54.36066 ], [ -5.62214, 54.37665 ], [ -5.5797, 54.38369 ], [ -5.55053, 54.36542 ], [ -5.54068, 54.32734 ], [ -5.55305, 54.29853 ], [ -5.5795, 54.2757 ], [ -5.61262, 54.25556 ], [ -5.61718, 54.25479 ], [ -5.62853, 54.25654 ], [ -5.63313, 54.25556 ], [ -5.63996, 54.23505 ], [ -5.64684, 54.23216 ], [ -5.65575, 54.22968 ], [ -5.6634, 54.23086 ], [ -5.66666, 54.23884 ], [ -5.67882, 54.24616 ], [ -5.73689, 54.24909 ], [ -5.77945, 54.24653 ], [ -5.82266, 54.23721 ], [ -5.84227, 54.23505 ], [ -5.86205, 54.23054 ], [ -5.86803, 54.21849 ], [ -5.86604, 54.18415 ], [ -5.86583, 54.18049 ], [ -5.86852, 54.16132 ], [ -5.87462, 54.14053 ], [ -5.88321, 54.12075 ], [ -5.89379, 54.10468 ], [ -5.91198, 54.09129 ], [ -5.95385, 54.07868 ], [ -5.98473, 54.05931 ], [ -6.02725, 54.04023 ], [ -6.04052, 54.03644 ], [ -6.07958, 54.03457 ], [ -6.09545, 54.03636 ], [ -6.1129, 54.04389 ], [ -6.1129, 54.05012 ], [ -6.09301, 54.05589 ], [ -6.08495, 54.05695 ], [ -6.16153, 54.07372 ], [ -6.17431, 54.07429 ], [ -6.18586, 54.09268 ], [ -6.21255, 54.09846 ], [ -6.2425, 54.09976 ], [ -6.26366, 54.10468 ], [ -6.26989, 54.09789 ], [ -6.28465, 54.10523 ], [ -6.29958, 54.10404 ], [ -6.3138, 54.0997 ], [ -6.32713, 54.09789 ], [ -6.33896, 54.10295 ], [ -6.34666, 54.10988 ], [ -6.35483, 54.11065 ], [ -6.36811, 54.09732 ], [ -6.36935, 54.09112 ], [ -6.36764, 54.08342 ], [ -6.36692, 54.0751 ], [ -6.37116, 54.06678 ], [ -6.37751, 54.06326 ], [ -6.40103, 54.06089 ], [ -6.42676, 54.05541 ], [ -6.43389, 54.05531 ], [ -6.4403, 54.05799 ], [ -6.44624, 54.06244 ], [ -6.45022, 54.06668 ], [ -6.45089, 54.06843 ], [ -6.47854, 54.06771 ], [ -6.56401, 54.04895 ], [ -6.57187, 54.04952 ], [ -6.58716, 54.05334 ], [ -6.59507, 54.05241 ], [ -6.60029, 54.04895 ], [ -6.60522, 54.04448 ], [ -6.61099, 54.03923 ], [ -6.61646, 54.03727 ], [ -6.63062, 54.04182 ], [ -6.65729, 54.06115 ], [ -6.67253, 54.06843 ], [ -6.65708, 54.09194 ], [ -6.65579, 54.10331 ], [ -6.66644, 54.11479 ], [ -6.64396, 54.13184 ], [ -6.63455, 54.15013 ], [ -6.64034, 54.16801 ], [ -6.64845, 54.17366 ], [ -6.66303, 54.18383 ], [ -6.68395, 54.19437 ], [ -6.69465, 54.19798 ], [ -6.70654, 54.19892 ], [ -6.71723, 54.19514 ], [ -6.72478, 54.18863 ], [ -6.73284, 54.18357 ], [ -6.74478, 54.18419 ], [ -6.76648, 54.19235 ], [ -6.78782, 54.203 ], [ -6.80736, 54.21633 ], [ -6.82395, 54.23235 ], [ -6.82973, 54.24237 ], [ -6.8332, 54.25209 ], [ -6.83774, 54.26051 ], [ -6.84668, 54.26646 ], [ -6.88219, 54.27726 ], [ -6.86467, 54.28273 ], [ -6.85666, 54.29281 ], [ -6.85841, 54.30733 ], [ -6.87001, 54.326 ], [ -6.8797, 54.34159 ], [ -6.88596, 54.34562 ], [ -6.89789, 54.34619 ], [ -6.90596, 54.34904 ], [ -6.91505, 54.36593 ], [ -6.92203, 54.3727 ], [ -6.98409, 54.40309 ], [ -7.01784, 54.41317 ], [ -7.04925, 54.41151 ], [ -7.0785, 54.39472 ], [ -7.12703, 54.34976 ], [ -7.15989, 54.33519 ], [ -7.16806, 54.33503 ], [ -7.18563, 54.33694 ], [ -7.18947, 54.33569 ], [ -7.19245, 54.33472 ], [ -7.19395, 54.32997 ], [ -7.19147, 54.32387 ], [ -7.18764, 54.3188 ], [ -7.18501, 54.31725 ], [ -7.18465, 54.31663 ], [ -7.1924, 54.30738 ], [ -7.19369, 54.30754 ], [ -7.19917, 54.30346 ], [ -7.20666, 54.3049 ], [ -7.21147, 54.30418 ], [ -7.20904, 54.29343 ], [ -7.1755, 54.28366 ], [ -7.18149, 54.26976 ], [ -7.14589, 54.25209 ], [ -7.15974, 54.24067 ], [ -7.15333, 54.22424 ], [ -7.17473, 54.21607 ], [ -7.2295, 54.20755 ], [ -7.24087, 54.20233 ], [ -7.24909, 54.19742 ], [ -7.2555, 54.19085 ], [ -7.26113, 54.18088 ], [ -7.25632, 54.1769 ], [ -7.24702, 54.17225 ], [ -7.24578, 54.16698 ], [ -7.26537, 54.16114 ], [ -7.26087, 54.15117 ], [ -7.26351, 54.14099 ], [ -7.27074, 54.13225 ], [ -7.28004, 54.12615 ], [ -7.29379, 54.12202 ], [ -7.29735, 54.1259 ], [ -7.29632, 54.13499 ], [ -7.29642, 54.14652 ], [ -7.29503, 54.1554 ], [ -7.29213, 54.16264 ], [ -7.29554, 54.16512 ], [ -7.32598, 54.15458 ], [ -7.33317, 54.14941 ], [ -7.33317, 54.14274 ], [ -7.31032, 54.11468 ], [ -7.31649, 54.11428 ], [ -7.32696, 54.1136 ], [ -7.37549, 54.12331 ], [ -7.39022, 54.12119 ], [ -7.39466, 54.12192 ], [ -7.39662, 54.12626 ], [ -7.40396, 54.13504 ], [ -7.41223, 54.13644 ], [ -7.42226, 54.13546 ], [ -7.42577, 54.13696 ], [ -7.41466, 54.14569 ], [ -7.43962, 54.14693 ], [ -7.48075, 54.12765 ], [ -7.5023, 54.12512 ], [ -7.60901, 54.1399 ], [ -7.6208, 54.14496 ], [ -7.62405, 54.15334 ], [ -7.62571, 54.16217 ], [ -7.63268, 54.16853 ], [ -7.70477, 54.20036 ], [ -7.7226, 54.20233 ], [ -7.78208, 54.2 ], [ -7.83696, 54.20434 ], [ -7.85644, 54.21142 ], [ -7.86967, 54.22687 ], [ -7.87365, 54.27106 ], [ -7.88026, 54.28702 ], [ -7.89497, 54.29359 ], [ -7.93411, 54.29705 ], [ -7.94207, 54.29887 ], [ -7.9508, 54.30087 ], [ -7.96801, 54.31219 ], [ -7.98103, 54.32656 ], [ -8.00219, 54.35792 ], [ -8.03134, 54.35803 ], [ -8.05648, 54.36588 ], [ -8.07994, 54.3802 ], [ -8.12242, 54.41523 ], [ -8.14635, 54.43074 ], [ -8.15603, 54.43906 ], [ -8.15813, 54.44712 ], [ -8.16118, 54.45482 ], [ -8.17384, 54.46174 ], [ -8.16847, 54.46348 ], [ -8.15017, 54.46939 ], [ -8.09705, 54.47859 ], [ -8.07245, 54.48706 ], [ -8.06098, 54.49332 ], [ -8.05586, 54.49755 ], [ -8.04356, 54.51223 ], [ -8.02328, 54.5297 ], [ -8.00219, 54.54344 ], [ -7.92641, 54.53305 ], [ -7.88714, 54.53212 ], [ -7.84884, 54.54091 ], [ -7.74926, 54.59615 ], [ -7.70787, 54.60416 ], [ -7.70795, 54.60476 ], [ -7.71056, 54.62426 ], [ -7.7212, 54.62587 ], [ -7.73676, 54.61925 ], [ -7.75355, 54.6145 ], [ -7.76916, 54.61801 ], [ -7.8012, 54.63481 ], [ -7.815, 54.63946 ], [ -7.82254, 54.63811 ], [ -7.83804, 54.63124 ], [ -7.84642, 54.63145 ], [ -7.85427, 54.63641 ], [ -7.86435, 54.64907 ], [ -7.87277, 54.65222 ], [ -7.89008, 54.65506 ], [ -7.90662, 54.66132 ], [ -7.91484, 54.67165 ], [ -7.90714, 54.68669 ], [ -7.91323, 54.68865 ], [ -7.92967, 54.69671 ], [ -7.88011, 54.71103 ], [ -7.8459, 54.73103 ], [ -7.83215, 54.73061 ], [ -7.80358, 54.71614 ], [ -7.7705, 54.70602 ], [ -7.7366, 54.70746 ], [ -7.70229, 54.71888 ], [ -7.66751, 54.73878 ], [ -7.64968, 54.74488 ], [ -7.61537, 54.73935 ], [ -7.5854, 54.74472 ], [ -7.56664, 54.73868 ], [ -7.55615, 54.73837 ], [ -7.54307, 54.74167 ], [ -7.54302, 54.74379 ], [ -7.5484, 54.7472 ], [ -7.5517, 54.7547 ], [ -7.54974, 54.7796 ], [ -7.54338, 54.79309 ], [ -7.47083, 54.84528 ], [ -7.45507, 54.86301 ], [ -7.44473, 54.88445 ], [ -7.44473, 54.89489 ], [ -7.44897, 54.92032 ], [ -7.44525, 54.93215 ], [ -7.43698, 54.9383 ], [ -7.41714, 54.94306 ], [ -7.41576, 54.94437 ], [ -7.40866, 54.95112 ], [ -7.40742, 54.95944 ], [ -7.41311, 54.98497 ], [ -7.40908, 54.99204 ], [ -7.40376, 54.99313 ], [ -7.40112, 54.99484 ], [ -7.40525, 55.00357 ], [ -7.37699, 55.02889 ], [ -7.36696, 55.03556 ], [ -7.35502, 55.04093 ], [ -7.29115, 55.04662 ], [ -7.28299, 55.05183 ], [ -7.27529, 55.05886 ], [ -7.2665, 55.06517 ], [ -7.2471, 55.06932 ] ] ] } }
]
}
我可以访问任何 Python 库,包括 Geopandas 和 Shapely。
我需要将这些项目转换成什么数据结构,我需要使用什么空间函数来计算多边形内外线的长度?
编辑:
请参阅下面的答案。
然后我使用以下代码计算了距离(英国国家电网)。
from pyproj import Proj, Transformer
import shapely.ops as sp_ops
my_transformer = Transformer.from_crs('EPSG:4326', 'EPSG:27700', always_xy=True)
#Route in KM rounded to 2 decimal places
routeLength = round(sp_ops.transform(my_transformer.transform, route).length/1000,2)
使用 Shapely(参见 documentation),您可以使用 class Polygon
表示多边形,并使用 LineString
.
表示折线
那么,相交的长度就很容易计算了,例如:
total = road_linestring.length
inside = road_linestring.intersection(ni_poly).length
print("Length of road in Northern Ireland is", inside)
print("Length of road outside Northern Ireland is", total - inside)
我有一条 Google 编码多段线,我通过调用 Google 地图路线 API.
"apflIffec@lFgKdAfq@jQvo@f[||AzzAdmBx`@hsAfy@p\hwAkEv`Bhl@toA|s@ni@|sAnvAffDtOphAfvBdxAtd@htAhaCtsBzu@~bBt^Yrj@wT|U`T`NpuC~bAbeBtoAbeAfm@bTb`ArrA|~@d{Cxz@jwBth@xTne@r|@fp@vrClo@juArZpr@xq@|YngCyI|sE~lBfzBh`@~fAqFdu@TfR~WvThlA|Iv{An[jo@ht@vI|hBoAp|B}DrxAs}Ahp@gIdh@fb@lx@t}@jnAph@~cCoc@`|Buq@|gBdk@ls@`h@th@dfArTfgBkArwBdWjeBjt@n|@xiAdl@z|@iF`|Bk{Ah|B_y@~{Dqh@hzCt[t`DxfA|uAaGxaCkk@dwBsuAzpBas@fyBhJlyBrz@d{ApSlrAioAlmAk[p~A_@baCc{CphCmtCxfA}`E~bAwaGdq@mqBfi@kc@xaB{g@~cAkoAxzBu{BfsDpTdbBmHtpAcn@n_AjM`{@i`@vaAkPx}@j`@|l@vD~lAuVluAv@nrAtWv_CjvAhgAfZoDhwA~_@~uLtkBdcHfnBdgCjpCrs@tz@cAhvAyxAbV_\lHxPxd@~lDdbBrsDbd@t`C|m@z`D~q@z~E|lB`lH`d@`~DvbB`wGif@|oBnJpuBnfAzyCj_BteArx@|pAjk@hRzy@|}@rdBlpC|~@nfFkPvxAd\xjH~h@jhGwPvjJlw@pdK~|@dlBjwAre@zn@|hCjOpuH~|@lkF|dBl}D~fClbGbrAvhB|sA`b@jeB|pBla@tzAjDnrDcY|oBuG~oCp}@p|DfoAl|Cfd@`_D|nBx[nyCrgAtlBx|Cp}@xmAhuAzZdxBd_@nz@gRnaAu`@bvAn`@tdAp}@faA~AtlAyi@vx@`IzjCj~DptC~sDx`@duAhh@f`@daAbStzA`uApsB|uFlnCpzGf~A`gC|i@|_Cbd@t`Cvt@roAd_DnzC~vCr~DxcC|tBdmCbwDt{@jv@zw@sT`~@ePjdAjk@jyB|uDr{@vz@jhAfNl~CfPdcDb^teCzIzh@`r@nNtz@n_AbaB~zA`kDxmArbD~jAdmBleA~}EnaA~~Hfs@|fGvaAphDhgChkIp_AzzAr`B~yA`~AhpC~{@tZd`Agl@nqAud@rkAaNnnDic@rjBwEvrAy_@h`Adu@diB|`AjrCrsB`hAvh@fcAlBn`Btx@rsEpgDdnBfxBbrB`_BtgB|rA|pApNbv@k~Ad]cJ|a@xq@nkAgKjk@ji@kN~bAlNrqClKrpDlIr}BfIv^"
这条折线表示从北爱尔兰到爱尔兰共和国的行车路线。我需要计算北爱尔兰路线的距离(英里/公里)和爱尔兰共和国路线的距离。
我有一个北爱尔兰多边形边界的 GeoJSON 文件:
{
"type": "FeatureCollection",
"name": "northernIreland_5",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "featurecla": "Admin-0 country", "scalerank": 0, "LABELRANK": 2, "SOVEREIGNT": "United Kingdom", "SOV_A3": "GB1", "ADM0_DIF": 1, "LEVEL": 2, "TYPE": "Country", "ADMIN": "United Kingdom", "ADM0_A3": "GBR", "GEOU_DIF": 0, "GEOUNIT": "United Kingdom", "GU_A3": "GBR", "SU_DIF": 0, "SUBUNIT": "United Kingdom", "SU_A3": "GBR", "BRK_DIFF": 0, "NAME": "United Kingdom", "NAME_LONG": "United Kingdom", "BRK_A3": "GBR", "BRK_NAME": "United Kingdom", "BRK_GROUP": null, "ABBREV": "U.K.", "POSTAL": "GB", "FORMAL_EN": "United Kingdom of Great Britain and Northern Ireland", "FORMAL_FR": null, "NAME_CIAWF": "United Kingdom", "NOTE_ADM0": null, "NOTE_BRK": null, "NAME_SORT": "United Kingdom", "NAME_ALT": null, "MAPCOLOR7": 6, "MAPCOLOR8": 6, "MAPCOLOR9": 6, "MAPCOLOR13": 3, "POP_EST": 64769452, "POP_RANK": 16, "GDP_MD_EST": 2788000.0, "POP_YEAR": 2017, "LASTCENSUS": 2011, "GDP_YEAR": 2016, "ECONOMY": "1. Developed region: G7", "INCOME_GRP": "1. High income: OECD", "WIKIPEDIA": -99, "FIPS_10_": "UK", "ISO_A2": "GB", "ISO_A3": "GBR", "ISO_A3_EH": "GBR", "ISO_N3": "826", "UN_A3": "826", "WB_A2": "GB", "WB_A3": "GBR", "WOE_ID": -90, "WOE_ID_EH": 23424975, "WOE_NOTE": "Eh ID includes Channel Islands and Isle of Man. UK constituent countries of England (24554868), Wales (12578049), Scotland (12578048), and Northern Ireland (20070563).", "ADM0_A3_IS": "GBR", "ADM0_A3_US": "GBR", "ADM0_A3_UN": -99, "ADM0_A3_WB": -99, "CONTINENT": "Europe", "REGION_UN": "Europe", "SUBREGION": "Northern Europe", "REGION_WB": "Europe & Central Asia", "NAME_LEN": 14, "LONG_LEN": 14, "ABBREV_LEN": 4, "TINY": -99, "HOMEPART": 1, "MIN_ZOOM": 0.0, "MIN_LABEL": 1.7, "MAX_LABEL": 6.7, "NE_ID": 1159320713, "WIKIDATAID": "Q145", "NAME_AR": "المملكة المتحدة", "NAME_BN": "যুক্তরাজ্য", "NAME_DE": "Vereinigtes Königreich", "NAME_EN": "United Kingdom", "NAME_ES": "Reino Unido", "NAME_FR": "Royaume-Uni", "NAME_EL": "Ηνωμένο Βασίλειο", "NAME_HI": "यूनाइटेड किंगडम", "NAME_HU": "Egyesült Királyság", "NAME_ID": "Britania Raya", "NAME_IT": "Regno Unito", "NAME_JA": "イギリス", "NAME_KO": "영국", "NAME_NL": "Verenigd Koninkrijk", "NAME_PL": "Wielka Brytania", "NAME_PT": "Reino Unido", "NAME_RU": "Великобритания", "NAME_SV": "Storbritannien", "NAME_TR": "Birleşik Krallık", "NAME_VI": "Vương quốc Liên hiệp Anh và Bắc Ireland", "NAME_ZH": "英国" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -7.2471, 55.06932 ], [ -7.25674, 55.05069 ], [ -7.24096, 55.05028 ], [ -7.19542, 55.05805 ], [ -7.17748, 55.05695 ], [ -7.1339, 55.04385 ], [ -7.09948, 55.04096 ], [ -7.06505, 55.04385 ], [ -7.0537, 55.04873 ], [ -7.03189, 55.06493 ], [ -7.0172, 55.07111 ], [ -7.01781, 55.08397 ], [ -7.00992, 55.10224 ], [ -6.99795, 55.11864 ], [ -6.98648, 55.12572 ], [ -6.97492, 55.13544 ], [ -6.96866, 55.18065 ], [ -6.96255, 55.19465 ], [ -6.94669, 55.19538 ], [ -6.90355, 55.17866 ], [ -6.88378, 55.17414 ], [ -6.75451, 55.1778 ], [ -6.64045, 55.20832 ], [ -6.57128, 55.21125 ], [ -6.55451, 55.21857 ], [ -6.53917, 55.23066 ], [ -6.51985, 55.24067 ], [ -6.49812, 55.24714 ], [ -6.47594, 55.24868 ], [ -6.44001, 55.23603 ], [ -6.41592, 55.23188 ], [ -6.37816, 55.24624 ], [ -6.35289, 55.24262 ], [ -6.25585, 55.21088 ], [ -6.23982, 55.20832 ], [ -6.21764, 55.21039 ], [ -6.17955, 55.21971 ], [ -6.16002, 55.22191 ], [ -6.12084, 55.21784 ], [ -6.10098, 55.21239 ], [ -6.0924, 55.2049 ], [ -6.08422, 55.20222 ], [ -6.04723, 55.17853 ], [ -6.0371, 55.16791 ], [ -6.04064, 55.11205 ], [ -6.04743, 55.09565 ], [ -6.06208, 55.07412 ], [ -6.05435, 55.06513 ], [ -6.03539, 55.06363 ], [ -6.01667, 55.06428 ], [ -6.00353, 55.06318 ], [ -5.98868, 55.05948 ], [ -5.97574, 55.05305 ], [ -5.96825, 55.04385 ], [ -5.9702, 55.02582 ], [ -5.98827, 54.98867 ], [ -5.98624, 54.98176 ], [ -5.95714, 54.97895 ], [ -5.93033, 54.97089 ], [ -5.90661, 54.95795 ], [ -5.88634, 54.94082 ], [ -5.88199, 54.93403 ], [ -5.87523, 54.91791 ], [ -5.86925, 54.91039 ], [ -5.86278, 54.90595 ], [ -5.84704, 54.89814 ], [ -5.83918, 54.89301 ], [ -5.82999, 54.88516 ], [ -5.82095, 54.87507 ], [ -5.81395, 54.86278 ], [ -5.81119, 54.84833 ], [ -5.80053, 54.82075 ], [ -5.77526, 54.81151 ], [ -5.74559, 54.80459 ], [ -5.72183, 54.78376 ], [ -5.71565, 54.78376 ], [ -5.73375, 54.80524 ], [ -5.7976, 54.84455 ], [ -5.78173, 54.86172 ], [ -5.75162, 54.85688 ], [ -5.72061, 54.84101 ], [ -5.70198, 54.82469 ], [ -5.68985, 54.79312 ], [ -5.69262, 54.7652 ], [ -5.7069, 54.74299 ], [ -5.72932, 54.7285 ], [ -5.7589, 54.71992 ], [ -5.81843, 54.70962 ], [ -5.84537, 54.70124 ], [ -5.87149, 54.68732 ], [ -5.89074, 54.67231 ], [ -5.91434, 54.64684 ], [ -5.92724, 54.63296 ], [ -5.91515, 54.62824 ], [ -5.91096, 54.61945 ], [ -5.90998, 54.61054 ], [ -5.90738, 54.60562 ], [ -5.89489, 54.6048 ], [ -5.88728, 54.60981 ], [ -5.88199, 54.61616 ], [ -5.871, 54.6223 ], [ -5.84878, 54.64322 ], [ -5.83902, 54.64973 ], [ -5.80382, 54.65961 ], [ -5.76952, 54.67463 ], [ -5.74795, 54.68041 ], [ -5.73241, 54.67699 ], [ -5.71662, 54.66987 ], [ -5.69469, 54.66869 ], [ -5.5747, 54.68008 ], [ -5.569, 54.67695 ], [ -5.55671, 54.66279 ], [ -5.54711, 54.65961 ], [ -5.53661, 54.65746 ], [ -5.53327, 54.65168 ], [ -5.53279, 54.64322 ], [ -5.5301, 54.63296 ], [ -5.51439, 54.59789 ], [ -5.50255, 54.58348 ], [ -5.48571, 54.5777 ], [ -5.47891, 54.56948 ], [ -5.47289, 54.5301 ], [ -5.46862, 54.51626 ], [ -5.43708, 54.48786 ], [ -5.43078, 54.48517 ], [ -5.43757, 54.47565 ], [ -5.43651, 54.4702 ], [ -5.43346, 54.46625 ], [ -5.43383, 54.461 ], [ -5.43883, 54.4549 ], [ -5.45812, 54.4374 ], [ -5.46426, 54.42524 ], [ -5.45739, 54.40868 ], [ -5.46117, 54.39208 ], [ -5.47086, 54.38434 ], [ -5.484, 54.37759 ], [ -5.48913, 54.36957 ], [ -5.47484, 54.35859 ], [ -5.48957, 54.35371 ], [ -5.50202, 54.33967 ], [ -5.51578, 54.33808 ], [ -5.52766, 54.34528 ], [ -5.53698, 54.35928 ], [ -5.54711, 54.3791 ], [ -5.55899, 54.38264 ], [ -5.56949, 54.39151 ], [ -5.57665, 54.40278 ], [ -5.57844, 54.4138 ], [ -5.57169, 54.4256 ], [ -5.5487, 54.44282 ], [ -5.54369, 54.45783 ], [ -5.54735, 54.48908 ], [ -5.55801, 54.51191 ], [ -5.57531, 54.529 ], [ -5.64489, 54.56778 ], [ -5.67186, 54.57681 ], [ -5.70198, 54.5777 ], [ -5.70198, 54.57079 ], [ -5.69465, 54.5611 ], [ -5.69742, 54.55121 ], [ -5.70604, 54.54267 ], [ -5.71565, 54.53669 ], [ -5.70153, 54.53632 ], [ -5.69042, 54.53205 ], [ -5.68151, 54.52684 ], [ -5.67406, 54.52367 ], [ -5.63695, 54.52204 ], [ -5.6256, 54.51626 ], [ -5.64192, 54.51264 ], [ -5.66393, 54.5102 ], [ -5.67032, 54.50568 ], [ -5.63996, 54.49575 ], [ -5.64476, 54.48371 ], [ -5.6446, 54.47211 ], [ -5.6385, 54.46357 ], [ -5.6256, 54.461 ], [ -5.6267, 54.45669 ], [ -5.628, 54.4538 ], [ -5.63313, 54.44733 ], [ -5.6256, 54.44111 ], [ -5.65355, 54.38898 ], [ -5.66145, 54.37958 ], [ -5.69791, 54.36229 ], [ -5.70885, 54.35175 ], [ -5.66832, 54.36066 ], [ -5.62214, 54.37665 ], [ -5.5797, 54.38369 ], [ -5.55053, 54.36542 ], [ -5.54068, 54.32734 ], [ -5.55305, 54.29853 ], [ -5.5795, 54.2757 ], [ -5.61262, 54.25556 ], [ -5.61718, 54.25479 ], [ -5.62853, 54.25654 ], [ -5.63313, 54.25556 ], [ -5.63996, 54.23505 ], [ -5.64684, 54.23216 ], [ -5.65575, 54.22968 ], [ -5.6634, 54.23086 ], [ -5.66666, 54.23884 ], [ -5.67882, 54.24616 ], [ -5.73689, 54.24909 ], [ -5.77945, 54.24653 ], [ -5.82266, 54.23721 ], [ -5.84227, 54.23505 ], [ -5.86205, 54.23054 ], [ -5.86803, 54.21849 ], [ -5.86604, 54.18415 ], [ -5.86583, 54.18049 ], [ -5.86852, 54.16132 ], [ -5.87462, 54.14053 ], [ -5.88321, 54.12075 ], [ -5.89379, 54.10468 ], [ -5.91198, 54.09129 ], [ -5.95385, 54.07868 ], [ -5.98473, 54.05931 ], [ -6.02725, 54.04023 ], [ -6.04052, 54.03644 ], [ -6.07958, 54.03457 ], [ -6.09545, 54.03636 ], [ -6.1129, 54.04389 ], [ -6.1129, 54.05012 ], [ -6.09301, 54.05589 ], [ -6.08495, 54.05695 ], [ -6.16153, 54.07372 ], [ -6.17431, 54.07429 ], [ -6.18586, 54.09268 ], [ -6.21255, 54.09846 ], [ -6.2425, 54.09976 ], [ -6.26366, 54.10468 ], [ -6.26989, 54.09789 ], [ -6.28465, 54.10523 ], [ -6.29958, 54.10404 ], [ -6.3138, 54.0997 ], [ -6.32713, 54.09789 ], [ -6.33896, 54.10295 ], [ -6.34666, 54.10988 ], [ -6.35483, 54.11065 ], [ -6.36811, 54.09732 ], [ -6.36935, 54.09112 ], [ -6.36764, 54.08342 ], [ -6.36692, 54.0751 ], [ -6.37116, 54.06678 ], [ -6.37751, 54.06326 ], [ -6.40103, 54.06089 ], [ -6.42676, 54.05541 ], [ -6.43389, 54.05531 ], [ -6.4403, 54.05799 ], [ -6.44624, 54.06244 ], [ -6.45022, 54.06668 ], [ -6.45089, 54.06843 ], [ -6.47854, 54.06771 ], [ -6.56401, 54.04895 ], [ -6.57187, 54.04952 ], [ -6.58716, 54.05334 ], [ -6.59507, 54.05241 ], [ -6.60029, 54.04895 ], [ -6.60522, 54.04448 ], [ -6.61099, 54.03923 ], [ -6.61646, 54.03727 ], [ -6.63062, 54.04182 ], [ -6.65729, 54.06115 ], [ -6.67253, 54.06843 ], [ -6.65708, 54.09194 ], [ -6.65579, 54.10331 ], [ -6.66644, 54.11479 ], [ -6.64396, 54.13184 ], [ -6.63455, 54.15013 ], [ -6.64034, 54.16801 ], [ -6.64845, 54.17366 ], [ -6.66303, 54.18383 ], [ -6.68395, 54.19437 ], [ -6.69465, 54.19798 ], [ -6.70654, 54.19892 ], [ -6.71723, 54.19514 ], [ -6.72478, 54.18863 ], [ -6.73284, 54.18357 ], [ -6.74478, 54.18419 ], [ -6.76648, 54.19235 ], [ -6.78782, 54.203 ], [ -6.80736, 54.21633 ], [ -6.82395, 54.23235 ], [ -6.82973, 54.24237 ], [ -6.8332, 54.25209 ], [ -6.83774, 54.26051 ], [ -6.84668, 54.26646 ], [ -6.88219, 54.27726 ], [ -6.86467, 54.28273 ], [ -6.85666, 54.29281 ], [ -6.85841, 54.30733 ], [ -6.87001, 54.326 ], [ -6.8797, 54.34159 ], [ -6.88596, 54.34562 ], [ -6.89789, 54.34619 ], [ -6.90596, 54.34904 ], [ -6.91505, 54.36593 ], [ -6.92203, 54.3727 ], [ -6.98409, 54.40309 ], [ -7.01784, 54.41317 ], [ -7.04925, 54.41151 ], [ -7.0785, 54.39472 ], [ -7.12703, 54.34976 ], [ -7.15989, 54.33519 ], [ -7.16806, 54.33503 ], [ -7.18563, 54.33694 ], [ -7.18947, 54.33569 ], [ -7.19245, 54.33472 ], [ -7.19395, 54.32997 ], [ -7.19147, 54.32387 ], [ -7.18764, 54.3188 ], [ -7.18501, 54.31725 ], [ -7.18465, 54.31663 ], [ -7.1924, 54.30738 ], [ -7.19369, 54.30754 ], [ -7.19917, 54.30346 ], [ -7.20666, 54.3049 ], [ -7.21147, 54.30418 ], [ -7.20904, 54.29343 ], [ -7.1755, 54.28366 ], [ -7.18149, 54.26976 ], [ -7.14589, 54.25209 ], [ -7.15974, 54.24067 ], [ -7.15333, 54.22424 ], [ -7.17473, 54.21607 ], [ -7.2295, 54.20755 ], [ -7.24087, 54.20233 ], [ -7.24909, 54.19742 ], [ -7.2555, 54.19085 ], [ -7.26113, 54.18088 ], [ -7.25632, 54.1769 ], [ -7.24702, 54.17225 ], [ -7.24578, 54.16698 ], [ -7.26537, 54.16114 ], [ -7.26087, 54.15117 ], [ -7.26351, 54.14099 ], [ -7.27074, 54.13225 ], [ -7.28004, 54.12615 ], [ -7.29379, 54.12202 ], [ -7.29735, 54.1259 ], [ -7.29632, 54.13499 ], [ -7.29642, 54.14652 ], [ -7.29503, 54.1554 ], [ -7.29213, 54.16264 ], [ -7.29554, 54.16512 ], [ -7.32598, 54.15458 ], [ -7.33317, 54.14941 ], [ -7.33317, 54.14274 ], [ -7.31032, 54.11468 ], [ -7.31649, 54.11428 ], [ -7.32696, 54.1136 ], [ -7.37549, 54.12331 ], [ -7.39022, 54.12119 ], [ -7.39466, 54.12192 ], [ -7.39662, 54.12626 ], [ -7.40396, 54.13504 ], [ -7.41223, 54.13644 ], [ -7.42226, 54.13546 ], [ -7.42577, 54.13696 ], [ -7.41466, 54.14569 ], [ -7.43962, 54.14693 ], [ -7.48075, 54.12765 ], [ -7.5023, 54.12512 ], [ -7.60901, 54.1399 ], [ -7.6208, 54.14496 ], [ -7.62405, 54.15334 ], [ -7.62571, 54.16217 ], [ -7.63268, 54.16853 ], [ -7.70477, 54.20036 ], [ -7.7226, 54.20233 ], [ -7.78208, 54.2 ], [ -7.83696, 54.20434 ], [ -7.85644, 54.21142 ], [ -7.86967, 54.22687 ], [ -7.87365, 54.27106 ], [ -7.88026, 54.28702 ], [ -7.89497, 54.29359 ], [ -7.93411, 54.29705 ], [ -7.94207, 54.29887 ], [ -7.9508, 54.30087 ], [ -7.96801, 54.31219 ], [ -7.98103, 54.32656 ], [ -8.00219, 54.35792 ], [ -8.03134, 54.35803 ], [ -8.05648, 54.36588 ], [ -8.07994, 54.3802 ], [ -8.12242, 54.41523 ], [ -8.14635, 54.43074 ], [ -8.15603, 54.43906 ], [ -8.15813, 54.44712 ], [ -8.16118, 54.45482 ], [ -8.17384, 54.46174 ], [ -8.16847, 54.46348 ], [ -8.15017, 54.46939 ], [ -8.09705, 54.47859 ], [ -8.07245, 54.48706 ], [ -8.06098, 54.49332 ], [ -8.05586, 54.49755 ], [ -8.04356, 54.51223 ], [ -8.02328, 54.5297 ], [ -8.00219, 54.54344 ], [ -7.92641, 54.53305 ], [ -7.88714, 54.53212 ], [ -7.84884, 54.54091 ], [ -7.74926, 54.59615 ], [ -7.70787, 54.60416 ], [ -7.70795, 54.60476 ], [ -7.71056, 54.62426 ], [ -7.7212, 54.62587 ], [ -7.73676, 54.61925 ], [ -7.75355, 54.6145 ], [ -7.76916, 54.61801 ], [ -7.8012, 54.63481 ], [ -7.815, 54.63946 ], [ -7.82254, 54.63811 ], [ -7.83804, 54.63124 ], [ -7.84642, 54.63145 ], [ -7.85427, 54.63641 ], [ -7.86435, 54.64907 ], [ -7.87277, 54.65222 ], [ -7.89008, 54.65506 ], [ -7.90662, 54.66132 ], [ -7.91484, 54.67165 ], [ -7.90714, 54.68669 ], [ -7.91323, 54.68865 ], [ -7.92967, 54.69671 ], [ -7.88011, 54.71103 ], [ -7.8459, 54.73103 ], [ -7.83215, 54.73061 ], [ -7.80358, 54.71614 ], [ -7.7705, 54.70602 ], [ -7.7366, 54.70746 ], [ -7.70229, 54.71888 ], [ -7.66751, 54.73878 ], [ -7.64968, 54.74488 ], [ -7.61537, 54.73935 ], [ -7.5854, 54.74472 ], [ -7.56664, 54.73868 ], [ -7.55615, 54.73837 ], [ -7.54307, 54.74167 ], [ -7.54302, 54.74379 ], [ -7.5484, 54.7472 ], [ -7.5517, 54.7547 ], [ -7.54974, 54.7796 ], [ -7.54338, 54.79309 ], [ -7.47083, 54.84528 ], [ -7.45507, 54.86301 ], [ -7.44473, 54.88445 ], [ -7.44473, 54.89489 ], [ -7.44897, 54.92032 ], [ -7.44525, 54.93215 ], [ -7.43698, 54.9383 ], [ -7.41714, 54.94306 ], [ -7.41576, 54.94437 ], [ -7.40866, 54.95112 ], [ -7.40742, 54.95944 ], [ -7.41311, 54.98497 ], [ -7.40908, 54.99204 ], [ -7.40376, 54.99313 ], [ -7.40112, 54.99484 ], [ -7.40525, 55.00357 ], [ -7.37699, 55.02889 ], [ -7.36696, 55.03556 ], [ -7.35502, 55.04093 ], [ -7.29115, 55.04662 ], [ -7.28299, 55.05183 ], [ -7.27529, 55.05886 ], [ -7.2665, 55.06517 ], [ -7.2471, 55.06932 ] ] ] } }
]
}
我可以访问任何 Python 库,包括 Geopandas 和 Shapely。
我需要将这些项目转换成什么数据结构,我需要使用什么空间函数来计算多边形内外线的长度?
编辑:
请参阅下面的答案。
然后我使用以下代码计算了距离(英国国家电网)。
from pyproj import Proj, Transformer
import shapely.ops as sp_ops
my_transformer = Transformer.from_crs('EPSG:4326', 'EPSG:27700', always_xy=True)
#Route in KM rounded to 2 decimal places
routeLength = round(sp_ops.transform(my_transformer.transform, route).length/1000,2)
使用 Shapely(参见 documentation),您可以使用 class Polygon
表示多边形,并使用 LineString
.
那么,相交的长度就很容易计算了,例如:
total = road_linestring.length
inside = road_linestring.intersection(ni_poly).length
print("Length of road in Northern Ireland is", inside)
print("Length of road outside Northern Ireland is", total - inside)