• No results found

Map Overlay

In document DiplThesisJena07 (Page 75-82)

6.3 Set Operations

6.3.2 Map Overlay

Research held in the the last decade has yielded different algorithms for the poly- gon overlay (seeSet Operations, Chapter 6.3). Most of the algorithms are based on three basic steps:

1. Find all intersections between the two input geometriesby building a topo- logical graph of the geometries and searching intersection points between the components, resulting in a completely noded graph

2. Label the componentswith its position in relation to the other geometry 3. Select the components according to the desired operation (intersection,

union, difference, symmetric difference) toconstruct the output geometry

The above mentioned steps, specially the first two, can be carried out in a mani- fold manner. The possibilities for computing intersections of line segments, which is used to construct a noded graph, are discussed in the next paragraphIntersec- tions between segment sets(section 6.3.2). The data structure used to store this graph has been thoroughly discussed above (section 6.1). An intelligent data structure will bring remarkable performance benefits to the construction of the resulting geometric object in the third step. The second step determines which line segments will make part of the result geometry. There are differing techniques for labelling the edges and vertices (see literature mentioned above and [Sch95]). However, they are all based on the same idea: the position of the edges and vertices of the objects are marked in relationship to one another and in relationship to the geo- metric object itself. The technique applied is explained in detail in the paragraph Labelling (see 6.3.2) below.

Intersections between segment sets. A map overlay needs to compute all intersections between two sets of line segments in order to create a noded graph. The runtime of a naive brute force test between all line segments performed in O n2time is not acceptable for large datasets.

[FPM] reviews the comprehensive research results on intersections between segment sets such as the segment tree based approach of Palazzi and Snoeyink [PS93] and varioussweep linebased algorithms.

Plane sweepalgorithms uses sweep lines and have been specifically designed to search intersections in sets of objects, however, they are also used to solve other

problems such as thepolygon triangulation. Plane sweep algorithms are commonly used in map overlay operations, since they perform well on GIS data and offer a competitive runtime. The first algorithms based on this paradigm were published in [SH76], [LP76] and [BO79].

Plane sweep is anoutput-sensitive algorithm, i.e. the runtime depends not only on the size of input data, but also on the size of the output data as well. Given that the size of the output is the number of intersections between the line segments, such an algorithm can also be calledintersection-sensitive[dBvKOS97].

The basic idea of the algorithm is to move a horizontal line, thesweep line, from the top to the bottom of the plane (which holds the two input graphs) and to mon- itor all segments which intersect the sweep line. In addition, it is necessary to test for intersections between the segments that intersect the line at each position of the sweep line. Such proceeding tests all segments against each other. In worst case (when the line is at a position where it intersects all segments), the algorithm is still not intersection-sensitive. The key observation is that all intersecting segments are adjacent, at least, in one position of the down-moving sweep line. Hence, segments need to be tested only against its neighbours. Figure 6.13 shows the use of the algorithm within the map overlay operation. Note that the algorithm holds the invariant that all intersections above the sweep line are already found.

At each level of the down-moving sweep line, the line holds a status, which is an ordered sequence of the segments that intersect the line from left to right. For example, the status in figure 6.11 holds all four segmentssj, sk, sl andsm since

they all intersect with the sweep linel. In fact, the status is only altered, where a new segment begins or ends or where two segments intersect. These positions (where the sweep line changes status) are calledevent pointsand are stored in an ordered sequence. Therefore, it is only necessary to move the sweep line from one event point to the next that its status will change accordingly:

• A new segment begins (event point is upper end point of the segment): We insert the segment into the status and test the new segment for intersections with its two neighbours within the segment sequence. If the segments inter- sect, the new intersection point will be inserted as an event point.

• A segment ends (event point is lower end point of the segment): We delete the segment from the status. The former left neighbour and the former right

neighbour of the deleted segment are then adjacent and it is necessary to test if they intersect. If the segments do intersect, the new intersection point will be inserted as an event point.

• At an intersection point: The order within the status changes. In this event point the two intersecting segments must be tested against their new neigh- bours. Figure 6.11 illustrates the sweep line at an intersection point between sk andsl. Above the intersection point, sl has already been tested against

sj andsk againstsm. Just below the intersection pointslandskinvert their

positions in the status sequence and must be tested againstsj andsmrespec-

tively.

Figure 6.11:The sweep line moves down to the next event point: As the event point is an intersection point, the involved segmentsskandslmust be tested against their new neighbours

Note that event points are only visited once. In particular, geographic data hold several structures with connected segments (i.e. segments intersecting in end points), such as rings, and therefore the same event point would have to be inserted several times. However, event points are only inserted if they are not already present in the event point sequence.

The running time of the plane sweep algorithm for a setS ofnline segments in the plane isO(n·log(n) +I·log(n)), whereIis the number of intersection points of segments inS. The algorithm starts constructing an event queue. As a balanced binary search tree this takes O(n·log(n)) time. Each deletion and insertion in this tree lastsO(log(n))time. If there aremevent points, the algorithm will need O(m·log(n))time, because the intersection test and the computation of a segment intersection is performed in linear time. See [dBvKOS97] for a detailed proof (page 28) and pseudo code of the algorithm (page 20 et seqq).

