28 May 2010

Geoserver rendering Openstreetmap update1 (windows)

Two years ago, I started using Geoserver and PostGIS. I was very
exciting and satisfied about performance. Since 2009, I don't have a
lot of work about Geoserver. Time flies, last week I have some
assignment about Geoserver again. So I can refresh my geoserver
memory.

For today, what I am going to do :
1.import latest Openstreetmap data into PostGIS
2.Render it by Geoserver 2.0.1

Here is information about local settings.

--Platform: windows XP SP3
--Postgresql 8.3 + PostGIS 1.3.5
--uDig 1.1.1
--Tomcat 6.0 + Geoserver 2.0.1

To import osm data into PostGIS:
I suggest that you read following articles before you start.

--general information about osm2pgsql tool
http://wiki.openstreetmap.org/wiki/Osm2pgsql

-- There is some important information about osm2pgsql tool and PostGIS
http://wiki.openstreetmap.org/wiki/Mapnik

-- general information about OpenStreetmap dataset
http://wiki.openstreetmap.org/wiki/Planet.osm

Data and tools:

osm2pgsql windows version
-- http://tile.openstreetmap.org/osm2pgsql.zip

osm dataset(I used planet-nl-100423.osm.gz , around 500MB)
http://hypercube.telascience.org/planet/
(sometimes, their service is not available.)

before start:
I have already created one postgis database.

Step1: unzip osm2pgsql to c:\ osm2pgsql\ and add the osm2pgsql path to
system path.
http://farm5.static.flickr.com/4055/4647620497_c8424365c8_o.jpg
add c:\osm2pgsql\osm2pgsql to system path
windows Key + E, show file explorer.
Then on file tree, right click mouse, then click properties.
On properties windows, click 'Advance 'Tab
click Environment variable
http://farm5.static.flickr.com/4041/4647620813_ccc8d9a41d_o.jpg
Edit path :
http://farm4.static.flickr.com/3493/4647621133_9989696093_o.jpg
click ok and ok...

Step2: In the osm2pgsql folder, there is a sql query which named 900913.sql.
Run it on your database, you can run it via pgadmin or psql tool.
Step 3, import data into database.
Open one command window,
type "osm2pgsql -h"

http://farm5.static.flickr.com/4025/4648235534_3700e68f3e_o.jpg

then type "osm2pgsql -c -d YOURDATABASENAME -U postgres -s -v -S c
:\osm2pgsql\osm2pgsql\default.style D:\openstreetmap\planet-nl-
100423.osm.gz"

(When you import data, better switch off all other programs, because
importing would take a lot of your ram.)

After a while you should see something like this:
osm2pgsql SVN version 0.69-20874M

Using projection SRS 900913 (Spherical Mercator)
Setting up table: planet_osm_point
NOTICE: table "planet_osm_point" does not exist, skipping
NOTICE: table "planet_osm_point_tmp" does not exist, skipping
Setting up table: planet_osm_line
NOTICE: table "planet_osm_line" does not exist, skipping
NOTICE: table "planet_osm_line_tmp" does not exist, skipping
Setting up table: planet_osm_polygon
NOTICE: table "planet_osm_polygon" does not exist, skipping
NOTICE: table "planet_osm_polygon_tmp" does not exist, skipping
Setting up table: planet_osm_roads
NOTICE: table "planet_osm_roads" does not exist, skipping
NOTICE: table "planet_osm_roads_tmp" does not exist, skipping
Mid: pgsql, scale=100, cache=800MB, maxblocks=102401*8192
Setting up table: planet_osm_nodes
*** WARNING: intarray contrib module not installed
*** The resulting database will not be usable for applying diffs.
NOTICE: table "planet_osm_nodes" does not exist, skipping
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "planet_osm_nodes
_pkey" for table "planet_osm_nodes"
Setting up table: planet_osm_ways
NOTICE: table "planet_osm_ways" does not exist, skipping
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "planet_osm_ways_
pkey" for table "planet_osm_ways"
Setting up table: planet_osm_rels
NOTICE: table "planet_osm_rels" does not exist, skipping
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "planet_osm_rels_
pkey" for table "planet_osm_rels"

!! You are running this on 32bit system, so at most
!! 3GB of RAM can be used. If you encounter unexpected
!! exceptions during import, you should try running in slim
!! mode using parameter -s.

Reading in file: D:\openstreetmap\planet-nl-100423.osm.gz
Processing: Node(28102k) Way(4756k) Relation(30k)
Node stats: total(28102656), max(704144199)
Way stats: total(4756486), max(56116903)
Relation stats: total(30289), max(571919)

Going over pending ways
processing way (2981k)

Going over pending relations

node cache: stored: 26780303(95.29%), storage efficiency: 25.54%, hit rate: 94.1
1%
Stopping table: planet_osm_nodes
Stopped table: planet_osm_nodes
Stopping table: planet_osm_ways
Stopped table: planet_osm_ways
Stopping table: planet_osm_rels
Stopped table: planet_osm_rels
Committing transaction for planet_osm_point
Sorting data and creating indexes for planet_osm_point
Completed planet_osm_point
Committing transaction for planet_osm_line
Sorting data and creating indexes for planet_osm_line
Completed planet_osm_line
Committing transaction for planet_osm_polygon
Sorting data and creating indexes for planet_osm_polygon
Completed planet_osm_polygon
Committing transaction for planet_osm_roads
Sorting data and creating indexes for planet_osm_roads
Completed planet_osm_roads

With pgadmin you should see like this:
http://farm5.static.flickr.com/4072/4648235806_d464e37db9_o.jpg
note: if there is error during import, there is a lot of how-to-fix in
the wiki from openstreemap


The second part: link PostGIS to Geoserver:


before start :
download one example sld for osm_line,
http://blog.geoserver.org/wp-content/uploads/osm_roadssld.zip

add this sld to your geoserver.
There is some information about SLD :
http://blog.geoserver.org/2010/04/09/sld-cookbook/


Let start!
Go http://localhost:8080/geoserver/
login with admin

Step 1: click store

step 2: add new store and click postgis(not postigs jndi)

select workspace topp
fill in information for your database.
You see something like this:
because I have already publish some layers, you wont see same screen like this.

Step3 publish new layer planet_osm_line
Just click publish planet_osm_line

then click compute from data and compute from native bounds.

Then then click publishing tab
chang default style to osm_line.
Click save.
Then go to your demo page

there are more screen dumps here
http://www.flickr.com/photos/43687674@N07/
--
Xiaoyu Guan (Sam)
http://guanxiaoyu.blogspot.com

4 comments:

qman said...

hi there,

i saw your layer config on geoserver, the Native SRS is 900913, i am unable to edit the native srs (it is 4326 and not editable) on my geoserver (v2.0.1 on tomcat 5.5.28), how do you edit the native srs?

Thanks

steve said...
This comment has been removed by the author.
steve said...

Xiaouyu, are you able to import the latest osm without running out of memory using slim mode? I have problem importing the whole osm even in slim mode. It failed in "pending_ways" out of memory for query result

Xiaoyu said...

yes, I did import the data in slim mode without any problem.

about reporjectting geodata, you d better read geoserver manual. it is good start place.