GeoServer with OSM data not showing water

Hello,

I’m testing GeoServer as WMS server.
First I downloaded OSM data from Geofabrik Download Server

After that I filled a PostgreSQL database with that data:

osm2pgsql -s -H localhost -P 5432 -U postgres -W -d osm_neth_germ_belg merged.osm.pbf -E 3857 --keep-coastlines

Then I split the data in separate tables for creating different layers in GeoServer.
My query to create a separate water layer:


insert into osm.water(osm_id, name, geom) 
  SELECT planet_osm_polygon.osm_id, 
    planet_osm_polygon.name,  
    st_multi(planet_osm_polygon.way)::geometry(MultiPolygon, 3857) as way
  FROM planet_osm_polygon
  WHERE planet_osm_polygon."natural"   = 'water'::text
     OR planet_osm_polygon."natural"   = 'coastline'::text
     OR planet_osm_polygon."natural"   = 'strait'::text
     OR planet_osm_polygon."natural"   = 'wetland'::text
     OR planet_osm_polygon."natural"   = 'shoal'::text
     OR planet_osm_polygon."natural"   = 'bay'::text
     OR planet_osm_polygon."natural"   = 'beach'::text
     OR planet_osm_polygon."waterway"  = 'dock'::text
     OR planet_osm_polygon."place"     = 'sea'::text
     OR planet_osm_polygon."landuse"   = 'water'::text
     OR planet_osm_polygon.water    IS NOT NULL 
     OR planet_osm_polygon.waterway IS NOT NULL
     OR planet_osm_polygon.wetland  IS NOT NULL;

I have a problem with my water layer.
Not all waters are added to that layer. Example:
The water “Westerschelde Netherlands” is not colored blue. See image.

Does anybody knows what’s going wrong?

Excuse my English, it’s not my native language.

With the water:

I do suspect that natural = coastline generates the issue. The thing is, in original data coastline is a (Multi)LineString. And usually, you will find it in planet_osm_line table. If you are using the data for whole planet, then the easiest thing would be to download water polygons from Water polygons and import it to PostgreSQL/PostGIS. If that’s only Netherlands, you can take a bounding box, create a polygon, and split the polygon by coastline.

Regards,
Grzegorz

Thank you for your answer, I appreciate it.

I also created a map without planet_osm_polygon.“natural” = ‘coastline’::text and without the osm2pgsql --keep-coastlines parameter. That map has the same problem.

I think maybe it has to do something with the border of the country and the small dataset. The map in the example was a merged map with data sets for Netherlands, Belgium and Germany. With the dataset for only the Netherlands I have the same problem.

I bought me a bigger SSD and processing a dataset for Europe at this moment. I hope this will solve my problem. I let you know.

Het water wat je mist lijkt deels overeen te komen met de Westerschelde & Saeftinghe maar dat is een protected_area, geen water.

Zie Coastline en de Duitse versie van die pagina.

The presentation of the coastline is often more complex than that for other features.

Ik zou eens proberen met alleen natural=coastline, zonder die andere tags.

I don’t know if I need the coastlines. I tried that because I had problems. By the way I have the same problem in the north of the Netherlands (Eems). Also at the border (Germany).

Protected area is interesting, maybe I can add that to the query…

At this moment I’m processing the Europe dataset. This takes a lot of time (days). If that doesn’t work I give your suggestions a try.

Nee, protected_area’s toevoegen zal je probleem niet oplossen.

Het zou goed te weten zijn wat je doel is, is dat een waterkaart maken? Alleen van Nederland of …

Nee, een “gewone” kaart. GeoServer maakt van verschillende lagen weer een geheel. Per laag kan je, eenvoudig gezegd, een kleur aangeven. Omdat ik problemen met de waterlaag heb krijg je witte plekken.

In principe heb ik alleen Nederland nodig.

Als je alleen Nederland wilt afbeelden dan moet netherlands.pbf genoeg zijn.

Zoals de pagina Coastline schrijft is de kustlijn anders dan andere objecten in OSM. Andere water-objecten zijn gesloten wegen, bijv. het IJsselmeer.

De kustlijn is geen gesloten weg, het is set van lijnen waarbij voor elke lijn geldt dat links van de lijn water is en land rechts van de lijn water. Het is niet voor niets dat je voor osm2pgsql een aparte parameter nodig hebt om dat kustlijnen mee te nemen :wink:

Ik ben begonnen met: netherlands-latest.osm.pbf

Ik heb het vermoeden dat het probleem is dat het water van de Westerschelde een polygon is die zich van Nederland tot in Belgie uitstrekt. Zie afbeelding (cirkel) Doordat ik alleen de dataset gebruik van Nederland krijg je een onvolledige polygon waarmee osm2pgsql niet mee om kan gaan. Ook omdat ik het zelfde probleem heb op de grens met Duitsland. Door de dataset van Europa te gebruiken hoop ik wat meer duidelijkheid te krijgen wat betreft mijn vermoedens.

