GeoHelm/app/latest/components/osm2pgsql/index.html

501 lines
24 KiB
HTML
Raw Normal View History

2024-01-27 19:04:46 +00:00
<!DOCTYPE html>
<html lang="en" >
<!-- Mirrored from geohelm.docs.acugis.com/en/latest/components/osm2pgsql/index.html by HTTrack Website Copier/3.x [XR&CO'2014], Thu, 13 Jul 2023 23:22:10 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>osm2pgsql &mdash; AcuGIS GeoHelm 0.4.3 documentation</title>
<!-- AcuGIS 1 -->
<!--[if lt IE 9]>
<script src="../../_static/js/html5shiv.min.js"></script>
<![endif]-->
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script type="text/javascript" src="../../_static/jquery.js"></script>
<script type="text/javascript" src="../../_static/underscore.js"></script>
<script type="text/javascript" src="../../_static/doctools.js"></script>
<script type="text/javascript" src="../../_static/language_data.js"></script>
<script async="async" type="text/javascript" src="../../../../_/static/javascript/readthedocs-doc-embed.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/custom.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="raster2pgsql" href="../raster2pgsql/index.html" />
<link rel="prev" title="shp2pgsql" href="../shp2pgsql/index.html" />
<!-- RTD Extra Head -->
<link rel="stylesheet" href="../../../../_/static/css/readthedocs-doc-embed.css" type="text/css" />
<script type="application/json" id="READTHEDOCS_DATA">{"ad_free": false, "api_host": "https://readthedocs.org", "builder": "sphinx", "canonical_url": null, "docroot": "/docs/", "features": {"docsearch_disabled": false}, "global_analytics_code": "UA-17997319-1", "language": "en", "page": "components/osm2pgsql/index", "programming_language": "perl", "project": "geohelm", "proxied_api_host": "/_", "source_suffix": ".rst", "subprojects": {}, "theme": "sphinx_rtd_theme", "user_analytics_code": "", "version": "latest"}</script>
<!--
Using this variable directly instead of using `JSON.parse` is deprecated.
The READTHEDOCS_DATA global variable will be removed in the future.
-->
<script type="text/javascript">
READTHEDOCS_DATA = JSON.parse(document.getElementById('READTHEDOCS_DATA').innerHTML);
</script>
<script type="text/javascript" src="../../../../_/static/javascript/readthedocs-analytics.js" async="async"></script>
<!-- end RTD <extrahead> -->
</head>
<div id="header" style="position: fixed; height: 70px; padding-bottom: 20px; overflow: hidden; background-color: #28728d; display: block; z-index: 1000; width: 100%;">
<div class="acugis_geosuite" style="color:#fff!important; padding-left:30px; font-size:26px; padding-top: 20px;"><a href="https://geohelm.docs.acugis.com/" style="color:#fff!important; text-decoration:none!important">AcuGIS GeoHelm</a></div>
</div>
</div>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div id="header2"> </div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation" style="padding-top: 45px;">
<p class="caption"><span class="caption-text">Getting Started</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Intro</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../installing.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../layout.html">Layout</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../webmin.html">Control Panel</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../webmin.html#removing-the-control-panel">Removing the Control Panel</a></li>
</ul>
<p class="caption"><span class="caption-text">PostGIS</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../createdb/index.html">Create Database</a></li>
<li class="toctree-l1"><a class="reference internal" href="../postgresql/index.html">PostgreSQL</a></li>
<li class="toctree-l1"><a class="reference internal" href="../postgis/index.html">PostGIS</a></li>
<li class="toctree-l1"><a class="reference internal" href="../pgrouting/index.html">PgRouting</a></li>
<li class="toctree-l1"><a class="reference internal" href="../shp2pgsql/index.html">shp2pgsql</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">osm2pgsql</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#osm-loader-tool">OSM Loader Tool</a></li>
<li class="toctree-l2"><a class="reference internal" href="#load-via-osm-file-loader">Load via OSM File Loader</a></li>
<li class="toctree-l2"><a class="reference internal" href="#confirm-data-load">Confirm Data Load</a></li>
<li class="toctree-l2"><a class="reference internal" href="#osm-tool-options">OSM Tool Options</a></li>
<li class="toctree-l2"><a class="reference internal" href="#load-via-comamnd-line">Load via Comamnd Line</a></li>
<li class="toctree-l2"><a class="reference internal" href="#troubleshooting">Troubleshooting</a></li>
<li class="toctree-l2"><a class="reference internal" href="#documentation">Documentation</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../raster2pgsql/index.html">raster2pgsql</a></li>
</ul>
<p class="caption"><span class="caption-text">GeoServer</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../geoserver/admin/index.html">Access</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../geoserver/geoservers/index.html">Overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../geoserver/tomcat/index.html">Apache Tomcat</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../geoserver/workspace/index.html">Create a Workspace</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../geoserver/store/index.html">Create Store</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../geoserver/layer/index.html">Add Layer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../geoserver/shp/index.html">Load ESRI Shapefile</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../geoserver/styles/index.html">Styles</a></li>
</ul>
<p class="caption"><span class="caption-text">pg_tileserv</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../pgtileserv/index.html">pg_tileserv</a></li>
<li class="toctree-l1"><a class="reference internal" href="../pgfeatureserv/index.html">pg_featureserv</a></li>
</ul>
<p class="caption"><span class="caption-text">Database Operations</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../database/snapshot/index.html">Database Snapshots</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../database/clone/index.html">Clone Database</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../database/restore/index.html">Restore Database</a></li>
</ul>
<p class="caption"><span class="caption-text">QGIS</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../qgis/home.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../qgis/pgservice.html">pg_service.conf</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../qgis/qgis.html">Create a QGIS Project</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../qgis/publish.html">Publish Layers</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../qgis/style-only.html">Publish Styles Only</a></li>
</ul>
<p class="caption"><span class="caption-text">LeafletJS</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../apps/choropleth.html">Leaflet Choropleth App</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../apps/geojson.html">Leaflet GeoJson</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../apps/php.html">Leaflet and PHP</a></li>
</ul>
<p class="caption"><span class="caption-text">Resources</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../resources/documents.html">Documentation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../resources/css.html">CSS</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../resources/security.html">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../resources/nagios.html">Nagios</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../resources/support.html">Project Support</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../resources/commercial.html">Commercial Support</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../resources/license.html">License</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index-2.html">AcuGIS GeoHelm</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index-2.html" class="icon icon-home"></a> &raquo;</li>
<li>osm2pgsql</li>
<li class="wy-breadcrumbs-aside">
<a href="https://github.com/AcuGIS/GeoHelm/blob/master/docs/components/osm2pgsql/index.rst" class="fa fa-github"> Edit on GitHub</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="osm2pgsql">
<h1><a class="toc-backref" href="#id1">osm2pgsql</a><a class="headerlink" href="#osm2pgsql" title="Permalink to this headline"></a></h1>
<div class="contents topic" id="table-of-contents">
<p class="topic-title">Table of Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#osm2pgsql" id="id1">osm2pgsql</a><ul>
<li><a class="reference internal" href="#osm-loader-tool" id="id2">OSM Loader Tool</a></li>
<li><a class="reference internal" href="#load-via-osm-file-loader" id="id3">Load via OSM File Loader</a></li>
<li><a class="reference internal" href="#confirm-data-load" id="id4">Confirm Data Load</a></li>
<li><a class="reference internal" href="#osm-tool-options" id="id5">OSM Tool Options</a></li>
<li><a class="reference internal" href="#load-via-comamnd-line" id="id6">Load via Comamnd Line</a></li>
<li><a class="reference internal" href="#troubleshooting" id="id7">Troubleshooting</a></li>
<li><a class="reference internal" href="#documentation" id="id8">Documentation</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="osm-loader-tool">
<h2><a class="toc-backref" href="#id2">OSM Loader Tool</a><a class="headerlink" href="#osm-loader-tool" title="Permalink to this headline"></a></h2>
<p>There are two ways to load OSM file into PostGIS.</p>
<ol class="arabic simple">
<li>Load using the OSM Loader in Webmin.</li>
<li>Load using command line.</li>
</ol>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">In our examples, we will be loading the PBF for Andorra available from GeoFabrik (<a class="reference external" href="https://download.geofabrik.de/europe/andorra.html">https://download.geofabrik.de/europe/andorra.html</a>).</p>
</div>
</div>
<div class="section" id="load-via-osm-file-loader">
<h2><a class="toc-backref" href="#id3">Load via OSM File Loader</a><a class="headerlink" href="#load-via-osm-file-loader" title="Permalink to this headline"></a></h2>
<p>Click the osm2pgsql tab as shown below</p>
<img alt="../../_images/osm2pgsql-tab.png" src="../../_images/osm2pgsql-tab.png" />
<p>The load options are displayed below.</p>
<img alt="../../_images/OSM-default.png" src="../../_images/OSM-default.png" />
<p>For our example, well load the smallest PDF availabel from GeoFabrick, Andorra</p>
<p><strong>1. Go to the Europe section of the GeoFabrik Download Server:</strong></p>
<p><a class="reference external" href="https://download.geofabrik.de/europe.html">https://download.geofabrik.de/europe.html</a></p>
<p><strong>2. Locate the file for Andorra</strong></p>
<img alt="../../_images/osm-Andorra.png" src="../../_images/osm-Andorra.png" />
<img alt="../../_images/spacer2.png" src="../../_images/spacer2.png" />
<p><strong>3. On the PBF link, right click and select “Copy Link Location”</strong></p>
<img alt="../../_images/osm-Andorra-2.png" src="../../_images/osm-Andorra-2.png" />
<img alt="../../_images/spacer2.png" src="../../_images/spacer2.png" />
<p><strong>4. Paste the copied link into the FTP or HTTP URL field</strong></p>
<img alt="../../_images/OSM-main.png" src="../../_images/OSM-main.png" />
<ul class="simple">
<li>For database, select postgisftw.</li>
<li>For user, select pgis</li>
<li>For EPSG Projection, enter 4326</li>
<li>Select both the Slim and Hstore options</li>
</ul>
<p><strong>5. Click the Load button</strong></p>
</div>
<div class="section" id="confirm-data-load">
<h2><a class="toc-backref" href="#id4">Confirm Data Load</a><a class="headerlink" href="#confirm-data-load" title="Permalink to this headline"></a></h2>
<p>If we examine the tables in our postgisftw database, we see that 4 new tables were added:</p>
<img alt="../../_images/OSM-feature-view.png" src="../../_images/OSM-feature-view.png" />
<p>We can also now view our data using pg_featursrv (or pg_tileserv)</p>
<p>Go to :9000 and note that 4 items have been added to the available Feature Collections (Line, Point, Polygon, and Roads):</p>
<img alt="../../_images/OSM-feature-1.png" src="../../_images/OSM-feature-1.png" />
<img alt="../../_images/spacer2.png" src="../../_images/spacer2.png" />
<p>Click the View link for the Polygon:</p>
<img alt="../../_images/OSM-feature-2.png" src="../../_images/OSM-feature-2.png" />
<p>The layer is displayed as below</p>
<img alt="../../_images/OSM-feature-3.png" src="../../_images/OSM-feature-3.png" />
<img alt="../../_images/spacer2.png" src="../../_images/spacer2.png" />
</div>
<div class="section" id="osm-tool-options">
<h2><a class="toc-backref" href="#id5">OSM Tool Options</a><a class="headerlink" href="#osm-tool-options" title="Permalink to this headline"></a></h2>
<p><strong>1. General Options</strong></p>
<p><em>Database</em>: select the database you wish to load the shape file to.</p>
<p><em>Database Username</em>: The postgres user who will load the file.</p>
<p><em>Schema</em>: Select a schema from the drop-down or create a new schema.</p>
<p><em>OSM source (.pbf)</em>: The options are Local file, Uploaded file, or FTP or HTTP URL</p>
<p><strong>2. Load options</strong>:</p>
<p><em>Store temporary data in the database ( slim )</em>: Enable the slim option</p>
<p><em>Add tags without column to an additional hstore (key/value) column ( hstore )</em></p>
<p><em>Coordinate format</em>: Options are Mercator or Lat&amp;Lon</p>
<p><em>EPSG Projection</em>: Set ESPG projection (e.g. 4326)</p>
<p><em>Memory for caching nodes</em>: Default options are 200 MB, 800 MB, 1000 MB, along with increments depending on available RAM.</p>
<p><em>Number of parallel processes</em>: The drop-down will display the number available based on your hardware.</p>
</div>
<div class="section" id="load-via-comamnd-line">
<h2><a class="toc-backref" href="#id6">Load via Comamnd Line</a><a class="headerlink" href="#load-via-comamnd-line" title="Permalink to this headline"></a></h2>
<p>Usage</p>
<p>To load the same PBF we loaded above via osm2pgsql command line, we could use below:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">osm2pgsql --slim --hstore -C 200 --username postgres --database demodb /opt/rhode-island-latest.osm.pbf</span>
</pre></div>
</div>
<p>The full usage commands are show in the help section below.</p>
<p>osm2pgsql usage can be found using the osm2pgsl help command:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">[root@postgis ~]# </span>osm2pgsql<span class="w"> </span>--help
<span class="go">osm2pgsql: /usr/pgsql-12/lib/libpq.so.5: no version information available (required by osm2pgsql)</span>
<span class="go">osm2pgsql version 1.2.0</span>
<span class="go">Usage:</span>
<span class="go"> osm2pgsql [options] planet.osm</span>
<span class="go"> osm2pgsql [options] planet.osm.{pbf,gz,bz2}</span>
<span class="go"> osm2pgsql [options] file1.osm file2.osm file3.osm</span>
<span class="go">This will import the data from the OSM file(s) into a PostgreSQL database</span>
<span class="go">suitable for use by the Mapnik renderer.</span>
<span class="go"> Common options:</span>
<span class="go"> -a|--append Add the OSM file into the database without removing</span>
<span class="go"> existing data.</span>
<span class="go"> -c|--create Remove existing data from the database. This is the</span>
<span class="go"> default if --append is not specified.</span>
<span class="go"> -l|--latlong Store data in degrees of latitude &amp; longitude.</span>
<span class="go"> -m|--merc Store data in proper spherical mercator (default).</span>
<span class="go"> -E|--proj num Use projection EPSG:num.</span>
<span class="go"> -s|--slim Store temporary data in the database. This greatly</span>
<span class="go"> reduces the RAM usage but is much slower. This switch is</span>
<span class="go"> required if you want to update with --append later.</span>
<span class="go"> -S|--style Location of the style file. Defaults to</span>
<span class="go"> /usr/share/osm2pgsql/default.style.</span>
<span class="go"> -C|--cache Use up to this many MB for caching nodes (default: 800)</span>
<span class="go"> -F|--flat-nodes Specifies the flat file to use to persistently store node</span>
<span class="go"> information in slim mode instead of in PostgreSQL.</span>
<span class="go"> This file is a single &gt; 40Gb large file. Only recommended</span>
<span class="go"> for full planet imports. Default is disabled.</span>
<span class="go"> Database options:</span>
<span class="go"> -d|--database The name of the PostgreSQL database to connect to.</span>
<span class="go"> -U|--username PostgreSQL user name (specify passsword in PGPASSWORD</span>
<span class="go"> environment variable or use -W).</span>
<span class="go"> -W|--password Force password prompt.</span>
<span class="go"> -H|--host Database server host name or socket location.</span>
<span class="go"> -P|--port Database server port.</span>
<span class="go">A typical command to import a full planet is</span>
<span class="go"> osm2pgsql -c -d gis --slim -C &lt;cache size&gt; -k \</span>
<span class="go"> --flat-nodes &lt;flat nodes&gt; planet-latest.osm.pbf</span>
<span class="go">where</span>
<span class="go"> &lt;cache size&gt; should be equivalent to the size of the</span>
<span class="go"> pbf file to be imported if there is enough RAM</span>
<span class="go"> or about 75% of memory in MB on machines with less</span>
<span class="go"> &lt;flat nodes&gt; is a location where a 50+GB file can be saved.</span>
<span class="go">A typical command to update a database imported with the above command is</span>
<span class="go"> osmosis --rri workingDirectory=&lt;osmosis dir&gt; --simc --wxc - \</span>
<span class="go"> | osm2pgsql -a -d gis --slim -k --flat-nodes &lt;flat nodes&gt; -r xml -</span>
<span class="go">where</span>
<span class="go"> &lt;flat nodes&gt; is the same location as above.</span>
<span class="go"> &lt;osmosis dir&gt; is the location osmosis replication was initialized to.</span>
<span class="go">Run osm2pgsql --help --verbose (-h -v) for a full list of options.</span>
</pre></div>
</div>
</div>
<div class="section" id="troubleshooting">
<h2><a class="toc-backref" href="#id7">Troubleshooting</a><a class="headerlink" href="#troubleshooting" title="Permalink to this headline"></a></h2>
<p>If the above commands produce osm2pgsql command not found, close your existing SSH session and create a new one.</p>
</div>
<div class="section" id="documentation">
<h2><a class="toc-backref" href="#id8">Documentation</a><a class="headerlink" href="#documentation" title="Permalink to this headline"></a></h2>
<p>Below are resources to get started with ogr2ogr and gdal_translate:</p>
<ul class="simple">
<li><a class="reference external" href="https://wiki.openstreetmap.org/wiki/Osm2pgsql">OSM OSM2PGSQL Wiki</a></li>
<li><a class="reference external" href="https://learnosm.org/en/osm-data/osm2pgsql/">Learn OSM Website: OSM2PGSQL</a></li>
</ul>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="../raster2pgsql/index.html" class="btn btn-neutral float-right" title="raster2pgsql" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="../shp2pgsql/index.html" class="btn btn-neutral float-left" title="shp2pgsql" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright acugis
<span class="commit">
Revision <code>db2a027e</code>.
</span>
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org/">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="versions">
<span class="rst-current-version" data-toggle="rst-current-version">
<span class="fa fa-book"> Read the Docs</span>
v: latest
<span class="fa fa-caret-down"></span>
</span>
<div class="rst-other-versions">
<dl>
<dt>Versions</dt>
<dd><a href="../../index.html">latest</a></dd>
</dl>
<dl>
<dt>Downloads</dt>
<dd><a href="http://geohelm.docs.acugis.com/_/downloads/en/latest/pdf/">pdf</a></dd>
<dd><a href="http://geohelm.docs.acugis.com/_/downloads/en/latest/htmlzip/">html</a></dd>
<dd><a href="http://geohelm.docs.acugis.com/_/downloads/en/latest/epub/">epub</a></dd>
</dl>
<dl>
<dt>On Read the Docs</dt>
<dd>
<a href="http://readthedocs.org/projects/geohelm/?fromdocs=geohelm">Project Home</a>
</dd>
<dd>
<a href="http://readthedocs.org/builds/geohelm/?fromdocs=geohelm">Builds</a>
</dd>
</dl>
</div>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
<!-- Mirrored from geohelm.docs.acugis.com/en/latest/components/osm2pgsql/index.html by HTTrack Website Copier/3.x [XR&CO'2014], Thu, 13 Jul 2023 23:22:16 GMT -->
</html>