Ticket #1652: JoinAreasFunction with support for adjacent areas.patch
| File JoinAreasFunction with support for adjacent areas.patch, 65.8 KB (added by , 17 years ago) |
|---|
-
data/Join
1 <?xml version='1.0' encoding='UTF-8'?> 2 <osm version='0.5' generator='JOSM'> 3 <bounds minlat='49.6358455937926' minlon='8.97891998291015' maxlat='49.6659612524238' maxlon='9.01926040649414' origin='JOSM' /> 4 <node id='-1' visible='true' lat='49.665557350679464' lon='8.980018030697323'> 5 <tag k='name' v='Multipolygon' /> 6 </node> 7 <node id='-2' visible='true' lat='49.66293444373006' lon='8.979904268383734' /> 8 <node id='-3' visible='true' lat='49.66309431357888' lon='8.98771163350794' /> 9 <node id='-4' visible='true' lat='49.66550322539429' lon='8.987481709734286' /> 10 <node id='-5' visible='true' lat='49.661140812390876' lon='8.980754551545285' /> 11 <node id='-6' visible='true' lat='49.66414787714609' lon='8.98167662069808' /> 12 <node id='-7' visible='true' lat='49.66193599760082' lon='8.983668051096597' /> 13 <node id='-8' visible='true' lat='49.66423062929877' lon='8.985896954118042' /> 14 <node id='-9' visible='true' lat='49.66122094281029' lon='8.987593944961972' /> 15 <node id='-10' visible='true' lat='49.665246272951265' lon='8.996673744036638'> 16 <tag k='name' v='No Additional Inner Nodes' /> 17 </node> 18 <node id='-11' visible='true' lat='49.66260897027721' lon='8.996995205661822' /> 19 <node id='-12' visible='true' lat='49.66247822670222' lon='9.006405902938653' /> 20 <node id='-13' visible='true' lat='49.66509579743186' lon='9.006492938770437' /> 21 <node id='-14' visible='true' lat='49.663673852556485' lon='9.001872836660935' /> 22 <node id='-15' visible='true' lat='49.66356462957665' lon='9.003786018319271' /> 23 <node id='-16' visible='true' lat='49.659381328509475' lon='9.002998050852923' /> 24 <node id='-17' visible='true' lat='49.66102960777179' lon='9.004102187558955' /> 25 <node id='-18' visible='true' lat='49.658143795735675' lon='9.001321365825214' /> 26 <node id='-19' visible='true' lat='49.65470614469758' lon='9.000967096568774' /> 27 <node id='-20' visible='true' lat='49.65966007592634' lon='8.995756927212474'> 28 <tag k='name' v='With Inner Nodes, resolve tag conflicts beforehand' /> 29 </node> 30 <node id='-21' visible='true' lat='49.65482452933729' lon='8.99800181533644' /> 31 <node id='-22' visible='true' lat='49.658215448844345' lon='8.998101909487305' /> 32 <node id='-23' visible='true' lat='49.656334599426415' lon='8.99596685442522' /> 33 <node id='-24' visible='true' lat='49.65622420968986' lon='8.999630518959972' /> 34 <node id='-25' visible='true' lat='49.65595437351232' lon='9.002670090930014' /> 35 <node id='-26' visible='true' lat='49.664767306664714' lon='9.00358600531296' /> 36 <node id='-27' visible='true' lat='49.652897713964435' lon='8.995398194580462'> 37 <tag k='name' v='Overlapping Itself' /> 38 </node> 39 <node id='-28' visible='true' lat='49.66298227683501' lon='9.007574342263663' /> 40 <node id='-29' visible='true' lat='49.657294551336726' lon='9.005523880219158' /> 41 <node id='-30' visible='true' lat='49.64759565941927' lon='8.995601060044594' /> 42 <node id='-31' visible='true' lat='49.659323888301465' lon='9.00052935158495' /> 43 <node id='-32' visible='true' lat='49.65131105391522' lon='9.00298658642922' /> 44 <node id='-33' visible='true' lat='49.64965980248303' lon='9.003039719712563' /> 45 <node id='-34' visible='true' lat='49.647526853143034' lon='8.99921412331189' /> 46 <node id='-35' visible='true' lat='49.65151745640557' lon='8.997992057795011' /> 47 <node id='-36' visible='true' lat='49.648042897844014' lon='9.003942985529385' /> 48 <node id='-37' visible='true' lat='49.6534782364111' lon='9.003730452396017' /> 49 <node id='-38' visible='true' lat='49.64965980248303' lon='8.997301325111557' /> 50 <node id='-39' visible='true' lat='49.64862774189198' lon='8.99756699152827' /> 51 <node id='-40' visible='true' lat='49.650123242376026' lon='8.984223634986959' /> 52 <node id='-41' visible='true' lat='49.64837612802103' lon='8.982669694368326' /> 53 <node id='-42' visible='true' lat='49.65267519581664' lon='8.982531354736969'> 54 <tag k='name' v='Joining an two areas with self-overlap' /> 55 </node> 56 <node id='-43' visible='true' lat='49.648702988205066' lon='8.99108732452821' /> 57 <node id='-44' visible='true' lat='49.6498411096278' lon='8.989584718400737' /> 58 <node id='-45' visible='true' lat='49.65180728142213' lon='8.98635078159476' /> 59 <node id='-46' visible='true' lat='49.65154365880048' lon='8.989894759403137' /> 60 <node id='-47' visible='true' lat='49.64821655131596' lon='8.986618619738293' /> 61 <node id='-48' visible='true' lat='49.65263419499493' lon='8.992015874465995' /> 62 <node id='-49' visible='true' lat='49.64910487989931' lon='8.98434746261959' /> 63 <node id='-50' visible='true' lat='49.661575265881794' lon='9.002417415068946' /> 64 <node id='-51' visible='true' lat='49.66111564855195' lon='8.994837077867599' /> 65 <node id='-52' visible='true' lat='49.664258008517386' lon='8.994834196254615' /> 66 <node id='-53' visible='true' lat='49.66327697326473' lon='8.996037451903568' /> 67 <node id='-54' visible='true' lat='49.66163205844883' lon='8.996182583343169' /> 68 <node id='-55' visible='true' lat='49.66336086872286' lon='9.000172520579218' /> 69 <node id='-56' visible='true' lat='49.66439890567706' lon='9.000253362850133' /> 70 <node id='-57' visible='true' lat='49.653656418352305' lon='8.980925219001294' /> 71 <node id='-58' visible='true' lat='49.65083240952062' lon='8.981009751040055' /> 72 <node id='-59' visible='true' lat='49.65093842995153' lon='8.98362536207706' /> 73 <node id='-60' visible='true' lat='49.65366266054767' lon='8.983765181752341' /> 74 <node id='-61' visible='true' lat='49.65918199608578' lon='8.984744990288629' /> 75 <node id='-62' visible='true' lat='49.65684188230803' lon='8.984902160770126' /> 76 <node id='-63' visible='true' lat='49.65687579780412' lon='8.979558364399258' /> 77 <node id='-64' visible='true' lat='49.65918199608578' lon='8.97945358407826'> 78 <tag k='name' v='Intersection already have nodes added' /> 79 </node> 80 <node id='-65' visible='true' lat='49.65545132661812' lon='8.981025288893223' /> 81 <node id='-66' visible='true' lat='49.65558501959522' lon='8.988437026602341' /> 82 <node id='-67' visible='true' lat='49.65931567881406' lon='8.986865321787379'> 83 <tag k='name' v='SOME Intersection already have nodes added' /> 84 </node> 85 <node id='-68' visible='true' lat='49.65700948686801' lon='8.986970102108378' /> 86 <node id='-69' visible='true' lat='49.65687579780412' lon='8.980815728251226' /> 87 <node id='-70' visible='true' lat='49.65809673992071' lon='8.980815728251226' /> 88 <node id='-71' visible='true' lat='49.65792716645855' lon='8.983382846115664' /> 89 <node id='-72' visible='true' lat='49.65701145955204' lon='8.98306850515267' /> 90 <node id='-73' visible='true' lat='49.65700948686801' lon='8.988227465960346' /> 91 <node id='-74' visible='true' lat='49.660221488976575' lon='8.977137289660517' /> 92 <node id='-75' visible='true' lat='49.66019710027813' lon='9.021519330497165' /> 93 <node id='-76' visible='true' lat='49.66824309940781' lon='8.99379608098765' /> 94 <node id='-77' visible='true' lat='49.65823042563044' lon='8.988227465960346' /> 95 <node id='-78' visible='true' lat='49.65931567881406' lon='8.992156727997747' /> 96 <node id='-79' visible='true' lat='49.65697557146509' lon='8.992313898479246' /> 97 <node id='-80' visible='true' lat='49.65806085263415' lon='8.990794583824783' /> 98 <node id='-81' action='modify' visible='true' lat='49.6353930124394' lon='8.99395938766279' /> 99 <node id='-82' visible='true' lat='49.66770174614116' lon='9.008788568211484' /> 100 <node id='-83' action='modify' visible='true' lat='49.63560427014124' lon='9.009633761966247' /> 101 <node id='-84' visible='true' lat='49.654142227092336' lon='8.97793106762297' /> 102 <node id='-85' visible='true' lat='49.65418064466472' lon='9.02166564057246' /> 103 <node id='-86' visible='true' lat='49.665325869211465' lon='9.010629016616129'> 104 <tag k='name' v='Member of some (i.e. not multigon) relation' /> 105 </node> 106 <node id='-87' visible='true' lat='49.66089950426598' lon='9.010651964271892' /> 107 <node id='-88' visible='true' lat='49.66084008723247' lon='9.01744447037755' /> 108 <node id='-89' visible='true' lat='49.66210268358402' lon='9.017513313344837' /> 109 <node id='-90' visible='true' lat='49.662236368338334' lon='9.011707556436962' /> 110 <node id='-91' visible='true' lat='49.663989090028004' lon='9.01179934706001' /> 111 <node id='-92' visible='true' lat='49.663929676767346' lon='9.01471369934183' /> 112 <node id='-93' visible='true' lat='49.66156794089354' lon='9.014644856374543' /> 113 <node id='-94' visible='true' lat='49.66149367061061' lon='9.016824883671967' /> 114 <node id='-95' visible='true' lat='49.665266457583265' lon='9.016733093048918' /> 115 <node id='-96' visible='true' lat='49.6657566013461' lon='9.017559208656362' /> 116 <node id='-97' visible='true' lat='49.66572689580407' lon='9.018683643788718' /> 117 <node id='-98' visible='true' lat='49.66467233731082' lon='9.018729539100242' /> 118 <node id='-99' visible='true' lat='49.65954150350348' lon='9.010225255249217'> 119 <tag k='name' v='One Area already part of multipolygon (as outer)' /> 120 </node> 121 <node id='-100' visible='true' lat='49.65948208481168' lon='9.016329331682007' /> 122 <node id='-101' visible='true' lat='49.65507724377221' lon='9.016274166792183' /> 123 <node id='-102' visible='true' lat='49.65831483593041' lon='9.011804408209608' /> 124 <node id='-103' visible='true' lat='49.656561909834345' lon='9.011712617586559' /> 125 <node id='-104' visible='true' lat='49.65825541574074' lon='9.014718760491427' /> 126 <node id='-105' visible='true' lat='49.655114612313845' lon='9.01024820290498' /> 127 <node id='-106' visible='true' lat='49.65649630973553' lon='9.01456121513066' /> 128 <node id='-107' visible='true' lat='49.659983770585875' lon='9.015660786026782' /> 129 <node id='-108' visible='true' lat='49.65777838791238' lon='9.0156778202983' /> 130 <node id='-109' visible='true' lat='49.6577783879124' lon='9.01859068072843' /> 131 <node id='-110' visible='true' lat='49.659950690584154' lon='9.018522543642344' /> 132 <node id='-111' visible='true' lat='49.650467504431084' lon='9.01556653387284' /> 133 <node id='-112' visible='true' lat='49.650467504431084' lon='9.012653673442712' /> 134 <node id='-113' visible='true' lat='49.649036528490285' lon='9.01626713010843' /> 135 <node id='-114' visible='true' lat='49.651484566652904' lon='9.01400037262895' /> 136 <node id='-115' visible='true' lat='49.653441916259965' lon='9.016322294998254' /> 137 <node id='-116' visible='true' lat='49.65267321841768' lon='9.012636639171191' /> 138 <node id='-117' visible='true' lat='49.652640133446276' lon='9.015498396786755' /> 139 <node id='-118' visible='true' lat='49.64972521590133' lon='9.013842827268181' /> 140 <node id='-119' visible='true' lat='49.64907390166997' lon='9.010241166221228' /> 141 <node id='-120' visible='true' lat='49.649790825127035' lon='9.010994229724082' /> 142 <node id='-121' visible='true' lat='49.65350134232707' lon='9.010218218565463'> 143 <tag k='name' v='One Area already part of multipolygon (as inner)' /> 144 </node> 145 <node id='-122' visible='true' lat='49.651543995109876' lon='9.011086020347133' /> 146 <node id='-123' visible='true' lat='49.64702795382207' lon='9.021373906176958' /> 147 <node id='-124' visible='true' lat='49.64698953060391' lon='8.97763933322747' /> 148 <node id='-125' visible='true' lat='49.6440995060445' lon='9.015089670434026' /> 149 <node id='-126' visible='true' lat='49.64633804682556' lon='9.016044421132413' /> 150 <node id='-127' visible='true' lat='49.64329477394559' lon='9.00982115694612' /> 151 <node id='-128' visible='true' lat='49.64474487637503' lon='9.013313148784425' /> 152 <node id='-129' visible='true' lat='49.646452701397266' lon='9.00974135512665'> 153 <tag k='name' v='Both part of other relations' /> 154 </node> 155 <node id='-130' visible='true' lat='49.645694403782294' lon='9.012131348650524' /> 156 <node id='-131' visible='true' lat='49.64477854294109' lon='9.010865000644996' /> 157 <node id='-132' visible='true' lat='49.64566131406722' lon='9.01503858959705' /> 158 <node id='-133' visible='true' lat='49.64333102750582' lon='9.015932402078883' /> 159 <node id='-134' visible='true' lat='49.6436516438452' lon='9.013337536747516' /> 160 <node id='-135' visible='true' lat='49.6440995060445' lon='9.012176810003897' /> 161 <node id='-136' visible='true' lat='49.64364363066422' lon='9.010830064185653' /> 162 <node id='-137' visible='true' lat='49.64634787643868' lon='9.01859251804108' /> 163 <node id='-138' visible='true' lat='49.64442618533402' lon='9.018507236795525' /> 164 <node id='-139' visible='true' lat='49.64446300005248' lon='9.017591884759854' /> 165 <node id='-140' visible='true' lat='49.646377327053195' lon='9.017591884759854' /> 166 <node id='-141' action='modify' visible='true' lat='49.645108516691536' lon='9.00501200093294' /> 167 <node id='-142' action='modify' visible='true' lat='49.644279396738646' lon='8.99701844322583' /> 168 <node id='-143' action='modify' visible='true' lat='49.643570600890634' lon='9.005424239693767' /> 169 <node id='-144' action='modify' visible='true' lat='49.64579713321828' lon='9.001725329495672' /> 170 <node id='-145' action='modify' visible='true' lat='49.645870282835396' lon='9.000573288940334' /> 171 <node id='-146' action='modify' visible='true' lat='49.644533441390884' lon='9.001738472218983' /> 172 <node id='-147' action='modify' visible='true' lat='49.64620102922634' lon='8.995285052653605' /> 173 <node id='-148' action='modify' visible='true' lat='49.645549394972946' lon='8.997512960693886' /> 174 <node id='-149' action='modify' visible='true' lat='49.64390917555046' lon='9.00236900726505' /> 175 <node id='-150' action='modify' visible='true' lat='49.643583272941804' lon='8.996426078862356' /> 176 <node id='-151' action='modify' visible='true' lat='49.645064815871' lon='8.999528632035787' /> 177 <node id='-152' action='modify' visible='true' lat='49.64660348405886' lon='9.007804150387257' /> 178 <node id='-153' action='modify' visible='true' lat='49.644215448513066' lon='8.987601210318644' /> 179 <node id='-154' action='modify' visible='true' lat='49.64509437228782' lon='8.985632145182455' /> 180 <node id='-155' action='modify' visible='true' lat='49.64512070290696' lon='8.990191229749867' /> 181 <node id='-156' action='modify' visible='true' lat='49.64400653203681' lon='8.985527741087623' /> 182 <node id='-157' action='modify' visible='true' lat='49.64362715512701' lon='8.983795590458412' /> 183 <node id='-158' action='modify' visible='true' lat='49.6438359138228' lon='8.988873075900425' /> 184 <node id='-159' action='modify' visible='true' lat='49.64624752120218' lon='8.990209078516749' /> 185 <node id='-160' action='modify' visible='true' lat='49.64561767902291' lon='8.987111582364214' /> 186 <node id='-161' action='modify' visible='true' lat='49.64560080131112' lon='8.988407502515859' /> 187 <node id='-162' action='modify' visible='true' lat='49.64619224514668' lon='8.984061673983168' /> 188 <node id='-163' visible='true' lat='49.664846643627826' lon='9.02334771024883' /> 189 <node id='-164' visible='true' lat='49.66903704959538' lon='9.022880487521558' /> 190 <node id='-165' action='modify' visible='true' lat='49.64222947566583' lon='8.976745109963648' /> 191 <node id='-166' action='modify' visible='true' lat='49.64226790264086' lon='9.020479682913138' /> 192 <node id='-167' visible='true' lat='49.6687778596993' lon='9.028553906352727' /> 193 <node id='-168' visible='true' lat='49.66476023970688' lon='9.029688590118962' /> 194 <node id='-169' action='modify' visible='true' lat='49.64654691824636' lon='8.982418392157395' /> 195 <node id='-170' action='modify' visible='true' lat='49.64294039575888' lon='8.98264180269116' /> 196 <node id='-171' visible='true' lat='49.66726589111355' lon='9.018808975183893' /> 197 <node id='-172' visible='true' lat='49.67180165588925' lon='9.019276197911166'> 198 <tag k='name' v='out of bounds' /> 199 </node> 200 <node id='-173' visible='true' lat='49.671931242953896' lon='9.026017554404675' /> 201 <node id='-174' visible='true' lat='49.66722269132057' lon='9.026351284924155' /> 202 <node id='-175' action='modify' visible='true' lat='49.64305580574678' lon='8.992869020494213' /> 203 <node id='-176' action='modify' visible='true' lat='49.6465677851024' lon='8.992596999330347' /> 204 <node id='-177' visible='true' lat='49.63635979087037' lon='8.9920314546263' /> 205 <node id='-178' visible='true' lat='49.63665997892509' lon='8.979825569886037' /> 206 <node id='-179' visible='true' lat='49.64166284075567' lon='8.990370527272402' /> 207 <node id='-180' visible='true' lat='49.64038715981111' lon='8.984846978165258' /> 208 <node id='-181' visible='true' lat='49.639336573937996' lon='8.985619502515908' /> 209 <node id='-182' visible='true' lat='49.64153777547409' lon='8.98052084180162' /> 210 <node id='-183' visible='true' lat='49.64158780162527' lon='8.984460715989934' /> 211 <node id='-184' visible='true' lat='49.63671001008765' lon='8.985696754950974' /> 212 <node id='-185' visible='true' lat='49.63620969614912' lon='8.984267584902272' /> 213 <node id='-186' visible='true' lat='49.63831098015055' lon='8.986005764691233' /> 214 <node id='-187' visible='true' lat='49.63766059241029' lon='8.985426371428245' /> 215 <node id='-188' action='modify' visible='true' lat='49.64113713627012' lon='8.99764014460778' /> 216 <node id='-189' action='modify' visible='true' lat='49.636707497273726' lon='8.996902491147958' /> 217 <node id='-190' action='modify' visible='true' lat='49.63672921217317' lon='9.001496060420484' /> 218 <node id='-191' action='modify' visible='true' lat='49.63833608786159' lon='9.001965476258553' /> 219 <node id='-192' action='modify' visible='true' lat='49.63866179944343' lon='9.001060174285136' /> 220 <node id='-193' action='modify' visible='true' lat='49.63983876223289' lon='8.999763400318008' /> 221 <node id='-194' action='modify' visible='true' lat='49.640355464550595' lon='9.000557228744347' /> 222 <node id='-195' action='modify' visible='true' lat='49.640355464550595' lon='9.00163017923136' /> 223 <node id='-196' action='modify' visible='true' lat='49.640963432528' lon='9.002300773285747' /> 224 <node id='-197' action='modify' visible='true' lat='49.641397690721426' lon='9.002032535663991' /> 225 <node id='-198' visible='true' lat='49.64135304304343' lon='9.008042625328157' /> 226 <node id='-199' visible='true' lat='49.641505032635514' lon='9.005561427326938' /> 227 <node id='-200' visible='true' lat='49.639702839791006' lon='9.002946110514843' /> 228 <node id='-201' visible='true' lat='49.638889008438305' lon='9.003170088929009' /> 229 <node id='-202' visible='true' lat='49.63655427055324' lon='9.003685105162774' /> 230 <node id='-203' visible='true' lat='49.636803870494575' lon='9.005634441607576' /> 231 <node id='-204' visible='true' lat='49.63766439678692' lon='9.008322826347838' /> 232 <node id='-205' action='modify' visible='true' lat='49.63919649619353' lon='9.000021094269913' /> 233 <way id='-206' visible='true'> 234 <nd ref='-162' /> 235 <nd ref='-159' /> 236 <nd ref='-155' /> 237 <nd ref='-154' /> 238 <nd ref='-156' /> 239 <nd ref='-153' /> 240 <nd ref='-160' /> 241 <nd ref='-161' /> 242 <nd ref='-158' /> 243 <nd ref='-157' /> 244 <nd ref='-162' /> 245 <tag k='name' v='Thing in the Middle' /> 246 </way> 247 <way id='-207' visible='true'> 248 <nd ref='-25' /> 249 <nd ref='-16' /> 250 <nd ref='-20' /> 251 <nd ref='-23' /> 252 <nd ref='-24' /> 253 <nd ref='-25' /> 254 <tag k='landuse' v='retail' /> 255 </way> 256 <way id='-208' visible='true'> 257 <nd ref='-64' /> 258 <nd ref='-63' /> 259 <nd ref='-69' /> 260 <nd ref='-72' /> 261 <nd ref='-62' /> 262 <nd ref='-61' /> 263 <nd ref='-64' /> 264 <tag k='parking' v='surface' /> 265 <tag k='amenity' v='parking' /> 266 </way> 267 <way id='-209' visible='true'> 268 <nd ref='-10' /> 269 <nd ref='-11' /> 270 <nd ref='-12' /> 271 <nd ref='-13' /> 272 <nd ref='-10' /> 273 <tag k='parking' v='surface' /> 274 <tag k='amenity' v='parking' /> 275 </way> 276 <way id='-210' visible='true'> 277 <nd ref='-118' /> 278 <nd ref='-120' /> 279 <nd ref='-122' /> 280 <nd ref='-114' /> 281 <nd ref='-118' /> 282 </way> 283 <way id='-211' visible='true'> 284 <nd ref='-65' /> 285 <nd ref='-69' /> 286 <nd ref='-70' /> 287 <nd ref='-71' /> 288 <nd ref='-72' /> 289 <nd ref='-65' /> 290 <tag k='parking' v='surface' /> 291 <tag k='amenity' v='parking' /> 292 </way> 293 <way id='-212' visible='true'> 294 <nd ref='-67' /> 295 <nd ref='-68' /> 296 <nd ref='-73' /> 297 <nd ref='-79' /> 298 <nd ref='-78' /> 299 <nd ref='-67' /> 300 <tag k='parking' v='surface' /> 301 <tag k='amenity' v='parking' /> 302 </way> 303 <way id='-213' visible='true'> 304 <nd ref='-134' /> 305 <nd ref='-136' /> 306 <nd ref='-131' /> 307 <nd ref='-128' /> 308 <nd ref='-134' /> 309 </way> 310 <way id='-214' visible='true'> 311 <nd ref='-82' /> 312 <nd ref='-83' /> 313 <tag k='highway' v='motorway' /> 314 <tag k='lanes' v='5' /> 315 </way> 316 <way id='-215' visible='true'> 317 <nd ref='-172' /> 318 <nd ref='-171' /> 319 <nd ref='-174' /> 320 <nd ref='-173' /> 321 <nd ref='-172' /> 322 <tag k='parking' v='surface' /> 323 <tag k='amenity' v='parking' /> 324 </way> 325 <way id='-216' visible='true'> 326 <nd ref='-42' /> 327 <nd ref='-48' /> 328 <nd ref='-43' /> 329 <nd ref='-49' /> 330 <nd ref='-40' /> 331 <nd ref='-44' /> 332 <nd ref='-46' /> 333 <nd ref='-45' /> 334 <nd ref='-47' /> 335 <nd ref='-41' /> 336 <nd ref='-42' /> 337 <tag k='parking' v='surface' /> 338 <tag k='amenity' v='parking' /> 339 </way> 340 <way id='-217' visible='true'> 341 <nd ref='-130' /> 342 <nd ref='-135' /> 343 <nd ref='-125' /> 344 <nd ref='-132' /> 345 <nd ref='-130' /> 346 </way> 347 <way id='-218' visible='true'> 348 <nd ref='-116' /> 349 <nd ref='-112' /> 350 <nd ref='-111' /> 351 <nd ref='-117' /> 352 <nd ref='-116' /> 353 </way> 354 <way id='-219' visible='true'> 355 <nd ref='-164' /> 356 <nd ref='-163' /> 357 <nd ref='-168' /> 358 <nd ref='-167' /> 359 <nd ref='-164' /> 360 <tag k='parking' v='surface' /> 361 <tag k='amenity' v='parking' /> 362 </way> 363 <way id='-220' visible='true'> 364 <nd ref='-150' /> 365 <nd ref='-147' /> 366 <nd ref='-152' /> 367 <nd ref='-143' /> 368 <nd ref='-150' /> 369 <tag k='parking' v='surface' /> 370 <tag k='amenity' v='parking' /> 371 </way> 372 <way id='-221' visible='true'> 373 <nd ref='-17' /> 374 <nd ref='-51' /> 375 <nd ref='-52' /> 376 <nd ref='-56' /> 377 <nd ref='-55' /> 378 <nd ref='-53' /> 379 <nd ref='-54' /> 380 <nd ref='-50' /> 381 <nd ref='-14' /> 382 <nd ref='-15' /> 383 <nd ref='-17' /> 384 <tag k='parking' v='surface' /> 385 <tag k='amenity' v='parking' /> 386 </way> 387 <way id='-222' visible='true'> 388 <nd ref='-26' /> 389 <nd ref='-15' /> 390 <nd ref='-28' /> 391 <tag k='highway' v='footway' /> 392 </way> 393 <way id='-223' visible='true'> 394 <nd ref='-124' /> 395 <nd ref='-123' /> 396 <tag k='highway' v='motorway' /> 397 <tag k='lanes' v='5' /> 398 </way> 399 <way id='-224' visible='true'> 400 <nd ref='-84' /> 401 <nd ref='-85' /> 402 <tag k='highway' v='motorway' /> 403 <tag k='lanes' v='5' /> 404 </way> 405 <way id='-225' visible='true'> 406 <nd ref='-151' /> 407 <nd ref='-144' /> 408 <nd ref='-141' /> 409 <nd ref='-149' /> 410 <nd ref='-151' /> 411 </way> 412 <way id='-226' visible='true'> 413 <nd ref='-113' /> 414 <nd ref='-115' /> 415 <nd ref='-121' /> 416 <nd ref='-119' /> 417 <nd ref='-113' /> 418 <tag k='parking' v='surface' /> 419 <tag k='amenity' v='parking' /> 420 </way> 421 <way id='-227' visible='true'> 422 <nd ref='-1' /> 423 <nd ref='-2' /> 424 <nd ref='-3' /> 425 <nd ref='-4' /> 426 <nd ref='-1' /> 427 <tag k='parking' v='surface' /> 428 <tag k='amenity' v='parking' /> 429 </way> 430 <way id='-228' visible='true'> 431 <nd ref='-96' /> 432 <nd ref='-97' /> 433 <nd ref='-98' /> 434 </way> 435 <way id='-229' visible='true'> 436 <nd ref='-27' /> 437 <nd ref='-37' /> 438 <nd ref='-36' /> 439 <nd ref='-39' /> 440 <nd ref='-38' /> 441 <nd ref='-33' /> 442 <nd ref='-32' /> 443 <nd ref='-35' /> 444 <nd ref='-34' /> 445 <nd ref='-30' /> 446 <nd ref='-27' /> 447 <tag k='parking' v='surface' /> 448 <tag k='amenity' v='parking' /> 449 </way> 450 <way id='-230' visible='true'> 451 <nd ref='-66' /> 452 <nd ref='-73' /> 453 <nd ref='-77' /> 454 <nd ref='-80' /> 455 <nd ref='-66' /> 456 <tag k='parking' v='surface' /> 457 <tag k='amenity' v='parking' /> 458 </way> 459 <way id='-231' visible='true'> 460 <nd ref='-107' /> 461 <nd ref='-108' /> 462 <nd ref='-109' /> 463 <nd ref='-110' /> 464 <nd ref='-107' /> 465 </way> 466 <way id='-232' visible='true'> 467 <nd ref='-86' /> 468 <nd ref='-87' /> 469 <nd ref='-88' /> 470 <nd ref='-89' /> 471 <nd ref='-90' /> 472 <nd ref='-91' /> 473 <nd ref='-92' /> 474 <nd ref='-93' /> 475 <nd ref='-94' /> 476 <nd ref='-95' /> 477 <nd ref='-86' /> 478 <tag k='parking' v='surface' /> 479 <tag k='amenity' v='parking' /> 480 </way> 481 <way id='-233' visible='true'> 482 <nd ref='-145' /> 483 <nd ref='-146' /> 484 <nd ref='-142' /> 485 <nd ref='-148' /> 486 <nd ref='-145' /> 487 </way> 488 <way id='-234' visible='true'> 489 <nd ref='-57' /> 490 <nd ref='-58' /> 491 <nd ref='-59' /> 492 <nd ref='-60' /> 493 <nd ref='-57' /> 494 <tag k='parking' v='surface' /> 495 <tag k='amenity' v='parking' /> 496 </way> 497 <way id='-235' visible='true'> 498 <nd ref='-165' /> 499 <nd ref='-166' /> 500 <tag k='highway' v='motorway' /> 501 <tag k='lanes' v='5' /> 502 </way> 503 <way id='-236' visible='true'> 504 <nd ref='-74' /> 505 <nd ref='-75' /> 506 <tag k='highway' v='motorway' /> 507 <tag k='lanes' v='5' /> 508 </way> 509 <way id='-237' visible='true'> 510 <nd ref='-76' /> 511 <nd ref='-81' /> 512 <tag k='highway' v='motorway' /> 513 <tag k='lanes' v='5' /> 514 </way> 515 <way id='-238' action='modify' visible='true'> 516 <nd ref='-182' /> 517 <nd ref='-183' /> 518 <nd ref='-180' /> 519 <nd ref='-181' /> 520 <nd ref='-186' /> 521 <nd ref='-187' /> 522 <nd ref='-184' /> 523 <nd ref='-185' /> 524 <nd ref='-178' /> 525 <nd ref='-182' /> 526 <tag k='amenity' v='parking' /> 527 </way> 528 <way id='-239' action='modify' visible='true'> 529 <nd ref='-179' /> 530 <nd ref='-183' /> 531 <nd ref='-180' /> 532 <nd ref='-181' /> 533 <nd ref='-186' /> 534 <nd ref='-187' /> 535 <nd ref='-184' /> 536 <nd ref='-185' /> 537 <nd ref='-177' /> 538 <nd ref='-179' /> 539 <tag k='amenity' v='parking' /> 540 </way> 541 <way id='-240' visible='true'> 542 <nd ref='-21' /> 543 <nd ref='-22' /> 544 <nd ref='-18' /> 545 <nd ref='-19' /> 546 <nd ref='-21' /> 547 <tag k='landuse' v='basin' /> 548 </way> 549 <way id='-241' visible='true'> 550 <nd ref='-101' /> 551 <nd ref='-100' /> 552 <nd ref='-99' /> 553 <nd ref='-105' /> 554 <nd ref='-101' /> 555 <tag k='parking' v='surface' /> 556 <tag k='amenity' v='parking' /> 557 </way> 558 <way id='-242' visible='true'> 559 <nd ref='-137' /> 560 <nd ref='-138' /> 561 <nd ref='-139' /> 562 <nd ref='-140' /> 563 <nd ref='-137' /> 564 </way> 565 <way id='-243' visible='true'> 566 <nd ref='-169' /> 567 <nd ref='-170' /> 568 <nd ref='-175' /> 569 <nd ref='-176' /> 570 <nd ref='-169' /> 571 <tag k='parking' v='surface' /> 572 <tag k='name' v='Outer blob' /> 573 <tag k='amenity' v='parking' /> 574 </way> 575 <way id='-244' visible='true'> 576 <nd ref='-31' /> 577 <nd ref='-18' /> 578 <nd ref='-29' /> 579 <tag k='highway' v='footway' /> 580 </way> 581 <way id='-245' visible='true'> 582 <nd ref='-133' /> 583 <nd ref='-126' /> 584 <nd ref='-129' /> 585 <nd ref='-127' /> 586 <nd ref='-133' /> 587 <tag k='parking' v='surface' /> 588 <tag k='amenity' v='parking' /> 589 </way> 590 <way id='-246' visible='true'> 591 <nd ref='-106' /> 592 <nd ref='-103' /> 593 <nd ref='-102' /> 594 <nd ref='-104' /> 595 <nd ref='-106' /> 596 </way> 597 <way id='-247' visible='true'> 598 <nd ref='-5' /> 599 <nd ref='-6' /> 600 <nd ref='-7' /> 601 <nd ref='-8' /> 602 <nd ref='-9' /> 603 <nd ref='-5' /> 604 <tag k='parking' v='surface' /> 605 <tag k='amenity' v='parking' /> 606 </way> 607 <way id='-248' action='modify' visible='true'> 608 <nd ref='-188' /> 609 <nd ref='-189' /> 610 <nd ref='-190' /> 611 <nd ref='-191' /> 612 <nd ref='-192' /> 613 <nd ref='-205' /> 614 <nd ref='-193' /> 615 <nd ref='-194' /> 616 <nd ref='-195' /> 617 <nd ref='-196' /> 618 <nd ref='-197' /> 619 <nd ref='-188' /> 620 <tag k='parking' v='surface' /> 621 <tag k='amenity' v='parking' /> 622 </way> 623 <way id='-249' action='modify' visible='true'> 624 <nd ref='-198' /> 625 <nd ref='-199' /> 626 <nd ref='-197' /> 627 <nd ref='-196' /> 628 <nd ref='-195' /> 629 <nd ref='-200' /> 630 <nd ref='-201' /> 631 <nd ref='-191' /> 632 <nd ref='-190' /> 633 <nd ref='-202' /> 634 <nd ref='-203' /> 635 <nd ref='-204' /> 636 <nd ref='-198' /> 637 <tag k='parking' v='surface' /> 638 <tag k='amenity' v='parking' /> 639 </way> 640 <relation id='-250' visible='true'> 641 <member type='way' ref='-246' role='inner' /> 642 <member type='way' ref='-241' role='outer' /> 643 <tag k='name' v='2.' /> 644 <tag k='type' v='multipolygon' /> 645 </relation> 646 <relation id='-251' visible='true'> 647 </relation> 648 <relation id='-252' visible='true'> 649 <member type='way' ref='-242' role='' /> 650 <member type='way' ref='-217' role='' /> 651 <tag k='name ' v='4. b' /> 652 </relation> 653 <relation id='-253' visible='true'> 654 <member type='way' ref='-213' role='inner' /> 655 <member type='way' ref='-245' role='outer' /> 656 <tag k='name' v='4. a' /> 657 <tag k='type' v='multipolygon' /> 658 </relation> 659 <relation id='-254' visible='true'> 660 <member type='way' ref='-210' role='inner' /> 661 <member type='way' ref='-226' role='outer' /> 662 <tag k='name' v='3.' /> 663 <tag k='type' v='multipolygon' /> 664 </relation> 665 <relation id='-255' visible='true'> 666 <member type='way' ref='-233' role='inner' /> 667 <member type='way' ref='-225' role='inner' /> 668 <member type='way' ref='-220' role='outer' /> 669 <tag k='name' v='5.' /> 670 <tag k='type' v='multipolygon' /> 671 </relation> 672 <relation id='-256' visible='true'> 673 <member type='way' ref='-206' role='inner' /> 674 <member type='way' ref='-243' role='outer' /> 675 <tag k='name' v='6.' /> 676 <tag k='type' v='multipolygon' /> 677 </relation> 678 <relation id='-257' visible='true'> 679 <member type='way' ref='-232' role='area' /> 680 <member type='node' ref='-90' role='node in area' /> 681 <member type='node' ref='-92' role='node in area' /> 682 <member type='way' ref='-228' role='some other way' /> 683 <member type='node' ref='-93' role='to be deleted node in area' /> 684 <tag k='name' v='1.' /> 685 </relation> 686 </osm> -
src/UtilsPlugin/JoinAreasAction.java
Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: images\joinareas.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream
1 package UtilsPlugin; 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 import static org.openstreetmap.josm.tools.I18n.trn; 5 6 import java.awt.event.ActionEvent; 7 import java.awt.event.KeyEvent; 8 import java.awt.geom.Line2D; 9 import java.awt.geom.Point2D; 10 import java.awt.GridBagLayout; 11 import java.awt.Point; 12 import java.awt.Polygon; 13 14 import java.util.ArrayList; 15 import java.util.Arrays; 16 import java.util.Collection; 17 import java.util.Collections; 18 import java.util.Comparator; 19 import java.util.HashMap; 20 import java.util.LinkedList; 21 import java.util.List; 22 import java.util.Map; 23 import java.util.Map.Entry; 24 import java.util.Set; 25 import java.util.TreeMap; 26 import java.util.TreeSet; 27 28 import javax.swing.Box; 29 import javax.swing.JComboBox; 30 import javax.swing.JLabel; 31 import javax.swing.JOptionPane; 32 import javax.swing.JPanel; 33 34 import org.openstreetmap.josm.actions.CombineWayAction; 35 import org.openstreetmap.josm.actions.JosmAction; 36 import org.openstreetmap.josm.actions.ReverseWayAction; 37 import org.openstreetmap.josm.actions.SplitWayAction; 38 39 import org.openstreetmap.josm.command.AddCommand; 40 import org.openstreetmap.josm.command.ChangeCommand; 41 import org.openstreetmap.josm.command.Command; 42 import org.openstreetmap.josm.command.DeleteCommand; 43 import org.openstreetmap.josm.command.SequenceCommand; 44 45 import org.openstreetmap.josm.data.Bounds; 46 import org.openstreetmap.josm.data.coor.EastNorth; 47 import org.openstreetmap.josm.data.coor.LatLon; 48 import org.openstreetmap.josm.data.osm.DataSet; 49 import org.openstreetmap.josm.data.osm.DataSource; 50 import org.openstreetmap.josm.data.osm.Node; 51 import org.openstreetmap.josm.data.osm.OsmPrimitive; 52 import org.openstreetmap.josm.data.osm.Relation; 53 import org.openstreetmap.josm.data.osm.RelationMember; 54 import org.openstreetmap.josm.data.osm.TigerUtils; 55 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; 56 import org.openstreetmap.josm.data.osm.Way; 57 import org.openstreetmap.josm.data.osm.WaySegment; 58 import org.openstreetmap.josm.data.projection.Epsg4326; 59 import org.openstreetmap.josm.data.projection.Lambert; 60 import org.openstreetmap.josm.data.projection.Mercator; 61 import org.openstreetmap.josm.data.UndoRedoHandler; 62 63 import org.openstreetmap.josm.gui.ExtendedDialog; 64 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 65 import org.openstreetmap.josm.Main; 66 import org.openstreetmap.josm.tools.GBC; 67 import org.openstreetmap.josm.tools.Pair; 68 import org.openstreetmap.josm.tools.Shortcut; 69 70 public class JoinAreasAction extends JosmAction { 71 // This will be used to commit commands and unite them into one large command sequence at the end 72 private LinkedList<Command> cmds = new LinkedList<Command>(); 73 private int cmdsCount = 0; 74 75 // HelperClass 76 // Saves a node and two positions where to insert the node into the ways 77 private class NodeToSegs implements Comparable<NodeToSegs> { 78 public int pos; 79 public Node n; 80 public double dis; 81 public NodeToSegs(int pos, Node n, LatLon dis) { 82 this.pos = pos; 83 this.n = n; 84 this.dis = n.coor.greatCircleDistance(dis); 85 } 86 87 public int compareTo(NodeToSegs o) { 88 if(this.pos == o.pos) 89 return (this.dis - o.dis) > 0 ? 1 : -1; 90 return this.pos - o.pos; 91 } 92 }; 93 94 // HelperClass 95 // Saves a relation and a role an OsmPrimitve was part of until it was stripped from all relations 96 private class RelationRole { 97 public Relation rel; 98 public String role; 99 public RelationRole(Relation rel, String role) { 100 this.rel = rel; 101 this.role = role; 102 } 103 104 public boolean equals(Object other) { 105 if (!(other instanceof RelationRole)) return false; 106 RelationRole otherMember = (RelationRole) other; 107 return otherMember.role.equals(role) && otherMember.rel.equals(rel); 108 } 109 } 110 111 // Adds the menu entry, Shortcuts, etc. 112 public JoinAreasAction() { 113 super(tr("Join overlapping Areas"), "joinareas", tr("Joins areas that overlap each other"), Shortcut.registerShortcut("tools:joinareas", tr("Tool: {0}", tr("Join overlapping Areas")), 114 KeyEvent.VK_J, Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true); 115 } 116 117 /** 118 * Gets called whenever the shortcut is pressed or the menu entry is selected 119 * Checks whether the selected objects are suitable to join and joins them if so 120 */ 121 public void actionPerformed(ActionEvent e) { 122 int result = new ExtendedDialog(Main.parent, 123 tr("Enter values for all conflicts."), 124 new JLabel(tr("THIS IS EXPERIMENTAL. Save your work and verify before uploading.")), 125 new String[] {tr("Continue anyway"), tr("Cancel")}, 126 new String[] {"joinareas.png", "cancel.png"}).getValue(); 127 if(result != 1) return; 128 129 Collection<OsmPrimitive> selection = Main.ds.getSelectedWays(); 130 131 int ways = 0; 132 Way[] selWays = new Way[2]; 133 134 LinkedList<Bounds> bounds = new LinkedList<Bounds>(); 135 OsmDataLayer dataLayer = Main.main.editLayer(); 136 for (DataSource ds : dataLayer.data.dataSources) { 137 if (ds.bounds != null) 138 bounds.add(ds.bounds); 139 } 140 141 boolean askedAlready = false; 142 for (OsmPrimitive prim : selection) { 143 Way way = (Way) prim; 144 145 // Too many ways 146 if(ways == 2) { 147 JOptionPane.showMessageDialog(Main.parent, tr("Only up to two areas can be joined at the moment.")); 148 return; 149 } 150 151 if(!way.isClosed()) { 152 JOptionPane.showMessageDialog(Main.parent, tr("\"{0}\" is not closed and therefore can't be joined.", way.getName())); 153 return; 154 } 155 156 // This is copied from SimplifyAction and should be probably ported to tools 157 for (Node node : way.nodes) { 158 if(askedAlready) break; 159 boolean isInsideOneBoundingBox = false; 160 for (Bounds b : bounds) { 161 if (b.contains(node.coor)) { 162 isInsideOneBoundingBox = true; 163 break; 164 } 165 } 166 167 if (!isInsideOneBoundingBox) { 168 int option = JOptionPane.showConfirmDialog(Main.parent, 169 tr("The selected way(s) have nodes outside of the downloaded data region.\n" 170 + "This can lead to nodes being deleted accidentally.\n" 171 + "Are you really sure to continue?"), 172 tr("Please abort if you are not sure"), JOptionPane.YES_NO_OPTION, 173 JOptionPane.WARNING_MESSAGE); 174 175 if (option != JOptionPane.YES_OPTION) return; 176 askedAlready = true; 177 break; 178 } 179 } 180 181 selWays[ways] = way; 182 ways++; 183 } 184 185 if (ways < 1) { 186 JOptionPane.showMessageDialog(Main.parent, tr("Please select at least one closed way the should be joined.")); 187 return; 188 } 189 190 if(joinAreas(selWays[0], selWays[ways == 2 ? 1 : 0])) { 191 Main.map.mapView.repaint(); 192 DataSet.fireSelectionChanged(Main.ds.getSelected()); 193 } else 194 JOptionPane.showMessageDialog(Main.parent, tr("No intersections found. Nothing was changed.")); 195 } 196 197 198 /** 199 * Will join two overlapping areas 200 * @param Way First way/area 201 * @param Way Second way/area 202 * @return boolean Whether to display the "no operation" message 203 */ 204 private boolean joinAreas(Way a, Way b) { 205 // Fix self-overlapping first or other errors 206 boolean same = a.equals(b); 207 boolean hadChanges = false; 208 if(!same) { 209 if(checkForTagConflicts(a, b)) return true; // User aborted, so don't warn again 210 hadChanges = joinAreas(a, a); 211 hadChanges = joinAreas(b, b) || hadChanges; 212 } 213 214 ArrayList<OsmPrimitive> nodes = addIntersections(a, b); 215 if(nodes.size() == 0) return hadChanges; 216 commitCommands("Added node on all intersections"); 217 218 // Remove ways from all relations so ways can be combined/split quietly 219 ArrayList<RelationRole> relations = removeFromRelations(a); 220 if(!same) relations.addAll(removeFromRelations(b)); 221 222 // Don't warn now, because it will really look corrupted 223 boolean warnAboutRelations = relations.size() > 0; 224 225 Collection<Way> allWays = splitWaysOnNodes(a, b, nodes); 226 227 // Find all nodes and inner ways save them to a list 228 Collection<Node> allNodes = getNodesFromWays(allWays); 229 Collection<Way> innerWays = findInnerWays(allWays, allNodes); 230 231 // Join outer ways 232 Way outerWay = joinOuterWays(allWays, innerWays); 233 234 // Fix Multipolygons if there are any 235 Collection<Way> newInnerWays = fixMultigons(innerWays, outerWay); 236 237 // Delete the remaining inner ways 238 cmds.add(DeleteCommand.delete(innerWays, true)); 239 commitCommands("Delete Ways that are not part of an inner multipolygon"); 240 241 // We can attach our new multipolygon relation and pretend it has always been there 242 addOwnMultigonRelation(newInnerWays, outerWay, relations); 243 fixRelations(relations, outerWay); 244 commitCommands("Fix relations"); 245 246 stripTags(newInnerWays); 247 makeCommitsOneAction( 248 a.equals(b) 249 ? "Joined self-overlapping area " + a.getName() 250 : "Joined overlapping areas " + a.getName() + " and " + b.getName() 251 ); 252 253 if(warnAboutRelations) 254 JOptionPane.showMessageDialog(Main.parent, tr("Some of the ways were part of relations that have been modified. Please verify no errors have been introduced.")); 255 256 return true; 257 } 258 259 /** 260 * Checks if tags of two given ways differ, and presents the user a dialog to solve conflicts 261 * @param Way First way to check 262 * @param Way Second Way to check 263 * @return boolean True if not all conflicts could be resolved, False if everything's fine 264 */ 265 private boolean checkForTagConflicts(Way a, Way b) { 266 ArrayList<Way> ways = new ArrayList<Way>(); 267 ways.add(a); 268 ways.add(b); 269 270 // This is mostly copied and pasted from CombineWayAction.java and one day should be moved into tools 271 Map<String, Set<String>> props = new TreeMap<String, Set<String>>(); 272 for (Way w : ways) { 273 for (Entry<String,String> e : w.entrySet()) { 274 if (!props.containsKey(e.getKey())) 275 props.put(e.getKey(), new TreeSet<String>()); 276 props.get(e.getKey()).add(e.getValue()); 277 } 278 } 279 280 Way ax = new Way(a); 281 Way bx = new Way(b); 282 283 Map<String, JComboBox> components = new HashMap<String, JComboBox>(); 284 JPanel p = new JPanel(new GridBagLayout()); 285 for (Entry<String, Set<String>> e : props.entrySet()) { 286 if (TigerUtils.isTigerTag(e.getKey())) { 287 String combined = TigerUtils.combineTags(e.getKey(), e.getValue()); 288 ax.put(e.getKey(), combined); 289 bx.put(e.getKey(), combined); 290 } else if (e.getValue().size() > 1) { 291 if("created_by".equals(e.getKey())) 292 { 293 ax.put("created_by", "JOSM"); 294 bx.put("created_by", "JOSM"); 295 } else { 296 JComboBox c = new JComboBox(e.getValue().toArray()); 297 c.setEditable(true); 298 p.add(new JLabel(e.getKey()), GBC.std()); 299 p.add(Box.createHorizontalStrut(10), GBC.std()); 300 p.add(c, GBC.eol()); 301 components.put(e.getKey(), c); 302 } 303 } else { 304 String val = e.getValue().iterator().next(); 305 ax.put(e.getKey(), val); 306 bx.put(e.getKey(), val); 307 } 308 } 309 310 if (components.isEmpty()) 311 return false; // No conflicts found 312 313 int result = new ExtendedDialog(Main.parent, 314 tr("Enter values for all conflicts."), 315 p, 316 new String[] {tr("Solve Conflicts"), tr("Cancel")}, 317 new String[] {"dialogs/conflict.png", "cancel.png"}).getValue(); 318 319 if (result != 1) return true; // user cancel, unresolvable conflicts 320 321 for (Entry<String, JComboBox> e : components.entrySet()) { 322 String val = e.getValue().getEditor().getItem().toString(); 323 ax.put(e.getKey(), val); 324 bx.put(e.getKey(), val); 325 } 326 327 cmds.add(new ChangeCommand(a, ax)); 328 cmds.add(new ChangeCommand(b, bx)); 329 commitCommands("Fix tag conflicts"); 330 return false; 331 } 332 333 /** 334 * Will find all intersection and add nodes there for two given ways 335 * @param Way First way 336 * @param Way Second way 337 * @return ArrayList<OsmPrimitive> List of new nodes 338 */ 339 private ArrayList<OsmPrimitive> addIntersections(Way a, Way b) { 340 boolean same = a.equals(b); 341 int nodesSizeA = a.nodes.size(); 342 int nodesSizeB = b.nodes.size(); 343 344 // We use OsmPrimitive here instead of Node because we later need to split a way at these nodes. 345 // With OsmPrimitve we can simply add the way and don't have to loop over the nodes 346 ArrayList<OsmPrimitive> nodes = new ArrayList<OsmPrimitive>(); 347 ArrayList<NodeToSegs> nodesA = new ArrayList<NodeToSegs>(); 348 ArrayList<NodeToSegs> nodesB = new ArrayList<NodeToSegs>(); 349 350 for (int i = (same ? 1 : 0); i < nodesSizeA - 1; i++) { 351 for (int j = (same ? i + 2 : 0); j < nodesSizeB - 1; j++) { 352 // Avoid re-adding nodes that already exist on (some) intersections 353 if(a.nodes.get(i).equals(b.nodes.get(j)) || a.nodes.get(i+1).equals(b.nodes.get(j))) { 354 nodes.add(b.nodes.get(j)); 355 continue; 356 } else 357 if(a.nodes.get(i).equals(b.nodes.get(j+1)) || a.nodes.get(i+1).equals(b.nodes.get(j+1))) { 358 nodes.add(b.nodes.get(j+1)); 359 continue; 360 } 361 LatLon intersection = getLineLineIntersection( 362 a.nodes.get(i) .eastNorth.east(), a.nodes.get(i) .eastNorth.north(), 363 a.nodes.get(i+1).eastNorth.east(), a.nodes.get(i+1).eastNorth.north(), 364 b.nodes.get(j) .eastNorth.east(), b.nodes.get(j) .eastNorth.north(), 365 b.nodes.get(j+1).eastNorth.east(), b.nodes.get(j+1).eastNorth.north()); 366 if(intersection == null) continue; 367 368 // Create the node. Adding them to the ways must be delayed because we still loop over them 369 Node n = new Node(intersection); 370 cmds.add(new AddCommand(n)); 371 nodes.add(n); 372 // The distance is needed to sort and add the nodes in direction of the way 373 nodesA.add(new NodeToSegs(i, n, a.nodes.get(i).coor)); 374 if(same) 375 nodesA.add(new NodeToSegs(j, n, a.nodes.get(j).coor)); 376 else 377 nodesB.add(new NodeToSegs(j, n, b.nodes.get(j).coor)); 378 } 379 } 380 381 addNodesToWay(a, nodesA); 382 if(!same) addNodesToWay(b, nodesB); 383 384 return nodes; 385 } 386 387 /** 388 * Finds the intersection of two lines 389 * @return LatLon null if no intersection was found, the LatLon coordinates of the intersection otherwise 390 */ 391 static private LatLon getLineLineIntersection( 392 double x1, double y1, double x2, double y2, 393 double x3, double y3, double x4, double y4) { 394 395 if (!Line2D.linesIntersect(x1, y1, x2, y2, x3, y3, x4, y4)) return null; 396 397 // Convert line from (point, point) form to ax+by=c 398 double a1 = y2 - y1; 399 double b1 = x1 - x2; 400 double c1 = x2*y1 - x1*y2; 401 402 double a2 = y4 - y3; 403 double b2 = x3 - x4; 404 double c2 = x4*y3 - x3*y4; 405 406 // Solve the equations 407 double det = a1*b2 - a2*b1; 408 if(det == 0) return null; // Lines are parallel 409 410 return Main.proj.eastNorth2latlon(new EastNorth( 411 (b1*c2 - b2*c1)/det, 412 (a2*c1 -a1*c2)/det 413 )); 414 } 415 416 /** 417 * Inserts given nodes with positions into the given ways 418 * @param Way The way to insert the nodes into 419 * @param Collection<NodeToSegs> The list of nodes with positions to insert 420 */ 421 private void addNodesToWay(Way a, ArrayList<NodeToSegs> nodes) { 422 Way ax=new Way(a); 423 List<NodeToSegs> newnodes = new ArrayList<NodeToSegs>(); 424 Collections.sort(nodes); 425 426 int numOfAdds = 1; 427 for(NodeToSegs n : nodes) { 428 ax.addNode(n.pos + numOfAdds, n.n); 429 numOfAdds++; 430 } 431 432 cmds.add(new ChangeCommand(a, ax)); 433 } 434 435 /** 436 * Commits the command list with a description 437 * @param String The description of what the commands do 438 */ 439 private void commitCommands(String description) { 440 switch(cmds.size()) { 441 case 0: 442 return; 443 case 1: 444 Main.main.undoRedo.add(cmds.getFirst()); 445 break; 446 default: 447 Command c = new SequenceCommand(tr(description), cmds); 448 Main.main.undoRedo.add(c); 449 break; 450 } 451 452 cmds.clear(); 453 cmdsCount++; 454 } 455 456 /** 457 * Removes a given OsmPrimitive from all relations 458 * @param OsmPrimitive Element to remove from all relations 459 * @return ArrayList<RelationRole> List of relations with roles the primitives was part of 460 */ 461 private ArrayList<RelationRole> removeFromRelations(OsmPrimitive osm) { 462 ArrayList<RelationRole> result = new ArrayList<RelationRole>(); 463 for (Relation r : Main.ds.relations) { 464 if (r.deleted || r.incomplete) continue; 465 for (RelationMember rm : r.members) { 466 if (rm.member != osm) continue; 467 468 Relation newRel = new Relation(r); 469 newRel.members.remove(rm); 470 471 cmds.add(new ChangeCommand(r, newRel)); 472 RelationRole saverel = new RelationRole(r, rm.role); 473 if(!result.contains(saverel)) result.add(saverel); 474 break; 475 } 476 } 477 478 commitCommands("Removed Element from Relations"); 479 return result; 480 } 481 482 /** 483 * This is a hacky implementation to make use of the splitWayAction code and 484 * should be improved. SplitWayAction needs to expose its splitWay function though. 485 */ 486 private Collection<Way> splitWaysOnNodes(Way a, Way b, Collection<OsmPrimitive> nodes) { 487 ArrayList<Way> ways = new ArrayList<Way>(); 488 ways.add(a); 489 if(!a.equals(b)) ways.add(b); 490 491 List<OsmPrimitive> affected = new ArrayList<OsmPrimitive>(); 492 for (Way way : ways) { 493 nodes.add(way); 494 Main.ds.setSelected(nodes); 495 nodes.remove(way); 496 new SplitWayAction().actionPerformed(null); 497 cmdsCount++; 498 affected.addAll(Main.ds.getSelectedWays()); 499 } 500 return osmprim2way(affected); 501 } 502 503 /** 504 * Converts a list of OsmPrimitives to a list of Ways 505 * @param Collection<OsmPrimitive> The OsmPrimitives list that's needed as a list of Ways 506 * @return Collection<Way> The list as list of Ways 507 */ 508 static private Collection<Way> osmprim2way(Collection<OsmPrimitive> ways) { 509 Collection<Way> result = new ArrayList<Way>(); 510 for(OsmPrimitive w: ways) { 511 if(w instanceof Way) result.add((Way) w); 512 } 513 return result; 514 } 515 516 /** 517 * Returns all nodes for given ways 518 * @param Collection<Way> The list of ways which nodes are to be returned 519 * @return Collection<Node> The list of nodes the ways contain 520 */ 521 private Collection<Node> getNodesFromWays(Collection<Way> ways) { 522 Collection<Node> allNodes = new ArrayList<Node>(); 523 for(Way w: ways) allNodes.addAll(w.nodes); 524 return allNodes; 525 } 526 527 /** 528 * Finds all inner ways for a given list of Ways and Nodes from a multigon by constructing a polygon 529 * for each way, looking for inner nodes that are not part of this way. If a node is found, all ways 530 * containing this node are added to the list 531 * @param Collection<Way> A list of (splitted) ways that form a multigon 532 * @param Collection<Node> A list of nodes that belong to the multigon 533 * @return Collection<Way> A list of ways that are positioned inside the outer borders of the multigon 534 */ 535 private Collection<Way> findInnerWays(Collection<Way> multigonWays, Collection<Node> multigonNodes) { 536 Collection<Way> innerWays = new ArrayList<Way>(); 537 for(Way w: multigonWays) { 538 Polygon poly = new Polygon(); 539 for(Node n: ((Way)w).nodes) poly.addPoint(latlonToXY(n.coor.lat()), latlonToXY(n.coor.lon())); 540 541 for(Node n: multigonNodes) { 542 if(!((Way)w).nodes.contains(n) && poly.contains(latlonToXY(n.coor.lat()), latlonToXY(n.coor.lon()))) { 543 innerWays.addAll(getWaysByNode(multigonWays, n)); 544 } 545 } 546 } 547 548 return innerWays; 549 } 550 551 // Polygon only supports int coordinates, so convert them 552 private int latlonToXY(double val) { 553 return (int)Math.round(val*1000000); 554 } 555 556 /** 557 * Finds all ways that contain the given node. 558 * @param Collection<OsmPrimitive> A collection of OsmPrimitives, but only ways will be honored 559 * @param Node The node the ways should be checked against 560 * @return Collection<Way> A list of ways that contain the given node 561 */ 562 private Collection<Way> getWaysByNode(Collection<Way> w, Node n) { 563 Collection<Way> deletedWays = new ArrayList<Way>(); 564 for(Way way : w) { 565 if(!((Way)way).nodes.contains(n)) continue; 566 if(!deletedWays.contains(way)) deletedWays.add(way); // Will need this later for multigons 567 } 568 return deletedWays; 569 } 570 571 /** 572 * Joins the two outer ways and deletes all short ways that can't be part of a multipolygon anyway 573 * @param Collection<OsmPrimitive> The list of all ways that belong to that multigon 574 * @param Collection<Way> The list of inner ways that belong to that multigon 575 * @return Way The newly created outer way 576 */ 577 private Way joinOuterWays(Collection<Way> multigonWays, Collection<Way> innerWays) { 578 ArrayList<Way> join = new ArrayList<Way>(); 579 for(Way w: multigonWays) { 580 // Skip inner ways 581 if(innerWays.contains(w)) continue; 582 583 if(w.nodes.size() <= 2) 584 cmds.add(new DeleteCommand(w)); 585 else 586 join.add(w); 587 } 588 589 commitCommands("Join Areas: Remove Short Ways"); 590 return joinWays(join); 591 } 592 593 /** 594 * Joins a list of ways (using CombineWayAction and ReverseWayAction if necessary to quiet the former) 595 * @param ArrayList<Way> The list of ways to join 596 * @return Way The newly created way 597 */ 598 private Way joinWays(ArrayList<Way> ways) { 599 if(ways.size() < 2) return ways.get(0); 600 //Main.ds.setSelected(ways); 601 602 // This will turn ways so all of them point in the same direction and CombineAction won't bug 603 // the user about this. 604 Way a = null; 605 for(Way b : ways) { 606 if(a == null) { 607 a = b; 608 continue; 609 } 610 if(a.nodes.get(0).equals(b.nodes.get(0)) || 611 a.nodes.get(a.nodes.size()-1).equals(b.nodes.get(b.nodes.size()-1))) { 612 Main.ds.setSelected(b); 613 new ReverseWayAction().actionPerformed(null); 614 cmdsCount++; 615 } 616 a = b; 617 } 618 Main.ds.setSelected(ways); 619 new CombineWayAction().actionPerformed(null); 620 cmdsCount++; 621 return (Way)(Main.ds.getSelectedWays().toArray())[0]; 622 } 623 624 /** 625 * Finds all ways that may be part of a multipolygon relation and removes them from the given list. 626 * It will automatically combine "good" ways 627 * @param Collection<Way> The list of inner ways to check 628 * @param Way The newly created outer way 629 * @return ArrayList<Way> The List of newly created inner ways 630 */ 631 private ArrayList<Way> fixMultigons(Collection<Way> uninterestingWays, Way outerWay) { 632 Collection<Node> innerNodes = getNodesFromWays(uninterestingWays); 633 Collection<Node> outerNodes = outerWay.nodes; 634 635 // The newly created inner ways. uninterestingWays is passed by reference and therefore modified in-place 636 ArrayList<Way> newInnerWays = new ArrayList<Way>(); 637 638 // Now we need to find all inner ways that contain a remaining node, but no outer nodes 639 // Remaining nodes are those that contain to more than one way. All nodes that belong to an 640 // inner multigon part will have at least two ways, so we can use this to find which ways do 641 // belong to the multigon. 642 Collection<Way> possibleWays = new ArrayList<Way>(); 643 wayIterator: for(Way w : uninterestingWays) { 644 boolean hasInnerNodes = false; 645 for(Node n : w.nodes) { 646 if(outerNodes.contains(n)) continue wayIterator; 647 if(!hasInnerNodes && innerNodes.contains(n)) hasInnerNodes = true; 648 } 649 if(!hasInnerNodes && w.nodes.size() >= 2) continue; 650 possibleWays.add(w); 651 } 652 653 // Join all ways that have one start/ending node in common 654 Way joined = null; 655 outerIterator: do { 656 joined = null; 657 for(Way w1 : possibleWays) { 658 if(w1.isClosed()) { 659 if(!wayIsCollapsed(w1)) { 660 uninterestingWays.remove(w1); 661 newInnerWays.add(w1); 662 } 663 joined = w1; 664 possibleWays.remove(w1); 665 continue outerIterator; 666 } 667 for(Way w2 : possibleWays) { 668 // w2 cannot be closed, otherwise it would have been removed above 669 if(!waysCanBeCombined(w1, w2)) continue; 670 671 ArrayList<Way> joinThem = new ArrayList<Way>(); 672 joinThem.add(w1); 673 joinThem.add(w2); 674 uninterestingWays.removeAll(joinThem); 675 possibleWays.removeAll(joinThem); 676 677 // Although we joined the ways, we cannot simply assume that they are closed 678 joined = joinWays(joinThem); 679 uninterestingWays.add(joined); 680 possibleWays.add(joined); 681 continue outerIterator; 682 } 683 } 684 } while(joined != null); 685 return newInnerWays; 686 } 687 688 /** 689 * Checks if a way is collapsed (i.e. looks like <---->) 690 * @param Way A *closed* way to check if it is collapsed 691 * @return boolean If the closed way is collapsed or not 692 */ 693 private boolean wayIsCollapsed(Way w) { 694 if(w.nodes.size() <= 3) return true; 695 696 // If a way contains more than one node twice, it must be collapsed (only start/end node may be the same) 697 Way x = new Way(w); 698 int count = 0; 699 for(Node n : w.nodes) { 700 x.nodes.remove(n); 701 if(x.nodes.contains(n)) count++; 702 if(count == 2) return true; 703 } 704 return false; 705 } 706 707 /** 708 * Checks if two ways share one starting/ending node 709 * @param Way first way 710 * @param Way second way 711 * @return boolean Wheter the ways share a starting/ending node or not 712 */ 713 private boolean waysCanBeCombined(Way w1, Way w2) { 714 if(w1.equals(w2)) return false; 715 716 if(w1.nodes.get(0).equals(w2.nodes.get(0))) return true; 717 if(w1.nodes.get(0).equals(w2.nodes.get(w2.nodes.size()-1))) return true; 718 719 if(w1.nodes.get(w1.nodes.size()-1).equals(w2.nodes.get(0))) return true; 720 if(w1.nodes.get(w1.nodes.size()-1).equals(w2.nodes.get(w2.nodes.size()-1))) return true; 721 722 return false; 723 } 724 725 /** 726 * Will add own multipolygon relation to the "previously existing" relations. Fixup is done by fixRelations 727 * @param Collection<Way> List of already closed inner ways 728 * @param Way The outer way 729 * @param ArrayList<RelationRole> The list of relation with roles to add own relation to 730 */ 731 private void addOwnMultigonRelation(Collection<Way> inner, Way outer, ArrayList<RelationRole> rels) { 732 if(inner.size() == 0) return; 733 // Create new multipolygon relation and add all inner ways to it 734 Relation newRel = new Relation(); 735 newRel.put("type", "multipolygon"); 736 for(Way w : inner) 737 newRel.members.add(new RelationMember("inner", w)); 738 cmds.add(new AddCommand(newRel)); 739 740 // We don't add outer to the relation because it will be handed to fixRelations() 741 // which will then do the remaining work. Collections are passed by reference, so no 742 // need to return it 743 rels.add(new RelationRole(newRel, "outer")); 744 //return rels; 745 } 746 747 /** 748 * Adds the previously removed relations again to the outer way. If there are multiple multipolygon 749 * relations where the joined areas were in "outer" role a new relation is created instead with all 750 * members of both. This function depends on multigon relations to be valid already, it won't fix them. 751 * @param ArrayList<RelationRole> List of relations with roles the (original) ways were part of 752 * @param Way The newly created outer area/way 753 */ 754 private void fixRelations(ArrayList<RelationRole> rels, Way outer) { 755 ArrayList<RelationRole> multiouters = new ArrayList<RelationRole>(); 756 for(RelationRole r : rels) { 757 if( r.rel.get("type") != null && 758 r.rel.get("type").equalsIgnoreCase("multipolygon") && 759 r.role.equalsIgnoreCase("outer") 760 ) { 761 multiouters.add(r); 762 continue; 763 } 764 // Add it back! 765 Relation newRel = new Relation(r.rel); 766 newRel.members.add(new RelationMember(r.role, outer)); 767 cmds.add(new ChangeCommand(r.rel, newRel)); 768 } 769 770 Relation newRel = null; 771 switch(multiouters.size()) { 772 case 0: 773 return; 774 case 1: 775 // Found only one to be part of a multipolygon relation, so just add it back as well 776 newRel = new Relation(multiouters.get(0).rel); 777 newRel.members.add(new RelationMember(multiouters.get(0).role, outer)); 778 cmds.add(new ChangeCommand(multiouters.get(0).rel, newRel)); 779 return; 780 default: 781 // Create a new relation with all previous members and (Way)outer as outer. 782 newRel = new Relation(); 783 for(RelationRole r : multiouters) { 784 // Add members 785 for(RelationMember rm : r.rel.members) 786 if(!newRel.members.contains(rm)) newRel.members.add(rm); 787 // Add tags 788 for (String key : r.rel.keys.keySet()) { 789 newRel.put(key, r.rel.keys.get(key)); 790 } 791 // Delete old relation 792 cmds.add(new DeleteCommand(r.rel)); 793 } 794 newRel.members.add(new RelationMember("outer", outer)); 795 cmds.add(new AddCommand(newRel)); 796 } 797 } 798 799 /** 800 * @param Collection<Way> The List of Ways to remove all tags from 801 */ 802 private void stripTags(Collection<Way> ways) { 803 for(Way w: ways) stripTags(w); 804 commitCommands("Remove tags from inner ways"); 805 } 806 807 /** 808 * @param Way The Way to remove all tags from 809 */ 810 private void stripTags(Way x) { 811 if(x.keys == null) return; 812 Way y = new Way(x); 813 for (String key : x.keys.keySet()) 814 y.remove(key); 815 cmds.add(new ChangeCommand(x, y)); 816 } 817 818 /** 819 * Takes the last cmdsCount actions back and combines them into a single action 820 * (for when the user wants to undo the join action) 821 * @param String The commit message to display 822 */ 823 private void makeCommitsOneAction(String message) { 824 UndoRedoHandler ur = Main.main.undoRedo; 825 cmds.clear(); 826 for(int i = ur.commands.size() - cmdsCount; i < ur.commands.size(); i++) 827 cmds.add(ur.commands.get(i)); 828 829 for(int i = 0; i < cmdsCount; i++) 830 ur.undo(); 831 832 commitCommands(message == null ? "Join Areas Function" : message); 833 cmdsCount = 0; 834 } 835 } -
src/UtilsPlugin/UtilsPlugin.java
22 22 23 23 public class UtilsPlugin extends Plugin { 24 24 JMenuItem SimplifyWay; 25 JMenuItem JoinAreas; 25 26 JumpToAction JumpToAct = new JumpToAction(); 26 27 27 28 public UtilsPlugin() { 28 29 SimplifyWay = MainMenu.add(Main.main.menu.toolsMenu, new SimplifyWayAction()); 30 JoinAreas = MainMenu.add(Main.main.menu.toolsMenu, new JoinAreasAction()); 29 31 SimplifyWay.setEnabled(false); 30 32 } 31 33 … … 33 35 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 34 36 if (oldFrame == null && newFrame != null) { 35 37 SimplifyWay.setEnabled(true); 38 JoinAreas.setEnabled(true); 36 39 newFrame.statusLine.addMouseListener(JumpToAct); 37 40 } 38 41 }
