# How to calculate distance between two points on a MultiLineString in Shapely?

``````from shapely.geometry import MultiLineString
coords = [((0, 0), (3, 3)), ((-1, 0), (1, 0))]
lines = MultiLineString(coords)
pt1 = lines.interpolate(1)
pt2 = lines.interpolate(2)
``````

How would I find the distance, along the line, between these two points? I believe

``````pt1.distance(pt2)
``````

returns the Euclidean distance between the two.

EDIT: assume my Multiline string is much more complex (below), and I want to find distance between any two points (or move a point by some arbitrary distance on the line)

``````line.wkt = 'MULTILINESTRING ((517952.1120014446 180907.3778603508, 517952.0585772707 180907.3754776951), (517952.1121808029 180907.3774474508, 518322.2161963926 180944.8592887305), (518323.0402337386 180943.9710099294, 518343.7125065899 180945.5107595754, 518399.2645568835 180949.0855189138, 518454.820218219 180951.0142323658, 518603.5015156692 180952.8571421161, 518647.4738425545 180952.8598047864, 518763.4854213292 180952.008813744, 518911.2089778162 180956.2305814849, 518954.7731027289 180960.3320922453, 519002.2499760573 180968.6980922449, 519040.1433601086 180981.045951964, 519077.1725361857 180996.7897428998, 519111.4833476449 181015.0626201402, 519150.9227597158 181043.1695649572, 519185.8083144043 181073.617909153, 519233.4080098552 181125.5166170792, 519268.592450542 181168.623637778, 519321.5646570628 181230.2294229127, 519354.8252035461 181270.6549041138, 519395.4003371921 181319.2209660792), (519397.6005794832 181321.8403942209, 519424.176225765 181353.308858702, 519503.1070766576 181447.6607794612, 519562.7986393921 181522.8906896975, 519657.3362771584 181638.1413048934, 519756.809595566 181754.9566684381, 519845.7278455998 181865.8839367744, 519931.7525436428 181965.7291303253, 520003.1864829637 182036.9692736626, 520073.6069702752 182076.9981917402, 520130.4476269386 182100.6955725611, 520164.1712074715 182109.5822543741, 520208.7739226164 182116.2897925265, 520260.9049645913 182118.9922482244, 520298.9386594402 182115.8536534164, 520338.7986652991 182109.1646423307, 520454.3188287076 182073.8818688538, 520618.1033470051 182022.7232167933, 520830.2934518904 181956.6559184307), (520833.0003071616 181955.8131831602, 520917.9901906942 181929.3538454586, 520962.0162804312 181913.9674471538, 521015.6957450535 181893.7152340659, 521131.9728055829 181858.2763782708, 521197.3015326894 181833.6416132338, 521245.0134169575 181806.4063878522, 521284.8664299373 181780.4082350155, 521338.7427714979 181732.8475433236, 521384.9386760949 181675.2899937549, 521474.6525383473 181546.8821611112, 521488.4457017841 181527.1390057409, 521565.0745666514 181409.0793538654, 521666.5261495773 181259.6473914613, 521690.7659105266 181228.6974633491), (521693.0362544187 181226.1209023954, 521728.8294471474 181190.1831229523, 521762.9158424716 181159.7553541883, 521799.9182211301 181134.2601429647, 521843.9767173152 181107.7994076303, 521893.4965016851 181084.9304908686, 521946.7990000906 181069.6412203054, 521995.515760978 181060.3065898639, 522070.5936169028 181055.2885336467, 522095.7659458991 181056.7722404549, 522179.6815652025 181067.6459723942, 522239.5607955241 181075.4059672341, 522330.056112562 181090.65758401, 522375.6205507822 181097.518309089, 522459.4651658445 181111.0098367983, 522479.5335552722 181114.2640608624, 522499.4565464804 181116.9251312392, 522519.6411286149 181118.8136991492, 522562.9493736136 181121.048545875, 522579.1711629611 181122.0183882094, 522595.6776158112 181123.562625237, 522611.4949435793 181125.7579088872, 522626.7795026561 181128.7415294253, 522645.5442101624 181133.3669587257, 522684.9433646658 181144.8218006217, 522712.8169513628 181151.1472757808, 522738.6705324028 181156.3114212868, 522769.9135580525 181161.383353904, 522797.1378088034 181163.8325461621, 522824.468461872 181165.0382332973, 522857.0638652682 181165.2808937064, 522892.3028695018 181163.5737021674, 522924.5270364418 181159.9356202476, 522967.3562038018 181153.8393433157, 523009.4822966962 181145.245081957, 523048.5372436661 181134.1844956557, 523077.0774919117 181125.5845411715, 523109.4368859954 181113.5166110944, 523144.0328930641 181098.5432877953, 523172.641978361 181087.1192599023, 523186.0665101609 181080.6237726648, 523198.0088210083 181073.4136399049, 523211.1088374524 181063.9839414503, 523222.0788691424 181054.2133285731, 523228.1997780476 181047.4407270441, 523245.5392603829 181027.8102791673, 523259.684684658 181001.0478825343, 523265.7059850891 180983.5019409733, 523304.1592616967 180840.7847394201, 523310.1894257015 180802.8543361751, 523312.5022148016 180775.3487927186, 523313.4590574321 180734.8247426937), (523313.5852137556 180730.3823901292, 523313.9758697514 180718.6144387866, 523314.6096928587 180699.3578013795, 523318.1188827896 180577.3238045931, 523318.9957358316 180552.3426484718, 523320.1970987297 180518.2785857375, 523320.3254565182 180515.2774027666, 523321.7345459627 180482.954197472, 523321.93236023 180477.6625324757, 523329.4712696794 180237.3236917898, 523328.8955505334 180216.6913540821, 523326.9342723583 180189.9166695915, 523323.6054769404 180164.5553258671, 523319.8445642025 180138.972091098, 523316.1391699367 180117.3959349418, 523314.7563285272 180096.2544388204, 523312.4949583365 180071.2528138107, 523312.816331223 180049.1289728333, 523313.7990984195 180029.2243244642, 523317.6295751119 180009.5779105633, 523321.8533945273 179994.6143871999, 523328.9450653624 179981.6565365372, 523338.6291633909 179970.6086718833, 523351.3936510167 179961.3936308437, 523373.9855959364 179951.8273628096, 523399.7882116641 179944.1639523559, 523548.9234702412 179912.8359606295, 523565.8707837494 179909.5425270466, 523632.0059342108 179896.1510924404, 523638.1781632617 179895.0549605786, 523645.2665688228 179894.5485966542, 523660.9040272491 179895.1514658005, 523669.5253753836 179894.7158029705, 523682.1041044751 179892.8854015666, 523697.1264598617 179891.3704064646, 523711.6767112768 179890.422574097, 523723.958365327 179890.2429767562, 523746.1083915731 179891.4608078512, 523770.6529487936 179894.4394686381, 523786.9630658171 179897.3624020272, 523819.0635925519 179906.8676998212, 523836.0206916863 179913.1674878929), (523838.6836447633 179914.1505537384, 524387.2720915276 180115.4177709155, 524625.8758948976 180230.4295490196), (524628.5047576218 180231.6862488536, 524875.4897323852 180348.7727884009, 524975.651967396 180386.3294281727, 525043.5094902888 180402.2298697699, 525100.2770927537 180415.0542434999, 525232.8654467037 180444.3344243292, 525283.1335574746 180460.7775152219), (525285.8024063534 180461.7093322488, 525326.1114444134 180476.6760138152, 525570.1632271186 180567.6999592768, 525636.5183746398 180584.3947913225, 525742.4323728953 180602.6587226963, 525894.6787014238 180620.8849163629), (525897.4092731796 180621.317412472, 526038.0345578383 180649.0812945864, 526327.7819077392 180706.2916254801, 526729.476901344 180794.0428405801), (526732.1936193742 180794.5862667871, 527490.9906111445 180932.4801039465, 527786.0913043805 180981.1407730209, 527844.1268338035 180990.5787127642, 527925.8799577742 181009.6574063866), (527928.589268009 181010.259312287, 528043.3553810236 181034.473610028, 528206.2559646484 181053.580324546, 528473.3794183874 181101.9624833416, 528537.6915777642 181112.60269928), (528540.4070064862 181113.1548390575, 528750.2566558265 181163.8524329753, 529014.0976614507 181233.8662173112), (529016.7999942949 181234.5229254425, 529103.0664596838 181253.5677212651, 529142.8842458106 181262.0015438361, 529187.748849446 181269.9074566081, 529303.3490946331 181287.5248527131, 529535.5514010807 181340.3079995684, 529668.9442611571 181364.6967699708, 529723.6672985676 181372.8256774999, 529812.6076010399 181383.4332398997), (529815.3541689421 181383.7342527536, 529844.3879156984 181386.6359670691, 529860.681036458 181389.1331881644, 529916.9043554395 181405.6371345041, 529993.8936222623 181427.5356913633, 530097.2639410548 181450.8007164356, 530177.3923947937 181467.99759735, 530222.3690272854 181476.0269324649, 530318.952368455 181492.345871716, 530383.6768875103 181502.1294617597, 530527.2019748654 181529.342115723), (530529.9216875471 181529.8578208134, 530559.9647381124 181535.5546123974, 530685.1911638521 181555.9215893672, 530797.2886711347 181582.4856835881, 530996.8186832126 181595.315116965, 531084.6559533289 181599.1469953415), (531087.4167081292 181599.0877440526, 531476.0941960954 181565.3083271807, 531534.5242154773 181544.6095074898, 531571.2409060189 181529.7030201364, 531797.5134091205 181416.2993138076, 531914.1827678308 181359.2476911565, 531970.2091249244 181334.496427901, 532022.2572540119 181311.6342812338, 532065.5954075204 181292.3965041493, 532109.5789535588 181271.7617372062), (532112.2577669564 181270.5049965298, 532192.7322030889 181232.7521025384, 532221.3984817112 181221.613367029, 532262.9212519747 181210.2975100139, 532392.4269359774 181181.1653817323, 532505.7223217544 181152.2814603797, 532613.122211703 181125.872338909, 532646.5044871408 181118.4644367888, 532660.5249840914 181116.5269487904, 532672.6334358397 181116.2866572752, 532681.7469199295 181116.9363236568, 532688.929126011 181117.8916718895, 532699.3766315753 181120.3677905051, 532703.1060052584 181121.8929233325), (532705.7443794713 181123.0595333464, 532751.5866128337 181144.8647910674, 532782.8802973609 181160.094450631, 532874.1922561447 181194.0398933498, 532884.8752008205 181199.983336259, 532896.2831720633 181207.9376574077, 532936.8345827907 181268.3322969055, 532946.2520652707 181278.5826572992, 532955.8221056047 181285.6544473952, 532966.9461523031 181291.9768380564, 532979.5745044758 181300.7756323186, 532993.0829428573 181313.881738671, 533006.8130585947 181330.1873971299, 533014.6854272018 181341.6326517679, 533026.3091742186 181360.4203972876, 533028.0001652889 181363.191004667, 533055.1136749787 181417.7711336002, 533064.8788478157 181439.3813200848, 533073.6335200693 181467.2300848301, 533083.7666037568 181515.0784646599, 533093.5695752727 181559.0381625827), (533094.5449475957 181563.1141164702, 533101.2482094849 181589.3033760744, 533105.8672330112 181601.9432925424, 533110.8745269234 181611.4219270553, 533120.4553018841 181631.0355236727, 533135.3850627299 181659.2687800031, 533154.2723183134 181691.9902055793, 533169.0564492053 181715.4347511751, 533183.9460179799 181734.5867270653, 533461.2319364526 182079.4073762461, 533515.4912925062 182135.9276889776, 533565.346476938 182189.0834714765, 533606.2757567647 182228.9519024612, 533855.0656001999 182417.0658837026, 533976.0249752069 182512.2946115925, 534124.9326521563 182607.7969692118, 534165.6750122608 182629.7491775769, 534207.6532142251 182646.9493208046, 534260.2166496542 182662.8382984981, 534557.2260275101 182713.5743053654, 534709.0203584387 182741.5121639288, 534764.0995951786 182751.7088321878, 534821.3817499544 182758.9266073686, 534867.2307625602 182760.9450644842, 534907.9882285276 182759.1786733964, 534986.1180789419 182743.4051949653), (534988.8302695542 182742.6130072358, 535065.1848296274 182713.3354951051, 535561.9620949547 182458.5590419491, 535645.4575540402 182418.5231812677, 535692.5049622845 182402.3084839845, 535743.9934687389 182392.1442113718, 535785.7392243529 182387.3063628021, 535833.8214571537 182381.7480338423, 535926.41848039 182376.8469595745, 536028.8855839792 182377.7092024156, 536123.7172454087 182386.5815270632, 536159.1638644659 182393.7855984807, 536193.0465095564 182403.6521497812, 536221.4802334545 182414.2741931566, 536264.5942330327 182432.9798015895, 536376.8174552231 182497.575256145, 536435.0839582257 182524.1866011961, 536453.0190776647 182529.9525444587, 536486.6599765491 182538.1658223245, 536521.4977830236 182548.2055656098), (536524.1486315851 182549.2628636542, 536560.7000415154 182567.9969400846, 536579.5315470549 182580.939318418, 536618.3713562662 182598.723457759, 536885.6859026861 182701.579318628, 537021.2645781131 182765.5282584064, 537098.6285281252 182812.285051187, 537212.1730383131 182893.3386655037, 537306.3719878626 182972.9927919005, 537559.6773025161 183290.5183306972, 537660.8944739553 183406.7818737991, 537775.7799239024 183522.5282298738, 538004.9018167557 183738.25399657, 538161.2203998976 183899.3161267039, 538273.9243879429 184062.9902954105, 538294.8591885534 184095.1876215708, 538320.1577175962 184136.3399442448, 538366.6351850258 184213.1576933076, 538376.260468734 184226.3958497188, 538405.888440331 184268.8017849543, 538469.8207265557 184328.402229663, 538523.3264137164 184397.2989298767), (538525.51491431 184399.8993580898, 538615.9275855741 184498.8164615138, 538666.3049486338 184555.7792911155, 538692.8647135743 184587.3976681171, 538739.7706929632 184645.3793159967, 538760.8721528464 184672.0413829351, 538781.6256127863 184700.7639400809, 538802.0770389081 184734.6864870328, 538821.4623858837 184771.5512917324, 538835.8717134633 184812.2418322808, 538841.2736739992 184843.0598422978, 538841.2566996422 184884.0123952025, 538837.6386651647 184915.5741155726, 538829.7361666132 184951.570215236, 538818.492018935 184990.5130160411, 538803.2607869426 185030.3817480671, 538779.139639935 185078.1868963059, 538759.5845082881 185112.2842112527, 538734.4796469059 185145.3395986132, 538699.981125733 185180.1526284499, 538657.7931153777 185213.0197292491, 538620.0629035792 185240.7006125421, 538562.2074760274 185275.1659310274, 538464.6655153736 185326.9665855907, 538421.1723301878 185354.6251724097, 538384.1090156828 185384.9077151133, 538346.9617838692 185418.7938566744, 538299.024136652 185468.0439630699, 538272.9165395185 185503.7004390833, 538258.9021768761 185527.378395683, 538245.6112788897 185558.1204317425, 538224.4791038199 185611.5958499246, 538209.5461147362 185674.8774594811, 538205.8689599894 185717.6776422222, 538206.4346118462 185759.3136123459, 538219.3705823094 185835.8071351536, 538247.790273357 185907.2028408403, 538298.3135354822 185991.4870582844, 538334.3246609971 186038.5519217544, 538371.7634609649 186077.893955208), (538374.0280910408 186080.3031540973, 538436.8194340458 186147.9253355927, 538642.52510516 186369.4250871284, 538749.4554108353 186484.7914429777, 538858.0723451008 186605.5147885447, 539047.6168403139 186877.0251864636, 539096.3034575681 186967.9898373909, 539142.7304173298 187065.9152103161, 539240.9974891741 187314.9885437941, 539263.6230624022 187372.4993255943, 539292.850527277 187432.450373782), (539294.5357873811 187435.8599664451, 539306.6916747546 187460.1182694393, 539327.2220464122 187495.1365248472, 539357.712321809 187546.7654110178, 539414.786167889 187624.0534457291, 539478.3989852732 187700.0419515889, 539478.4438457098 187700.0902852857, 539514.8505302279 187739.3161543421, 539553.9171609229 187777.5386205692, 539636.260498347 187848.8588709703, 539722.5760958329 187925.9322688184, 539760.0894293777 187958.7607679168, 539785.7555336631 187984.8862032222, 539814.7081087409 188020.8288823265, 539860.7470110914 188100.5114150044, 539920.1502371056 188239.1225037144, 539985.132236785 188390.5307267444, 540106.2848470521 188673.0305358581, 540164.2755280793 188808.2549206244), (540165.8051974855 188811.8229604972, 540171.8841951587 188826.0057255612, 540176.4690669311 188836.9719086139, 540186.8808361952 188861.876628615, 540213.250790439 188932.2385695462, 540251.5829757473 189049.0937522139, 540325.0152079145 189254.8493698075, 540331.5259452181 189270.598781737, 540390.1173807508 189423.973397581, 540422.2287445488 189515.5848473806, 540457.8270955809 189631.164465406, 540489.3062993737 189753.730405234, 540511.9360443549 189867.3819089964, 540528.2600778055 189978.6552003453, 540537.3506666328 190064.9170362847), (540537.7939993404 190069.2376530846, 540567.9059318658 190370.8658219533, 540585.2531478567 190489.8467995246, 540602.5553332733 190581.1937786826, 540619.2197064392 190657.2877919173, 540673.3333618695 190861.6019789398, 540802.73673506 191276.0298237847, 540885.561109468 191540.8183873968, 540906.2608922038 191607.811359319, 540939.4702380253 191714.8345034129), (540940.7251132338 191718.6893720847, 540971.652712075 191809.3723001909, 541005.5259042865 191900.8933596894, 541063.3905144277 192039.5461244449, 541233.6231112521 192408.1066359569, 541321.4238420206 192597.0106471003, 541392.6318791359 192751.2319263978, 541392.9961058436 192752.0207916904, 541463.0595734654 192906.0663239578, 541536.2915566528 193066.0554859982, 541594.432415816 193205.6584226613, 541619.3649087795 193269.3014012448, 541637.1697032163 193319.2790193707, 541660.440289975 193394.9840943947, 541692.7731530331 193497.5858024526, 541730.865943869 193651.4645671216, 541764.2898680647 193817.8666596455, 541775.443550827 193884.8693687124), (541776.0840423855 193889.1454437239, 541787.9999314253 193978.5882552357, 541808.1110191763 194108.2483039374, 541817.9916341908 194160.5199546553, 541830.1890365235 194218.0983407642, 541847.798523102 194296.8178179727, 541866.3658258945 194364.0790926123, 541884.9439516643 194435.3806065027, 541907.5726977951 194502.5000171455, 541931.0876441696 194570.1007136002, 541971.3038893804 194673.5939002859, 542033.738597545 194815.2160971513, 542101.709966728 194973.5993297754, 542137.6726032482 195077.6313522862, 542158.7490267485 195153.6675312371, 542180.6786492362 195245.6423927793, 542192.8769251315 195323.1208843358, 542206.129779872 195403.46699568, 542218.0521359516 195455.7527352828, 542233.5532182811 195505.8576874743, 542260.2848599087 195556.4788785063, 542274.0809668284 195576.3316933282, 542292.093938957 195597.4160870878, 542311.8259376852 195616.4822996751), (542314.1805026275 195618.6168450385, 542337.6289946721 195638.5171875764, 542362.3485932685 195656.4963807983, 542388.6899732316 195670.4814944855, 542417.1423870948 195681.7884328825, 542445.8844721096 195691.6569110752, 542456.0807700444 195695.4608800488, 542476.8883438751 195702.1012095318, 542525.5735848732 195713.8897310022, 542572.6343923673 195720.168541478, 542604.1150625469 195721.0560317046, 542662.9446053924 195718.586148509, 542829.0093325867 195712.5221978943, 542908.6416664427 195710.4868476326, 542997.3765095775 195709.2999343892, 543076.072475489 195713.9405015343, 543159.7045969327 195720.3246143702, 543279.251036224 195733.3921428714, 543295.8067466992 195735.8532923256, 543385.2263867102 195750.3291284839, 543512.2165478678 195778.7378587802, 543617.8264409128 195807.2772114833, 543778.0631052277 195860.5870663754, 543873.7973506081 195898.8229859776, 543954.8030244227 195933.636630103, 544034.9187377815 195972.4328171318, 544111.6508680714 196013.5378386724, 544170.3615577089 196048.4654952642, 544193.0040824725 196063.4900750652, 544258.6024850273 196109.5188184926), (544261.0675388041 196111.3344711891, 544312.9945365611 196151.4286383837, 544364.2554291545 196196.6744315519, 544399.4312064478 196232.7138163355, 544433.2743258639 196271.2751521406, 544465.8531772926 196306.3282728844, 544586.5553482379 196435.3614447161, 544683.0048139026 196554.7446636392, 544758.5472280096 196668.1224821588, 544823.734721368 196778.8900870137, 544928.1005670491 196984.1793936206, 544985.7589839123 197131.7389175092, 545037.4367038682 197291.2253635954, 545103.6066094465 197494.5777473251, 545158.3665514157 197632.0179374085, 545261.5462399297 197851.1713602957, 545303.8198212266 197946.1743025776, 545337.3170877057 198039.9125218355, 545372.6556328205 198166.0795860341, 545393.2942875755 198264.7349612527, 545406.1080921721 198361.0952417632, 545416.5073145211 198493.0004035889, 545420.3607169173 198557.9849616901, 545427.2836383579 198619.2293370363, 545442.6418088864 198711.0332124536, 545453.4471545866 198754.7046803704, 545485.3904107262 198889.3561523061, 545533.2147615867 199088.066265855), (545534.1946809848 199092.1303967987, 545566.1315444401 199224.3422225185, 545664.3745077096 199632.9558409049, 545749.3287891279 199984.9959177756, 545805.7721792039 200199.2659624452, 545908.8736133894 200618.0214705577, 545971.4523842268 200878.1918282461, 545977.9475742332 200900.9392444197, 546021.0599746921 201077.877357939, 546040.0744171058 201153.0177704446, 546053.8703020645 201204.0898413169, 546074.5655563162 201264.6102698376, 546084.6442932439 201295.9089283504, 546087.9002229677 201304.5840557524, 546096.1530565085 201326.5478315895, 546123.1372895191 201392.2365752733, 546152.6721395938 201452.7016530045, 546178.7702018305 201506.4230523311, 546223.6412120585 201580.3877560349, 546242.9229326635 201606.5484263477))'
``````

