{"title":"Installing Geospatial libraries","version":"2.2","locale":"en","docname":"ref/contrib/gis/install/geolibs","url":"/en/2.2/ref/contrib/gis/install/geolibs/","canonical":"https://djangodocs.dev/en/2.2/ref/contrib/gis/install/geolibs/","summary":"GeoDjango uses and/or provides interfaces for the following open source geospatial libraries: Program Description Required Supported Versions GEOS Geometry Engine…","html":"<h1>Installing Geospatial libraries<a class=\"heading-anchor\" href=\"#installing-geospatial-libraries\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>GeoDjango uses and/or provides interfaces for the following open source\ngeospatial libraries:</p>\n<div class=\"table-scroll\" role=\"region\" tabindex=\"0\" aria-label=\"Table\"><table class=\"docutils align-default\">\n<thead>\n<tr class=\"row-odd\"><th class=\"head\"><p>Program</p></th>\n<th class=\"head\"><p>Description</p></th>\n<th class=\"head\"><p>Required</p></th>\n<th class=\"head\"><p>Supported Versions</p></th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/en/2.2/ref/contrib/gis/geos/\"><span class=\"doc\">GEOS</span></a></p></td>\n<td><p>Geometry Engine Open Source</p></td>\n<td><p>Yes</p></td>\n<td><p>3.7, 3.6, 3.5, 3.4</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference external\" href=\"https://github.com/OSGeo/proj.4/wiki/\">PROJ.4</a></p></td>\n<td><p>Cartographic Projections library</p></td>\n<td><p>Yes (PostgreSQL and SQLite only)</p></td>\n<td><p>5.2, 5.1, 5.0, 4.x</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference internal\" href=\"/en/2.2/ref/contrib/gis/gdal/\"><span class=\"doc\">GDAL</span></a></p></td>\n<td><p>Geospatial Data Abstraction Library</p></td>\n<td><p>Yes</p></td>\n<td><p>2.3, 2.2, 2.1, 2.0, 1.11</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference internal\" href=\"/en/2.2/ref/contrib/gis/geoip2/\"><span class=\"doc\">GeoIP</span></a></p></td>\n<td><p>IP-based geolocation library</p></td>\n<td><p>No</p></td>\n<td><p>2</p></td>\n</tr>\n<tr class=\"row-even\"><td><p><a class=\"reference external\" href=\"https://postgis.net/\">PostGIS</a></p></td>\n<td><p>Spatial extensions for PostgreSQL</p></td>\n<td><p>Yes (PostgreSQL only)</p></td>\n<td><p>2.5, 2.4, 2.3, 2.2, 2.1</p></td>\n</tr>\n<tr class=\"row-odd\"><td><p><a class=\"reference external\" href=\"https://www.gaia-gis.it/gaia-sins/\">SpatiaLite</a></p></td>\n<td><p>Spatial extensions for SQLite</p></td>\n<td><p>Yes (SQLite only)</p></td>\n<td><p>4.3, 4.2, 4.1</p></td>\n</tr>\n</tbody>\n</table>\n</div>\n<p>Note that older or more recent versions of these libraries <em>may</em> also work\ntotally fine with GeoDjango. Your mileage may vary.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>The GeoDjango interfaces to GEOS, GDAL, and GeoIP may be used\nindependently of Django.  In other words, no database or settings file\nrequired – just import them as normal from <a class=\"reference internal\" href=\"/en/2.2/ref/contrib/gis/#module-django.contrib.gis\" title=\"django.contrib.gis: Geographic Information System (GIS) extensions for Django\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">django.contrib.gis</span></code></a>.</p>\n</aside>\n<p>On Debian/Ubuntu, you are advised to install the following packages which will\ninstall, directly or by dependency, the required geospatial libraries:</p>\n<div class=\"code-block\" data-language=\"console\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code><span class=\"gp\">$ </span>sudo<span class=\"w\"> </span>apt-get<span class=\"w\"> </span>install<span class=\"w\"> </span>binutils<span class=\"w\"> </span>libproj-dev<span class=\"w\"> </span>gdal-bin\n</code></pre></div>\n<p>Please also consult platform-specific instructions if you are on <a class=\"reference internal\" href=\"/en/2.2/ref/contrib/gis/install/#macos\"><span class=\"std std-ref\">macOS</span></a>\nor <a class=\"reference internal\" href=\"/en/2.2/ref/contrib/gis/testing/#windows\"><span class=\"std std-ref\">Windows</span></a>.</p>\n<section id=\"building-from-source\">\n<span id=\"build-from-source\"></span><h2>Building from source<a class=\"heading-anchor\" href=\"#building-from-source\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>When installing from source on UNIX and GNU/Linux systems, please follow\nthe installation instructions carefully, and install the libraries in the\ngiven order.  If using MySQL or Oracle as the spatial database, only GEOS\nis required.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>On Linux platforms, it may be necessary to run the <code class=\"docutils literal notranslate\"><span class=\"pre\">ldconfig</span></code> command\nafter installing each library. For example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>$ sudo make install\n$ sudo ldconfig\n</code></pre></div>\n</aside>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>macOS users must install <a class=\"reference external\" href=\"https://developer.apple.com/xcode/\">Xcode</a> in order to compile software from source.</p>\n</aside>\n<section id=\"geos\">\n<span id=\"geosbuild\"></span><h3>GEOS<a class=\"heading-anchor\" href=\"#geos\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>GEOS is a C++ library for performing geometric operations, and is the default\ninternal geometry representation used by GeoDjango (it’s behind the “lazy”\ngeometries).  Specifically, the C API library is called (e.g., <code class=\"docutils literal notranslate\"><span class=\"pre\">libgeos_c.so</span></code>)\ndirectly from Python using ctypes.</p>\n<p>First, download GEOS from the GEOS website and untar the source archive:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>$ wget https://download.osgeo.org/geos/geos-X.Y.Z.tar.bz2\n$ tar xjf geos-X.Y.Z.tar.bz2\n</code></pre></div>\n<p>Next, change into the directory where GEOS was unpacked, run the configure\nscript, compile, and install:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>$ cd geos-X.Y.Z\n$ ./configure\n$ make\n$ sudo make install\n$ cd ..\n</code></pre></div>\n<section id=\"troubleshooting\">\n<h4>Troubleshooting<a class=\"heading-anchor\" href=\"#troubleshooting\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<section id=\"can-t-find-geos-library\">\n<h5>Can’t find GEOS library<a class=\"heading-anchor\" href=\"#can-t-find-geos-library\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>When GeoDjango can’t find GEOS, this error is raised:</p>\n<div class=\"code-block\" data-language=\"text\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Text</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Text code\"><code>ImportError: Could not find the GEOS library (tried &quot;geos_c&quot;). Try setting GEOS_LIBRARY_PATH in your settings.\n</code></pre></div>\n<p>The most common solution is to properly configure your <a class=\"reference internal\" href=\"/en/2.2/ref/contrib/gis/install/#libsettings\"><span class=\"std std-ref\">Library environment settings</span></a> <em>or</em> set\n<a class=\"reference internal\" href=\"#geoslibrarypath\"><span class=\"std std-ref\">GEOS_LIBRARY_PATH</span></a> in your settings.</p>\n<p>If using a binary package of GEOS (e.g., on Ubuntu), you may need to <a class=\"reference internal\" href=\"/en/2.2/ref/contrib/gis/install/#binutils\"><span class=\"std std-ref\">Install binutils</span></a>.</p>\n</section>\n<section id=\"geos-library-path\">\n<span id=\"geoslibrarypath\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">GEOS_LIBRARY_PATH</span></code><a class=\"heading-anchor\" href=\"#geos-library-path\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>If your GEOS library is in a non-standard location, or you don’t want to\nmodify the system’s library path then the <a class=\"reference internal\" href=\"/en/2.2/ref/contrib/gis/geos/#std-setting-GEOS_LIBRARY_PATH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">GEOS_LIBRARY_PATH</span></code></a>\nsetting may be added to your Django settings file with the full path to the\nGEOS C library.  For example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">GEOS_LIBRARY_PATH</span> <span class=\"o\">=</span> <span class=\"s1\">&#39;/home/bob/local/lib/libgeos_c.so&#39;</span>\n</code></pre></div>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>The setting must be the <em>full</em> path to the <strong>C</strong> shared library; in\nother words you want to use <code class=\"docutils literal notranslate\"><span class=\"pre\">libgeos_c.so</span></code>, not <code class=\"docutils literal notranslate\"><span class=\"pre\">libgeos.so</span></code>.</p>\n</aside>\n<p>See also <a class=\"reference internal\" href=\"/en/2.2/ref/contrib/gis/geos/#geos-exceptions-in-logfile\"><span class=\"std std-ref\">My logs are filled with GEOS-related errors</span></a>.</p>\n</section>\n</section>\n</section>\n<section id=\"proj4\">\n<span id=\"id3\"></span><h3>PROJ.4<a class=\"heading-anchor\" href=\"#proj4\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p><a class=\"reference external\" href=\"https://github.com/OSGeo/proj.4/wiki/\">PROJ.4</a> is a library for converting geospatial data to different coordinate\nreference systems.</p>\n<p>First, download the PROJ.4 source code and datum shifting files <a class=\"footnote-reference brackets\" href=\"#id9\" id=\"id4\" role=\"doc-noteref\"><span class=\"fn-bracket\">[</span>1<span class=\"fn-bracket\">]</span></a>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>$ wget https://download.osgeo.org/proj/proj-X.Y.Z.tar.gz\n$ wget https://download.osgeo.org/proj/proj-datumgrid-X.Y.tar.gz\n</code></pre></div>\n<p>Next, untar the source code archive, and extract the datum shifting files in the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">nad</span></code> subdirectory.  This must be done <em>prior</em> to configuration:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>$ tar xzf proj-X.Y.Z.tar.gz\n$ cd proj-X.Y.Z/nad\n$ tar xzf ../../proj-datumgrid-X.Y.tar.gz\n$ cd ..\n</code></pre></div>\n<p>Finally, configure, make and install PROJ.4:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>$ ./configure\n$ make\n$ sudo make install\n$ cd ..\n</code></pre></div>\n</section>\n<section id=\"gdal\">\n<span id=\"gdalbuild\"></span><h3>GDAL<a class=\"heading-anchor\" href=\"#gdal\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p><a class=\"reference external\" href=\"https://trac.osgeo.org/gdal/\">GDAL</a> is an excellent open source geospatial library that has support for\nreading most vector and raster spatial data formats.  Currently, GeoDjango only\nsupports <a class=\"reference internal\" href=\"/en/2.2/ref/contrib/gis/gdal/\"><span class=\"doc\">GDAL’s vector data</span></a> capabilities <a class=\"footnote-reference brackets\" href=\"#id10\" id=\"id5\" role=\"doc-noteref\"><span class=\"fn-bracket\">[</span>2<span class=\"fn-bracket\">]</span></a>.\n<a class=\"reference internal\" href=\"#geosbuild\"><span class=\"std std-ref\">GEOS</span></a> and <a class=\"reference internal\" href=\"#proj4\"><span class=\"std std-ref\">PROJ.4</span></a> should be installed prior to building GDAL.</p>\n<p>First download the latest GDAL release version and untar the archive:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>$ wget https://download.osgeo.org/gdal/X.Y.Z/gdal-X.Y.Z.tar.gz\n$ tar xzf gdal-X.Y.Z.tar.gz\n$ cd gdal-X.Y.Z\n</code></pre></div>\n<p>Configure, make and install:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>$ ./configure\n$ make # Go get some coffee, this takes a while.\n$ sudo make install\n$ cd ..\n</code></pre></div>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>Because GeoDjango has its own Python interface, the preceding instructions\ndo not build GDAL’s own Python bindings. The bindings may be built by\nadding the <code class=\"docutils literal notranslate\"><span class=\"pre\">--with-python</span></code> flag when running <code class=\"docutils literal notranslate\"><span class=\"pre\">configure</span></code>. See\n<a class=\"reference external\" href=\"https://trac.osgeo.org/gdal/wiki/GdalOgrInPython\">GDAL/OGR In Python</a> for more information on GDAL’s bindings.</p>\n</aside>\n<p>If you have any problems, please see the troubleshooting section below for\nsuggestions and solutions.</p>\n<section id=\"gdaltrouble\">\n<span id=\"id8\"></span><h4>Troubleshooting<a class=\"heading-anchor\" href=\"#gdaltrouble\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<section id=\"can-t-find-gdal-library\">\n<h5>Can’t find GDAL library<a class=\"heading-anchor\" href=\"#can-t-find-gdal-library\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>When GeoDjango can’t find the GDAL library, configure your <a class=\"reference internal\" href=\"/en/2.2/ref/contrib/gis/install/#libsettings\"><span class=\"std std-ref\">Library environment settings</span></a>\n<em>or</em> set <a class=\"reference internal\" href=\"#gdallibrarypath\"><span class=\"std std-ref\">GDAL_LIBRARY_PATH</span></a> in your settings.</p>\n</section>\n<section id=\"gdal-library-path\">\n<span id=\"gdallibrarypath\"></span><h5><code class=\"docutils literal notranslate\"><span class=\"pre\">GDAL_LIBRARY_PATH</span></code><a class=\"heading-anchor\" href=\"#gdal-library-path\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>If your GDAL library is in a non-standard location, or you don’t want to\nmodify the system’s library path then the <a class=\"reference internal\" href=\"/en/2.2/ref/contrib/gis/gdal/#std-setting-GDAL_LIBRARY_PATH\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">GDAL_LIBRARY_PATH</span></code></a>\nsetting may be added to your Django settings file with the full path to\nthe GDAL library.  For example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">GDAL_LIBRARY_PATH</span> <span class=\"o\">=</span> <span class=\"s1\">&#39;/home/sue/local/lib/libgdal.so&#39;</span>\n</code></pre></div>\n<p class=\"rubric\">Footnotes</p>\n<aside class=\"footnote-list brackets\">\n<aside class=\"footnote brackets\" id=\"id9\" role=\"doc-footnote\">\n<span class=\"label\"><span class=\"fn-bracket\">[</span><a role=\"doc-backlink\" href=\"#id4\">1</a><span class=\"fn-bracket\">]</span></span>\n<p>The datum shifting files are needed for converting data to and from\ncertain projections.\nFor example, the PROJ.4 string for the <a class=\"reference external\" href=\"http://spatialreference.org/ref/sr-org/6864/prj/\">Google projection (900913 or 3857)</a> requires the\n<code class=\"docutils literal notranslate\"><span class=\"pre\">null</span></code> grid file only included in the extra datum shifting files.\nIt is easier to install the shifting files now, then to have debug a\nproblem caused by their absence later.</p>\n</aside>\n<aside class=\"footnote brackets\" id=\"id10\" role=\"doc-footnote\">\n<span class=\"label\"><span class=\"fn-bracket\">[</span><a role=\"doc-backlink\" href=\"#id5\">2</a><span class=\"fn-bracket\">]</span></span>\n<p>Specifically, GeoDjango provides support for the <a class=\"reference external\" href=\"https://gdal.org/user/vector_data_model.html\">OGR</a> library, a component of\nGDAL.</p>\n</aside>\n</aside>\n</section>\n</section>\n</section>\n</section>","rootId":"installing-geospatial-libraries","toc":[{"title":"Building from source","anchor":"building-from-source","children":[{"title":"GEOS","anchor":"geos","children":[{"title":"Troubleshooting","anchor":"troubleshooting","children":[{"title":"Can’t find GEOS library","anchor":"can-t-find-geos-library","children":[]},{"title":"GEOS_LIBRARY_PATH","anchor":"geos-library-path","children":[]}]}]},{"title":"PROJ.4","anchor":"proj4","children":[]},{"title":"GDAL","anchor":"gdal","children":[{"title":"Troubleshooting","anchor":"gdaltrouble","children":[{"title":"Can’t find GDAL library","anchor":"can-t-find-gdal-library","children":[]},{"title":"GDAL_LIBRARY_PATH","anchor":"gdal-library-path","children":[]}]}]}]}],"breadcrumbs":[{"docname":"ref/index","title":"API Reference","url":"/en/2.2/ref/"},{"docname":"ref/contrib/index","title":"contrib packages","url":"/en/2.2/ref/contrib/"},{"docname":"ref/contrib/gis/index","title":"GeoDjango","url":"/en/2.2/ref/contrib/gis/"},{"docname":"ref/contrib/gis/install/index","title":"GeoDjango Installation","url":"/en/2.2/ref/contrib/gis/install/"}],"prev":{"docname":"ref/contrib/gis/install/index","title":"GeoDjango Installation","url":"/en/2.2/ref/contrib/gis/install/"},"next":{"docname":"ref/contrib/gis/install/postgis","title":"Installing PostGIS","url":"/en/2.2/ref/contrib/gis/install/postgis/"},"formats":{"html":"/en/2.2/ref/contrib/gis/install/geolibs/","markdown":"/en/2.2/ref/contrib/gis/install/geolibs.md","json":"/en/2.2/ref/contrib/gis/install/geolibs.json"},"source":"https://github.com/django/django/blob/stable/2.2.x/docs/ref/contrib/gis/install/geolibs.txt","official":"https://docs.djangoproject.com/en/2.2/ref/contrib/gis/install/geolibs/","inVersions":["dev","6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10","1.9","1.8"],"inLocales":["en","zh-hans","fr","ja","id","pt-br","ko","es","el","pl"]}