L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems...

25
L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithm : Sadegh Jamali (source: Lecture notes in GIS, Lars Harrie) 1

Transcript of L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems...

Page 1: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

1

L10 – Map labeling algorithms

NGEN06(TEK230) – Algorithms in Geographical Information Systems

L10- Map labeling algorithms

by: Sadegh Jamali (source: Lecture notes in GIS, Lars Harrie)

Page 2: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

• Labels are an essential aspect of maps.

For example, on maps for mobile applications, it is necessary to label roads, landmarks, and …. to help users understand their location and the environment.

• The labels should be easy to read and should follow

basic cartographic rules.

• The cartographic rules are analytically defined and implemented in computer programs.

L10- Map labeling algorithms

Background

2

Page 3: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

3

to provide some basics of algorithms for automated map labelling.

L10- Map labeling algorithms

Aim

Content

1. Basic cartography theory

2. Label placement by combinatorial optimization

3. Label placement by slider model

Page 4: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

4

L10- Map labeling algorithms

Generally, there are two things that are important for labels:

• proper font type and size • good position.

1. Basic cartography theory

Page 5: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

5

L10- Map labeling algorithms

Font type and size

Figure. The two main font families (From Jenny et al. 2008).

Example of Sans Serif family: Verdena and Frutiger Font size: at least 12 points.

Note: to distinguish between different label types, you could use wide letter spacing, varying font size and bold/italic style.

Page 6: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

6

L10- Map labeling algorithms

Label position

To be good positioned, the labels should:

1) not overlap 2) not obscure other map objects 3) placed in a good position relative to the referent.

Page 7: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

7

Preferred positions for point labels

Slocum et al. (2005)

L10- Map labeling algorithms

Page 8: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

8Slocum et al. (2005)

L10- Map labeling algorithms

Preferred positions for line labels

Page 9: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

9Slocum et al. (2005)

L10- Map labeling algorithms

Preferred positions for area labels

Page 10: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

10

L10- Map labeling algorithms

2. Label placement by combinatorial optimization

Label placement can be defined as a combinatorial optimization problem.

To find the optimal combination of placement a cost function (f) is created.

Page 11: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

L10- Map labeling algorithms

11

Cost function

The best solution: the solution with the smallest cost.

Page 12: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

L10- Map labeling algorithms

12

But the search space is LARGE! For example, for n point labels with 6 possible placement of each label, the possible number of combinations is .

This is not a feasible approach even for small numbers of labels.

So how to find the best possible solution? we can adopt an iterative improvement

algorithm.

Challenge!

Page 13: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

13

• simulated annealing allows moving towards both lower (better) and upper (worse) neighboring positions, where a worse position is accepted with a probability decreasing over time

• the probability is controlled by a parameter denoted as temperature, which decreases over time and thus forms a number of temperature stages

• by accepting worse positions with a decreasing probability, simulated annealing may escape from a local optimal position and reach the global optimal position (Russell and Norvig 1995).

L10- Map labeling algorithms

Iterative improvement algorithm • can be illustrated as a search process

on the surface of a landscape• each position = a specific configuration,

i.e., a solution, with an elevation representing the “cost” of the solution

• moves around to find the lowest position on the landscape

• can be realized by a slope descending algorithm

• slope descending may be terminated at local lowest positions

Page 14: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

14

L10- Map labeling algorithms

Combinatorial optimization schema

1) Labels are initially placed at the position with best placement properties. 2) Create a cost function to reflect cartographic requirements and aesthetic principles. 3) Start an optimization using the simulated annealing schema. For each iteration a label is randomly selected. 4) Run the process until a minimum of the cost function is found.

Page 15: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

15

L10- Map labeling algorithms

3. Label placement by slider model

In the combinatorial optimization: a fixed number of positions are allowed.

Slider model: much more positions are allowed (leads to enhanced cartographic quality of the labels).

Constraints:1) labels should be legible2) each label should be properly associated to the

feature that it describes (i.e. feature and its label are not separated).

Page 16: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

16

L10- Map labeling algorithms

Slider Model (Zhang and Harrie(2006a,b))

Phases:1) all possible positions for the label are computed. 2) the candidate positions are reduced according

to conflict detection. 3) finally a position is selected from the reduced

candidate set to label the feature.

Page 17: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

17

L10- Map labeling algorithms

Slider Model: point labeling algorithm

Input data: a point set (to be labeled) and other feature classes (acting as obstacles)

Algorithm workflow:1. Select a point sequentially from the point set, and

create four rectangular boxes around the point (“range boxes”).

Figure: (a) The top range box of a point feature.

Page 18: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

18

L10- Map labeling algorithms

The workflow:

2. Select the range boxes of a point feature sequentially, and search for the obstacles in conflict with this box.

3. For each conflicting obstacle, compute the intersection between the obstacle and the range box. If any intersection exists, reduce the range box using the intersection.

Figure: (b) The reduced range boxes (left and bottom) of a point feature in conflict with a line feature.

Page 19: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

19

L10- Map labeling algorithms

Reduction of a range box:depends on the location and size of the intersection between the range box and the obstacle.

Suppose the point is to be labelled, and a range box RB is attached to the point P

If there is an object O (label or cartographic feature) that overlaps the range box RB, then the intersection I has the properties:

where MBR is the minimum bounding box function.

Page 20: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

20

L10- Map labeling algorithms

Then the range box RB will be reduced to a new range box RBnew as follows (if it is a top or bottom range boxes; left and right range boxes are treated similarly):

Figure: Reduce a range box in conflict with an obstacle

Page 21: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

21

L10- Map labeling algorithms

The workflow:

4. select a position to place the label inside the reduced range box according to position preference. 5. Go back to step 1) to deal with the next point’s labelling.

The computational complexity: O (nk+nm)

Step 2): O (nk)n: the number of point features to be labeledk: the number of obstacles

Step 3): O (nm)m: the average number of conflicting obstacles for each point to be labeled

Page 22: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

22

L10- Map labeling algorithms

Slider Model: line labeling algorithm

Steps:1) search for all the long line segments along a

line as candidate positions.

2) Candidate positions along each segment are reduced to a part of the original positions, without conflict to any obstacles.

Page 23: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

23

L10- Map labeling algorithms

Input data: a line set (to be labeled) and several feature classes (acting as obstacles)

Algorithm workflow: 1. Select a line sequentially, and create its generalized version

using the Douglas-Peucker algorithm.2. Search for segments long enough for label placement. 3. Search for the longest segment. 4. Create a range box with orientation along the longest segment. 5. Search for obstacles in conflict with the range box, and shrink

the range box according to conflict detection. 6. If the reduced range box is long enough, then reduce its size to

the size of corresponding label text, shrinking its two sides towards the centroid. Otherwise, search for the second longest segment, then go back to step 4) to find a labelling position for the line.

7. Go back to step 1) to deal with the next line’s labelling.

Page 24: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

24

L10- Map labeling algorithms

The computational complexity: O (nk+nm)

n: the number of line features to be labeledk: the number of obstaclesm: the average number of conflicting obstacles for each line to be labeled.

Page 25: L10 – Map labeling algorithms NGEN06(TEK230) – Algorithms in Geographical Information Systems L10- Map labeling algorithms by: Sadegh Jamali (source: Lecture.

25

L10- Map labeling algorithms

A case study

Note: only one label is created for each road feature. So the routine for merging the road segments was successful in this case study.

Figure: Labels placed automatically by the slider method (source: National Land Survey of Finland)