扩展 geopandas 中的多边形,使它们不相互重叠
Expand polygons in geopandas so that they do not overlap each other
我有一个在地图上标出区域的 ploygons 列表
Zones value geometry
1 1693 POLYGON ((77.29454313715819 28.47571416392315, 77.3199164281738 28.49027682729388, 77.35455943354494 28.43844171633418, 77.35099203082447 28.4155937527752, 77.35600769695169 28.39666709859215, 77.35779928311231 28.35940788949793, 77.36412903746491 28.33260780173257, 77.3012575403107 28.3352091448401, 77.29224428233032 28.34524629850734, 77.28795067652591 28.34416850236445, 77.28966314753418 28.35047325770129, 77.28072847041015 28.3600605171088, 77.27066380366209 28.36946497611132, 77.26034164484864 28.40733427164579, 77.29454313715819 28.47571416392315))
2 10993 POLYGON ((77.03790937861326 28.5330381857626, 77.04354161127927 28.53153248584327, 77.07742843684079 28.5263304934327, 77.09299855860597 28.51407615782515, 77.13139964350587 28.43874360964733, 77.13036138972168 28.43677589941487, 77.10323474940184 28.41918615610694, 77.04297746333008 28.40159349018953, 77.03810555323484 28.39083571552191, 77.02916281374816 28.39199700493522, 77.01953342875366 28.39195018327294, 77.0126506257904 28.3825401283973, 77.00019700201874 28.37851443527498, 76.99504307373887 28.38477038394979, 76.99113573392752 28.37925203381539, 76.97819573589688 28.37619068029685, 76.97811322604021 28.37352737297728, 76.97609703506895 28.37354121505453, 76.97373752134378 28.372950897997, 76.97064927697451 28.36995773581435, 76.9667043861364 28.36850265126604, 76.96207284979047 28.36795383459731, 76.9397701541138 28.36303959656517, 76.93155697467454 28.36771200501251, 76.97675705012207 28.40348392524276, 76.97968551310427 28.41837566978024, 76.96613448389891 28.46526278237416, 76.97249617442013 28.48587939584601, 76.99696303042295 28.49045319025032, 77.03790937861326 28.5330381857626))
3 3247 POLYGON ((77.31033598383787 28.59873388307277, 77.33519429072263 28.60740221282772, 77.41972122248532 28.61007840819339, 77.40789397105102 28.57954784289011, 77.4008732381714 28.54780209506535, 77.40537120112306 28.54461720308592, 77.43336571952227 28.51459259960198, 77.44667633321409 28.49595639956125, 77.46136023792153 28.48033469259327, 77.48952641769772 28.48575438389362, 77.4975369863761 28.4820517241389, 77.49771207624204 28.48129427248859, 77.49829486187822 28.48049909370604, 77.49868707021599 28.48013067494649, 77.49948398920419 28.47962582841654, 77.4977918182266 28.47925300708565, 77.49726731690292 28.47888395248925, 77.49691923555257 28.47829862398783, 77.49652823885803 28.47729834171326, 77.4910255576027 28.46259357481066, 77.48466456946259 28.44660382010556, 77.48254268320926 28.43545036561961, 77.42049678858642 28.47430303814806, 77.38086239680179 28.46537960783657, 77.35051710566407 28.48480458777587, 77.34029496821289 28.4969443981592, 77.32089161356808 28.49173042532265, 77.30835471400144 28.5694665901361, 77.31006008967283 28.57080531113324, 77.30557441767579 28.58825553510934, 77.31033598383787 28.59873388307277))
4 4135 POLYGON ((77.18691145380858 28.60932125983482, 77.23992222651364 28.60442574397036, 77.24857482966306 28.60197790049529, 77.2745304647339 28.58598288034893, 77.27686527689822 28.57768296256933, 77.29106169995198 28.57242436313873, 77.30731805952912 28.57078374662981, 77.31991805895692 28.49149079493422, 77.29430629023439 28.47647348779957, 77.25959556445005 28.41140445339038, 77.22900471171265 28.4284501117526, 77.2133132711304 28.43219543160846, 77.21025451716308 28.44074228406376, 77.17564122065433 28.43579741892371, 77.14074690302735 28.45247345647804, 77.13138307246093 28.44114794898787, 77.09322929438477 28.51501169079233, 77.13869708308104 28.56428779683038, 77.18691145380858 28.60932125983482))
5 1308 POLYGON ((77.26124083002924 28.64409949616386, 77.25858265932916 28.65137824760606, 77.25617125185842 28.65795982056132, 77.24904452093958 28.6643432873366, 77.24548115548015 28.66755370228748, 77.24217597802993 28.67052853245401, 77.24256152018425 28.67062281801585, 77.23697512396693 28.68922219242313, 77.23417119702222 28.69855828445484, 77.2327585047138 28.7032636600628, 77.23206825181369 28.70556451212478, 77.2313395694745 28.70802056983299, 77.2315442958725 28.70815231972278, 77.23561116989971 28.70435310495424, 77.23939909418938 28.70078431431497, 77.23962698038942 28.71836731113308, 77.28749089869382 28.73462558669139, 77.29690341528772 28.7000563470265, 77.32116464098819 28.69966124618137, 77.31252422722696 28.64569537395644, 77.33830191954499 28.62244566765305, 77.33526898630974 28.60863853007654, 77.31011230906368 28.599891990708, 77.30493893870235 28.58915158756186, 77.30972192820433 28.57117399566029, 77.29133063181756 28.57339629389778, 77.27774585398559 28.57848276988614, 77.27514845713495 28.58673730028487, 77.24643280806664 28.60485372277467, 77.25230923306469 28.60510763946608, 77.25451371392136 28.60523910516036, 77.25410589083558 28.61099312614292, 77.25390734371075 28.61393123862198, 77.25378929468523 28.6155050431833, 77.2536980137704 28.61677384770526, 77.25362282610963 28.61796258286686, 77.25359583240279 28.6184140322341, 77.25355793824323 28.61897316746057, 77.25369706987864 28.62028102677204, 77.25370745548138 28.62038338452646, 77.25378444167499 28.62586523688889, 77.25401163157345 28.63236382588393, 77.25786226519466 28.63863672549747, 77.26124083002924 28.64409949616386))
6 958 POLYGON ((77.21516047915338 28.66597948534356, 77.21631380363822 28.66604465103062, 77.21933394559737 28.66629809257334, 77.22326064881204 28.66651785433174, 77.22932770403737 28.66681617046364, 77.23263414641734 28.66775843166092, 77.23582257160066 28.66870303777846, 77.24214577778694 28.67052162394007, 77.25618972262261 28.65784631115324, 77.25651778396487 28.65694769740808, 77.25682975205302 28.65608908845685, 77.25745905264735 28.65436714203107, 77.25872838267207 28.65090904159019, 77.26125631388551 28.64400191438832, 77.26080862374131 28.64328068681139, 77.2603502047611 28.64253356049823, 77.25944409563665 28.64107224809361, 77.25763724180581 28.63813543774733, 77.25398732432244 28.63227746136464, 77.25378780516505 28.62628044445501, 77.25358828600761 28.62028308492239, 77.25353257044672 28.61921280119006, 77.25451548060299 28.60524697934101, 77.24960868462446 28.60499905087913, 77.24642041447285 28.60486209271374, 77.24646420618419 28.60480990814211, 77.24630234416844 28.6047997320147, 77.24208941706539 28.60458157412442, 77.22110174235227 28.60672781330178, 77.18633617075805 28.61041735855603, 77.14220795878293 28.62201671035822, 77.14755883845208 28.63832954413859, 77.15029865130303 28.64646617899701, 77.15305992182607 28.65458335301816, 77.14974982127069 28.66104210226824, 77.15978077372432 28.6626055954999, 77.16925382670284 28.66408433957725, 77.19232785233379 28.66492130335962, 77.21516047915338 28.66597948534356))
7 4503 POLYGON ((77.06992020210146 28.68236059625499, 77.08392324324964 28.67671364423962, 77.09095695033189 28.67387593441254, 77.09444027626034 28.67247117052307, 77.09620339689668 28.67176054488183, 77.09792091997976 28.67106756446835, 77.11132784017443 28.66565946862678, 77.11801386591316 28.66295884632811, 77.12136224320051 28.66160615553191, 77.12310482817411 28.66090979826501, 77.12464088305352 28.66028522063559, 77.1371144452941 28.66118753001421, 77.14332306321975 28.66163985856645, 77.14644346543665 28.66186366856446, 77.14809888496515 28.66198145724323, 77.14992194255707 28.66222869045784, 77.15009626075148 28.66151924791238, 77.15019414868472 28.66111863037267, 77.14974218376994 28.66104515728381, 77.1514057985199 28.65779498581888, 77.15222419484981 28.65619928321949, 77.15264814516433 28.65536964797548, 77.15292851665149 28.65482066683309, 77.15305197891122 28.65458001923899, 77.14726908549187 28.63758751557275, 77.142179543103 28.62200257891848, 77.16451290568239 28.61604126927492, 77.18611670740961 28.61026799768646, 77.13701326807859 28.56406259592672, 77.09293092402345 28.51553666463697, 77.07719683131097 28.52733934836335, 77.04790148981931 28.53114785034047, 77.04439712008367 28.53266550172155, 77.04213729533079 28.5329389409001, 77.03770347651357 28.53480540563039, 77.03314768084401 28.53615334632705, 77.0328670388114 28.53977032475289, 77.02620358547085 28.54105096791524, 77.0188534866225 28.54383956869035, 77.01314236124868 28.54926342742028, 77.01643330439447 28.57084300053098, 76.97791576441647 28.56688701736958, 76.9134671369446 28.56911149017505, 76.92965133150942 28.62779766988017, 76.95596354731448 28.64277038658997, 77.00607541962982 28.63243784378461, 77.06992020210146 28.68236059625499))
8 1023 POLYGON ((77.37608229121092 28.73372761629155, 77.41486146601559 28.71434712237117, 77.45844715937497 28.71272989337348, 77.45740089472653 28.69726055875203, 77.45772792109376 28.68239132895908, 77.48946870478515 28.63417830618302, 77.45905443438413 28.62242922169765, 77.42555025919799 28.61550112591348, 77.42068332728267 28.61098737908513, 77.33713507136227 28.60889187081393, 77.3380442129028 28.61553690614739, 77.34032664545896 28.62218152105002, 77.31306416376951 28.64604411587624, 77.32239723261719 28.70037837855093, 77.29774134882811 28.70079392497996, 77.28850331171871 28.73487461470751, 77.25367189082029 28.74348260079652, 77.27299171503904 28.78390087523045, 77.37608229121092 28.73372761629155))
9 7263 POLYGON ((77.05868040522459 28.76036689063784, 77.05995800090108 28.76055183853124, 77.07136855014315 28.76030572105028, 77.10088937465375 28.75938241548826, 77.10483265399832 28.75988872730943, 77.10620101268859 28.76039503667498, 77.1067061321688 28.75854841896483, 77.13584910764816 28.73836846998568, 77.14023338624361 28.71726870434995, 77.1483152979267 28.72805699537252, 77.1596726027382 28.73668637896795, 77.17071423872832 28.7361831545565, 77.17185482272033 28.74390657951703, 77.19370538767697 28.76807957681535, 77.20405464037776 28.76320816821191, 77.21268727930905 28.7571326204508, 77.19915264948727 28.74757728960068, 77.20504237421876 28.72876506719509, 77.23057596835025 28.70843136407468, 77.24214113577729 28.67100547651979, 77.23001703318481 28.66731033018249, 77.16834664782411 28.66458906480836, 77.15096489771732 28.66156647444533, 77.15061743220215 28.66258051596164, 77.12537492426758 28.66084292667155, 77.06986290797117 28.68321033590825, 77.00765609797364 28.73673509441722, 77.05868040522459 28.76036689063784))
我按如下方式将这些多边形添加到地图上
gdf.crs = "epsg:4326"
map_test = folium.Map(location=[28.626458, 77.208751],tiles="openstreetmap", zoom_start=11)
folium.GeoJson(data=gdf["geometry"]).add_to(map_test)
我正在尝试使用下面的爆炸选项来缩小这些多边形之间的间隙,但正如您所看到的图像,间隙不是恒定的。
我该如何解决这个问题,以便我可以 explode/update 多边形几何图形而不重叠它们。
gdf.geometry = gdf.geometry.buffer(0.0005)
- 从缓冲多边形开始
- 使用这种方法https://gis.stackexchange.com/questions/370521/erase-overlapping-qgis-polygon-using-geopandas-within-jupyter
- 使用您的数据的完整 MWE
import io
import pandas as pd
import geopandas as gpd
import shapely
from itertools import combinations
df = pd.read_csv(io.StringIO("""Zones value geometry
1 1693 POLYGON ((77.29454313715819 28.47571416392315, 77.3199164281738 28.49027682729388, 77.35455943354494 28.43844171633418, 77.35099203082447 28.4155937527752, 77.35600769695169 28.39666709859215, 77.35779928311231 28.35940788949793, 77.36412903746491 28.33260780173257, 77.3012575403107 28.3352091448401, 77.29224428233032 28.34524629850734, 77.28795067652591 28.34416850236445, 77.28966314753418 28.35047325770129, 77.28072847041015 28.3600605171088, 77.27066380366209 28.36946497611132, 77.26034164484864 28.40733427164579, 77.29454313715819 28.47571416392315))
2 10993 POLYGON ((77.03790937861326 28.5330381857626, 77.04354161127927 28.53153248584327, 77.07742843684079 28.5263304934327, 77.09299855860597 28.51407615782515, 77.13139964350587 28.43874360964733, 77.13036138972168 28.43677589941487, 77.10323474940184 28.41918615610694, 77.04297746333008 28.40159349018953, 77.03810555323484 28.39083571552191, 77.02916281374816 28.39199700493522, 77.01953342875366 28.39195018327294, 77.0126506257904 28.3825401283973, 77.00019700201874 28.37851443527498, 76.99504307373887 28.38477038394979, 76.99113573392752 28.37925203381539, 76.97819573589688 28.37619068029685, 76.97811322604021 28.37352737297728, 76.97609703506895 28.37354121505453, 76.97373752134378 28.372950897997, 76.97064927697451 28.36995773581435, 76.9667043861364 28.36850265126604, 76.96207284979047 28.36795383459731, 76.9397701541138 28.36303959656517, 76.93155697467454 28.36771200501251, 76.97675705012207 28.40348392524276, 76.97968551310427 28.41837566978024, 76.96613448389891 28.46526278237416, 76.97249617442013 28.48587939584601, 76.99696303042295 28.49045319025032, 77.03790937861326 28.5330381857626))
3 3247 POLYGON ((77.31033598383787 28.59873388307277, 77.33519429072263 28.60740221282772, 77.41972122248532 28.61007840819339, 77.40789397105102 28.57954784289011, 77.4008732381714 28.54780209506535, 77.40537120112306 28.54461720308592, 77.43336571952227 28.51459259960198, 77.44667633321409 28.49595639956125, 77.46136023792153 28.48033469259327, 77.48952641769772 28.48575438389362, 77.4975369863761 28.4820517241389, 77.49771207624204 28.48129427248859, 77.49829486187822 28.48049909370604, 77.49868707021599 28.48013067494649, 77.49948398920419 28.47962582841654, 77.4977918182266 28.47925300708565, 77.49726731690292 28.47888395248925, 77.49691923555257 28.47829862398783, 77.49652823885803 28.47729834171326, 77.4910255576027 28.46259357481066, 77.48466456946259 28.44660382010556, 77.48254268320926 28.43545036561961, 77.42049678858642 28.47430303814806, 77.38086239680179 28.46537960783657, 77.35051710566407 28.48480458777587, 77.34029496821289 28.4969443981592, 77.32089161356808 28.49173042532265, 77.30835471400144 28.5694665901361, 77.31006008967283 28.57080531113324, 77.30557441767579 28.58825553510934, 77.31033598383787 28.59873388307277))
4 4135 POLYGON ((77.18691145380858 28.60932125983482, 77.23992222651364 28.60442574397036, 77.24857482966306 28.60197790049529, 77.2745304647339 28.58598288034893, 77.27686527689822 28.57768296256933, 77.29106169995198 28.57242436313873, 77.30731805952912 28.57078374662981, 77.31991805895692 28.49149079493422, 77.29430629023439 28.47647348779957, 77.25959556445005 28.41140445339038, 77.22900471171265 28.4284501117526, 77.2133132711304 28.43219543160846, 77.21025451716308 28.44074228406376, 77.17564122065433 28.43579741892371, 77.14074690302735 28.45247345647804, 77.13138307246093 28.44114794898787, 77.09322929438477 28.51501169079233, 77.13869708308104 28.56428779683038, 77.18691145380858 28.60932125983482))
5 1308 POLYGON ((77.26124083002924 28.64409949616386, 77.25858265932916 28.65137824760606, 77.25617125185842 28.65795982056132, 77.24904452093958 28.6643432873366, 77.24548115548015 28.66755370228748, 77.24217597802993 28.67052853245401, 77.24256152018425 28.67062281801585, 77.23697512396693 28.68922219242313, 77.23417119702222 28.69855828445484, 77.2327585047138 28.7032636600628, 77.23206825181369 28.70556451212478, 77.2313395694745 28.70802056983299, 77.2315442958725 28.70815231972278, 77.23561116989971 28.70435310495424, 77.23939909418938 28.70078431431497, 77.23962698038942 28.71836731113308, 77.28749089869382 28.73462558669139, 77.29690341528772 28.7000563470265, 77.32116464098819 28.69966124618137, 77.31252422722696 28.64569537395644, 77.33830191954499 28.62244566765305, 77.33526898630974 28.60863853007654, 77.31011230906368 28.599891990708, 77.30493893870235 28.58915158756186, 77.30972192820433 28.57117399566029, 77.29133063181756 28.57339629389778, 77.27774585398559 28.57848276988614, 77.27514845713495 28.58673730028487, 77.24643280806664 28.60485372277467, 77.25230923306469 28.60510763946608, 77.25451371392136 28.60523910516036, 77.25410589083558 28.61099312614292, 77.25390734371075 28.61393123862198, 77.25378929468523 28.6155050431833, 77.2536980137704 28.61677384770526, 77.25362282610963 28.61796258286686, 77.25359583240279 28.6184140322341, 77.25355793824323 28.61897316746057, 77.25369706987864 28.62028102677204, 77.25370745548138 28.62038338452646, 77.25378444167499 28.62586523688889, 77.25401163157345 28.63236382588393, 77.25786226519466 28.63863672549747, 77.26124083002924 28.64409949616386))
6 958 POLYGON ((77.21516047915338 28.66597948534356, 77.21631380363822 28.66604465103062, 77.21933394559737 28.66629809257334, 77.22326064881204 28.66651785433174, 77.22932770403737 28.66681617046364, 77.23263414641734 28.66775843166092, 77.23582257160066 28.66870303777846, 77.24214577778694 28.67052162394007, 77.25618972262261 28.65784631115324, 77.25651778396487 28.65694769740808, 77.25682975205302 28.65608908845685, 77.25745905264735 28.65436714203107, 77.25872838267207 28.65090904159019, 77.26125631388551 28.64400191438832, 77.26080862374131 28.64328068681139, 77.2603502047611 28.64253356049823, 77.25944409563665 28.64107224809361, 77.25763724180581 28.63813543774733, 77.25398732432244 28.63227746136464, 77.25378780516505 28.62628044445501, 77.25358828600761 28.62028308492239, 77.25353257044672 28.61921280119006, 77.25451548060299 28.60524697934101, 77.24960868462446 28.60499905087913, 77.24642041447285 28.60486209271374, 77.24646420618419 28.60480990814211, 77.24630234416844 28.6047997320147, 77.24208941706539 28.60458157412442, 77.22110174235227 28.60672781330178, 77.18633617075805 28.61041735855603, 77.14220795878293 28.62201671035822, 77.14755883845208 28.63832954413859, 77.15029865130303 28.64646617899701, 77.15305992182607 28.65458335301816, 77.14974982127069 28.66104210226824, 77.15978077372432 28.6626055954999, 77.16925382670284 28.66408433957725, 77.19232785233379 28.66492130335962, 77.21516047915338 28.66597948534356))
7 4503 POLYGON ((77.06992020210146 28.68236059625499, 77.08392324324964 28.67671364423962, 77.09095695033189 28.67387593441254, 77.09444027626034 28.67247117052307, 77.09620339689668 28.67176054488183, 77.09792091997976 28.67106756446835, 77.11132784017443 28.66565946862678, 77.11801386591316 28.66295884632811, 77.12136224320051 28.66160615553191, 77.12310482817411 28.66090979826501, 77.12464088305352 28.66028522063559, 77.1371144452941 28.66118753001421, 77.14332306321975 28.66163985856645, 77.14644346543665 28.66186366856446, 77.14809888496515 28.66198145724323, 77.14992194255707 28.66222869045784, 77.15009626075148 28.66151924791238, 77.15019414868472 28.66111863037267, 77.14974218376994 28.66104515728381, 77.1514057985199 28.65779498581888, 77.15222419484981 28.65619928321949, 77.15264814516433 28.65536964797548, 77.15292851665149 28.65482066683309, 77.15305197891122 28.65458001923899, 77.14726908549187 28.63758751557275, 77.142179543103 28.62200257891848, 77.16451290568239 28.61604126927492, 77.18611670740961 28.61026799768646, 77.13701326807859 28.56406259592672, 77.09293092402345 28.51553666463697, 77.07719683131097 28.52733934836335, 77.04790148981931 28.53114785034047, 77.04439712008367 28.53266550172155, 77.04213729533079 28.5329389409001, 77.03770347651357 28.53480540563039, 77.03314768084401 28.53615334632705, 77.0328670388114 28.53977032475289, 77.02620358547085 28.54105096791524, 77.0188534866225 28.54383956869035, 77.01314236124868 28.54926342742028, 77.01643330439447 28.57084300053098, 76.97791576441647 28.56688701736958, 76.9134671369446 28.56911149017505, 76.92965133150942 28.62779766988017, 76.95596354731448 28.64277038658997, 77.00607541962982 28.63243784378461, 77.06992020210146 28.68236059625499))
8 1023 POLYGON ((77.37608229121092 28.73372761629155, 77.41486146601559 28.71434712237117, 77.45844715937497 28.71272989337348, 77.45740089472653 28.69726055875203, 77.45772792109376 28.68239132895908, 77.48946870478515 28.63417830618302, 77.45905443438413 28.62242922169765, 77.42555025919799 28.61550112591348, 77.42068332728267 28.61098737908513, 77.33713507136227 28.60889187081393, 77.3380442129028 28.61553690614739, 77.34032664545896 28.62218152105002, 77.31306416376951 28.64604411587624, 77.32239723261719 28.70037837855093, 77.29774134882811 28.70079392497996, 77.28850331171871 28.73487461470751, 77.25367189082029 28.74348260079652, 77.27299171503904 28.78390087523045, 77.37608229121092 28.73372761629155))
9 7263 POLYGON ((77.05868040522459 28.76036689063784, 77.05995800090108 28.76055183853124, 77.07136855014315 28.76030572105028, 77.10088937465375 28.75938241548826, 77.10483265399832 28.75988872730943, 77.10620101268859 28.76039503667498, 77.1067061321688 28.75854841896483, 77.13584910764816 28.73836846998568, 77.14023338624361 28.71726870434995, 77.1483152979267 28.72805699537252, 77.1596726027382 28.73668637896795, 77.17071423872832 28.7361831545565, 77.17185482272033 28.74390657951703, 77.19370538767697 28.76807957681535, 77.20405464037776 28.76320816821191, 77.21268727930905 28.7571326204508, 77.19915264948727 28.74757728960068, 77.20504237421876 28.72876506719509, 77.23057596835025 28.70843136407468, 77.24214113577729 28.67100547651979, 77.23001703318481 28.66731033018249, 77.16834664782411 28.66458906480836, 77.15096489771732 28.66156647444533, 77.15061743220215 28.66258051596164, 77.12537492426758 28.66084292667155, 77.06986290797117 28.68321033590825, 77.00765609797364 28.73673509441722, 77.05868040522459 28.76036689063784))
"""), sep="\s\s+", engine="python")
gdf = gpd.GeoDataFrame(df, geometry=df["geometry"].apply(shapely.wkt.loads), crs="epsg:4386")
# add a buffer
gdf.geometry = gdf.geometry.buffer(0.001)
# remove overlaps https://gis.stackexchange.com/questions/370521/erase-overlapping-qgis-polygon-using-geopandas-within-jupyter
poly = gdf.geometry
for p1_idx, p2_idx in combinations(poly.index, 2):
if poly.loc[p1_idx].intersects(poly.loc[p2_idx]):
# Store intermediary results back to poly
poly.loc[p2_idx] -= poly.loc[p1_idx]
gdf["geometry"] = poly
gdf.explore()
我有一个在地图上标出区域的 ploygons 列表
Zones value geometry
1 1693 POLYGON ((77.29454313715819 28.47571416392315, 77.3199164281738 28.49027682729388, 77.35455943354494 28.43844171633418, 77.35099203082447 28.4155937527752, 77.35600769695169 28.39666709859215, 77.35779928311231 28.35940788949793, 77.36412903746491 28.33260780173257, 77.3012575403107 28.3352091448401, 77.29224428233032 28.34524629850734, 77.28795067652591 28.34416850236445, 77.28966314753418 28.35047325770129, 77.28072847041015 28.3600605171088, 77.27066380366209 28.36946497611132, 77.26034164484864 28.40733427164579, 77.29454313715819 28.47571416392315))
2 10993 POLYGON ((77.03790937861326 28.5330381857626, 77.04354161127927 28.53153248584327, 77.07742843684079 28.5263304934327, 77.09299855860597 28.51407615782515, 77.13139964350587 28.43874360964733, 77.13036138972168 28.43677589941487, 77.10323474940184 28.41918615610694, 77.04297746333008 28.40159349018953, 77.03810555323484 28.39083571552191, 77.02916281374816 28.39199700493522, 77.01953342875366 28.39195018327294, 77.0126506257904 28.3825401283973, 77.00019700201874 28.37851443527498, 76.99504307373887 28.38477038394979, 76.99113573392752 28.37925203381539, 76.97819573589688 28.37619068029685, 76.97811322604021 28.37352737297728, 76.97609703506895 28.37354121505453, 76.97373752134378 28.372950897997, 76.97064927697451 28.36995773581435, 76.9667043861364 28.36850265126604, 76.96207284979047 28.36795383459731, 76.9397701541138 28.36303959656517, 76.93155697467454 28.36771200501251, 76.97675705012207 28.40348392524276, 76.97968551310427 28.41837566978024, 76.96613448389891 28.46526278237416, 76.97249617442013 28.48587939584601, 76.99696303042295 28.49045319025032, 77.03790937861326 28.5330381857626))
3 3247 POLYGON ((77.31033598383787 28.59873388307277, 77.33519429072263 28.60740221282772, 77.41972122248532 28.61007840819339, 77.40789397105102 28.57954784289011, 77.4008732381714 28.54780209506535, 77.40537120112306 28.54461720308592, 77.43336571952227 28.51459259960198, 77.44667633321409 28.49595639956125, 77.46136023792153 28.48033469259327, 77.48952641769772 28.48575438389362, 77.4975369863761 28.4820517241389, 77.49771207624204 28.48129427248859, 77.49829486187822 28.48049909370604, 77.49868707021599 28.48013067494649, 77.49948398920419 28.47962582841654, 77.4977918182266 28.47925300708565, 77.49726731690292 28.47888395248925, 77.49691923555257 28.47829862398783, 77.49652823885803 28.47729834171326, 77.4910255576027 28.46259357481066, 77.48466456946259 28.44660382010556, 77.48254268320926 28.43545036561961, 77.42049678858642 28.47430303814806, 77.38086239680179 28.46537960783657, 77.35051710566407 28.48480458777587, 77.34029496821289 28.4969443981592, 77.32089161356808 28.49173042532265, 77.30835471400144 28.5694665901361, 77.31006008967283 28.57080531113324, 77.30557441767579 28.58825553510934, 77.31033598383787 28.59873388307277))
4 4135 POLYGON ((77.18691145380858 28.60932125983482, 77.23992222651364 28.60442574397036, 77.24857482966306 28.60197790049529, 77.2745304647339 28.58598288034893, 77.27686527689822 28.57768296256933, 77.29106169995198 28.57242436313873, 77.30731805952912 28.57078374662981, 77.31991805895692 28.49149079493422, 77.29430629023439 28.47647348779957, 77.25959556445005 28.41140445339038, 77.22900471171265 28.4284501117526, 77.2133132711304 28.43219543160846, 77.21025451716308 28.44074228406376, 77.17564122065433 28.43579741892371, 77.14074690302735 28.45247345647804, 77.13138307246093 28.44114794898787, 77.09322929438477 28.51501169079233, 77.13869708308104 28.56428779683038, 77.18691145380858 28.60932125983482))
5 1308 POLYGON ((77.26124083002924 28.64409949616386, 77.25858265932916 28.65137824760606, 77.25617125185842 28.65795982056132, 77.24904452093958 28.6643432873366, 77.24548115548015 28.66755370228748, 77.24217597802993 28.67052853245401, 77.24256152018425 28.67062281801585, 77.23697512396693 28.68922219242313, 77.23417119702222 28.69855828445484, 77.2327585047138 28.7032636600628, 77.23206825181369 28.70556451212478, 77.2313395694745 28.70802056983299, 77.2315442958725 28.70815231972278, 77.23561116989971 28.70435310495424, 77.23939909418938 28.70078431431497, 77.23962698038942 28.71836731113308, 77.28749089869382 28.73462558669139, 77.29690341528772 28.7000563470265, 77.32116464098819 28.69966124618137, 77.31252422722696 28.64569537395644, 77.33830191954499 28.62244566765305, 77.33526898630974 28.60863853007654, 77.31011230906368 28.599891990708, 77.30493893870235 28.58915158756186, 77.30972192820433 28.57117399566029, 77.29133063181756 28.57339629389778, 77.27774585398559 28.57848276988614, 77.27514845713495 28.58673730028487, 77.24643280806664 28.60485372277467, 77.25230923306469 28.60510763946608, 77.25451371392136 28.60523910516036, 77.25410589083558 28.61099312614292, 77.25390734371075 28.61393123862198, 77.25378929468523 28.6155050431833, 77.2536980137704 28.61677384770526, 77.25362282610963 28.61796258286686, 77.25359583240279 28.6184140322341, 77.25355793824323 28.61897316746057, 77.25369706987864 28.62028102677204, 77.25370745548138 28.62038338452646, 77.25378444167499 28.62586523688889, 77.25401163157345 28.63236382588393, 77.25786226519466 28.63863672549747, 77.26124083002924 28.64409949616386))
6 958 POLYGON ((77.21516047915338 28.66597948534356, 77.21631380363822 28.66604465103062, 77.21933394559737 28.66629809257334, 77.22326064881204 28.66651785433174, 77.22932770403737 28.66681617046364, 77.23263414641734 28.66775843166092, 77.23582257160066 28.66870303777846, 77.24214577778694 28.67052162394007, 77.25618972262261 28.65784631115324, 77.25651778396487 28.65694769740808, 77.25682975205302 28.65608908845685, 77.25745905264735 28.65436714203107, 77.25872838267207 28.65090904159019, 77.26125631388551 28.64400191438832, 77.26080862374131 28.64328068681139, 77.2603502047611 28.64253356049823, 77.25944409563665 28.64107224809361, 77.25763724180581 28.63813543774733, 77.25398732432244 28.63227746136464, 77.25378780516505 28.62628044445501, 77.25358828600761 28.62028308492239, 77.25353257044672 28.61921280119006, 77.25451548060299 28.60524697934101, 77.24960868462446 28.60499905087913, 77.24642041447285 28.60486209271374, 77.24646420618419 28.60480990814211, 77.24630234416844 28.6047997320147, 77.24208941706539 28.60458157412442, 77.22110174235227 28.60672781330178, 77.18633617075805 28.61041735855603, 77.14220795878293 28.62201671035822, 77.14755883845208 28.63832954413859, 77.15029865130303 28.64646617899701, 77.15305992182607 28.65458335301816, 77.14974982127069 28.66104210226824, 77.15978077372432 28.6626055954999, 77.16925382670284 28.66408433957725, 77.19232785233379 28.66492130335962, 77.21516047915338 28.66597948534356))
7 4503 POLYGON ((77.06992020210146 28.68236059625499, 77.08392324324964 28.67671364423962, 77.09095695033189 28.67387593441254, 77.09444027626034 28.67247117052307, 77.09620339689668 28.67176054488183, 77.09792091997976 28.67106756446835, 77.11132784017443 28.66565946862678, 77.11801386591316 28.66295884632811, 77.12136224320051 28.66160615553191, 77.12310482817411 28.66090979826501, 77.12464088305352 28.66028522063559, 77.1371144452941 28.66118753001421, 77.14332306321975 28.66163985856645, 77.14644346543665 28.66186366856446, 77.14809888496515 28.66198145724323, 77.14992194255707 28.66222869045784, 77.15009626075148 28.66151924791238, 77.15019414868472 28.66111863037267, 77.14974218376994 28.66104515728381, 77.1514057985199 28.65779498581888, 77.15222419484981 28.65619928321949, 77.15264814516433 28.65536964797548, 77.15292851665149 28.65482066683309, 77.15305197891122 28.65458001923899, 77.14726908549187 28.63758751557275, 77.142179543103 28.62200257891848, 77.16451290568239 28.61604126927492, 77.18611670740961 28.61026799768646, 77.13701326807859 28.56406259592672, 77.09293092402345 28.51553666463697, 77.07719683131097 28.52733934836335, 77.04790148981931 28.53114785034047, 77.04439712008367 28.53266550172155, 77.04213729533079 28.5329389409001, 77.03770347651357 28.53480540563039, 77.03314768084401 28.53615334632705, 77.0328670388114 28.53977032475289, 77.02620358547085 28.54105096791524, 77.0188534866225 28.54383956869035, 77.01314236124868 28.54926342742028, 77.01643330439447 28.57084300053098, 76.97791576441647 28.56688701736958, 76.9134671369446 28.56911149017505, 76.92965133150942 28.62779766988017, 76.95596354731448 28.64277038658997, 77.00607541962982 28.63243784378461, 77.06992020210146 28.68236059625499))
8 1023 POLYGON ((77.37608229121092 28.73372761629155, 77.41486146601559 28.71434712237117, 77.45844715937497 28.71272989337348, 77.45740089472653 28.69726055875203, 77.45772792109376 28.68239132895908, 77.48946870478515 28.63417830618302, 77.45905443438413 28.62242922169765, 77.42555025919799 28.61550112591348, 77.42068332728267 28.61098737908513, 77.33713507136227 28.60889187081393, 77.3380442129028 28.61553690614739, 77.34032664545896 28.62218152105002, 77.31306416376951 28.64604411587624, 77.32239723261719 28.70037837855093, 77.29774134882811 28.70079392497996, 77.28850331171871 28.73487461470751, 77.25367189082029 28.74348260079652, 77.27299171503904 28.78390087523045, 77.37608229121092 28.73372761629155))
9 7263 POLYGON ((77.05868040522459 28.76036689063784, 77.05995800090108 28.76055183853124, 77.07136855014315 28.76030572105028, 77.10088937465375 28.75938241548826, 77.10483265399832 28.75988872730943, 77.10620101268859 28.76039503667498, 77.1067061321688 28.75854841896483, 77.13584910764816 28.73836846998568, 77.14023338624361 28.71726870434995, 77.1483152979267 28.72805699537252, 77.1596726027382 28.73668637896795, 77.17071423872832 28.7361831545565, 77.17185482272033 28.74390657951703, 77.19370538767697 28.76807957681535, 77.20405464037776 28.76320816821191, 77.21268727930905 28.7571326204508, 77.19915264948727 28.74757728960068, 77.20504237421876 28.72876506719509, 77.23057596835025 28.70843136407468, 77.24214113577729 28.67100547651979, 77.23001703318481 28.66731033018249, 77.16834664782411 28.66458906480836, 77.15096489771732 28.66156647444533, 77.15061743220215 28.66258051596164, 77.12537492426758 28.66084292667155, 77.06986290797117 28.68321033590825, 77.00765609797364 28.73673509441722, 77.05868040522459 28.76036689063784))
我按如下方式将这些多边形添加到地图上
gdf.crs = "epsg:4326"
map_test = folium.Map(location=[28.626458, 77.208751],tiles="openstreetmap", zoom_start=11)
folium.GeoJson(data=gdf["geometry"]).add_to(map_test)
我正在尝试使用下面的爆炸选项来缩小这些多边形之间的间隙,但正如您所看到的图像,间隙不是恒定的。
我该如何解决这个问题,以便我可以 explode/update 多边形几何图形而不重叠它们。
gdf.geometry = gdf.geometry.buffer(0.0005)
- 从缓冲多边形开始
- 使用这种方法https://gis.stackexchange.com/questions/370521/erase-overlapping-qgis-polygon-using-geopandas-within-jupyter
- 使用您的数据的完整 MWE
import io
import pandas as pd
import geopandas as gpd
import shapely
from itertools import combinations
df = pd.read_csv(io.StringIO("""Zones value geometry
1 1693 POLYGON ((77.29454313715819 28.47571416392315, 77.3199164281738 28.49027682729388, 77.35455943354494 28.43844171633418, 77.35099203082447 28.4155937527752, 77.35600769695169 28.39666709859215, 77.35779928311231 28.35940788949793, 77.36412903746491 28.33260780173257, 77.3012575403107 28.3352091448401, 77.29224428233032 28.34524629850734, 77.28795067652591 28.34416850236445, 77.28966314753418 28.35047325770129, 77.28072847041015 28.3600605171088, 77.27066380366209 28.36946497611132, 77.26034164484864 28.40733427164579, 77.29454313715819 28.47571416392315))
2 10993 POLYGON ((77.03790937861326 28.5330381857626, 77.04354161127927 28.53153248584327, 77.07742843684079 28.5263304934327, 77.09299855860597 28.51407615782515, 77.13139964350587 28.43874360964733, 77.13036138972168 28.43677589941487, 77.10323474940184 28.41918615610694, 77.04297746333008 28.40159349018953, 77.03810555323484 28.39083571552191, 77.02916281374816 28.39199700493522, 77.01953342875366 28.39195018327294, 77.0126506257904 28.3825401283973, 77.00019700201874 28.37851443527498, 76.99504307373887 28.38477038394979, 76.99113573392752 28.37925203381539, 76.97819573589688 28.37619068029685, 76.97811322604021 28.37352737297728, 76.97609703506895 28.37354121505453, 76.97373752134378 28.372950897997, 76.97064927697451 28.36995773581435, 76.9667043861364 28.36850265126604, 76.96207284979047 28.36795383459731, 76.9397701541138 28.36303959656517, 76.93155697467454 28.36771200501251, 76.97675705012207 28.40348392524276, 76.97968551310427 28.41837566978024, 76.96613448389891 28.46526278237416, 76.97249617442013 28.48587939584601, 76.99696303042295 28.49045319025032, 77.03790937861326 28.5330381857626))
3 3247 POLYGON ((77.31033598383787 28.59873388307277, 77.33519429072263 28.60740221282772, 77.41972122248532 28.61007840819339, 77.40789397105102 28.57954784289011, 77.4008732381714 28.54780209506535, 77.40537120112306 28.54461720308592, 77.43336571952227 28.51459259960198, 77.44667633321409 28.49595639956125, 77.46136023792153 28.48033469259327, 77.48952641769772 28.48575438389362, 77.4975369863761 28.4820517241389, 77.49771207624204 28.48129427248859, 77.49829486187822 28.48049909370604, 77.49868707021599 28.48013067494649, 77.49948398920419 28.47962582841654, 77.4977918182266 28.47925300708565, 77.49726731690292 28.47888395248925, 77.49691923555257 28.47829862398783, 77.49652823885803 28.47729834171326, 77.4910255576027 28.46259357481066, 77.48466456946259 28.44660382010556, 77.48254268320926 28.43545036561961, 77.42049678858642 28.47430303814806, 77.38086239680179 28.46537960783657, 77.35051710566407 28.48480458777587, 77.34029496821289 28.4969443981592, 77.32089161356808 28.49173042532265, 77.30835471400144 28.5694665901361, 77.31006008967283 28.57080531113324, 77.30557441767579 28.58825553510934, 77.31033598383787 28.59873388307277))
4 4135 POLYGON ((77.18691145380858 28.60932125983482, 77.23992222651364 28.60442574397036, 77.24857482966306 28.60197790049529, 77.2745304647339 28.58598288034893, 77.27686527689822 28.57768296256933, 77.29106169995198 28.57242436313873, 77.30731805952912 28.57078374662981, 77.31991805895692 28.49149079493422, 77.29430629023439 28.47647348779957, 77.25959556445005 28.41140445339038, 77.22900471171265 28.4284501117526, 77.2133132711304 28.43219543160846, 77.21025451716308 28.44074228406376, 77.17564122065433 28.43579741892371, 77.14074690302735 28.45247345647804, 77.13138307246093 28.44114794898787, 77.09322929438477 28.51501169079233, 77.13869708308104 28.56428779683038, 77.18691145380858 28.60932125983482))
5 1308 POLYGON ((77.26124083002924 28.64409949616386, 77.25858265932916 28.65137824760606, 77.25617125185842 28.65795982056132, 77.24904452093958 28.6643432873366, 77.24548115548015 28.66755370228748, 77.24217597802993 28.67052853245401, 77.24256152018425 28.67062281801585, 77.23697512396693 28.68922219242313, 77.23417119702222 28.69855828445484, 77.2327585047138 28.7032636600628, 77.23206825181369 28.70556451212478, 77.2313395694745 28.70802056983299, 77.2315442958725 28.70815231972278, 77.23561116989971 28.70435310495424, 77.23939909418938 28.70078431431497, 77.23962698038942 28.71836731113308, 77.28749089869382 28.73462558669139, 77.29690341528772 28.7000563470265, 77.32116464098819 28.69966124618137, 77.31252422722696 28.64569537395644, 77.33830191954499 28.62244566765305, 77.33526898630974 28.60863853007654, 77.31011230906368 28.599891990708, 77.30493893870235 28.58915158756186, 77.30972192820433 28.57117399566029, 77.29133063181756 28.57339629389778, 77.27774585398559 28.57848276988614, 77.27514845713495 28.58673730028487, 77.24643280806664 28.60485372277467, 77.25230923306469 28.60510763946608, 77.25451371392136 28.60523910516036, 77.25410589083558 28.61099312614292, 77.25390734371075 28.61393123862198, 77.25378929468523 28.6155050431833, 77.2536980137704 28.61677384770526, 77.25362282610963 28.61796258286686, 77.25359583240279 28.6184140322341, 77.25355793824323 28.61897316746057, 77.25369706987864 28.62028102677204, 77.25370745548138 28.62038338452646, 77.25378444167499 28.62586523688889, 77.25401163157345 28.63236382588393, 77.25786226519466 28.63863672549747, 77.26124083002924 28.64409949616386))
6 958 POLYGON ((77.21516047915338 28.66597948534356, 77.21631380363822 28.66604465103062, 77.21933394559737 28.66629809257334, 77.22326064881204 28.66651785433174, 77.22932770403737 28.66681617046364, 77.23263414641734 28.66775843166092, 77.23582257160066 28.66870303777846, 77.24214577778694 28.67052162394007, 77.25618972262261 28.65784631115324, 77.25651778396487 28.65694769740808, 77.25682975205302 28.65608908845685, 77.25745905264735 28.65436714203107, 77.25872838267207 28.65090904159019, 77.26125631388551 28.64400191438832, 77.26080862374131 28.64328068681139, 77.2603502047611 28.64253356049823, 77.25944409563665 28.64107224809361, 77.25763724180581 28.63813543774733, 77.25398732432244 28.63227746136464, 77.25378780516505 28.62628044445501, 77.25358828600761 28.62028308492239, 77.25353257044672 28.61921280119006, 77.25451548060299 28.60524697934101, 77.24960868462446 28.60499905087913, 77.24642041447285 28.60486209271374, 77.24646420618419 28.60480990814211, 77.24630234416844 28.6047997320147, 77.24208941706539 28.60458157412442, 77.22110174235227 28.60672781330178, 77.18633617075805 28.61041735855603, 77.14220795878293 28.62201671035822, 77.14755883845208 28.63832954413859, 77.15029865130303 28.64646617899701, 77.15305992182607 28.65458335301816, 77.14974982127069 28.66104210226824, 77.15978077372432 28.6626055954999, 77.16925382670284 28.66408433957725, 77.19232785233379 28.66492130335962, 77.21516047915338 28.66597948534356))
7 4503 POLYGON ((77.06992020210146 28.68236059625499, 77.08392324324964 28.67671364423962, 77.09095695033189 28.67387593441254, 77.09444027626034 28.67247117052307, 77.09620339689668 28.67176054488183, 77.09792091997976 28.67106756446835, 77.11132784017443 28.66565946862678, 77.11801386591316 28.66295884632811, 77.12136224320051 28.66160615553191, 77.12310482817411 28.66090979826501, 77.12464088305352 28.66028522063559, 77.1371144452941 28.66118753001421, 77.14332306321975 28.66163985856645, 77.14644346543665 28.66186366856446, 77.14809888496515 28.66198145724323, 77.14992194255707 28.66222869045784, 77.15009626075148 28.66151924791238, 77.15019414868472 28.66111863037267, 77.14974218376994 28.66104515728381, 77.1514057985199 28.65779498581888, 77.15222419484981 28.65619928321949, 77.15264814516433 28.65536964797548, 77.15292851665149 28.65482066683309, 77.15305197891122 28.65458001923899, 77.14726908549187 28.63758751557275, 77.142179543103 28.62200257891848, 77.16451290568239 28.61604126927492, 77.18611670740961 28.61026799768646, 77.13701326807859 28.56406259592672, 77.09293092402345 28.51553666463697, 77.07719683131097 28.52733934836335, 77.04790148981931 28.53114785034047, 77.04439712008367 28.53266550172155, 77.04213729533079 28.5329389409001, 77.03770347651357 28.53480540563039, 77.03314768084401 28.53615334632705, 77.0328670388114 28.53977032475289, 77.02620358547085 28.54105096791524, 77.0188534866225 28.54383956869035, 77.01314236124868 28.54926342742028, 77.01643330439447 28.57084300053098, 76.97791576441647 28.56688701736958, 76.9134671369446 28.56911149017505, 76.92965133150942 28.62779766988017, 76.95596354731448 28.64277038658997, 77.00607541962982 28.63243784378461, 77.06992020210146 28.68236059625499))
8 1023 POLYGON ((77.37608229121092 28.73372761629155, 77.41486146601559 28.71434712237117, 77.45844715937497 28.71272989337348, 77.45740089472653 28.69726055875203, 77.45772792109376 28.68239132895908, 77.48946870478515 28.63417830618302, 77.45905443438413 28.62242922169765, 77.42555025919799 28.61550112591348, 77.42068332728267 28.61098737908513, 77.33713507136227 28.60889187081393, 77.3380442129028 28.61553690614739, 77.34032664545896 28.62218152105002, 77.31306416376951 28.64604411587624, 77.32239723261719 28.70037837855093, 77.29774134882811 28.70079392497996, 77.28850331171871 28.73487461470751, 77.25367189082029 28.74348260079652, 77.27299171503904 28.78390087523045, 77.37608229121092 28.73372761629155))
9 7263 POLYGON ((77.05868040522459 28.76036689063784, 77.05995800090108 28.76055183853124, 77.07136855014315 28.76030572105028, 77.10088937465375 28.75938241548826, 77.10483265399832 28.75988872730943, 77.10620101268859 28.76039503667498, 77.1067061321688 28.75854841896483, 77.13584910764816 28.73836846998568, 77.14023338624361 28.71726870434995, 77.1483152979267 28.72805699537252, 77.1596726027382 28.73668637896795, 77.17071423872832 28.7361831545565, 77.17185482272033 28.74390657951703, 77.19370538767697 28.76807957681535, 77.20405464037776 28.76320816821191, 77.21268727930905 28.7571326204508, 77.19915264948727 28.74757728960068, 77.20504237421876 28.72876506719509, 77.23057596835025 28.70843136407468, 77.24214113577729 28.67100547651979, 77.23001703318481 28.66731033018249, 77.16834664782411 28.66458906480836, 77.15096489771732 28.66156647444533, 77.15061743220215 28.66258051596164, 77.12537492426758 28.66084292667155, 77.06986290797117 28.68321033590825, 77.00765609797364 28.73673509441722, 77.05868040522459 28.76036689063784))
"""), sep="\s\s+", engine="python")
gdf = gpd.GeoDataFrame(df, geometry=df["geometry"].apply(shapely.wkt.loads), crs="epsg:4386")
# add a buffer
gdf.geometry = gdf.geometry.buffer(0.001)
# remove overlaps https://gis.stackexchange.com/questions/370521/erase-overlapping-qgis-polygon-using-geopandas-within-jupyter
poly = gdf.geometry
for p1_idx, p2_idx in combinations(poly.index, 2):
if poly.loc[p1_idx].intersects(poly.loc[p2_idx]):
# Store intermediary results back to poly
poly.loc[p2_idx] -= poly.loc[p1_idx]
gdf["geometry"] = poly
gdf.explore()