Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contains may return True for a Polygon that does not contain all elements of a MultiLineString #1146

Open
kdpenner opened this issue Jun 7, 2021 · 1 comment

Comments

@kdpenner
Copy link

kdpenner commented Jun 7, 2021

Expected behavior and actual behavior.

Expected behavior: contains should return False for a Polygon that does not contain all line strings in a MultiLineString.

Actual behavior: contains may return True.

Steps to reproduce the problem.

from shapely import wkt


poly_wkt = "POLYGON Z ((-1.104637272529936e-09 -9020047.848073646 0, -2032367.180664854 -8962624.286015626 0, -3219571.660515582 -8875238.180592071 0, -4208282.261133032 -8771194.518661426 0, -5083349.903212329 -8654545.142404413 0, -5879879.246663817 -8527486.04177697 0, -6616652.80111027 -8391438.470782464 0, -7305172.184825933 -8247416.445108698 0, -7953102.590787794 -8096190.646016134 0, -8565859.083932672 -7938373.745301367 0, -9147433.628621655 -7774469.607891488 0, -9700866.147036478 -7604903.824563359 0, -10228531.31474128 -7430043.739264075 0, -10732322.52246332 -7250212.169308884 0, -11213774.9412278 -7065697.139943861 0, -11674150.7492767 -6876758.993328802 0, -12114499.89305586 -6683635.70721994 0, -12535704.48877531 -6486546.956899537 0, -12938511.96661401 -6285697.272696523 0, -13323560.27365207 -6081278.53252325 0, -13691397.3517892 -5873471.95621065 0, -14042496.40850673 -5662449.720377821 0, -14377268.04270542 -5448376.28001117 0, -14696069.9834189 -5231409.460379818 0, -14999214.99140367 -5011701.366996126 0, -15286977.32902141 -4789399.149897031 0, -15559598.10147072 -4564645.650180879 0, -15817289.69880917 -4337579.950562795 0, -16060239.51449518 -4108337.847086079 0, -16288613.07646981 -3877052.25561923 0, -16502556.6970796 -3643853.564079695 0, -16702199.72564747 -3408869.939244301 0, -16887656.47029104 -3172227.595381085 0, -17059027.84229327 -2934051.030657752 0, -17216402.76596054 -2694463.236267031 0, -17359859.38874261 -2453585.88239932 0, -17489466.11990741 -2211539.484542548 0, -17605282.52087259 -1968443.553064851 0, -17707360.06609954 -1724416.728611123 0, -17795742.79003251 -1479576.905500183 0, -17870467.83274514 -1234041.34502995 0, -17931565.89460749 -987926.7803716012 0, -17979061.60830563 -741349.5145514553 0, -18012973.8348511 -494425.512873709 0, -18033315.88874405 -247270.4910231342 0, -18040095.69614729 0 0, -18033315.88874405 247270.4910231342 0, -18012973.8348511 494425.512873709 0, -17979061.60830563 741349.5145514553 0, -17931565.89460749 987926.7803716012 0, -17870467.83274514 1234041.34502995 0, -17795742.79003251 1479576.905500183 0, -17707360.06609954 1724416.728611123 0, -17605282.52087259 1968443.553064851 0, -17489466.11990741 2211539.484542548 0, -17359859.38874261 2453585.88239932 0, -17216402.76596054 2694463.236267031 0, -17059027.84229327 2934051.030657752 0, -16887656.47029104 3172227.595381085 0, -16702199.72564747 3408869.939244301 0, -16502556.6970796 3643853.564079695 0, -16288613.07646981 3877052.25561923 0, -16060239.51449518 4108337.847086079 0, -15817289.69880917 4337579.950562795 0, -15559598.10147072 4564645.650180879 0, -15286977.32902141 4789399.149897031 0, -14999214.99140367 5011701.366996126 0, -14696069.9834189 5231409.460379818 0, -14377268.04270542 5448376.28001117 0, -14042496.40850673 5662449.720377821 0, -13691397.3517892 5873471.95621065 0, -13323560.27365207 6081278.53252325 0, -12938511.96661401 6285697.272696523 0, -12535704.48877531 6486546.956899537 0, -12114499.89305586 6683635.70721994 0, -11674150.7492767 6876758.993328802 0, -11213774.9412278 7065697.139943861 0, -10732322.52246332 7250212.169308884 0, -10228531.31474128 7430043.739264075 0, -9700866.147036478 7604903.824563359 0, -9147433.628621655 7774469.607891488 0, -8565859.083932672 7938373.745301367 0, -7953102.590787794 8096190.646016134 0, -7305172.184825933 8247416.445108698 0, -6616652.80111027 8391438.470782464 0, -5879879.246663817 8527486.04177697 0, -5083349.903212329 8654545.142404413 0, -4208282.261133032 8771194.518661426 0, -3219571.660515582 8875238.180592071 0, -2032367.180664854 8962624.286015626 0, -1.104637272529936e-09 9020047.848073646 0, 1.104637272529936e-09 9020047.848073646 0, 2032367.180664854 8962624.286015626 0, 3219571.660515582 8875238.180592071 0, 4208282.261133032 8771194.518661426 0, 5083349.903212329 8654545.142404413 0, 5879879.246663817 8527486.04177697 0, 6616652.80111027 8391438.470782464 0, 7305172.184825933 8247416.445108698 0, 7953102.590787794 8096190.646016134 0, 8565859.083932672 7938373.745301367 0, 9147433.628621655 7774469.607891488 0, 9700866.147036478 7604903.824563359 0, 10228531.31474128 7430043.739264075 0, 10732322.52246332 7250212.169308884 0, 11213774.9412278 7065697.139943861 0, 11674150.7492767 6876758.993328802 0, 12114499.89305586 6683635.70721994 0, 12535704.48877531 6486546.956899537 0, 12938511.96661401 6285697.272696523 0, 13323560.27365207 6081278.53252325 0, 13691397.3517892 5873471.95621065 0, 14042496.40850673 5662449.720377821 0, 14377268.04270542 5448376.28001117 0, 14696069.9834189 5231409.460379818 0, 14999214.99140367 5011701.366996126 0, 15286977.32902141 4789399.149897031 0, 15559598.10147072 4564645.650180879 0, 15817289.69880917 4337579.950562795 0, 16060239.51449518 4108337.847086079 0, 16288613.07646981 3877052.25561923 0, 16502556.6970796 3643853.564079695 0, 16702199.72564747 3408869.939244301 0, 16887656.47029104 3172227.595381085 0, 17059027.84229327 2934051.030657752 0, 17216402.76596054 2694463.236267031 0, 17359859.38874261 2453585.88239932 0, 17489466.11990741 2211539.484542548 0, 17605282.52087259 1968443.553064851 0, 17707360.06609954 1724416.728611123 0, 17795742.79003251 1479576.905500183 0, 17870467.83274514 1234041.34502995 0, 17931565.89460749 987926.7803716012 0, 17979061.60830563 741349.5145514553 0, 18012973.8348511 494425.512873709 0, 18033315.88874405 247270.4910231342 0, 18040095.69614729 0 0, 18033315.88874405 -247270.4910231342 0, 18012973.8348511 -494425.512873709 0, 17979061.60830563 -741349.5145514553 0, 17931565.89460749 -987926.7803716012 0, 17870467.83274514 -1234041.34502995 0, 17795742.79003251 -1479576.905500183 0, 17707360.06609954 -1724416.728611123 0, 17605282.52087259 -1968443.553064851 0, 17489466.11990741 -2211539.484542548 0, 17359859.38874261 -2453585.88239932 0, 17216402.76596054 -2694463.236267031 0, 17059027.84229327 -2934051.030657752 0, 16887656.47029104 -3172227.595381085 0, 16702199.72564747 -3408869.939244301 0, 16502556.6970796 -3643853.564079695 0, 16288613.07646981 -3877052.25561923 0, 16060239.51449518 -4108337.847086079 0, 15817289.69880917 -4337579.950562795 0, 15559598.10147072 -4564645.650180879 0, 15286977.32902141 -4789399.149897031 0, 14999214.99140367 -5011701.366996126 0, 14696069.9834189 -5231409.460379818 0, 14377268.04270542 -5448376.28001117 0, 14042496.40850673 -5662449.720377821 0, 13691397.3517892 -5873471.95621065 0, 13323560.27365207 -6081278.53252325 0, 12938511.96661401 -6285697.272696523 0, 12535704.48877531 -6486546.956899537 0, 12114499.89305586 -6683635.70721994 0, 11674150.7492767 -6876758.993328802 0, 11213774.9412278 -7065697.139943861 0, 10732322.52246332 -7250212.169308884 0, 10228531.31474128 -7430043.739264075 0, 9700866.147036478 -7604903.824563359 0, 9147433.628621655 -7774469.607891488 0, 8565859.083932672 -7938373.745301367 0, 7953102.590787794 -8096190.646016134 0, 7305172.184825933 -8247416.445108698 0, 6616652.80111027 -8391438.470782464 0, 5879879.246663817 -8527486.04177697 0, 5083349.903212329 -8654545.142404413 0, 4208282.261133032 -8771194.518661426 0, 3219571.660515582 -8875238.180592071 0, 2032367.180664854 -8962624.286015626 0, 1.104637272529936e-09 -9020047.848073646 0, -1.104637272529936e-09 -9020047.848073646 0))"
poly = wkt.loads(poly_wkt)