Ik ben nu eerst bezig met het verwerken van europe-latest.osm.pbf. Zolang dat bezig is kan ik geen andere dingen testen.

Ik heb “natural=coastline” uit netherlands.pbf geëxtraheerd:

> osmium tags-filter netherlands.pbf w/natural=coastline -o coastline.osm

En die in Josm geladen:

Screenshot_20221001_135445

Ik zie dat het compleet is voor Nederland maar dat betekend voor de Eems-Dollard:

Screenshot_20221001_140322

Ik heb de europa dataset verwerkt. 13h 6m 21s osm2pgsql + 1h 50m query. Zelfde probleem :sleepy:

Ik heb nu het volgende gedaan (kleiner dataset, alleen Zeeland):

osm2pgsql -v -H localhost -P 5432 -U postgres -W --keep-coastlines -d zeeland zeeland-latest.osm.pbf

create schema if not exists osm;

drop table if exists osm.water;

create table osm.water(
  id serial not null primary key,
  osm_id integer,
  name text,
  geom geometry(multipolygon, 3857)
);

create index gix_water on osm.water using gist(geom);

delete from osm.water;

insert into osm.water(osm_id, name, geom) 
  SELECT planet_osm_polygon.osm_id, 
                 planet_osm_polygon.name,  
                 st_multi(planet_osm_polygon.way)::geometry(MultiPolygon, 3857) as way
  FROM planet_osm_polygon
  WHERE planet_osm_polygon."natural"   = 'coastline'::text;

Ik zie nu maar een heel klein stuke coastline (zie afbeelding):

Ja, het probleem is precies wat ik dacht:

Het enige wat wordt getoond zijn de twee eilanden in de Westerschelde omdat dat gesloten objecten zijn, de rest is zoals ik eerder beschreef collectie lijnen waarbij links lands is en rechts water.

Het probleem zit niet in de data maar hoe die wordt weergegeven, ik vermoed dat dat GeoServer is en daar heb ik geen ervaring mee.

1 Like

Het probleem zou “opgelost” zijn als ik een world.osm.pbf gebruik , omdat de kustlijn dan gesloten is?

Ik laat het even op me inwerken, mocht je nog wat te binnen schieten laat het me dan weten.

Bedankt!

Nee, ook dat zal niet werken, de kustlijn is opgebouwd uit wegen als dit stuk kustlijn van de Westerschelde maar ook eilanden zoals De Bol. Je zult dus eerst alle stukken kustlijn aan elkaar moeten plakken maar ik zou verwachten dat GeoServer speciale ondersteuning heeft voor kustlijnen.

Het lijkt mij dat GeoServer het niet goed ondersteunt maar ik ben nog maar net bezig zowel OSM als GeoServer. Dus het kan ook best zijn dat het wel mogelijk is.

Ik heb de benodigde wateren als shapefile kunnen downloaden:

https://osmdata.openstreetmap.de/data/water-polygons.html

Met deze shapefile heb ik een laag gemaakt in GeoServer. Voor de duidelijkheid heb ik hem rood gemaakt. Later wordt dit lichtblauw. Met de water layer er boven is het nu goed.

Het probleem lijkt opgelost.

2 Likes

Yep, as suggested :slight_smile: The thing with --keep-coastlines is, that neither the zeeland-latest.osm.pbf, neither europe set doesn’t have all coastlines required to create the proper polygon. I’m glad you found the solution.

I marked your suggestion as “Solution”.
Do you think that the world.osm.pbf has enough coatlines to create a proper polygon?

Can you explain me (or have a URL) how to do this?

Might be, however on the coastline data page it’s written:

The coastline is handled somewhat differently than most other features in OSM. To mark it ways with the tag natural=coastline are used. Those ways need to connect end-to-end to form an unbroken line around every island and every continent. And the land always has to be on the left side, the water on the right side of those ways.

You might have the luck and get it without gaps, but I would stick to already prepared data set from Water polygons - that’s really easiest way.

ST_Split in this case. Something like:

WITH bbox AS (
	SELECT ST_Envelope(way)
      FROM planet_osm_polygon 
      WHERE planet_osm_polygon.boundary = 'administrative' 
        AND planet_osm_polygon.admin_level = '2' 
        AND name = 'Polska'
    ),
	splitline AS (
      SELECT ST_UNION(way) FROM planet_osm_line 
      WHERE planet_osm_line.natural = 'coastline' 	
	)
SELECT ST_Split(bbox, splitline)

Haven’t tested right now, as I don’t have coastlines in my db.

Regards,
Grzegorz

PS. There was similar topic on stackexchange: r - Plot filled areas for sea/ocean and land mass based on {osmdata} using {ggplot2} - Stack Overflow

1 Like

Yes, water polygons are working well.

That ST_Split is al little difficult. I don’t really need that at the moment. I keep it in mind, maybe I need it in the future. Then I spend some more time on it to get it working.

Thanks!