383 | | * http://weait.com/content/build-your-own-openstreetmap-server |
384 | | * http://weait.com/content/make-your-first-map |
385 | | * http://dbsgeo.com/foss4g2010/pdf/osm-rendering-foss4g2010.pdf |
386 | | |
387 | | !OpenStreetMap data can be stored in a PostGIS database & rendered using Mapnik. |
388 | | |
389 | | To support !Key/Value pairs: |
390 | | {{{ |
391 | | apt-get install postgresql-contrib-8.4 |
392 | | su postgres |
393 | | psql -d gis -f /usr/share/postgresql/8.4/contrib/hstore.sql |
394 | | }}} |
395 | | |
396 | | To support Planet diff files: |
397 | | {{{ |
398 | | su postgres |
399 | | psql gis < /usr/share/postgresql/8.4/contrib/_int.sql |
400 | | }}} |
401 | | |
402 | | === Osm2pgsql === |
403 | | * http://wiki.openstreetmap.org/wiki/Osm2pgsql |
404 | | |
405 | | It is recommended to use the latest version from source rather than an out of date package: |
406 | | {{{ |
407 | | apt-get install build-essential libxml2-dev libgeos-dev libpq-dev libbz2-dev proj autoconf subversion libtool |
408 | | svn export http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/ |
409 | | Optional (patch updated from original here): http://www.mail-archive.com/dev@openstreetmap.org/msg12768.html |
410 | | #wget http://eden.sahanafoundation.org/raw-attachment/wiki/InstallationGuidelinesGISDataLinux/osm2pgsql_centroid.patch |
411 | | cd osm2pgsql |
412 | | #patch -p0 < ../osm2pgsql_centroid.patch |
413 | | ./autogen.sh |
414 | | ./configure |
415 | | sed -i 's/-g -O2/-O2 -march=native -fomit-frame-pointer/' Makefile |
416 | | make |
417 | | make install |
418 | | # Fix needed for SVN version 0.70.5 |
419 | | cp default.style /usr/local/share |
420 | | }}} |
421 | | |
422 | | === Mapnik === |
423 | | * http://wiki.openstreetmap.org/wiki/Mapnik |
424 | | * http://mike.teczno.com/notes/mapnik.html (Advanced Tips) |
425 | | |
426 | | 0.7.1 is packaged for Squeeze: |
427 | | {{{ |
428 | | apt-get install python-mapnik unzip |
429 | | }}} |
430 | | |
431 | | Download the !OpenStreetMap extensions for Mapnik: |
432 | | {{{ |
433 | | cd |
434 | | svn export http://svn.openstreetmap.org/applications/rendering/mapnik |
435 | | }}} |
436 | | |
437 | | Download/decompress Coastlines: |
438 | | {{{ |
439 | | cd |
440 | | wget http://tile.openstreetmap.org/world_boundaries-spherical.tgz |
441 | | wget http://tile.openstreetmap.org/processed_p.tar.bz2 |
442 | | wget http://tile.openstreetmap.org/shoreline_300.tar.bz2 |
443 | | wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/10m-populated-places.zip |
444 | | wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/110m-admin-0-boundary-lines.zip |
445 | | cd ~/mapnik |
446 | | tar zxvf ~/world_boundaries-spherical.tgz |
447 | | tar jxvf ~/processed_p.tar.bz2 -C world_boundaries |
448 | | tar jxvf ~/shoreline_300.tar.bz2 -C world_boundaries |
449 | | unzip ~/10m-populated-places.zip -d world_boundaries |
450 | | unzip ~/110m-admin-0-boundary-lines.zip -d world_boundaries |
451 | | }}} |
452 | | |
453 | | Disable autovacuum: |
454 | | {{{ |
455 | | vim /etc/postgresql/8.4/main/postgresql.conf |
456 | | #autovacuum = on |
457 | | /etc/init.d/postgresql restart |
458 | | }}} |
459 | | |
460 | | Download/Import area of interest, e.g.: |
461 | | {{{ |
462 | | #wget http://downloads.cloudmade.com/north_america/haiti/haiti.osm.bz2 |
463 | | #su postgres |
464 | | #osm2pgsql -s -d gis haiti.osm.bz2 |
465 | | wget http://labs.geofabrik.de/haiti/2010-11-24-14-43.osm.bz2 |
466 | | su postgres |
467 | | osm2pgsql -s -d gis 2010-11-24-14-43.osm.bz2 |
468 | | }}} |
469 | | |
470 | | Re-enable autovacuum: |
471 | | {{{ |
472 | | vim /etc/postgresql/8.4/main/postgresql.conf |
473 | | autovacuum = on |
474 | | /etc/init.d/postgresql restart |
475 | | }}} |
476 | | |
477 | | Setup XML file: |
478 | | {{{ |
479 | | cd ~/mapnik |
480 | | ./generate_xml.py --accept-none --dbname gis --symbols ./symbols/ --world_boundaries ./world_boundaries/ |
481 | | }}} |
482 | | |
483 | | Render tiles: |
484 | | {{{ |
485 | | cd ~/mapnik |
486 | | vim generate_tiles.py |
487 | | render_tiles(bbox, mapfile, tile_dir, 0, 8, "World") |
488 | | #minZoom = 10 |
489 | | #maxZoom = 16 |
490 | | #bbox = (-2, 50.0,1.0,52.0) |
491 | | #render_tiles(bbox, mapfile, tile_dir, minZoom, maxZoom) |
492 | | # Haiti |
493 | | bbox = (-74.668, 17.884, -71.659, 20.232) |
494 | | render_tiles(bbox, mapfile, tile_dir, 9, 17, "Haiti") |
495 | | # Muenchen |
496 | | # comment all under here |
497 | | |
498 | | mkdir /var/www/tiles |
499 | | chown postgres /var/www/tiles |
500 | | ln -s /var/www/tiles |
501 | | su postgres |
502 | | MAPNIK_MAP_FILE="osm.xml" MAPNIK_TILE_DIR="tiles/" ./generate_tiles.py |
503 | | }}} |
504 | | === Contours === |
505 | | * http://wiki.openstreetmap.org/wiki/Contours#The_PostGIS_approach |
506 | | |
507 | | {{{ |
508 | | apt-get install gdal-bin |
509 | | }}} |
510 | | |
511 | | [http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/ SRTM3] data: |
512 | | {{{ |
513 | | mkdir ~/mapnik/srtm |
514 | | cd ~/mapnik/srtm |
515 | | wget http://mapnik-utils.googlecode.com/svn@170/sandbox/testing/hillshading/srtm_generate_hdr.sh |
516 | | chmod +x srtm_generate_hdr.sh |
517 | | cp srtm_generate_hdr.sh /usr/local/bin |
518 | | vim process_srtm3.sh |
519 | | #!/bin/bash |
520 | | PREP_TABLE="1" |
521 | | for X in *.hgt.zip; do |
522 | | yes | srtm_generate_hdr.sh $X |
523 | | rm -f "${X%%.zip}" |
524 | | |
525 | | # Import 10m contours |
526 | | rm -f "${X%%.hgt.zip}.shp" "${X%%.hgt.zip}.shx" "${X%%.hgt.zip}.dbf" |
527 | | gdal_contour -i 10 -snodata 32767 -a height "${X%%.hgt.zip}.tif" "${X%%.hgt.zip}.shp" |
528 | | [ "$PREP_TABLE" ] && shp2pgsql -p -I -g way "${X%%.hgt.zip}" contours | psql -q gis |
529 | | shp2pgsql -a -g way "${X%%.hgt.zip}" contours | psql -q gis |
530 | | |
531 | | rm -f "${X%%.hgt.zip}.shp" "${X%%.hgt.zip}.shx" "${X%%.hgt.zip}.dbf" |
532 | | rm -f "${X%%.hgt.zip}.bil" |
533 | | rm -f "${X%%.hgt.zip}.hdr" |
534 | | rm -f "${X%%.hgt.zip}.prj" |
535 | | rm -f "${X%%.hgt.zip}.tif" |
536 | | unset PREP_TABLE |
537 | | done |
538 | | |
539 | | # Haiti |
540 | | wget http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/North_America/N17W072.hgt.zip |
541 | | wget http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/North_America/N18W072.hgt.zip |
542 | | wget http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/North_America/N18W073.hgt.zip |
543 | | wget http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/North_America/N18W074.hgt.zip |
544 | | wget http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/North_America/N18W075.hgt.zip |
545 | | wget http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/North_America/N19W072.hgt.zip |
546 | | wget http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/North_America/N19W073.hgt.zip |
547 | | wget http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/North_America/N19W074.hgt.zip |
548 | | wget http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/North_America/N19W075.hgt.zip |
549 | | wget http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/North_America/N20W073.hgt.zip |
550 | | wget http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/North_America/N20W074.hgt.zip |
551 | | wget http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/North_America/N20W075.hgt.zip |
552 | | |
553 | | chown postgres . |
554 | | su postgres |
555 | | sh process_srtm3.sh |
556 | | }}} |
557 | | |
558 | | Since we are non-commercial, we should be able to use the SRTM4.1 data from [http://srtm.csi.cgiar.org CGIAR], however the Shapefile production crashed when it reached 2Gb.[[BR]] |
559 | | Example for Haiti: |
560 | | {{{ |
561 | | cd ~/mapnik/srtm |
562 | | wget http://srtm.csi.cgiar.org/SRT-ZIP/SRTM_V41/SRTM_Data_GeoTiff/srtm_22_09.zip |
563 | | unzip srtm_22_09.zip |
564 | | gdal_contour -i 10 -snodata 32767 -a height "srtm_22_09.tif" "srtm_22_09.shp" |
565 | | su postgres |
566 | | shp2pgsql -p -I -g way "srtm_22_09" contours | psql -q gis |
567 | | shp2pgsql -a -g way "srtm_22_09" contours | psql -q gis |
568 | | }}} |
569 | | |
570 | | Configure Mapnik: |
571 | | {{{ |
572 | | vim ~/mapnik/osm.xml |
573 | | # Under line &layer-shapefiles; |
574 | | &layer-contours; |
575 | | vim ~/mapnik/inc/layer-contours.xml.inc |
576 | | <Style name="contours10"> |
577 | | <Rule> |
578 | | &maxscale_zoom14; |
579 | | &minscale_zoom17; |
580 | | <LineSymbolizer> |
581 | | <CssParameter name="stroke">#9cb197</CssParameter> |
582 | | <CssParameter name="stroke-width">0.5</CssParameter> |
583 | | </LineSymbolizer> |
584 | | </Rule> |
585 | | </Style> |
586 | | <Style name="contours50"> |
587 | | <Rule> |
588 | | &maxscale_zoom14; |
589 | | &minscale_zoom17; |
590 | | <LineSymbolizer> |
591 | | <CssParameter name="stroke">#9cb197</CssParameter> |
592 | | <CssParameter name="stroke-width">0.6</CssParameter> |
593 | | </LineSymbolizer> |
594 | | </Rule> |
595 | | <Rule> |
596 | | &maxscale_zoom12; |
597 | | &minscale_zoom13; |
598 | | <LineSymbolizer> |
599 | | <CssParameter name="stroke">#747b90</CssParameter> |
600 | | <CssParameter name="stroke-width">0.6</CssParameter> |
601 | | </LineSymbolizer> |
602 | | </Rule> |
603 | | </Style> |
604 | | <Style name="contours100"> |
605 | | <Rule> |
606 | | &maxscale_zoom14; |
607 | | &minscale_zoom17; |
608 | | <LineSymbolizer> |
609 | | <CssParameter name="stroke">#9cb197</CssParameter> |
610 | | <CssParameter name="stroke-width">0.7</CssParameter> |
611 | | </LineSymbolizer> |
612 | | </Rule> |
613 | | <Rule> |
614 | | &maxscale_zoom12; |
615 | | &minscale_zoom13; |
616 | | <LineSymbolizer> |
617 | | <CssParameter name="stroke">#747b90</CssParameter> |
618 | | <CssParameter name="stroke-width">0.7</CssParameter> |
619 | | </LineSymbolizer> |
620 | | </Rule> |
621 | | <Rule> |
622 | | &maxscale_zoom10; |
623 | | &minscale_zoom11; |
624 | | <LineSymbolizer> |
625 | | <CssParameter name="stroke">#855d62</CssParameter> |
626 | | <CssParameter name="stroke-width">0.7</CssParameter> |
627 | | </LineSymbolizer> |
628 | | </Rule> |
629 | | </Style> |
630 | | <Style name="contours-text50"> |
631 | | <Rule> |
632 | | &maxscale_zoom14; |
633 | | &minscale_zoom17; |
634 | | <TextSymbolizer name="height" face_name="DejaVu Sans Book" size="8" fill="#747b90" halo_radius="1" placement="line" /> |
635 | | </Rule> |
636 | | </Style> |
637 | | <Style name="contours-text100"> |
638 | | <Rule> |
639 | | &maxscale_zoom14; |
640 | | &minscale_zoom17; |
641 | | <TextSymbolizer name="height" face_name="DejaVu Sans Book" size="8" fill="#747b90" halo_radius="1" placement="line" /> |
642 | | </Rule> |
643 | | <Rule> |
644 | | &maxscale_zoom12; |
645 | | &minscale_zoom13; |
646 | | <TextSymbolizer name="height" face_name="DejaVu Sans Book" size="8" fill="#855d62" halo_radius="1" placement="line" /> |
647 | | </Rule> |
648 | | </Style> |
649 | | <Layer name="srtm_10" status="on" srs="+proj=latlong +datum=WGS84"> |
650 | | <StyleName>contours10</StyleName> |
651 | | <StyleName>contours-text10</StyleName> |
652 | | <Datasource> |
653 | | <Parameter name="table">(select way,height from contours WHERE height::integer % 10 = 0 AND height::integer % 50 != 0 AND height::integer % 100 != 0) as "contours-10"</Parameter> |
654 | | &datasource-settings; |
655 | | </Datasource> |
656 | | </Layer> |
657 | | <Layer name="srtm_50" status="on" srs="+proj=latlong +datum=WGS84"> |
658 | | <StyleName>contours50</StyleName> |
659 | | <StyleName>contours-text50</StyleName> |
660 | | <Datasource> |
661 | | <Parameter name="table">(select way,height from contours WHERE height::integer % 50 = 0 AND height::integer % 100 != 0) as "contours-50"</Parameter> |
662 | | &datasource-settings; |
663 | | </Datasource> |
664 | | </Layer> |
665 | | <Layer name="srtm_100" status="on" srs="+proj=latlong +datum=WGS84"> |
666 | | <StyleName>contours100</StyleName> |
667 | | <StyleName>contours-text100</StyleName> |
668 | | <Datasource> |
669 | | <Parameter name="table">(select way,height from contours WHERE height::integer % 100 = 0) as "contours-100"</Parameter> |
670 | | &datasource-settings; |
671 | | </Datasource> |
672 | | </Layer> |
673 | | }}} |
674 | | |
675 | | ==== Hillshading ==== |
676 | | * http://wiki.openstreetmap.org/wiki/HikingBikingMaps#Hill_Shading |
677 | | |
678 | | === Serve Tiles === |
679 | | Tiles can simply be served by Apache: |
680 | | {{{ |
681 | | vim /etc/apache2/sites-available/mysite |
682 | | <VirtualHost *:80> |
683 | | ServerName mysite.org |
684 | | Alias /tiles /var/www/tiles |
685 | | <LocationMatch "/tiles/"> |
686 | | Order Allow,Deny |
687 | | Allow from all |
688 | | </LocationMatch> |
689 | | </VirtualHost> |
690 | | apache2ctl restart |
691 | | }}} |
692 | | |
693 | | === WMS === |
694 | | In order to serve the OSM data via WMS then can use mod_mapnik_wms: |
695 | | * http://wiki.openstreetmap.org/wiki/Mod_mapnik_wms |
696 | | {{{ |
697 | | gpg --gen-key |
698 | | apt-get install pbuilder debsigs apache2-prefork-dev libmapnik-dev libgd2-xpm-dev |
699 | | svn export http://svn.openstreetmap.org/applications/utils/mod_mapnik_wms |
700 | | cd mod_mapnik_wms |
701 | | sh autogen.sh |
702 | | vim debian/mapnik_wms.load |
703 | | LoadFile /usr/lib/libmapnik.so.0.7 |
704 | | |
705 | | debuild |
706 | | }}} |
707 | | |
708 | | This data can then be converted by !GeoServer into a KML !SuperOverlay to display in Google Earth: |
709 | | * http://geoserver.org/display/GEOS/GSIP+47+-+WMS+cascading |
710 | | * http://docs.geoserver.org/stable/en/user/googleearth/tutorials/superoverlaysgwc.html |
711 | | |
712 | | === Rails Port === |
713 | | This is needed to allow editing of the data using Potlatch, JOSM, etc |
714 | | * http://wiki.openstreetmap.org/wiki/The_Rails_Port |
715 | | |
716 | | {{{ |
717 | | apt-get install imagemagick libmagick9-dev |
718 | | apt-get install ruby ruby1.8-dev libxml2-dev libxml-ruby1.8 libxml-parser-ruby1.8 rubygems librmagick-ruby |
719 | | gem install -v=2.3.8 rails |
720 | | #gem install libxml-ruby |
721 | | #gem install composite_primary_keys |
722 | | #gem install rmagick |
723 | | gem install timecop |
724 | | gem install pg |
725 | | gem install oauth |
726 | | |
727 | | #svn co http://railsexpress.de/svn/plugins/sql_session_store/trunk sql_session_store |
728 | | |
729 | | apt-get install postgresql-contrib libpq-dev |
730 | | su postgres |
731 | | createuser openstreetmap -s -P |
732 | | createdb -E UTF8 -O openstreetmap openstreetmap |
733 | | createdb -E UTF8 -O openstreetmap osm_test |
734 | | createdb -E UTF8 -O openstreetmap osm |
735 | | psql -d openstreetmap < /usr/share/postgresql/8.4/contrib/btree_gist.sql |
736 | | |
737 | | apt-get install git |
738 | | cd /home |
739 | | git clone git://git.openstreetmap.org/rails.git |
740 | | cd rails |
741 | | cp config/postgres.example.database.yml config/database.yml |
742 | | vim config/database.yml |
743 | | |
744 | | rake gems:install |
745 | | rake db:migrate |
746 | | env RAILS_ENV=production rake db:migrate |
747 | | rake test |
748 | | |
749 | | osmosis --read-xml-0.6 file="planet.osm.bz2" --write-apidb-0.6 populateCurrentTables=yes host="localhost" database="openstreetmap" user="openstreetmap" password="openstreetmap" validateSchemaVersion=no |
750 | | |
751 | | select setval('acls_id_seq', (select max(id) from acls)); |
752 | | select setval('changesets_id_seq', (select max(id) from changesets)); |
753 | | select setval('countries_id_seq', (select max(id) from countries)); |
754 | | select setval('current_nodes_id_seq', (select max(id) from current_nodes)); |
755 | | select setval('current_relations_id_seq', (select max(id) from current_relations)); |
756 | | select setval('current_ways_id_seq', (select max(id) from current_ways)); |
757 | | select setval('diary_comments_id_seq', (select max(id) from diary_comments)); |
758 | | select setval('diary_entries_id_seq', (select max(id) from diary_entries)); |
759 | | select setval('friends_id_seq', (select max(id) from friends)); |
760 | | select setval('gpx_file_tags_id_seq', (select max(id) from gpx_file_tags)); |
761 | | select setval('gpx_files_id_seq', (select max(id) from gpx_files)); |
762 | | select setval('messages_id_seq', (select max(id) from messages)); |
763 | | select setval('sessions_id_seq', (select max(id) from sessions)); |
764 | | select setval('user_tokens_id_seq', (select max(id) from user_tokens)); |
765 | | select setval('users_id_seq', (select max(id) from users)); |
766 | | |
767 | | cd /home/rails |
768 | | ruby script/server |
769 | | |
770 | | cd db/functions |
771 | | make libpgosm.so |
772 | | |
773 | | * Log into PgSQL and execute the CREATE FUNCTION statement from maptile.c's comment: |
774 | | |
775 | | CREATE FUNCTION maptile_for_point(int8, int8, int4) RETURNS int4 |
776 | | AS '/path/to/rails-port/db/functions/libpgosm', 'maptile_for_point' |
777 | | LANGUAGE C STRICT; |
778 | | |
779 | | CREATE FUNCTION tile_for_point(int4, int4) RETURNS int8 |
780 | | AS '/path/to/rails-port/db/functions/libpgosm', 'tile_for_point' |
781 | | LANGUAGE C STRICT; |
782 | | |
783 | | }}} |
| 383 | * See [wiki:GIS/OpenStreetMap GIS/OpenStreetMap] |