Answers to: Clip part from map with a boundary polygon and adjust intersected polygons from boundaryhttps://help.openstreetmap.org/questions/45718/clip-part-from-map-with-a-boundary-polygon-and-adjust-intersected-polygons-from-boundary<p>I want to extract (clip) a part of the map with a predefined boundary polygon. I have seen that I can do it with <strong>osmosis</strong> or <strong>osmconvert</strong>. But I get the problem, that polygons that intersects the predefined boundary polygon are no more polygons but only lines (because the polygon gets cropped). How can I automatically adjust intersected polygons to the boundary polygon?</p>enTue, 06 Oct 2015 14:28:00 +0100Answer by sanserhttps://help.openstreetmap.org/questions/45718/clip-part-from-map-with-a-boundary-polygon-and-adjust-intersected-polygons-from-boundary/45751<p>From your question I understand that you are aiming at clipping the map objects to/by an arbitrary polygon (CP, the Clipping Polygon). Especially, clipping areas defined by Multi-polygon relations. The subject is pretty complex and I don't think you will find open/public code doing that. At the same time area clipping is one of the essential functions of any modern vector map-making so, many of us (must) have it. Here are some hints to one possible solution. <br>
1. Pre-processing. Eliminate any replications (nodes, vectors...) and convert area objects into simple/primitive disjunctive objects (one outer and arbitrary inner border polygons). Strictly, this step is not necessary but soon or later these events may cause algorithm exceptions. <br>
2. Detect and handle trivial cases (the area is guaranteed outside/inside the CP, the CP is inside a hole, the CP is covered by the area and so on). In these cases polygons don't need to be really clipped. <br>
3. For any area border polygon P, that should be clipped, detect the inside-out and the consecutive outside-in crossings with the CP (note that if one of these crossings exist the other one must exist too). Replace the outside P segment between these crossing points with the corresponding CP segment providing the same orientation. <br>
4. Now, you have all polygons inside the CP (strictly inside or eventually with partly overlapping borders exactly on the CP). Make the area restructuring (detect the outer and the corresponding inner polygons).
5. Finally, if you really want a precise area clipping, remove the overlapping outer-inner polygon segments and reconnect the 2 complementary outer/inner segment. <br>
Note that while this is working fine, in practice we usually use another model. We detect all vector tails that are not outside the CP (e.g. country border, district border). This tile coverage provides a bit more than the first (more or less academic) option. Note also that there are many fine details missing in the hints. Most of them you may find in Polygon Algebra and Topology student books.</p>sanserTue, 06 Oct 2015 14:28:00 +0100https://help.openstreetmap.org/questions/45718/clip-part-from-map-with-a-boundary-polygon-and-adjust-intersected-polygons-from-boundary/45751