mls_wkt = "MULTILINESTRING ((-4764358.859924736 -8697067.690160185, -4694910.60462997 -8701441.588589204, -4654275.08104053 -8708547.572879177, -4581406.588051898 -8717371.762836765, -4564761.229120585 -8723674.706204439), (-4457868.643023726 -8737923.826245038, -4148722.335072094 -8765271.960375579, -4027962.759751034 -8773901.351187924, -3837596.56576387 -8793169.538856495, -3747845.093459259 -8798170.991489783, -3669782.403232374 -8806584.041186478, -3531703.41771755 -8818914.71709552, -3498646.147654502 -8816191.08627674, -3402890.542377662 -8818674.396468302, -3132493.569103241 -8836937.90288469, -3088395.309692765 -8842726.225381462, -3080020.562874478 -8845647.855342411, -3163107.35290599 -8856503.134334119, -3150278.94443926 -8867946.913075319, -3067567.155053703 -8879901.364639776, -2987001.718253613 -8888642.255592138, -2918263.416429682 -8894999.512291284, -2821946.645601612 -8902674.098140869, -2639528.513047611 -8915460.51575101, -2563506.75141815 -8921166.51480687, -2409919.316204108 -8933021.04332402, -2333743.84212698 -8938381.20960428, -1914582.599986904 -8962296.527153192, -1785110.009491876 -8969610.415218227), (-7.298301842923006e-10 -9020047.848073646, -6.988082128305225e-10 -9020047.848073646, -6.916124591475106e-10 -9020047.848073646), (-719342.6657058225 -8999723.164524674, -707289.9184875957 -8997111.793131201, -1069706.502713425 -8960682.173552735, -1379911.638260131 -8916875.097665636, -1744425.469097161 -8869461.410756687, -2077450.885819135 -8817153.599032808, -1757965.178232176 -8841216.024403676, -1565884.71801243 -8828114.773026062, -1282340.819046155 -8841032.262674984, -1200953.554271547 -8839161.746462433, -1195259.959685203 -8816759.945755424, -1247798.064453379 -8793424.850355247, -1304049.708809776 -8776471.875135638, -1354590.243671938 -8762124.982998174, -1414088.587594351 -8748524.430804785, -1465483.693467818 -8740391.219279122, -1509000.792806843 -8741423.235533852, -1513799.184955954 -8751273.898848552, -1545865.411698435 -8771704.883900598, -1654497.839155751 -8766784.839472782, -1781744.883946618 -8739002.406984173, -1870855.803775097 -8731626.514787467, -1890234.948858054 -8726356.104693983, -1915891.085192057 -8699803.697992219, -1881090.812695354 -8693185.639977019, -1874232.34085256 -8681449.318749463, -1910530.778759489 -8675034.012455275, -1997128.68956743 -8669711.080111634, -2041993.284625229 -8657120.651277354, -2095327.408866333 -8621474.114707006, -2185888.459797449 -8570037.36903234, -2233441.073774669 -8551780.967303447, -2239804.642106932 -8543638.12716007, -2247223.370219811 -8536123.283202786, -2253422.913069476 -8534264.716354012, -2275727.425063358 -8539855.432073977, -2349370.660181472 -8538893.559687359, -2301139.452876771 -8531858.158737434, -2301276.275135382 -8525345.736498347, -2433405.204692264 -8506569.22235846, -2441272.501641633 -8500956.267950183, -2486455.296974394 -8496425.264356369, -2493584.352245067 -8496187.434032304, -2503135.463858067 -8499390.507582864, -2447354.849921366 -8513128.112082591, -2439244.416784253 -8514864.593273114, -2421697.003471549 -8519798.070647044, -2406570.496792325 -8526954.880232826, -2486723.721692292 -8513828.946612198, -2520894.825726033 -8505741.65045006, -2543195.978418801 -8501591.634227993, -2554483.985449331 -8499859.234898128, -2555271.834999873 -8499339.716778589, -2558243.49808286 -8498785.052394094, -2581531.548842141 -8500803.731863545, -2668082.610041395 -8486012.341561958, -2738344.357376733 -8472790.556103194, -2773918.15484584 -8464211.603193698, -2766570.964234427 -8453627.278869156, -2664601.461798028 -8468842.955233198, -2649675.377650904 -8469442.507179873, -2661566.479325622 -8464972.632949464, -2740296.708058076 -8453458.968722252, -2756401.657030685 -8448976.864085827, -2778424.75563349 -8440536.840028539, -2803855.500445608 -8439169.596548812, -2814386.202063061 -8430777.269564139, -2845516.97145668 -8422247.839594444, -2943543.372511121 -8398683.202221425, -2969904.157322195 -8393830.666021498, -2997024.33688469 -8385672.160164947, -3033115.187346036 -8380993.906777707, -3017715.406477534 -8369344.986326482, -2998127.932584463 -8375712.158585253, -2922319.364035875 -8391268.414581381, -2973553.007777028 -8368746.827455947, -3010057.55556404 -8359857.895533267, -3019502.297961875 -8355969.558842625, -2984871.841049096 -8327834.715066653, -3110306.882319482 -8296322.683520539, -3447129.641448218 -8278278.561505298, -3589885.012073769 -8324555.23246549, -3768995.706387411 -8357917.625078368, -3942606.838909308 -8379163.637678144, -4093732.923474622 -8402289.112583214, -4160464.791120189 -8405364.209521621, -4155101.69043878 -8406821.338774588, -4179572.48840843 -8440225.173226021, -4205223.155592469 -8450534.8341411, -4249291.518943704 -8459035.192879785, -4272124.94272534 -8468476.749631042, -4312397.771166404 -8478775.55919062, -4396495.501254228 -8490178.382785587, -4446030.239475174 -8499141.334012765, -4566170.055051253 -8517656.776179271, -4604005.123912279 -8525137.858163705, -4682008.000918958 -8531802.163049079, -4812853.836500324 -8532846.088136444, -4922546.692389229 -8530236.846852198, -4994593.916494365 -8523918.958388446, -5076637.893963936 -8512340.51060841, -5095395.428011818 -8509226.29998376, -5051788.565546789 -8520234.870946348, -5047966.195531255 -8523496.555652367, -5022342.858397909 -8527875.323764956, -5055587.396986793 -8530263.738330422, -5049626.188160041 -8532052.568002284, -5022253.564706062 -8536592.784188766, -5019353.788510586 -8539866.488932025, -5070164.355200028 -8532607.98566008, -5113238.937333671 -8528880.029559569, -5103479.818822949 -8532030.20343269, -5070556.516480329 -8538043.343867011, -5110462.685946132 -8535835.867690487, -5121574.54973886 -8541894.957931431, -5086492.506202673 -8548385.275513312, -5054210.383788968 -8553263.357201578, -5100945.67938507 -8560357.869603984, -5062266.341388045 -8570603.641462944, -4977819.905465838 -8582164.090490609, -4916039.307774154 -8588302.923592905, -4889420.229659438 -8592872.316754008, -4882242.080065151 -8595623.54611003, -5125909.263025612 -8574720.810395811, -5105451.2940099 -8581281.249272998, -5079785.745074108 -8584125.882490234, -5095805.592423089 -8589048.216844216, -5086268.947309235 -8591354.909496399, -5054086.400347551 -8596595.31172747, -4988314.560978157 -8601102.862953227, -4983297.105966513 -8596377.320151454, -4923035.138776992 -8598478.56994411, -4771308.869188873 -8613609.458927497, -4747872.084318195 -8617250.602494722, -4757093.24401804 -8620947.399524327, -4689703.906460191 -8626075.532282582, -4649246.117592908 -8632237.043236487, -4707450.634594806 -8630239.426839124, -4662885.559696229 -8634799.384301212, -4615481.38213711 -8642070.914527422, -4638527.762531516 -8640194.155607203, -4588387.208958791 -8647000.806034811, -4576694.288249486 -8647481.297842914, -4547438.726969938 -8653443.878232135, -4555261.916917278 -8655023.227437636, -4640758.800681854 -8644640.056076663, -4635921.114308648 -8646852.844362956, -4602013.740089788 -8652408.692842748, -4637128.811942601 -8649585.617914597, -4594538.547121155 -8656092.364250045, -4575099.281009424 -8660762.757675368, -4590914.50124614 -8664428.841921536, -4553451.182239653 -8669746.824754499, -4541270.619338041 -8672751.033376284, -4594460.44531012 -8668222.020549985, -4590973.259778024 -8671019.831529645, -4534370.417479398 -8675605.668382525, -4517410.221444165 -8680663.18517499, -4553448.076875925 -8679066.882039523, -4697722.591640066 -8664159.412374161, -4710295.474810818 -8664506.501283413, -4726826.831745301 -8660998.078225095, -4748066.5396527 -8658471.952458417, -4818047.024377794 -8653087.334278354, -4819135.07947701 -8654461.789912105, -4785928.95482418 -8659166.068858048, -4762194.255923755 -8664024.263124516, -4818012.731951122 -8662646.338173142, -4841770.855063512 -8660718.307171378, -4835428.968079068 -8657233.312236212, -4948382.88850846 -8646200.818918459, -4999759.939954013 -8643220.435227774, -4997551.913897177 -8646381.27617339, -5076153.707957353 -8639388.118000122, -5076735.670044489 -8642183.87888068, -5059021.774472645 -8645411.455067663, -5019144.107345255 -8650834.79202291, -4995040.757974664 -8657443.823503349, -5067291.094748129 -8650149.085938502, -5142426.118084169 -8640675.411116902, -5164352.410898246 -8639732.647867646, -5150692.3672301 -8642613.876218054, -5117181.548654078 -8646620.393150602, -5071467.075704413 -8654568.860953664, -4998061.744405479 -8663564.058808615, -4937282.319247646 -8674016.424878351))"
mls = wkt.loads(mls_wkt)

print(poly.contains(mls))
print([poly.contains(ls) for ls in mls])

Operating system

macOS 10.15.7

Shapely version

shapely 1.7.1

@dr-jts
Copy link

dr-jts commented Jun 18, 2021

This is a bug upstream in GEOS. It's due to the very large scale range in the coordinates. Not sure of a fix at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants