Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More

Geographic Information Systems (GIS) in Lino

use_gis

If set to True, Lino will check that the database is PostGIS capable and will load the GIS related code.

This requires the database to be postgresql with the PostGIS extension.

During prep in initdb Lino creates the PostGIS extension if it is not already there. Which requires root (actually the user postgres) user in psql to run actually CREATE EXTENSION postgis; command in the database, so prep now asks for sudo password to do that.

class lino_xl.lib.polygon.AdminLevels

The AdminLevels choicelist defines the supported administrative levels.

The administrative levels (e.g., ADM1 for provinces, ADM2 for districts) that can be imported and stored in the database. Each level corresponds to a specific tier of administrative division, and the importer validates that all detected levels in the input GeoJSON files are configured here.

The value`s of the choices must correnspond to the digits in an administrative level code (e.g., ‘1’ for ADM1, ‘2’ for ADM2). The `text is a human-readable label (e.g., “Province”, “District”). You can extend this choicelist to support additional levels as needed.

class lino_xl.lib.polygon.PlaceFeature

The PlaceFeature model represents the geometric boundaries of a geographic place.

A place (e.g., a province, district, etc.) as a MultiPolygon. Each feature is linked to a Place record that contains the hierarchical administrative information (name, level, parent). The importer creates or updates these features based on the input GeoJSON data, merging geometries when necessary to avoid duplicates.

place

A foreign key to the associated Place<lino_xl.lib.countries.Place record.

This links the geometric feature to its administrative information (name, level, parent).

geometry

A MultiPolygonField that stores the geometric boundaries of the place.

This field contains the actual geographic shape of the administrative region as defined in the input GeoJSON files.

representative_point

A PointField that stores a representative point (e.g., centroid) of the geometry.

This is used for spatial operations like parent hierarchy detection, where the importer checks if this point falls within a parent region’s geometry to establish hierarchical links.

May also, acts as the Locateable.location for any subclasses of Locateable when the user doesn’t explicitly set a location.

class lino_xl.lib.polygon.Locateable

A model mixin to be used for any model that should have a geographic location.

location

A PointField that stores the geographic location of the object.

This field can be used for any model that needs to have a specific geographic point associated with it (e.g., a city center, a landmark, etc.). When used in conjunction with PlaceFeature, it can default to the representative_point if not explicitly set by the user.

place_ladml

A foreign key to a Place that represents the administrative region where this object is located.

This allows any locateable object to be linked to a specific administrative place, enabling queries and operations based on geographic location and administrative hierarchy.

street_addr

A CharField for storing a street address.

This can be used to store a human-readable address for the object, which can be useful for display purposes or for geocoding operations to determine the location point.

set_location

An action to invoke geocoding based on the HTML5 Geolocation API, or android native API when invoked from a webview.

resolve_location

An action that uses geocoding to resolve the adminitrative place based on the location point.

This can be used to automatically link a locateable object to the correct administrative region based on its geographic coordinates.

Importing administrative boundaries

The import_geoboundaries command loads geoBoundaries GeoJSON files into countries.Place (hierarchy) and PlaceFeature (geometry) for all admin levels present in the input.

python manage.py import_geoboundaries /path/to/geoboundaries --country bd

Pass --dry-run to validate without writing to the database. Pass one or more files instead of a directory to import specific levels only.

Parent links between levels are detected by spatial containment: each child feature’s representative point is checked against parent geometries, with a nearest-neighbour fallback for simplified boundaries. Geometries for the same place are merged into a single MultiPolygon to avoid duplicates.

All detected levels must be present in AdminLevels; the command fails with a clear error if any are missing.