My attempt, seems to work.

``````# http://gis.stackexchange.com/questions/203048/split-lines-at-points-using-shapely
def cut_line_at_point(line, pt):
# First coords of line
if line.geom_type == 'LineString':
coords = line.coords[:]
else:
coords = [geo.coords[:] for geo in line.geoms]
coords = [item for sublist in coords for item in sublist]

# Add the coords from the points
coords += pt.coords
# Calculate the distance along the line for each point
dists = [line.project(Point(p)) for p in coords]
# sort the coordinates
coords = [p for (d, p) in sorted(zip(dists, coords))]
break_pt = find_index_of_point_w_min_distance(coords, pt.coords[:][0])

#     break_pt = coords.index(pt.coords[:][0])
if break_pt == 0:
# it is the first point on the line, "line_before" is meaningless
line_before = None
else:
line_before = LineString(coords[:break_pt+1])
if break_pt == len(coords)-1:
# it is the last point on the line, "line_after" is meaningless

line_after = None
else:
line_after = LineString(coords[break_pt:])
return(line_before, line_after)
``````

which then is used by

``````# http://gis.stackexchange.com/questions/203048/split-lines-at-points-using-shapely
def distance_btw_two_points_on_a_line(line, pt1, pt2):

if line.geom_type == 'LineString':
coords = line.coords[:]
else:
coords = [geo.coords[:] for geo in line.geoms]
coords = [item for sublist in coords for item in sublist]

