{"title":"Installing SpatiaLite","version":"4.2","locale":"es","docname":"ref/contrib/gis/install/spatialite","url":"/es/4.2/ref/contrib/gis/install/spatialite/","canonical":"https://djangodocs.dev/es/4.2/ref/contrib/gis/install/spatialite/","summary":"SpatiaLite adds spatial support to SQLite, turning it into a full-featured spatial database. First, check if you can install SpatiaLite from system packages or…","html":"<h1>Installing SpatiaLite<a class=\"heading-anchor\" href=\"#installing-spatialite\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p><a class=\"reference external\" href=\"https://www.gaia-gis.it/fossil/libspatialite/index\">SpatiaLite</a> adds spatial support to SQLite, turning it into a full-featured\nspatial database.</p>\n<p>First, check if you can install SpatiaLite from system packages or binaries.</p>\n<p>For example, on Debian-based distributions that package SpatiaLite 4.3+, try to\ninstall the <code class=\"docutils literal notranslate\"><span class=\"pre\">libsqlite3-mod-spatialite</span></code> package. For older releases install\n<code class=\"docutils literal notranslate\"><span class=\"pre\">spatialite-bin</span></code>.</p>\n<p>For macOS, follow the <a class=\"reference internal\" href=\"#spatialite-macos\"><span class=\"std std-ref\">instructions below</span></a>.</p>\n<p>For Windows, you may find binaries on the <a class=\"reference external\" href=\"https://www.gaia-gis.it/gaia-sins/\">Gaia-SINS</a> home page.</p>\n<p>In any case, you should always be able to <a class=\"reference internal\" href=\"#spatialite-source\"><span class=\"std std-ref\">install from source</span></a>.</p>\n<section id=\"installing-from-source\">\n<span id=\"spatialite-source\"></span><h2>Installing from source<a class=\"heading-anchor\" href=\"#installing-from-source\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p><a class=\"reference internal\" href=\"/es/4.2/ref/contrib/gis/install/geolibs/\"><span class=\"doc\">GEOS and PROJ</span></a> should be installed\nprior to building SpatiaLite.</p>\n<section id=\"sqlite\">\n<h3>SQLite<a class=\"heading-anchor\" href=\"#sqlite\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Check first if SQLite is compiled with the <a class=\"reference external\" href=\"https://www.sqlite.org/rtree.html\">R*Tree module</a>. Run the sqlite3\ncommand line interface and enter the following query:</p>\n<div class=\"code-block\" data-language=\"sqlite3\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Sqlite3</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=\"Sqlite3 code\"><code><span class=\"gp\">sqlite&gt;</span><span class=\"w\"> </span><span class=\"k\">CREATE</span><span class=\"w\"> </span><span class=\"n\">VIRTUAL</span><span class=\"w\"> </span><span class=\"k\">TABLE</span><span class=\"w\"> </span><span class=\"n\">testrtree</span><span class=\"w\"> </span><span class=\"k\">USING</span><span class=\"w\"> </span><span class=\"n\">rtree</span><span class=\"p\">(</span><span class=\"n\">id</span><span class=\"p\">,</span><span class=\"n\">minX</span><span class=\"p\">,</span><span class=\"n\">maxX</span><span class=\"p\">,</span><span class=\"n\">minY</span><span class=\"p\">,</span><span class=\"n\">maxY</span><span class=\"p\">);</span>\n</code></pre></div>\n<p>If you obtain an error, you will have to recompile SQLite from source. Otherwise,\nskip this section.</p>\n<p>To install from sources, download the latest amalgamation source archive from\nthe <a class=\"reference external\" href=\"https://www.sqlite.org/download.html\">SQLite download page</a>, and extract:</p>\n<div class=\"code-block\" data-language=\"shell\"><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=\"w\"> </span>wget<span class=\"w\"> </span>https://www.sqlite.org/YYYY/sqlite-amalgamation-XXX0000.zip\n$<span class=\"w\"> </span>unzip<span class=\"w\"> </span>sqlite-amalgamation-XXX0000.zip\n$<span class=\"w\"> </span><span class=\"nb\">cd</span><span class=\"w\"> </span>sqlite-amalgamation-XXX0000\n</code></pre></div>\n<p>Next, run the <code class=\"docutils literal notranslate\"><span class=\"pre\">configure</span></code> script – however the <code class=\"docutils literal notranslate\"><span class=\"pre\">CFLAGS</span></code> environment variable\nneeds to be customized so that SQLite knows to build the R*Tree module:</p>\n<div class=\"code-block\" data-language=\"shell\"><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=\"w\"> </span><span class=\"nv\">CFLAGS</span><span class=\"o\">=</span><span class=\"s2\">&quot;-DSQLITE_ENABLE_RTREE=1&quot;</span><span class=\"w\"> </span>./configure\n$<span class=\"w\"> </span>make\n$<span class=\"w\"> </span>sudo<span class=\"w\"> </span>make<span class=\"w\"> </span>install\n$<span class=\"w\"> </span><span class=\"nb\">cd</span><span class=\"w\"> </span>..\n</code></pre></div>\n</section>\n<section id=\"spatialite-library-libspatialite\">\n<span id=\"spatialitebuild\"></span><h3>SpatiaLite library (<code class=\"docutils literal notranslate\"><span class=\"pre\">libspatialite</span></code>)<a class=\"heading-anchor\" href=\"#spatialite-library-libspatialite\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Get the latest SpatiaLite library source bundle from the\n<a class=\"reference external\" href=\"https://www.gaia-gis.it/gaia-sins/libspatialite-sources/\">download page</a>:</p>\n<div class=\"code-block\" data-language=\"shell\"><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=\"w\"> </span>wget<span class=\"w\"> </span>https://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-X.Y.Z.tar.gz\n$<span class=\"w\"> </span>tar<span class=\"w\"> </span>xaf<span class=\"w\"> </span>libspatialite-X.Y.Z.tar.gz\n$<span class=\"w\"> </span><span class=\"nb\">cd</span><span class=\"w\"> </span>libspatialite-X.Y.Z\n$<span class=\"w\"> </span>./configure\n$<span class=\"w\"> </span>make\n$<span class=\"w\"> </span>sudo<span class=\"w\"> </span>make<span class=\"w\"> </span>install\n</code></pre></div>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Nota</p>\n<p>For macOS users building from source, the SpatiaLite library <em>and</em> tools\nneed to have their <code class=\"docutils literal notranslate\"><span class=\"pre\">target</span></code> configured:</p>\n<div class=\"code-block\" data-language=\"shell\"><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=\"w\"> </span>./configure<span class=\"w\"> </span>--target<span class=\"o\">=</span>macosx\n</code></pre></div>\n</aside>\n</section>\n</section>\n<section id=\"macos-specific-instructions\">\n<span id=\"spatialite-macos\"></span><h2>macOS-specific instructions<a class=\"heading-anchor\" href=\"#macos-specific-instructions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>To install the SpatiaLite library and tools, macOS users can use <a class=\"reference external\" href=\"https://brew.sh/\">Homebrew</a>.</p>\n<section id=\"homebrew\">\n<h3>Homebrew<a class=\"heading-anchor\" href=\"#homebrew\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p><a class=\"reference external\" href=\"https://brew.sh/\">Homebrew</a> handles all the SpatiaLite related packages on your behalf,\nincluding SQLite, SpatiaLite, PROJ, and GEOS. Install them like this:</p>\n<div class=\"code-block\" data-language=\"shell\"><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=\"w\"> </span>brew<span class=\"w\"> </span>update\n$<span class=\"w\"> </span>brew<span class=\"w\"> </span>install<span class=\"w\"> </span>spatialite-tools\n$<span class=\"w\"> </span>brew<span class=\"w\"> </span>install<span class=\"w\"> </span>gdal\n</code></pre></div>\n<p>Finally, for GeoDjango to be able to find the SpatiaLite library, add the\nfollowing to your <code class=\"docutils literal notranslate\"><span class=\"pre\">settings.py</span></code>:</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\">SPATIALITE_LIBRARY_PATH</span> <span class=\"o\">=</span> <span class=\"s2\">&quot;/usr/local/lib/mod_spatialite.dylib&quot;</span>\n</code></pre></div>\n</section>\n</section>","rootId":"installing-spatialite","toc":[{"title":"Installing from source","anchor":"installing-from-source","children":[{"title":"SQLite","anchor":"sqlite","children":[]},{"title":"SpatiaLite library (libspatialite)","anchor":"spatialite-library-libspatialite","children":[]}]},{"title":"macOS-specific instructions","anchor":"macos-specific-instructions","children":[{"title":"Homebrew","anchor":"homebrew","children":[]}]}],"breadcrumbs":[{"docname":"ref/index","title":"API Reference","url":"/es/4.2/ref/"},{"docname":"ref/contrib/index","title":"contrib packages","url":"/es/4.2/ref/contrib/"},{"docname":"ref/contrib/gis/index","title":"GeoDjango","url":"/es/4.2/ref/contrib/gis/"},{"docname":"ref/contrib/gis/install/index","title":"GeoDjango Installation","url":"/es/4.2/ref/contrib/gis/install/"}],"prev":{"docname":"ref/contrib/gis/install/postgis","title":"Installing PostGIS","url":"/es/4.2/ref/contrib/gis/install/postgis/"},"next":{"docname":"ref/contrib/gis/model-api","title":"GeoDjango Model API","url":"/es/4.2/ref/contrib/gis/model-api/"},"formats":{"html":"/es/4.2/ref/contrib/gis/install/spatialite/","markdown":"/es/4.2/ref/contrib/gis/install/spatialite.md","json":"/es/4.2/ref/contrib/gis/install/spatialite.json"},"source":"https://github.com/django/django/blob/stable/4.2.x/docs/ref/contrib/gis/install/spatialite.txt","official":"https://docs.djangoproject.com/es/4.2/ref/contrib/gis/install/spatialite/","inVersions":["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"],"inLocales":["en","zh-hans","fr","ja","id","it","pt-br","ko","es","el","pl"]}