Home Android Arch Linux Gentoo Linux LibreELEC Github Geo

OUTDATED

Gentoo - Einrichtung eines lokalen OSM-Servers

Software installieren



Vorbereitung zur Installation der benötigten Pakete
nano /etc/portage/package.keywords/sci-geosciences

/etc/portage/package.keywords/sci-geosciences

=sci-geosciences/osm2pgsql-0.8*
=sci-geosciences/mapnik-2.2*

nano /etc/portage/package.use/sci-geosciences

/etc/portage/package.use/sci-geosciences

sci-geosciences/mapnik cairo gdal postgres

die Pakete installieren
emerge -av mapnik mapnik-world-boundaries osm2pgsql postgresql postgis lxml flup lighttpd

  • mapnik - erzeugt die Karten
  • mapnik-world-boundaries - externe Daten (Shapefiles) für Küstenlinien, etc.
  • osm2pgsql - Konverter und Import-Werkzeug von Openstreetmap-Daten nach PostgreSQL
  • postgresql - PostgreSQL-Datenbank
  • postgis - Erweiterung für PostgreSQL für räumlich (geographische) Beziehungen
  • lxml - XML-Verarbeitung (upgrade_map_xml.py aus Mapnik benutzt dies für die entities in XML-Dateien, falls benötigt)
  • flup - WSGI Server
  • lighttpd - Webserver



ToDo