# Add the coords from the points
coords += pt1.coords
coords += pt2.coords
# Calculate the distance along the line for each point
dists = [line.project(Point(p)) for p in coords]
# sort the coordinates
coords = [p for (d, p) in sorted(zip(dists, coords))]
# get their orders
first_pt = coords.index(pt1.coords[:][0])
second_pt = coords.index(pt2.coords[:][0])
if first_pt > second_pt :
pt1, pt2 = pt2, pt1

first_line_part = cut_line_at_point(line, pt1)[1]

second_line_part = cut_line_at_point(first_line_part, pt2)[0]

distance = second_line_part.length
return distance

def find_index_of_point_w_min_distance(list_of_coords, coord):
temp = [Point(c).distance(Point(coord)) for c in list_of_coords]
return(temp.index(min(temp)) )
``````

It is much simpler, when you use interpolate() with a MultiLineString, it takes the first line

``````pt1 = lines.interpolate(0.5) # red point
# first LineString in the MultineString
pt11 = lines[0].interpolate(0.5) # red point
pt1==pt11
True
# second LineString in the MultineString
pt21 = lines[1].interpolate(0.5) # blue point
pt1==pt21
False
``````

Therefore in your case the result of the 2 interpolated points are on the first LineString and you can use `pt1.distance(pt2)`

What happens with the first example, the distance between pt11 and pt21

Euclidean distance (in green)

``````print pt11.distance(pt21)
0.923879532511
``````

MultiLineString distance (passing by the lines intersection)

``````intersect =lines[0].intersection(lines[1]) # orange point
one = pt11.distance(intersect)
two = intersect.distance(pt21)
print one + two
1

for line in lines:
if line.distance(pt11) < 1e-8:
print line
LINESTRING (0 0, 3 3)
for line in lines:
if line.distance(pt21) < 1e-8:
print line
LINESTRING (-1 0, 1 0)
``````

### New

• Thanks! For this to work, should I know which line has which point? (Is that why you are looping through lines at the end?) What if the two points are not on adjacent lines, such that intersects returns False? I'll update my question to include a more realistic scenario.
– Alex
Oct 21, 2016 at 1:22
• In this case it is very difficult because there are segments and disjointed lines in your polyline, see New
– gene
Oct 22, 2016 at 18:30