The implementation of this work uses the Plane Sweep algorithm implemented robustly within the JTS. Since a robust line segment intersection is a runtime

expensive process, the algorithm uses Monotone Chain indexing (see Monotone Chainsin Appendix B) to avoid a big part of unnecessary line segment intersection tests.

Figure 6.12:A noded graph with directed edges

Labelling. The algorithm uses labelsto mark the position of edges and nodes in relationship to both geometries. Nodes hold one position attribute<on>, edges hold three position attributes<left, on, right>: for the left side of the edge (left), for the right side of the edge (right) and the edge itself (on). The attributes have a value from the set{Interior, Boundary, Exterior}to describe the position. Figure 6.12 shows a simple example. The labels for the nodes are:

Nodes Geometry Location on

n1,n2,n4 A boundary B exterior n8,n9 A exterior B boundary n3,n5,n7 A boundary B boundary n6 A interior B boundary

The following table gives some examples for the edge labels. For example, edge ~e3,5 is part of both polygonAand polygonB. Thus, it is equally labelled in rela-

tionship to AandB. Its labelled with the valuesexterior(for the left side of the edge),boundary(for the position the edge is located) andinterior(for the right side of the edge). Its twin edge~e5,3 has the same label but with the left and right sides

Edges Geometry Location left Location on Location right

~e1,2,~e4,1,e~6,4,~e2,7 A exterior boundary interior

B exterior exterior exterior

~e2,1,~e1,4,e~4,6,~e7,2 A interior boundary exterior

B exterior exterior exterior

~e7,8,~e8,9,~e9,3 A exterior exterior exterior

B exterior boundary interior

~e8,7,~e9,8,~e3,9 A exterior exterior exterior

B interior boundary exterior

~e3,5 A exterior boundary interior

B exterior boundary interior

~e5,3 A interior boundary exterior

B interior boundary exterior

... ... ... ... ...

Algorithm in this Implementation. The implementation of this work does not strictly follow a published algorithm, instead it combines several approaches. It follows the three basic steps explained above and was modified to speed up performance. The implementation of the algorithm and all underlying used predicates have been adapted from the JTS according to the needs of the Feature Geometry. Points correspond toGM_Points,LineStrings toGM_Curves and Polygons toGM_Surfaces.

The main steps of the algorithm are:

1. Create two topological graphs A and B, one for each input geometry, and copy the edges and boundary nodes into appropriate data structures of the two graphs. The labels are initialized with the position to its own geometry. The rings of polygons are supposed to becw(clockwise) oriented. If the ring of a polygon isccw (counter clockwise) oriented the label will be inverted (in that way the algorithm is applicable for cw and ccw oriented rings). The label which represents the relationship with the other geometry is left empty. 2. Create a new empty topological graph C.

3. Compute the self intersections of each input geometry in A and Band store the intersection points (as new nodes). (Note that figure 6.13 does not show

Figure 6.13:Finding all intersections in the overlay operation using the plane sweep algo- rithm

this step, but only the complete intersection computation between both input objects. This step is processed to reduce the number of segments which have to be tested for an intersection in the next step.)

4. Compute the intersections between the two input geometries in A and B

and store the intersection points (as new nodes) (see figure 6.13(b)).

5. Compute new edges by noding A and Bbased on the intersection points (substitute edges with intersection by those new noded edges). Existing labels are applied; in case of a redundant edge in the two graphs, the edge will be inserted only once and the two labels will be merged.

6. Add all edgesas directed edges (twice: positive oriented and negative ori- ented)and intersection nodes to the new graph C(see figure 6.14).

Figure 6.14:Internal graph representation

7. Label edges and nodes of Cin relation to the input geometries in A and B. 8. Compute the labelling for isolated componentsof the graph. Add the iso-

lated components to the resultant graph.

9. Build the result polygonsbased on the labelled noded graph C. According to the selected operation, select edges located in the Interior/Boundary or in the Exterior of the geometries of A and B (edges with an INTERIOR on the right-hand-label are: CW oriented edges of an originally exterior ring, CCW oriented edges of an originally interior ring):

• Intersection: interior of A and interior of B • Union: interior of A or interior of B

• Difference: interior of A and exterior of B

• Symmetric difference: (interior of A and exterior of B) or (exterior of A and interior of B)

10. Build the result linesbased on the labelled noded graph C 11. Build the result pointsbased on the labelled noded graph C

12. Build the result geometrybased on the result polygons, lines and points Let n be the complexity of both geometries, that is the sum of all segments and vertices, and kthe complexity of the overlay, that is the number of all seg-

ment intersections within and between two geometric objects, then the complete set operation by a map overlay is performed in O(n·log(n) +I·log(n)) time. Copying the segments and points into new graphs take O(n) time. Comput- ing self intersections and intersections between both geometries is performed in O(n·log(n) +I ·log(n))time by the Plane Sweep algorithm. The computation of new edges requires linear time inkand the creation of directed edges linear time inn. The labelling of edges and vertices in relation to the other geometry can be done inO(n·log(n) +I·log(n))(see [dBvKOS97], page 39). The final collection of segments and points in order to create new polygons, lines and points need linear time inn.

Further documentation of the algorithm can be found in [viv03b]. Similar map overlay algorithms are explained in [dBvKOS97] and [MK89].

In document DiplThesisJena07 (Page 75-82)