djangosnippets.org: Latest snippets tagged with 'gis'https://djangosnippets.org/tags/gis/2021-03-24T08:13:25.964504-05:00Closest ORM models to a latitude/longitude point
2021-03-24T08:13:25.964504-05:00simonwhttps://djangosnippets.org/snippets/10854/<p>Here's how to find the 10 closest locations to a point for a model that has latitude and longitude columns, if you're not using GeoDjango.</p>
<p>This runs a brute force distance calculation against every row, so it should only be used on smaller tables - probably less than 100,000 rows. …</p>
Freely redistributableMap GPX files to 3D GeoDjango Models
2009-11-16T13:39:17.712634-06:00jbronnhttps://djangosnippets.org/snippets/1800/<p><code>GPXMapping</code> is a subclass of <code>LayerMapping</code> that imports GPX files into 3D GeoDjango models (requires Django 1.2 or SVN r11742 and higher). Here's an example of GeoDjango models for GPX points and tracks, respectively:</p>
<pre><code>from django.contrib.gis.db import models
class GPXPoint(models.Model):
timestamp = models.DateTimeField()
point = models.PointField(dim=3)
objects = models.GeoManager()
def …</code></pre>
Freely redistributablegoogle.js template for GoogleAdmin
2008-10-15T14:41:08.082595-05:00jbronnhttps://djangosnippets.org/snippets/1146/<p>JavaScript template for <a href="http://www.djangosnippets.org/snippets/1144/">GoogleAdmin</a>. Also requires the <a href="http://www.djangosnippets.org/snippets/1145/">google.html</a> template. Install in <code>gis/admin</code> somewhere in your template path. </p>
Freely redistributablegoogle.html template for GoogleAdmin
2008-10-15T14:38:49.251967-05:00jbronnhttps://djangosnippets.org/snippets/1145/<p>HTML template for <a href="http://www.djangosnippets.org/snippets/1144/">GoogleAdmin</a>. Also requires the <a href="http://www.djangosnippets.org/snippets/1146/">google.js</a> template. Install in <code>gis/admin</code> somewhere in your template path.</p>
Freely redistributableGoogleAdmin: GMaps base layer in Geographic Admin (GeoDjango)
2008-10-15T14:31:25.833769-05:00jbronnhttps://djangosnippets.org/snippets/1144/<p>This GeoDjango subclass substitutes in the Google Maps base layer instead of the default one provided by Open Street Map. Requires the <a href="http://www.djangosnippets.org/snippets/1145/">google.html</a> and <a href="http://www.djangosnippets.org/snippets/1146/">google.js</a> templates (must be placed in <code>gis/admin</code> somewhere in your template path).<br />
</p>
<p>Requires a Google Maps API key -- please abide by Google's <a href="http://code.google.com/apis/maps/terms.html">terms of service …</a></p>
Freely redistributablewidget to capture a geographic Point
2008-02-25T15:07:00.726792-06:00jerojasrohttps://djangosnippets.org/snippets/615/<p>The class LocationField renders a form field with map (from google maps) and a mark. It allows the user to drag the mark to point at some particular location, whose value (lat, lng) is saved in a hidden field.
</p>
<p>It requires jquery and google maps.
</p>
Freely redistributableMaxMind(R) GeoIP Lite CSV Import
2007-07-18T20:55:43.363148-05:00jbronnhttps://djangosnippets.org/snippets/328/<p>Use this script to import the Maxmind GeoIP lite CSV datasets into your database. This takes at least 200MB of RAM; the resulting database will be ~400MB. Stick in the same directory as the <a href="http://www.djangosnippets.org/snippets/327/">models</a>. Make sure to set <code>DEBUG=False</code> to prevent running out of memory during import.</p>
Freely redistributableMaxMind(R) GeoIP Lite geolocation models
2007-07-18T20:49:11.932111-05:00jbronnhttps://djangosnippets.org/snippets/327/<p>This provides GeoDjango models for the maxmind GeoIP Lite data products. Use the corresponding <a href="http://www.djangosnippets.org/snippets/328/">CSV import script</a> for data import. Requires: <a href="http://code.djangoproject.com/wiki/GeoDjango">GeoDjango</a> and the <a href="http://code.djangoproject.com/attachment/ticket/399/django-bigint-20070712.patch">BigIntegerField patch</a> by Peter Nixon. </p>
Freely redistributableFind nearby objects
2007-04-18T19:21:58.620102-05:00paulsmithhttps://djangosnippets.org/snippets/190/<p>This code assumes a) that you are using PostgreSQL with PostGIS and b) that the geometry column in your model's table is populated with points, no other type of geometry.</p>
<p>It also returns a list instead of a QuerySet, because it was simpler to sort by distance from the given …</p>
Freely redistributable