Version 90 (modified by Fran Boon, 14 years ago) ( diff )


User Guidelines for GIS Data

Assumes installation of the relevant tools: InstallationGuidelinesGISData

Import Data

See current urgent task: PakistanUnionCouncils




There is an import_geonames() function in S3GIS which downloads/unzips the country file (a TAB-separated list) from

It should be run for the different level sof hierarchy that you wish to import (generally just the lowest level as Geonames just has Point data, so it's best to use other sources for the Polygons 1st, that way the Geonames importer can locate these Points within the correct Polygons of the hierarchy)

NB It takes some time to do this import! Pakistan imports 95000 locations!

Python 2.5 doesn't support Zipfile.extract() & isn't unicode-safe. Until this is fixed, download the file manually 1st:

cd ~web2py/applications/eden/cache

In Web2py CLI:

gis.import_geonames('PK', 'L5')

Alternate approach:

  1. Transform each line in this file into XML by regular expression:

This can be done using an RE-capable editor (e.g. Kate), Perl or even Python. Note: Need to replace & with &amp; and to remove any invalid characters

  1. Transform into S3XRC-XML using XSLT, stylesheet is available at


See below: UserGuidelinesGISData


Inspect the data using qGIS.

Use ogr2ogr to convert the data:

ogr2ogr -f geojson TM_WORLD_BORDERS-0.3.json TM_WORLD_BORDERS-0.3.shp

If needing to reproject (e.g. for the Haiti Departements):

ogr2ogr -f CSV haiti_departments Haiti_departementes_edited_01132010.shp -s_srs EPSG:32618 -t_srs EPSG:4326 -lco GEOMETRY=AS_WKT

NB AS_WKT requires OGR v1.6+

There is a function available in modules/ to import from CSV.

Example for Pakistan:

tablename = "gis_location"
table = db[tablename]
db.executesql("DROP INDEX name__idx on %s;" % tablename)
# L0
db( < 166).delete()
db( > 166).delete()
import csv
csv.field_size_limit(2**20 * 10)  # 10 megs
db.import_from_csv_file(open("L0.csv", "rb"))
# L1
gis.import_csv("pak_adm1.csv", check_duplicates=False)
# L2
db( == "Baluchistan").update(name="Balochistan")
db( == "Northern Areas").update(name="Gilgit Baltistan")
db( == "N.W.F.P.").update(name="Khyber Pakhtunkhwa")
db( == "F.A.T.A.").update(name="FATA")
db( == "F.C.T.").update(name="Islamabad")
db( == "Azad Kashmir").update(name="AJK")
gis.import_csv("pak_adm2.csv", check_duplicates=False)
db( == "Sind").update(name="Sindh")
db( == "AJK").update(name="Pakistan Administered Kashmir")
db( == "FATA").update(name="Federally Administered Tribal Areas")
db(( == "Islamabad") & (table.level == "L1")).update(name="Federal Capital Territory")
# L3
db( == "Jaccobabad").update(name="Jacobabad")
db( == "Tando Allahyar").update(name="Tando Allah Yar")
db( == "Qambar Shahdad kot").update(name="Qambar Shahdadkot")
gis.import_csv("pak_adm3.csv", check_duplicates=False)
db( == "Islamabad").update(name="Islamabad Capital Territory")
db( == "Tando Allah Yar").update(name="Tando Allahyar")
db( == "Qambar Shahdadkot").update(name="Qambar Shahdad Kot")
db( == "Leiah").update(name="Layyah")
db( == "Leiah Tehsil").update(name="Layyah Tehsil")
db( == "Kalur Kot Tehsil").update(name="Kallur Kot Tehsil")
db( == "De-excluded Area").update(name="Tribal Area")
db( == "De-excluded Area D.g Khan").update(name="Tribal Area")
# L4
gis.import_csv("punjab_l4.csv", check_duplicates=False)
gis.import_csv("sindh_l4.csv", check_duplicates=False)
gis.import_csv("khyber_l4.csv", check_duplicates=False)
# L5
gis.import_csv("punjab_l5.csv", check_duplicates=False)
gis.import_csv("sindh_l5.csv", check_duplicates=False)
gis.import_csv("khyber_l5.csv", check_duplicates=False)
field = "name"
db.executesql("CREATE INDEX %s__idx on %s(%s);" % (field, tablename, field))



It is possible to use the WFS Plugin to get data into qGIS & thence export into other formats.

May need to use a Custom CRS (in Settings menu - remember to Save!) such as:

Can then go to the Layer Properties & Specify CRS to this User Defined Coordinate System.

Can then Save As and change the CRS to something like the standard WGS84.

Display Data


GeoServer can provide geospatial data in Raster (WMS) or Vector (WFS/KML) formats.

Once you have installed (Linux, Windows), then login:

  • l: admin
  • p: geoserver


Import Shapefiles

e.g. Country Outlines:

These can be loaded direct into GeoServer, however there will be better performance by importing into PostGIS:
(can also use pgAdmin III GUI's Shapefile loader on plugins menu)

su postgres
shp2pgsql -s 4326 -I TM_WORLD_BORDERS-0.3.shp public.countries | psql -d gis

To reproject the data into 900913 for a slight performance advantage:

drop constraint srid;
update table set geomcolumn=transform(geomcolumn,900913);

Configure GeoServer

Add WMS Layer to Sahana Eden

  • tbc


tbc: BluePrintGISGrid

Topographic Maps

Old Printed Maps

Old Printed Maps can be 'Rectified' to be overlaid on the base maps:


Base Map

We have out-of-the-box the ability to use OpenStreetMap Tiles as base layer.

This can include local OSM sites (OSM Taiwan is included as an example)

Vector Overlays

Can have OSM Vectors displayed over the top of other Base Layers (e.g. Satellite Images)


We have an XSLT stylesheet to import .osm files, but this needs work to understand the admin hierarchy properly.

Geofabrik have updated extracts daily for Pakistan:

Otherwise pull a BBOX directly using Osmosis:

Ruby script to generate KML of recently-added locations by a group of users:

Basemap for Garmin GPS

PostgreSQL management

  • Connect to Database (or use pgAdmin III GUI's PSQL Console on plugins menu)
    su postgres


psql -d my_spatial_db -U username
  • List Databases
  • List Tables
  • List Table structure
    \d tablename
    select field/* from tablename where field = 'value';

PostGIS functions

  • Centroids
    SELECT name, iso2, asText(ST_Transform(ST_Centroid(the_geom), 4326)) AS centroid FROM countries;

Data Sources



Attachments (12)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.