|
| 1 | + |
| 2 | +# Generalization |
| 3 | + |
| 4 | +There is an experimental new program `osm2pgsql-gen`. It is only built if the |
| 5 | +CImg and potrace libraries are available. |
| 6 | + |
| 7 | +This is part of a project to add generalization support to osm2pgsql. See |
| 8 | +https://osm2pgsql.org/generalization/ for more information. |
| 9 | + |
| 10 | +Generalization is currently only supported for Web Mercator (EPSG 3857). This |
| 11 | +is by far the most common use case, we can look at extending this later if |
| 12 | +needed. |
| 13 | + |
| 14 | +## Usage |
| 15 | + |
| 16 | +Run osm2pgsql as usual. This example assumes you have a table called |
| 17 | +`landcover` with a polygon geometry column called `geom` and a text column |
| 18 | +called `type` with the type of the landcover (forest, grass, etc.). |
| 19 | + |
| 20 | +Create a table `landcover_z10` with (at least) columns `geom` and `type` as |
| 21 | +well as integer columns `x`, and `y`. Then call this: |
| 22 | + |
| 23 | +``` |
| 24 | +PGDATABASE=mydb ./osm2pgsql-gen -t landcover -T landcover_z10 -g geom -G type -z 10 -m 0.125 -s raster-union |
| 25 | +``` |
| 26 | + |
| 27 | +The `landcover_z10` table will be filled with generalized polygons. |
| 28 | + |
| 29 | +Database connection parameters have to be specified using [environment |
| 30 | +variables](https://www.postgresql.org/docs/current/libpq-envars.html). |
| 31 | + |
| 32 | +Call `osm2pgsql-gen -h` for more command line options. |
| 33 | + |
| 34 | +## Extent |
| 35 | + |
| 36 | +You can process a single tile by setting `-x`, and `-y`. If `-X` and `-Y` are |
| 37 | +also set, all tiles between the arguments of `-x` and `-X`, and `-y` and `-Y` |
| 38 | +are processed. Without any of these, the program gets the extent from the data |
| 39 | +in the source table. |
| 40 | + |
| 41 | +You can also use the option `-e, --expire-list=TABLE` to read the list of tiles |
| 42 | +from a database table. |
| 43 | + |
| 44 | +In any case `-z` or `--zoom` sets the zoom level. |
| 45 | + |
| 46 | +## Parameters |
| 47 | + |
| 48 | +For a full list of parameters see `osm2pgsql-gen -h`. |
| 49 | + |
| 50 | +* `-s, --strategy=STRATEGY`: Set the strategy used for generalization. See |
| 51 | + below for available strategies. |
| 52 | +* `-m, --margin=MARGIN`: This sets the margin around the tile as a fraction of |
| 53 | + the tile size. So a value of 0.1 sets a 10% boundary on each side of the tile, |
| 54 | + so as a result the tiles will overlap by 20% of their size. When using the |
| 55 | + `raster-union` strategy the margin will be rounded up to the nearest multiple |
| 56 | + of 64 pixels. |
| 57 | +* `-w, --width=WIDTH`: Size of the imaged rendered when using the `raster-union` |
| 58 | + strategy, not used in the `vector-union` strategy. |
| 59 | +* `-b, --buffer=BUFFER`: The amount by which the polygons will be buffered. For |
| 60 | + the `raster-union` strategy this is in pixels, for the `vector-union` strategy |
| 61 | + this is in Mercator map units. |
| 62 | +* `-g, --group-by-column=COL`: Set this to the column describing the type of |
| 63 | + polygon if any, the program will group the data by this column before |
| 64 | + generalization. If this is not specified, no grouping is performed and |
| 65 | + the destination table also doesn't need a column for this. |
| 66 | +* `--img-path=PATH`: Used to dump PNGs of the "before" and "after" images |
| 67 | + generated with the `raster-union` strategy. Use something like this: |
| 68 | + `--img-path=some/dir/path/img`. Resulting images will be in the |
| 69 | + directory `some/dir/path` and are named `img-X-Y-TYPE-[io].png` for |
| 70 | + input (`i`) or output (`o`) images. The `TYPE` is the value from the |
| 71 | + column specified with the `-G` option. |
| 72 | +* `--img-table=TABLE`: Used to dump "before" and "after" raster images to the |
| 73 | + database. The table will be created if it doesn't exist already. |
| 74 | +* `-e, --expire-list=TABLE`: Get list of tiles to expire from the specified |
| 75 | + table. If this is set the options `-x`, `-X`, `-y`, and `-Y` are ignored. The |
| 76 | + content of the table is not removed after processing! |
| 77 | +* `-p, --param=KEY=VALUE`: Set any parameter. This allows for easier |
| 78 | + experimentation with new parameters. |
| 79 | + |
| 80 | +## Strategies |
| 81 | + |
| 82 | +Some strategies work on a tile-by-tile basis (`vector-union`, `raster-union`, |
| 83 | +`builtup`), some work for all data at once (`discrete-isolation`). |
| 84 | + |
| 85 | +* `vector-union`: Buffer and union polygons together in vector space to |
| 86 | + form generalized polygons for landcover and similar use. |
| 87 | +* `raster-union`: Buffer and union polygons together in raster space to |
| 88 | + form generalized polygons for landcover and similar use. |
| 89 | + See https://blog.jochentopf.com/2022-11-21-generalizing-polygons.html for |
| 90 | + details. |
| 91 | +* `builtup`: Aggregate data from several layers (such as landcover, buildings, |
| 92 | + and roads) to derive built-up areas. |
| 93 | +* `discrete-isolation`: Classify point geometries by importance to render |
| 94 | + only the most important places but still don't leave areas too empty. |
| 95 | + See https://blog.jochentopf.com/2022-12-19-selecting-settlements-to-display.html |
| 96 | + for some background. |
| 97 | + |
0 commit comments