我有2个OGR多边形相交,因此我想级联它们。我尝试了此操作,但它使我空了,没有合并它。似乎这仅适用于多边形而不适用于Mul; tipolygons。最好的方法是什么?
>>geom = ogr.Geometry(ogr.wkbMultiPolygon)
>>geom.AddGeometry(ogr.CreateGeometryFromWkt(x))
>>3
>>geom.AddGeometry(ogr.CreateGeometryFromWkt(y))
3
>>res=geom.UnionCascaded()
>>res
>>
它什么也不返回。这是我的2种几何:
x = 'MULTIPOLYGON (((-80.144005456 32.998288288,-80.142206271 32.99708629,-80.140567739 32.995526433,-80.14028373 32.994930019,-80.14046045 32.993069831,-80.140001753 32.993078283,-80.139787176 32.99268234,-80.139679888 32.992169413,-80.137963274 32.991125551,-80.138027647 32.990621613,-80.13772724 32.990360644,-80.137394646 32.990297651,-80.137072781 32.99047763,-80.136673024 32.990410528,-80.13617316 32.990302541,-80.135765464 32.990473521,-80.135244101 32.989842387,-80.136327714 32.989275449,-80.136681765 32.988798498,-80.136864155 32.988321544,-80.13704654599999 32.987862586,-80.137238166 32.988154355,-80.137817523 32.988235348,-80.13811793 32.988055365,-80.13830032 32.987830385,-80.138439795 32.987470416,-80.14054798799999 32.986913034,-80.143240926 32.986319078,-80.145622727 32.98505016,-80.14690840199999 32.985469873,-80.151162437 32.985548297,-80.151125732 32.987453228,-80.149590261 32.989615722,-80.148716551 32.991425901,-80.147150141 32.994426961,-80.146020711 32.996725207,-80.145539533 32.997557826,-80.14492637 32.998826283,-80.1446957 32.998808287,-80.144033639 32.998358603,-80.144005456 32.998288288)),((-80.13937310199999 32.981800809,-80.14200779399999 32.983604208,-80.144683875 32.984536711,-80.145617284 32.9821968,-80.148877635 32.977833414,-80.150456647 32.975353032,-80.151397835 32.974152078,-80.150574397 32.973549036,-80.14957125 32.97466736,-80.148844044 32.974613405,-80.148744802 32.974490772,-80.148460488 32.974277008,-80.146768095 32.97281335,-80.145263376 32.974669731,-80.143444925 32.976822785,-80.140580326 32.980215841,-80.13937310199999 32.981800809)),((-80.130111045 32.9959153,-80.124951306 32.993129272,-80.126108997 32.991150568,-80.128498417 32.987386329,-80.129400625 32.986172448,-80.131643247 32.985565802,-80.129700252 32.982397967,-80.131448198 32.981492096,-80.132106411 32.981377894,-80.133970909 32.981495601,-80.134585259 32.981569668,-80.136982582 32.982098327,-80.137367956 32.982338899,-80.138107789 32.982519423,-80.138379773 32.982367592,-80.138778307 32.982459057,-80.13793193 32.983421345,-80.136899089 32.984496223,-80.134162387 32.985017598,-80.134408612 32.985539158,-80.134086747 32.986151117,-80.133502025 32.987559508,-80.133695144 32.988085961,-80.133550305 32.988540418,-80.133807797 32.988814891,-80.133078236 32.989755292,-80.13387759 32.990254642,-80.130822622 32.99471916,-80.130111045 32.9959153)))'
y='MULTIPOLYGON (((-80.178879628 33.012076617,-80.178050825 33.01317646,-80.17668021599999 33.012501711,-80.177521838 33.011343274,-80.178879628 33.012076617)),((-80.172484266 33.007209137,-80.172977792 33.008369771,-80.173087763 33.008601312,-80.172299193 33.009021924,-80.17215879 33.009312777,-80.171807477 33.009789242,-80.17139262 33.010279195,-80.17074815399999 33.010754508,-80.170260728 33.011046178,-80.16967168799999 33.011464354,-80.168770466 33.010917798,-80.16848346899999 33.010780596,-80.16827425699999 33.010425219,-80.168360088 33.010141816,-80.168660495 33.009849416,-80.16883215599999 33.009601999,-80.168842885 33.009183639,-80.170036169 33.008576075,-80.172484266 33.007209137)),((-80.167833934 33.00238195,-80.169606333 33.004053896,-80.169946487 33.004392736,-80.167506212 33.007529211,-80.16530415 33.006391724,-80.167833934 33.00238195)),((-80.164800328 32.996660193,-80.163780148 32.996270031,-80.16460954199999 32.994841291,-80.16566365 32.99548918,-80.164800328 32.996660193)),((-80.158843042 33.016754353,-80.157925727 33.016093126,-80.160044045 33.01429135,-80.16098281799999 33.014743423,-80.158843042 33.016754353)),((-80.15742343 32.998939545,-80.155545884 32.998264688,-80.155889207 32.997616819,-80.156962091 32.997963249,-80.157915478 32.996016589,-80.156976705 32.995544173,-80.15725029 32.994860291,-80.15780818899999 32.994999767,-80.15775991 32.995359705,-80.157969122 32.995440691,-80.158387547 32.994887286,-80.158906001 32.995096759,-80.159549731 32.993715484,-80.158616322 32.99348602,-80.15776338 32.993175567,-80.157548803 32.992613149,-80.158376188 32.990721151,-80.160532685 32.991409564,-80.1608106 32.991747064,-80.160408269 32.993074377,-80.160174944 32.99370189,-80.15978334099999 32.993611904,-80.15901623 32.995159651,-80.159375088 32.995422048,-80.15742343 32.998939545)),((-80.155369709 33.005388797,-80.15676445699999 33.003193402,-80.158073375 33.003805239,-80.15738673 33.004893938,-80.159993837 33.006180566,-80.159199903 33.007305224,-80.155369709 33.005388797)),((-80.144737248 32.998979659,-80.143911128 32.998430776,-80.143696551 32.997881889,-80.143031363 32.997656934,-80.142215972 32.996883086,-80.140284781 32.995407356,-80.14035846199999 32.99496071,-80.140680327 32.994240829,-80.141012921 32.993529941,-80.140385284 32.993084508,-80.140288725 32.993525442,-80.140095606 32.994123848,-80.139768376 32.994681757,-80.13925875699999 32.994573775,-80.13914198 32.994273115,-80.13931900599999 32.99411564,-80.138793293 32.993998659,-80.138484839 32.994223623,-80.137587893 32.994740622,-80.137645707 32.995341704,-80.137358394 32.996039722,-80.136485886 32.99731219,-80.136012065 32.997926694,-80.135355277 32.99820958,-80.134671313 32.998232075,-80.134014729 32.997833243,-80.133627382 32.997270693,-80.132830766 32.997203206,-80.1319155 32.99671594,-80.130775506 32.996151809,-80.130560929 32.99558941,-80.130773274 32.995109536,-80.13111123199999 32.994778842,-80.131092263 32.994310062,-80.13150297 32.993974984,-80.131867808 32.994100243,-80.13188784499999 32.993446919,-80.132150171 32.993030092,-80.132466672 32.992825372,-80.13365200299999 32.992711212,-80.134585412 32.99237376,-80.135078226 32.991443305,-80.135459099 32.990777389,-80.135925804 32.990358939,-80.13668755099999 32.990462427,-80.137824808 32.990376937,-80.13803559199999 32.990873751,-80.13770299799999 32.991832128,-80.136410174 32.993033458,-80.135957623 32.992778515,-80.13557674899999 32.993327433,-80.136043453 32.99348041,-80.13556489 32.994277023,-80.134711947 32.994969908,-80.134098703 32.99523664,-80.134565407 32.996226463,-80.135311061 32.995988007,-80.135257417 32.995668564,-80.135808681 32.995175559,-80.136522148 32.994865112,-80.136870835 32.994082241,-80.138190482 32.993434342,-80.13836108 32.992876581,-80.138833149 32.99218368,-80.139573627 32.991885144,-80.14029245899999 32.992006628,-80.14172354199999 32.989975407,-80.14326313 32.991100272,-80.14717680699999 32.994395428,-80.144737248 32.998979659)))'
这里需要一些指导。
最佳答案
您需要将几何图形作为多边形直接添加到空几何图形中,
为此,需要为每个几何图形循环。
geom = ogr.Geometry(ogr.wkbMultiPolygon)
x_geom = ogr.CreateGeometryFromWkt(x)
for x in x_geom:
geom.AddGeometryDirectly(x)
y_geom = ogr.CreateGeometryFromWkt(y)
for y in y_geom:
geom.AddGeometryDirectly(y)
res=geom.UnionCascaded()
res
#<osgeo.ogr.Geometry; proxy of <Swig Object of type 'OGRGeometryShadow *' at #0x0000000002EEBBD0> >
res.GetArea()
#0.0003330705407145394
关于python - 我怎样才能级联OGR Multipolygons,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56299269/