[GIS] Why is this polygon “self intersected” and invalid

invalid-datapythonqgisshapely

I have a polygon defined as follows:

segment from 43:29:02 N 003:50:39 E to 43:34:12 N 003:43:04 E
arc(CW): center (43:34:49 N 003:58:16 E) from 43:34:12 N 003:43:04 E to 43:45:45 N 003:59:56 E
segment from 43:45:45 N 003:59:56 E to 43:40:01 N 004:06:40 E
arc(CCW): center(43:34:49 N 003:58:16 E) from 43:40:01 N 004:06:40 E to 43:29:02 N 003:50:39 E

The corresponding shapefile can be found at http://bordel.kataplop.net/mont2.zip

EDIT corresponding WKT:

POLYGON ((3.8441666666666667 43.4838888888888917, 3.7177777777777781 43.5700000000000003,3.7177777777777781 43.5700000000000003, 3.7175416922400166 3.5735823218689617, 3.7174122630334763 43.5767891717197671, 3.7173600981542299 3.5799971695780499, 3.7173852258405691 43.5832053383720393, 3.7174876507934393 3.5864127008216897, 3.7176673541599534 43.5896182797364418, 3.7179242935240802 3.5928210983129603, 3.7182584029045262 43.5960201804331646, 3.7186695927598370 3.5992145509620244, 3.7191577500007265 43.6024032360454115, 3.7197227380096543 3.6055852634076615, 3.7203643966676592 43.6087596626488931, 3.7210825423884666 3.6119254655418658, 3.7218769681598638 43.6150817063284819, 3.7227474435923660 3.6182274220155932, 3.7236937149751603 43.6213616526702097, 3.7247155053393355 3.6244834417140126, 3.7258125145283985 43.6275918362168653, 3.7269844192760679 3.6306858871895287, 3.7282308732913374 43.6337646498753315, 3.7295515073508057 3.6368271840406265, 3.7309459293982550 43.6398725542641515, 3.7324137246514693 3.6428998302249624, 3.7339544557162703 43.6459080869891309, 3.7355676627077550 3.6488964052947779, 3.7372528633787132 43.6518638718357153, 3.7390095532552006 3.6548095795431905, 3.7408372057792332 43.6577326278661104, 3.7427352724585923 3.6606321230492824, 3.7447031830236801 43.6635071784097093, 3.7467403455914190 3.6663569146109367, 3.7488461468361369 43.6691804599352409, 3.7510199521674097 3.6719769505535709, 3.7532611059148122 43.6747455307932810, 3.7555689315195373 3.6774853534034406, 3.7579427317328289 43.6801955798176920, 3.7603817888211850 3.6828753804145080, 3.7628853647782754 43.6855239347749134, 3.7654527015435106 3.6881404319373985, 3.7680830212272212 43.6907240706500630, 3.7707755263423635 3.6932740596198741, 3.7735294000427100 43.6957896177589262, 3.7763438063674428 3.6982699744277099, 3.7792178904920881 43.7007143696751754, 3.7821507789857174 3.7031220544756636, 3.7851415800743458 43.7054922909624679, 3.7881893839104470 3.7078243526580579, 3.7912932628485052 43.7101175247009124, 3.7944522717265268 3.7123711040687439, 3.7976654481534204 43.7145843997981558, 3.8009318128021703 3.7167567332007110, 3.8042503697087033 43.7188874380751002, 3.8076201065763597 3.7209758609156580, 3.8110399950858844 43.7230213611168708, 3.8145089912108232 3.7250233111740272, 3.8180260355382507 43.7269810968797614, 3.8215900535947016 3.7288941175165959, 3.8251999561772285 43.7307617860452567, 3.8288546396894598 3.7325835292888101, 3.8325529864825651 43.7343587881124947, 3.8362938652010095 3.7360870175992957, 3.8400761311329896 43.7377676872209449, 3.8438986265654367 3.7394002810046700, 3.8477601811434705 43.7409842976952632, 3.8516596122341884 3.7425192509126504, 3.8555957252946604 43.7440046693048501, 3.8595673142440319 3.7454400966961998, 3.8635731618395748 43.7468250922308997, 3.8676120400566001 3.7481592305117388, 3.8716827104720783 43.7494421017339974, 3.8757839246518482 3.7506733118145732, 3.8799144245412855 43.7518524825160000, 3.8840729428592957 3.7529792515656695, 3.8882582034955018 43.7540532727700295, 3.8924689219104849 3.7550742161236030, 3.8967038055389538 43.7560417679131319, 3.9009615541956921 3.7569556308164564, 3.9052408604841538 43.7578155239962783, 3.9095404102075606 3.7586211831888079, 3.9138588827823697 43.7593723607871041, 3.9181949516539527 3.7600688259191912, 3.9225472847143648 43.7607103645209961, 3.9269145447220355 3.7612967794038497, 3.9312953897232594 43.7618278903168019, 3.9356884734753175 3.7623035340034718, 3.9400924458711075 43.7627235642536689, 3.9445059533651090 3.7630878519495354, 3.9489276394005572 43.7633962851063103, 3.9533561448376653 3.7636487689077285, 3.9577901083827460 43.7638452257359774, 3.9622281670180910 3.7639855951961891, 3.9666689564324482 43.7640698341355332, 3.9711111114519491 3.7640979166568798, 3.9755532664713464 43.7640698341269285, 3.9799940558853892 3.7639855951789798, 3.9844321145202120 43.7638452257101846, 3.9888660780645604 3.7636487688733453, 3.9932945835007279 43.7633962850633438, 3.9988888888888892 3.7625000000000028, 3.9988888888888892 43.7625000000000028, 4.1111111111111107 3.6669444444444395, 4.1111111111111107 43.6669444444444395, 4.1081112312987518 3.6694234695150385, 4.1059413722282461 43.6711419317362726, 4.1037302561558127 3.6728326982839690, 4.1014785562310649 43.6744952517733864, 4.0991869581943616 3.6761290834102880, 4.0968561601681621 43.6777336931488875, 4.0944868724443211 3.6793085898469968, 4.0920798172674075 43.6808532914185932, 4.0896357286140903 3.6823673249835380, 4.0871553519686730 43.6838502270144886, 4.0846394440948499 3.6853015434809535, 4.0820887728037327 43.6867208299904419, 4.0795041167182582 3.6881076519267424, 4.0768862650339983 43.6894615845849543, 4.0742360172765091 3.6907822133038266, 4.0715541830552358 43.6920691335946785, 4.0688415818141008 3.6933219512673716, 4.0660990425788137 43.6945402825530920, 4.0633274037010221 3.6957237542238488, 4.0605275125993510 43.6968720037087905, 4.0577002254974373 3.6979846792071598, 4.0548464071590304 43.6990614397979940, 4.0519669306202575 3.7001019555463870, 4.0490626769191227 43.7011059076063972, 4.0461345348223459 3.7020729883204879, 4.0431834005496210 43.7030029013155357, 4.0402101774953803 3.7038953615952721, 4.0372157759481668 43.7047500956292794, 4.0342011128077022 3.7055668414383405, 4.0311671112997329 43.7063453486762228, 4.0281147006887696 3.7070853787079088, 4.0250448159887977 43.7077867046840609, 4.0219583976720550 3.7084491116119267, 4.0188563913759925 43.7090723964224779, 4.0157397476084853 3.7096563680338832, 4.0126094214514216 43.7102008474111940, 4.0094663722627448 3.7107056676222996, 4.0063115633770714 43.7111706738901589, 4.0031459618049512 3.7115957236411106, 3.9999705379309152 43.7119806865494525, 3.9967862652103707 3.7123254445782763, 3.9935941198654712 43.7126298920162455, 3.9903950805800497 3.7128939355107562, 3.9871901281937285 43.7131174940970979, 3.9839802453953022 3.7133004992237275, 3.9807664164154883 43.7134428947737987, 3.9775496267191737 3.7135446370826486, 3.9743308626972342 43.7136056949514540, 3.9711111113580424 3.7136260496570372, 3.9678913600187755 43.7136056949576854, 3.9646725959966083 3.7135446370951186, 3.9614558062999161 43.7134428947925002, 3.9582419773195738 3.7133004992486534, 3.9550320945204667 43.7131174941282339, 3.9518271421333155 3.7128939355481165, 3.9486281028469135 43.7126298920597947, 3.9454359575008815 3.7123254446280072, 3.9422516847790567 43.7119806866053580, 3.9390762609035903 3.7115957237031481, 3.9359106593298914 43.7111706739583425, 3.9327558504424895 3.7107056676965939, 3.9296128012519382 43.7102008474915635, 3.9264824750928522 3.7096563681203136, 3.9233658313231752 43.7090723965149621, 3.9202638250247972 3.7084491117104150, 3.9171774067055947 43.7077867047885249, 3.9141075220030173 3.7070853788183129, 3.9110551113893059 43.7063453487925457, 3.9080211098784452 3.7055668415605325, 3.9050064467349470 43.7047500957573263, 3.9020120451845597 3.7038953617291099, 3.8990388221270043 43.7030029014551289, 3.8960876878508262 3.7020729884658010, 3.8931595457504589 43.7011059077573663, 3.8902552920455964 3.7001019557029906, 3.8873758155029599 43.6990614399601753, 3.8845219971605558 3.6979846793748692, 3.8816947100545103 43.6968720038819711, 3.8788948189485768 3.6957237544024579, 3.8761231800663918 43.6945402827370586, 3.8733806408265834 3.6933219514566531, 3.8706680395807975 43.6920691337892180, 3.8679862053547485 3.6907822135035673, 3.8653359575923583 43.6894615847898251, 3.8627181059030749 3.6881076521366793, 3.8601334498124533 43.6867208302053953, 3.8575827785160706 3.6853015437008381, 3.8550668706368625 43.6838502272392475, 3.8525864939859447 3.6823673252131073, 3.8501424053270101 43.6808532916528804, 3.8477353501443670 3.6793085900859452, 3.8453660624146853 43.6777336933924261, 3.8430352643825345 3.6761290836583598, 3.8407436663397725 43.6744952520258849, 3.8384919664088604 3.6728326985408302, 3.8362808503301578 43.6711419319974112, 3.8341109912532807 3.6694234697803836, 3.8319830495325728 43.6676778377045736, 3.8298976725267480 3.6659055698518159, 3.8278554944027792 43.6641072084053476, 3.8258571359440796 3.6622833034818925, 3.8239032043630350 43.6604344129611803, 3.8219942931179487 3.6585611023132358, 3.8201309817344384 43.6566639444233147, 3.8183138356313546 3.6547435194146729, 3.8165434059512564 43.6528004144691408, 3.8148202293954965 3.6508352236455082, 3.8131448280639657 43.6488485476959980, 3.8115177092995394 3.6468409938806090, 3.8099393655372626 43.6448131757796389, 3.8084102741583297 3.6427657131041897, 3.8069308973488800 43.6406992315050104, 3.8055016819636593 3.6386143623794922, 3.8041230593945863 43.6365117426770084, 3.8027954454442381 3.6343920147025415, 3.8015192402043150 43.6322558259189250, 3.8002948279390880 3.6301038287473517, 3.7991225769738843 43.6279366803666306, 3.7980028395886105 3.6257550425109812, 3.7969359519163612 43.6235595812664769, 3.7959222338471279 3.6213509668663235, 3.7949619889366235 43.6191298734849511, 3.7940555043202560 3.6168969790308338, 3.7932030506322558 43.6146529649385144, 3.7924048819299858 3.6123985159593701, 3.7916612356234385 43.6101343199516833, 3.7909723324099347 3.6078610676696670, 3.7903383762140490 43.6055794525518365, 3.7897595541327438 3.6032901705085649, 3.7892360363857511 43.6009939197090617, 3.7887679762711817 3.5986914003676489, 3.7883555101263844 43.5963833145296107, 3.7879987572940457 3.5940703658565170, 3.7876978200935398 43.5917532594112060, 3.7874527837975256 3.5894327014423624, 3.7872637166137779 43.5871093991689307, 3.7871306696722700 3.5847840605642105, 3.7870536770174819 43.5824573941399649, 3.7870327556059387 3.5801301087303372, 3.7870679053089629 43.5778029132758391, 3.7871591089206373 3.5754765166073952, 3.7873063321709624 43.5731516272305015, 3.7875095237441907 3.5708289531096042, 3.7877686153023324 43.5685092014527555, 3.7880835215138080 3.5661930784965250, 3.7884541400872318 43.5638812892914302, 3.7888803518103069 3.5615745374877150, 3.7893620205938126 43.5592735251216610, 3.7898989935206520 3.5569789524026021, 3.7904911008999558 43.5546915175004443, 3.7911381563261894 3.5524119163339805, 3.7918399567432615 43.5501408423599798, 3.7925962825135917 3.5478789863630809, 3.7934068974921065 43.5456270362466569, 3.7942715491051477 3.5433856768245562, 3.7951899684342383 43.5411555896139717, 3.7961618703046902 3.5389374526292983, 3.7971869533790148 43.5367319401772264, 3.7982649002550923 3.5345397226530011, 3.7993953775690708 43.5323614663379459, 3.8005780361029542 3.5301978331983648, 3.8018125108968346 43.5280494806857661, 3.8030984213657404 3.5259170615385997, 3.8044353714210359 43.5238012235854583, 3.8058229495963545 3.5217026095498341, 3.8072607291780023 43.5196218568565456, 3.8087482683397917 3.5175595974398064, 3.8102851102822637 43.5155164575530122, 3.8118707833762437 3.5134930575803338, 3.8135048013106849 43.5114900118501922, 3.8151866632447473 3.5095079284505033, 3.8169158539640686 43.5075474090460617, 3.8186918440411657 3.5056090486977283, 3.8205140899999148 43.5036934356838216, 3.8223820344840700 3.5018011513235479, 3.8242951064297430 43.4999327698025624, 3.8262527212418074 3.4980888580008198, 3.8282542809741620 43.4962699753225621, 3.8302991745138009 3.4944766735287303, 3.8323867777686216 43.4927094965716705, 3.8345164538589263 3.4909689804321928, 3.8366875533125495 43.4892556529591516, 3.8388994142635458 3.4875700337114921, 3.8411513626543869 43.4859126338027835, 3.8441666666666667 3.4838888888888917))

I'm using shapely to handle my data, and it reports that this polygon is self intersecting. I checked with QGis (it is also complaining about this problem), and I don't see why it would be self-intersecting.

I've narrowed down the problem to the 2 "single points" of the second arc (beginning and end). It looks like the 2 segments are considered as crossing the second arc… Which is not true.
I'm not producing the data but I can ask for fixing it in case it is wrong. But in this case, I don't understand the problem (if any).

Is this an issue of some buggy python library (shared by shapely and qgis) or is it something else ?

Best Answer

If I zoom in here...

enter image description here

I see this:

enter image description here

I think the issue stems from the limitation that a shapefile cannot store arcs. Instead it does a linear approximation. When a polyline intersects (what is intended to be) a circular arc at a tangent the zig zag approximation results in an intersection.

I'd recommend storing the geometry in something that supports circular arcs, like a file geodatabase. There is an open source API available for it. When was Esri File Geodatabase API made available?