Sophie

Sophie

distrib > Mageia > 6 > i586 > by-pkgid > 65530c6176058f9b54858c3b4f6385e6 > files > 724

python-django-doc-1.8.19-1.mga6.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" lang="">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Installing Spatialite &#8212; Django 1.8.19 documentation</title>
    
    <link rel="stylesheet" href="../../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../../',
        VERSION:     '1.8.19',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </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>
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" />
    <link rel="top" title="Django 1.8.19 documentation" href="../../../../contents.html" />
    <link rel="up" title="GeoDjango Installation" href="index.html" />
    <link rel="next" title="GeoDjango Model API" href="../model-api.html" />
    <link rel="prev" title="Installing PostGIS" href="postgis.html" />



 
<script type="text/javascript" src="../../../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../../templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head>
  <body role="document">

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../../../index.html">Django 1.8.19 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../../../index.html">Home</a>  |
        <a title="Table of contents" href="../../../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../../../genindex.html">Index</a>  |
        <a title="Module index" href="../../../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="postgis.html" title="Installing PostGIS">previous</a>
     |
    <a href="../../../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="../model-api.html" title="GeoDjango Model API">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-contrib-gis-install-spatialite">
            
  <div class="section" id="s-installing-spatialite">
<span id="installing-spatialite"></span><h1>Installing Spatialite<a class="headerlink" href="#installing-spatialite" title="Permalink to this headline">¶</a></h1>
<p><a class="reference external" href="https://www.gaia-gis.it/fossil/libspatialite">SpatiaLite</a> adds spatial support to SQLite, turning it into a full-featured
spatial database.</p>
<p>Check first if you can install Spatialite from system packages or binaries. For
example, on Debian-based distributions, try to install the <code class="docutils literal"><span class="pre">spatialite-bin</span></code>
package. For Mac OS X, follow the
<a class="reference internal" href="#spatialite-macosx"><span class="std std-ref">specific instructions below</span></a>. For Windows, you may
find binaries on <a class="reference external" href="http://www.gaia-gis.it/gaia-sins/">Gaia-SINS</a> home page. 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>
<p>When you are done with the installation process, skip to <a class="reference internal" href="#create-spatialite-db"><span class="std std-ref">Creating a spatial database for SpatiaLite</span></a>.</p>
<div class="section" id="s-installing-from-source">
<span id="s-spatialite-source"></span><span id="installing-from-source"></span><span id="spatialite-source"></span><h2>Installing from source<a class="headerlink" href="#installing-from-source" title="Permalink to this headline">¶</a></h2>
<p><a class="reference internal" href="geolibs.html"><span class="doc">GEOS and PROJ.4</span></a> should be installed
prior to building SpatiaLite.</p>
<div class="section" id="s-sqlite">
<span id="sqlite"></span><h3>SQLite<a class="headerlink" href="#sqlite" title="Permalink to this headline">¶</a></h3>
<p>Check first if SQLite is compiled with the <a class="reference external" href="http://www.sqlite.org/rtree.html">R*Tree module</a>. Run the sqlite3
command line interface and enter the following query:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">sqlite</span><span class="o">&gt;</span> <span class="n">CREATE</span> <span class="n">VIRTUAL</span> <span class="n">TABLE</span> <span class="n">testrtree</span> <span class="n">USING</span> <span class="n">rtree</span><span class="p">(</span><span class="nb">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>
</pre></div>
</div>
<p>If you obtain an error, you will have to recompile SQLite from source. Otherwise,
just skip this section.</p>
<p>To install from sources, download the latest amalgamation source archive from
the <a class="reference external" href="http://www.sqlite.org/download.html">SQLite download page</a>, and extract:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>$ wget http://sqlite.org/sqlite-amalgamation-3.6.23.1.tar.gz
$ tar xzf sqlite-amalgamation-3.6.23.1.tar.gz
$ cd sqlite-3.6.23.1
</pre></div>
</div>
<p>Next, run the <code class="docutils literal"><span class="pre">configure</span></code> script &#8211; however the <code class="docutils literal"><span class="pre">CFLAGS</span></code> environment variable
needs to be customized so that SQLite knows to build the R*Tree module:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>$ CFLAGS=&quot;-DSQLITE_ENABLE_RTREE=1&quot; ./configure
$ make
$ sudo make install
$ cd ..
</pre></div>
</div>
</div>
<div class="section" id="s-spatialite-library-libspatialite">
<span id="s-spatialitebuild"></span><span id="spatialite-library-libspatialite"></span><span id="spatialitebuild"></span><h3>SpatiaLite library (<code class="docutils literal"><span class="pre">libspatialite</span></code>)<a class="headerlink" href="#spatialite-library-libspatialite" title="Permalink to this headline">¶</a></h3>
<p>Get the latest SpatiaLite library source bundle from the
<a class="reference external" href="http://www.gaia-gis.it/gaia-sins/libspatialite-sources/">download page</a>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>$ wget http://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-4.1.0.tar.gz
$ tar xaf libspatialite-4.1.0.tar.gz
$ cd libspatialite-4.1.0
$ ./configure
$ make
$ sudo make install
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>For Mac OS X users building from source, the SpatiaLite library <em>and</em> tools
need to have their <code class="docutils literal"><span class="pre">target</span></code> configured:</p>
<div class="last highlight-default"><div class="highlight"><pre><span></span>$ ./configure --target=macosx
</pre></div>
</div>
</div>
</div>
<div class="section" id="s-pysqlite2">
<span id="s-id6"></span><span id="pysqlite2"></span><span id="id6"></span><h3>pysqlite2<a class="headerlink" href="#pysqlite2" title="Permalink to this headline">¶</a></h3>
<p>If you&#8217;ve decided to use a <a class="reference internal" href="../../../databases.html#using-newer-versions-of-pysqlite"><span class="std std-ref">newer version of pysqlite2</span></a> instead of the <code class="docutils literal"><span class="pre">sqlite3</span></code> Python stdlib
module, then you need to make sure it can load external extensions (i.e. the
required <code class="docutils literal"><span class="pre">enable_load_extension</span></code> method is available so <code class="docutils literal"><span class="pre">SpatiaLite</span></code> can be
loaded).</p>
<p>This might involve building it yourself. For this, download pysqlite2 2.6, and
untar:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>$ wget https://pypi.python.org/packages/source/p/pysqlite/pysqlite-2.6.3.tar.gz
$ tar xzf pysqlite-2.6.3.tar.gz
$ cd pysqlite-2.6.3
</pre></div>
</div>
<p>Next, use a text editor to edit the <code class="docutils literal"><span class="pre">setup.cfg</span></code> file to look like the
following:</p>
<div class="highlight-ini"><div class="highlight"><pre><span></span><span class="k">[build_ext]</span>
<span class="c1">#define=</span>
<span class="na">include_dirs</span><span class="o">=</span><span class="s">/usr/local/include</span>
<span class="na">library_dirs</span><span class="o">=</span><span class="s">/usr/local/lib</span>
<span class="na">libraries</span><span class="o">=</span><span class="s">sqlite3</span>
<span class="c1">#define=SQLITE_OMIT_LOAD_EXTENSION</span>
</pre></div>
</div>
<p>or if you are on Mac OS X:</p>
<div class="highlight-ini"><div class="highlight"><pre><span></span><span class="k">[build_ext]</span>
<span class="c1">#define=</span>
<span class="na">include_dirs</span><span class="o">=</span><span class="s">/Library/Frameworks/SQLite3.framework/unix/include</span>
<span class="na">library_dirs</span><span class="o">=</span><span class="s">/Library/Frameworks/SQLite3.framework/unix/lib</span>
<span class="na">libraries</span><span class="o">=</span><span class="s">sqlite3</span>
<span class="c1">#define=SQLITE_OMIT_LOAD_EXTENSION</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The important thing here is to make sure you comment out the
<code class="docutils literal"><span class="pre">define=SQLITE_OMIT_LOAD_EXTENSION</span></code> flag and that the <code class="docutils literal"><span class="pre">include_dirs</span></code>
and <code class="docutils literal"><span class="pre">library_dirs</span></code> settings are uncommented and set to the appropriate
path if the SQLite header files and libraries are not in <code class="docutils literal"><span class="pre">/usr/include</span></code>
and <code class="docutils literal"><span class="pre">/usr/lib</span></code>, respectively.</p>
</div>
<p>After modifying <code class="docutils literal"><span class="pre">setup.cfg</span></code> appropriately, then run the <code class="docutils literal"><span class="pre">setup.py</span></code> script
to build and install:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>$ python setup.py install
</pre></div>
</div>
</div>
</div>
<div class="section" id="s-mac-os-x-specific-instructions">
<span id="s-spatialite-macosx"></span><span id="mac-os-x-specific-instructions"></span><span id="spatialite-macosx"></span><h2>Mac OS X-specific instructions<a class="headerlink" href="#mac-os-x-specific-instructions" title="Permalink to this headline">¶</a></h2>
<p>To install the SpatiaLite library and tools, Mac OS X users can choose between
<a class="reference internal" href="index.html#kyngchaos"><span class="std std-ref">KyngChaos packages</span></a> and <a class="reference external" href="http://brew.sh/">Homebrew</a>.</p>
<div class="section" id="s-kyngchaos">
<span id="kyngchaos"></span><h3>KyngChaos<a class="headerlink" href="#kyngchaos" title="Permalink to this headline">¶</a></h3>
<p>First, follow the instructions in the <a class="reference internal" href="index.html#kyngchaos"><span class="std std-ref">KyngChaos packages</span></a> section.</p>
<p>When <a class="reference internal" href="#create-spatialite-db"><span class="std std-ref">Creating a spatial database for SpatiaLite</span></a>, the <code class="docutils literal"><span class="pre">spatialite</span></code> program is required.
However, instead of attempting to compile the SpatiaLite tools from source,
download the <a class="reference external" href="http://www.gaia-gis.it/spatialite-2.3.1/binaries.html">SpatiaLite Binaries</a> for OS X, and install <code class="docutils literal"><span class="pre">spatialite</span></code> in a
location available in your <code class="docutils literal"><span class="pre">PATH</span></code>.  For example:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>$ curl -O http://www.gaia-gis.it/spatialite/spatialite-tools-osx-x86-2.3.1.tar.gz
$ tar xzf spatialite-tools-osx-x86-2.3.1.tar.gz
$ cd spatialite-tools-osx-x86-2.3.1/bin
$ sudo cp spatialite /Library/Frameworks/SQLite3.framework/Programs
</pre></div>
</div>
<p>Finally, for GeoDjango to be able to find the KyngChaos SpatiaLite library,
add the following to your <code class="docutils literal"><span class="pre">settings.py</span></code>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">SPATIALITE_LIBRARY_PATH</span><span class="o">=</span><span class="s1">&#39;/Library/Frameworks/SQLite3.framework/SQLite3&#39;</span>
</pre></div>
</div>
</div>
<div class="section" id="s-homebrew">
<span id="homebrew"></span><h3>Homebrew<a class="headerlink" href="#homebrew" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="http://brew.sh/">Homebrew</a> handles all the SpatiaLite related packages on your behalf,
including SQLite3, SpatiaLite, PROJ, and GEOS. Install them like this:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>$ brew update
$ brew install spatialite-tools
$ brew install gdal
</pre></div>
</div>
<p>Finally, for GeoDjango to be able to find the SpatiaLite library, add the
following to your <code class="docutils literal"><span class="pre">settings.py</span></code>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">SPATIALITE_LIBRARY_PATH</span><span class="o">=</span><span class="s1">&#39;/usr/local/lib/mod_spatialite.dylib&#39;</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="s-creating-a-spatial-database-for-spatialite">
<span id="s-create-spatialite-db"></span><span id="creating-a-spatial-database-for-spatialite"></span><span id="create-spatialite-db"></span><h2>Creating a spatial database for SpatiaLite<a class="headerlink" href="#creating-a-spatial-database-for-spatialite" title="Permalink to this headline">¶</a></h2>
<p>When running <code class="docutils literal"><span class="pre">manage.py</span> <span class="pre">migrate</span></code> with a SQLite or SpatiaLite database, the
database file will be automatically created if it doesn&#8217;t exist. Django will
also ensure that the spatial metadata are initialized in the database.</p>
<div class="versionchanged">
<span class="title">Changed in Django 1.8:</span> <p>Prior to Django 1.8, you had to initialize spatial metadata tables yourself
by manually running the &#8220;SELECT InitSpatialMetaData();&#8221; query.</p>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../../../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Installing Spatialite</a><ul>
<li><a class="reference internal" href="#installing-from-source">Installing from source</a><ul>
<li><a class="reference internal" href="#sqlite">SQLite</a></li>
<li><a class="reference internal" href="#spatialite-library-libspatialite">SpatiaLite library (<code class="docutils literal"><span class="pre">libspatialite</span></code>)</a></li>
<li><a class="reference internal" href="#pysqlite2">pysqlite2</a></li>
</ul>
</li>
<li><a class="reference internal" href="#mac-os-x-specific-instructions">Mac OS X-specific instructions</a><ul>
<li><a class="reference internal" href="#kyngchaos">KyngChaos</a></li>
<li><a class="reference internal" href="#homebrew">Homebrew</a></li>
</ul>
</li>
<li><a class="reference internal" href="#creating-a-spatial-database-for-spatialite">Creating a spatial database for SpatiaLite</a></li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="postgis.html">Installing PostGIS</a></li>
    
    
      <li>Next: <a href="../model-api.html">GeoDjango Model API</a></li>
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../../../../index.html">Django 1.8.19 documentation</a>
        
          <ul><li><a href="../../../index.html">API Reference</a>
        
          <ul><li><a href="../../index.html"><code class="docutils literal"><span class="pre">contrib</span></code> packages</a>
        
          <ul><li><a href="../index.html">GeoDjango</a>
        
          <ul><li><a href="index.html">GeoDjango Installation</a>
        
        <ul><li>Installing Spatialite</li></ul>
        </li></ul></li></ul></li></ul></li></ul>
      </li>
  </ul>

  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../../../_sources/ref/contrib/gis/install/spatialite.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="../../../../search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Mar 10, 2018</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="postgis.html" title="Installing PostGIS">previous</a>
     |
    <a href="../../../index.html" title="API Reference" accesskey="U">up</a>
   |
    <a href="../model-api.html" title="GeoDjango Model API">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>