* Messages for package dev-libs/json-c-0.11-r1:

 * 
 * Directory symlink(s) may need protection:
 * 
 * 	/usr/include/json-c/json
 * 
 * Searching all installed packages for files installed via above symlink(s)...
 * 
 * The above directory symlink(s) are all safe to remove. Removing them now...
 * 

 * Messages for package dev-db/postgresql-9.4.1:

 * Unable to find kernel sources at /usr/src/linux
 * Unable to calculate Linux Kernel version for build, attempting to use running version
 * If you need a global psqlrc-file, you can place it in:
 *     /etc/postgresql-9.4/
 * 
 * Gentoo specific documentation:
 * https://wiki.gentoo.org/wiki/PostgreSQL
 * 
 * Official documentation:
 * http://www.postgresql.org/docs/9.4/static/index.html
 * 
 * The default location of the Unix-domain socket is:
 *     /run/postgresql/
 * 
 * Before initializing the database, you may want to edit PG_INITDB_OPTS
 * so that it contains your preferred locale in:
 *     /etc/conf.d/postgresql-9.4
 * 
 * Then, execute the following command to setup the initial database
 * environment:
 *     emerge --config =dev-db/postgresql-9.4.1

 * Messages for package www-servers/lighttpd-1.4.35-r1:

 * IPv6 migration guide:
 * http://redmine.lighttpd.net/projects/lighttpd/wiki/IPv6-Config
 * 
 * (Note: Above message is only printed the first time package is
 * installed. Please look at /usr/share/doc/lighttpd-1.4.35-r1/README.gentoo*
 * for future reference)

 * Messages for package sci-geosciences/mapnik-2.2.0:

 * 
 * See the home page or wiki (http://trac.mapnik.org/) for more info
 * or the installed examples for the default mapnik ogcserver config.
 * 

 * Messages for package dev-db/postgis-2.1.1:

 * To finish installing or updating PostGIS edit:
 *     /etc/postgis_dbs
 * 
 * Then, run:
 *     emerge --config =dev-db/postgis-2.1.1
>>> Auto-cleaning packages...



zusätzliche Shapefiles herunterladen
siehe auch https://bugs.gentoo.org/show_bug.cgi?id=279046
cd /usr/share/mapnik/world_boundaries/
wget http://tile.openstreetmap.org/shoreline_300.tar.bz2
wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/10m-populated-places.zip
wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/110m-admin-0-boundary-lines.zip
tar -xjf shoreline_300.tar.bz2
unzip 10m-populated-places.zip
unzip 110m-admin-0-boundary-lines.zip
rm *.tar.bz2 *.zip


PostgresSQL

Installation


passwd postgres

eselect postgresql list

eselect postgresql list

Available PostgreSQL Slots
  9.4 *                      9.4.5-r1

emerge –config dev-db/postgresql:9.4

Tuning


nano /etc/postgresql-9.1/postgresql.conf

/etc/postgresql-9.1/postgresql.conf

...
#shared_buffers = 24MB                  # min 128kB
shared_buffers = 128MB
...
#checkpoint_segments = 3                # in logfile segments, min 1, 16MB each
checkpoint_segments = 20
...
#maintenance_work_mem = 16MB            # min 1MB
maintenance_work_mem = 256MB
...
autovacuum = off                        # Enable autovacuum subprocess?  'on'
                                        # requires track_counts to also be on.

nano /etc/sysctl.conf

/etc/sysctl.conf

# PostgreSQL
kernel.shmmax=268435456

sysctl kernel.shmmax=268435456

Server starten und einrichten

/etc/init.d/postgresql-9.1 start

su - postgres

psql -l

psql -l

                                  Liste der Datenbanken
   Name    | Eigentümer | Kodierung | Sortierfolge | Zeichentyp  |  Zugriffsprivilegien  
-----------+------------+-----------+--------------+-------------+-----------------------
 postgres  | postgres   | UTF8      | de_DE.UTF-8  | de_DE.UTF-8 | 
 template0 | postgres   | UTF8      | de_DE.UTF-8  | de_DE.UTF-8 | =c/postgres          +
           |            |           |              |             | postgres=CTc/postgres
 template1 | postgres   | UTF8      | de_DE.UTF-8  | de_DE.UTF-8 | =c/postgres          +
           |            |           |              |             | postgres=CTc/postgres
(3 Zeilen)

createuser -DSR gisuser

   -D, --no-createdb            Rolle kann keine Datenbanken erzeugen
   -S, --no-superuser           Rolle wird kein Superuser
   -R, --no-createrole          Rolle kann keine Rollen erzeugen

createdb -E UTF8 -O gisuser gis

   -E, --encoding=KODIERUNG     Kodierung für die Datenbank
   -O, --owner=EIGENTÜMER       Eigentümer der neuen Datenbank

psql -l

psql -l

                                  Liste der Datenbanken
   Name    | Eigentümer | Kodierung | Sortierfolge | Zeichentyp  |  Zugriffsprivilegien  
-----------+------------+-----------+--------------+-------------+-----------------------
 gis       | gisuser    | UTF8      | de_DE.UTF-8  | de_DE.UTF-8 | 
 postgres  | postgres   | UTF8      | de_DE.UTF-8  | de_DE.UTF-8 | 
 template0 | postgres   | UTF8      | de_DE.UTF-8  | de_DE.UTF-8 | =c/postgres          +
           |            |           |              |             | postgres=CTc/postgres
 template1 | postgres   | UTF8      | de_DE.UTF-8  | de_DE.UTF-8 | =c/postgres          +
           |            |           |              |             | postgres=CTc/postgres
(4 Zeilen)

psql -U postgres -d gis -f /usr/share/postgresql-9.1/contrib/postgis-2.0/postgis.sql

psql -U postgres -d gis -f /usr/share/postgresql-9.1/contrib/postgis-2.0/postgis.sql

SET
BEGIN
CREATE FUNCTION
CREATE FUNCTION
CREATE TYPE
...
CREATE FUNCTION
COMMIT

psql -U postgres -d gis -f /usr/share/postgresql-9.1/contrib/postgis-2.0/spatial_ref_sys.sql

psql -U postgres -d gis -f /usr/share/postgresql-9.1/contrib/postgis-2.0/spatial_ref_sys.sql

BEGIN
INSERT 0 1
INSERT 0 1
...
INSERT 0 1
INSERT 0 1
COMMIT
ANALYZE

psql -U postgres -d gis -f /usr/share/osm2pgsql/900913.sql

psql -U postgres -d gis -f /usr/share/osm2pgsql/900913.sql

INSERT 0 1

echo „ALTER TABLE geometry_columns OWNER TO gisuser; ALTER TABLE spatial_ref_sys OWNER TO gisuser;“ | psql -d gis

echo „ALTER TABLE geometry_columns OWNER TO gisuser; ALTER TABLE spatial_ref_sys OWNER TO gisuser;“ | psql -d gis

ALTER TABLE
ALTER TABLE

Import von OSM-Daten nach PostgreSQL (am Beispiel Berlin)

su - postgres

wget http://download.geofabrik.de/osm/europe/germany/berlin.osm.bz2

bunzip2 berlin.osm.bz2

osm2pgsql -s -C 2048 -d gis berlin.osm

rm berlin.osm

Mapnik & PostgreSQL testen

nano render.py

render.py

#!/usr/bin/env python2

from mapnik import *

mapfile = 'mapnik_style.xml'
map_output = 'berlin.png'

m = Map(4*1024,4*1024)
load_map(m, mapfile)
bbox=(Envelope( 13.0882,52.3418,13.7606,52.6697 ))

m.zoom_to_box(bbox)
print "Scale = " , m.scale()
render_to_file(m, map_output)

nano mapnik_style.xml

mapnik_style.xml

<Map background-color="#f2efe9" minimum-version="0.7.2" srs="+proj=latlong +datum=WGS84">
        <FontSet name="book-fonts">
                <Font face-name="DejaVu Sans Book"/>
        </FontSet>
	<Style name="highways1">
		<Rule>
			<Filter>
				[highway]='raceway' or [highway]='motorway' or [highway]='motorway_link' 
				or [highway]='motorway_junction' or [highway]='road' or [highway]='trunk' 
				or [highway]='trunk-link' or [highway]='primary' or [highway]='primary-link'
			</Filter>
                        <LineSymbolizer stroke="black" stroke-width="4" stroke-opacity="1.0"/>
			<LineSymbolizer stroke="red" stroke-width="3.0"/>
                </Rule>
	</Style>

	<Style name="highways2">
		<Rule>
			<Filter>
				[highway]='secondary' or [highway]='secondary_link' or [highway]='service'
				or [highway]='living_street' or [highway]='residential' 
				or [highway]='unclassified' or [highway]='road' or [highway]='track' 
				or [highway]='tertiary' or [highway]='tertiary_link'
			</Filter>
                        <LineSymbolizer stroke="black" stroke-width="3" stroke-opacity="0.5"/>
			<LineSymbolizer stroke="blue" stroke-width="2.0"/>
		</Rule>
	</Style>

	<Layer name="hihways2" status="on" srs="+proj=merc +a=6378137 +b=6378137 
		+lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over">
		<StyleName>highways2</StyleName>
		<Datasource>
			<Parameter name="table">
				(select way,highway from planet_osm_line
				where highway in ('secondary','secondary_link','service','living_street',
				'residental','unclassified','road','track','tertiary','tertiary_link')
				order by z_order) as roads
			</Parameter>
			<Parameter name="type">postgis</Parameter>
			<Parameter name="password"/>
			<Parameter name="host">localhost</Parameter>
			<Parameter name="port">5432</Parameter>
			<Parameter name="user">gisuser</Parameter>
			<Parameter name="dbname">gis</Parameter>
			<!-- this should be 'false' if you are manually providing the 'extent' -->
			<Parameter name="estimate_extent">false</Parameter>
			<!-- manually provided extent in epsg 900913 for whole globe -->
			<!-- providing this speeds up Mapnik database queries -->
			<Parameter name="extent">-20037508,-19929239,20037508,19929239</Parameter>
		</Datasource>
	</Layer>

	<Layer name="highways1" status="on" srs="+proj=merc +a=6378137 +b=6378137 
		+lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over">
		<StyleName>highways1</StyleName>
		<Datasource>
			<Parameter name="table">
				(select way,highway from planet_osm_line
				where highway in ('raceway','motorway','motorway_link',
				'motorway_junction','trunk','trunk-link','primary','primary-link')
				order by z_order) as roads
			</Parameter>
			<Parameter name="type">postgis</Parameter>
			<Parameter name="password"/>
			<Parameter name="host">localhost</Parameter>
			<Parameter name="port">5432</Parameter>
			<Parameter name="user">gisuser</Parameter>
			<Parameter name="dbname">gis</Parameter>
			<!-- this should be 'false' if you are manually providing the 'extent' -->
			<Parameter name="estimate_extent">false</Parameter>
			<!-- manually provided extent in epsg 900913 for whole globe -->
			<!-- providing this speeds up Mapnik database queries -->
			<Parameter name="extent">-20037508,-19929239,20037508,19929239</Parameter>
		</Datasource>
	</Layer>

</Map>

python render.py

python render.py

Datasource loader: registered: osm
Datasource loader: registered: postgis
Datasource loader: registered: shape
Datasource loader: registered: ogr
Datasource loader: registered: raster
Datasource loader: registered: gdal
Datasource loader: registered: hello
Datasource loader: registered: geos
size = 9
dbname=gis
estimate_extent=false
extent=-20037508,-19929239,20037508,19929239
host=localhost
password=
port=5432
table=
				(select way,highway from planet_osm_line
				where highway in ('secondary','secondary_link','service','living_street',
				'residental','unclassified','road','track','tertiary','tertiary_link')
				order by z_order) as roads
			
type=postgis
user=gisuser
.
.
.
end layer processing
start layer processing : highways1
datasource = 0x20cb240
borrow 0x20f9ce0
return 0x20f9ce0
end layer processing
end map processing
~stroker: destroy stroker:0x21050f0
PostGIS: postgresql connection closed - 0x20fda10
 destroyed singleton 
 destroyed singleton 
 destroyed singleton 
 destroyed singleton 

skalierte Version

Lighttpd

nano /etc/lighttpd/lighttpd.conf

/etc/lighttpd/lighttpd.conf

server.username         = "lighttpd"
server.groupname        = "lighttpd"
server.document-root    = "var/www/localhost/htdocs"
server.pid-file         = "/var/run/lighttpd.pid"
server.indexfiles       = ("index.html")
server.follow-symlink   = "enable"
server.port             = 80
accesslog.filename      = "/var/log/lighttpd/access.log"

server.errorlog         = "/var/log/lighttpd/error.log"

server.modules = (
        "mod_access",
        "mod_accesslog",
        "mod_redirect",
        "mod_auth"
)

dir-listing.activate = "enable"

include "mime-types.conf"

server.modules += (
        "mod_fastcgi"
)
fastcgi.debug = 1
include "mod_tilecache.conf"

nano /etc/lighttpd/mod_tilecache.conf

/etc/lighttpd/mod_tilecache.conf

fastcgi.server += (
        "tilecache.fcgi" => (
                "tilecache.fcgi" => (
                        "socket" => "/var/run/lighttpd/tilecache.socket",
                        "bin-path" => "/usr/bin/tilecache.fcgi",
                        "check-local" => "disable",
                        "max-procs" => 2,
                        "max-load-per-proc" => 2
                )
        )
)

nano /etc/tilecache.cfg

/etc/tilecache.cfg

[cache]
type=Disk
base=/var/www/localhost/htdocs/tilecache/

[osm]
debug=on
type=MapnikLayer
mapfile=/var/www/localhost/htdocs/styles/osm.xml
maxResolution=76.437028271
resolutions=76.437028271,38.218514136,19.109257068,9.554628534,4.777314267,2.388657133,1.194328567
bbox=-20037508.3427892,-20037508.3427892,20037508.3427892,20037508.3427892
levels=7
srs=EPSG:900913
extent_type=loose
size=256,256
metaTile=yes
metaSize=5,5

mkdir /var/www/localhost/htdocs/styles
mkdir /var/www/localhost/htdocs/tilecache

cd /var/www/localhost/htdocs
svn checkout http://svn.openstreetmap.org/applications/rendering/mapnik
cd mapnik
./generate_xml.py –host localhost –user postgres –dbname gis –symbols ./symbols/ –world_boundaries /usr/share/mapnik/world_boundaries/ –port 5432
cp osm.xml ../styles
cp -r symbols ../styles

chown -R lighttpd /var/www/localhost/htdocs/*

/etc/init.d/lighttpd start

OpenLayers

nano /var/www/localhost/htdocs/index.html

/var/www/localhost/htdocs/index.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head> 
<title>OpenLayers</title>
<style type="text/css">
	htmp, body, #map {
		width: 100%;
		height: 100%;
		margin: 0;
		padding: 0;
	}
	.olControlScaleLine {
		left: 5px;
		padding: 30;
	}
	#mouse_merc {
		bottom: 5px;
		left: 5px;
	}
	#mouse_4326 {
		bottom: 20px;
		left: 10px;
	}
</style>

<script src="libs/OpenLayers-2.12/lib/Firebug/firebug.js"></script>
<script src="libs/OpenLayers-2.12/OpenLayers.js"></script>
<script src="http://maps.google.com/maps/api/js?v=3.7&sensor=false"></script>

<script type="text/javascript">

function init(){

	var projmerc = new OpenLayers.Projection("EPSG:900913");
	var proj4326 = new OpenLayers.Projection("EPSG:4326");

	map = new OpenLayers.Map("map", {
		controls: [
			new OpenLayers.Control.Attribution(),
			new OpenLayers.Control.Navigation(),
			new OpenLayers.Control.PanZoomBar(),
			new OpenLayers.Control.ZoomBox(),
			new OpenLayers.Control.LayerSwitcher(),
			new OpenLayers.Control.ScaleLine(),
			new OpenLayers.Control.MousePosition(
				{id: "mouse_4326", prefix: "WSG84: ", numDigits: 4}
			),
			new OpenLayers.Control.MousePosition(
				{id: "mouse_merc", prefix: "Mercator: " , displayProjection: projmerc}
			),
			new OpenLayers.Control.KeyboardDefaults(),
		],

		projection: projmerc,
		displayProjection: proj4326,
		units: 'm',
		transitionEffect: "resize",

		resolutions: [
                        76.437028271,
                        38.218514136,
                        19.109257068,
                        9.554628534,
                        4.777314267,
                        2.388657133,
                        1.194328567,
                ],

		maxResolution: 76.437028271,
		maxExtent: new OpenLayers.Bounds(
			-20037508.3427892,
			-20037508.3427892,
			20037508.3427892,
			20037508.3427892
		),
		minZoomLevel: 11,
		maxZoomLevel: 17,
		numZoomLevels: 7,
	} );

	var wms = new OpenLayers.Layer.WMS(
		"Tilecache WMS",
		"tilecache.fcgi?", {
			layers: "osm",
			format: "image/png"
		}
	);

	var osm = new OpenLayers.Layer.OSM(
		"Mapnik@osm.org"
	);

        var gmap = new OpenLayers.Layer.Google(
                "Google Streets",
                {numZoomLevels: 20}
        );

        var gphy = new OpenLayers.Layer.Google(
                "Google Physical",
                {type: google.maps.MapTypeId.TERRAIN}
        );

        var ghyb = new OpenLayers.Layer.Google(
                "Google Hybrid",
                {type: google.maps.MapTypeId.HYBRID, numZoomLevels: 20}
        );

        var gsat = new OpenLayers.Layer.Google(
                "Google Satellite",
                {type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 22}
        );

	map.addLayers([wms, osm, gmap, gphy, ghyb, gsat]);

	var OverviewMapOptions = {
		size : new OpenLayers.Size(400, 300),
		maximized: true,
		minRextSize: 0,
		autoPan : true,
		mapOptions: {
			projection : projmerc,
			displayProjection : proj4326,
			units : "m",
			resolutions: [
        	                76.437028271,
                	        38.218514136,
                        	19.109257068,
	                        9.554628534,
        	                4.777314267,
	                ],
			numZoomLevels: 5
		}
	};

	map.addControl(new OpenLayers.Control.OverviewMap(OverviewMapOptions));

	if (!map.getCenter()){
		map.setCenter(new OpenLayers.LonLat(13.41,52.52).transform(proj4326,projmerc), 4)
	};

}

</script>
</head>
<body onload="init()">
	<div id="map"></div>
</body>
</html>

im Browser folgendes eingeben http://localhost:80

… und voilà

PostgreSQL-Befehle


Datenbank löschen
su - postgres
dropdb <db>

Benutzer löschen
su - postgres
dropuser <user>

Datenbank komplett neu-erstellen
/etc/init.d/postgresql-9.1 stop
rm -r /var/lib/postgresql/9.1/data/*
emerge –config =dev-db/postgresql-server-9.1.4
su - postgres
pg_resetxlog /var/lib/postgresql/9.1/data/
exit
/etc/init.d/postgresql-9.1 start
→ Datenbank neu befüllen