[[TOC]] = User Guidelines for GIS Data = Assumes installation of the relevant [wiki:GIS#Tools tools] == Import Data == === UUIDs === See: [wiki:UUID#Mapping] === CSV === There is a function available in {{{modules/s3/s3gis.py}}} to import from CSV. The CSV needs to have specific columns: * WKT column if we have polygon info (or Lat Lon for Points, if not) * For L1, we need these columns: ADM0_NAME, ADM1_NAME (& WKT) * For L2, we need these columns: ADM1_NAME, ADM2_NAME (& WKT) [ADM0_NAME can also be used to help separate duplicates] * For L3, we need these columns: ADM2_NAME, ADM3_NAME (& WKT) [ADM1_NAME can also be used to help separate duplicates] * CODE column is read, if-present * Ensure that names are consistent between Levels * The PROPER() spreadsheet function is useful to get the names in the correct format (then Paste as Text). * The VLOOKUP() spreadsheet function is useful if the different levels of the hierarchy are in different sheets & linked via a code instead of the name (as we need) Basic Hierarchy can often be found from Wikipedia (although currently there's no easy way to download this - a student project to enhance Wikipedia for this would be much appreciated!). For the Polygon data, it is normal to get this from Shapefiles (see below). Example for Pakistan: {{{ tablename = "gis_location" table = db[tablename] db.executesql("DROP INDEX name__idx on %s;" % tablename) # L0 import csv csv.field_size_limit(2**20 * 10) # 10 megs db.import_from_csv_file(open("L0.csv", "rb")) db.commit() # L1 gis.import_csv("pak_adm1.csv", check_duplicates=False) db.commit() # L2 db(table.name == "Baluchistan").update(name="Balochistan") db(table.name == "Northern Areas").update(name="Gilgit Baltistan") db(table.name == "N.W.F.P.").update(name="Khyber Pakhtunkhwa") db(table.name == "F.A.T.A.").update(name="FATA") db(table.name == "F.C.T.").update(name="Islamabad") db(table.name == "Azad Kashmir").update(name="AJK") gis.import_csv("pak_adm2.csv", check_duplicates=False) db(table.name == "Sind").update(name="Sindh") db(table.name == "AJK").update(name="Pakistan Administered Kashmir") db(table.name == "FATA").update(name="Federally Administered Tribal Areas") db((table.name == "Islamabad") & (table.level == "L1")).update(name="Federal Capital Territory") db.commit() # L3 db(table.name == "Jaccobabad").update(name="Jacobabad") db(table.name == "Tando Allahyar").update(name="Tando Allah Yar") db(table.name == "Qambar Shahdad kot").update(name="Qambar Shahdadkot") gis.import_csv("pak_adm3.csv", check_duplicates=False) db(table.name == "Islamabad").update(name="Islamabad Capital Territory") db(table.name == "Tando Allah Yar").update(name="Tando Allahyar") db(table.name == "Qambar Shahdadkot").update(name="Qambar Shahdad Kot") db(table.name == "Leiah").update(name="Layyah") db(table.name == "Leiah Tehsil").update(name="Layyah Tehsil") db(table.name == "Kalur Kot Tehsil").update(name="Kallur Kot Tehsil") db(table.name == "De-excluded Area").update(name="Tribal Area") db(table.name == "De-excluded Area D.g Khan").update(name="Tribal Area") db.commit() # L4 db(table.name == "Noorpur Tehsil").update(name="Noorpur Thal Tehsil") jhang = db((table.name == "Jhang") & (table.level==L2)).select(table.id, limitby=(0, 1)).first().id table.insert(name="Ahmadpur Sial", parent=jhang, level="L3", url="http://en.wikipedia.org/wiki/Ahmedpur_Sial_Tehsil") gis.import_csv("punjab_l4.csv", check_duplicates=False) db.commit() db(table.name == "Mirwah Taluka").update(name="Thari Mirwah Taluka") db(table.name == "Shah Bunder Taluka").update(name="Shah Bandar Taluka") badin = db((table.name == "Badin") & (table.level==L2)).select(table.id, limitby=(0, 1)).first().id table.insert(name="Talhar", parent=badin, level="L3", url="http://en.wikipedia.org/wiki/Talhar") jamshoro = db((table.name == "Jamshoro") & (table.level==L2)).select(table.id, limitby=(0, 1)).first().id table.insert(name="Manjhand Taluka", parent=jamshoro, level="L3", url="http://en.wikipedia.org/wiki/Jamshoro_District") gis.import_csv("sindh_l4.csv", check_duplicates=False) db.commit() db(table.name == "F.r Kala Dhaka").update(name="F.R. Kala Dhaka") db(table.name == "Martoong Tehsil").update(name="Martung Tehsil") db(table.name == "Takhat Nasrati Tehsil").update(name="Takht-e-Nasrati Tehsil") dikhan = db((table.name == "D. I. Khan") & (table.level == "L2")).select(table.id, limitby=(0, 1)).first().id table.insert(name="Daraban Tehsil", parent=dikhan, level="L3") table.insert(name="Paroa Tehsil", parent=dikhan, level="L3") lowerdir = db((table.name == "Lower Dir") & (table.level == "L2")).select(table.id, limitby=(0, 1)).first().id table.insert(name="Adenzai", parent=lowerdir, level="L3") table.insert(name="Balambat", parent=lowerdir, level="L3") table.insert(name="Khal", parent=lowerdir, level="L3") table.insert(name="Lal Qila", parent=lowerdir, level="L3") table.insert(name="Munda", parent=lowerdir, level="L3") table.insert(name="Samar Bagh", parent=lowerdir, level="L3") table.insert(name="Tazagram", parent=lowerdir, level="L3") table.insert(name="Timargara", parent=lowerdir, level="L3") upperdir = db((table.name == "Upper Dir") & (table.level == "L2")).select(table.id, limitby=(0, 1)).first().id table.insert(name="Barawal Tehsil", parent=upperdir, level="L3") table.insert(name="Chapar Tehsil", parent=upperdir, level="L3") table.insert(name="Dir Tehsil", parent=upperdir, level="L3") table.insert(name="Khal Tehsil", parent=upperdir, level="L3") table.insert(name="Kalkot Tehsil", parent=upperdir, level="L3") table.insert(name="Wari Tehsil", parent=upperdir, level="L3") gis.import_csv("khyber_l4.csv", check_duplicates=False) db.commit() # 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) db.commit() field = "name" db.executesql("CREATE INDEX %s__idx on %s(%s);" % (field, tablename, field)) }}} === Shapefiles === Inspect the data using [http://qgis.org qGIS]. Use ogr2ogr to convert the data to CSV: {{{ ogr2ogr -f CSV CSV TM_WORLD_BORDERS-0.3.shp -lco GEOMETRY=AS_WKT ogr2ogr -f geojson TM_WORLD_BORDERS-0.3.json TM_WORLD_BORDERS-0.3.shp }}} If needing to reproject (e.g. for the [https://www.geoint-online.net/community/haitiearthquake/Geospatial%20Data%20Files/haiti_departments01132010.zip 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+ === KML === Can convert a KML to CSV using the attached script: {{{python KML2WKT.py .kml}}} * requires [http://pypi.python.org/pypi/keytree/ keytree] This can then be imported into Sahana by editing the column headers & using {{{gis.import_csv(.csv)}}} qGIS can be used to convert this into a Shapefile (uses ogr2ogr so can also do using the CLI, if you prefer): give it column headers with 'WKT' for the WKT column name. * This is the easiest way to load into [wiki:InstallationGuidelinesGISDataLinux#PostGIS PostGIS] (using PGAdmin III's SHapefile Importer plugin) to allow !GeoServer to serve as WMS === Geonames === There is an import_geonames() function in S3GIS which downloads/unzips the country file (a TAB-separated list) from http://download.geonames.org/export/dump/ It should be run for the different levels of 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! Update: Geonames schema 2.2 supports parentADM(1-4): http://geonames.wordpress.com/2010/09/29/geonames-ontology-2-2/ * will be good for when we only have hierarchy, not polygons * need to check whether much data has this populated though. Python 2.5 doesn't support Zipfile.extract() & Zipfile.read() isn't unicode-safe. Until this is fixed, download the file manually 1st: {{{ cd ~web2py/applications/eden/cache wget http://download.geonames.org/export/dump/PK.zip unzip PK.zip }}} In Web2py CLI: {{{ gis.import_geonames('PK', 'L5') db.commit() }}} Alternate approach: 1. Transform each line in this file into XML by regular expression: {{{ ^(\d*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([0-9\.]*)\t([0-9\.]*)\t[^\t]*\t([A-Z]*).* into: $1 $2 $3 $4 $5 $6 $7 }}} This can be done using an RE-capable editor (e.g. Kate), Perl or even Python. Note: Need to replace & with & and to remove any invalid characters 2. Transform into S3XRC-XML using XSLT, stylesheet is available at * [http://pub.nursix.org/eden/geonames/geonames.xsl] === !OpenStreetMap === See below: [wiki:UserGuidelinesGISData#Import] === WFS === 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: * ESRI's Spherical Mercator ([http://www.cadmaps.com/gisblog/?p=81 different] to 900913) http://spatialreference.org/ref/esri/54004/proj4/ 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. === Yahoo === * http://developer.yahoo.com/geo/geoplanet/data/ * Script to process http://pastie.org/1139680 == Display Data == === !GeoServer === !GeoServer can provide geospatial data in Raster (WMS) or Vector (WFS/KML) formats. Once you have installed in [wiki:InstallationGuidelinesGISDataLinux#GeoServer Linux] or [wiki:InstallationGuidelinesGISDataWindows#GeoServer Windows], then login: * l: admin * p: geoserver [wiki:InstallationGuidelinesGISDataLinux#PostGIS PostGIS] is recommended as the main data store. Configure: * [http://geo.eden.sahanafoundation.org/geoserver/web/?wicket:bookmarkablePage=:org.geoserver.web.security.user.UserPage Admin Password] * [http://geo.eden.sahanafoundation.org/geoserver/web/?wicket:bookmarkablePage=:org.geoserver.web.admin.ContactPage Contact Details] * [http://geo.eden.sahanafoundation.org/geoserver/web/?wicket:bookmarkablePage=:org.geoserver.web.admin.GlobalSettingsPage Disable Global Services] (2.1+ only) * [http://geo.eden.sahanafoundation.org/geoserver/web/?wicket:bookmarkablePage=:org.geoserver.wfs.web.WFSAdminPage WFS Details] * [http://geo.eden.sahanafoundation.org/geoserver/web/?wicket:bookmarkablePage=:org.geoserver.wms.web.WMSAdminPage WMS Details] inc the Limited SRS List - probably to just: {{{4326, 900913}}} * Disable the demo [http://geo.eden.sahanafoundation.org/geoserver/web/?wicket:bookmarkablePage=:org.geoserver.web.data.layer.LayerPage Layers] & [http://geo.eden.sahanafoundation.org/geoserver/web/?wicket:bookmarkablePage=:org.geoserver.web.data.layergroup.LayerGroupPage Layer Groups] * Add [http://geo.eden.sahanafoundation.org/geoserver/web/?wicket:bookmarkablePage=:org.geoserver.web.data.workspace.WorkspacePage Workspace] * Add [http://geo.eden.sahanafoundation.org/geoserver/web/?wicket:bookmarkablePage=:org.geoserver.web.data.store.StorePage PostGIS Store] * http://docs.geoserver.org/stable/en/user/gettingstarted/web-admin-quickstart/index.html ==== Import Shapefiles ==== e.g. Country Outlines: * http://thematicmapping.org/downloads/TM_WORLD_BORDERS-0.3.zip These can be loaded direct into !GeoServer, however there will be better performance by importing into PostGIS: [[BR]](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); }}} For GADM: {{{ mkdir gadm cd gadm wget http://gadm.org/data/gadm_v1_lev0_shp.zip wget http://gadm.org/data/gadm_v1_lev1_shp.zip wget http://biogeo.ucdavis.edu/data/gadm/gadm_v1_lev2_shp.zip unzip gadm_v1_lev0_shp.zip unzip gadm_v1_lev1_shp.zip unzip gadm_v1_lev2_shp.zip su postgres createuser -s -P gadm # Mixed encodings! http://ww.gadm.org/node/287 createdb -O gadm -E SQL_ASCII gadm -T template0 createlang plpgsql -d gadm psql -d gadm -f /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql psql -d gadm -f /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql shp2pgsql -s 4326 -I gadm1_lev0.shp public.gadm1_lev0 | psql -d gadm shp2pgsql -s 4326 -I gadm1_lev1.shp public.gadm1_lev1 | psql -d gadm shp2pgsql -s 4326 -I gadm_v1_lev2.shp public.gadm1_lev2 | psql -d gadm }}} ==== Configure !GeoServer ==== * Add [http://geo.eden.sahanafoundation.org/geoserver/web/?wicket:bookmarkablePage=:org.geoserver.web.data.layer.LayerPage Layer] * Add [http://geo.eden.sahanafoundation.org/geoserver/web/?wicket:bookmarkablePage=:org.geoserver.wms.web.data.StylePage Style] for WMS presentation: * http://docs.geoserver.org/stable/en/user/styling/sld-introduction.html * Publish * Apply Style Colours: * http://www.colorsontheweb.com/colorwizard.asp Zoom Levels (in Spherical Mercator): ||= Zoom Level(s) =||= !MinScale =||= !MaxScale =|| || 1-3 || 50000000 || n/a || || 4 || 25000000 || 50000000 || || 5 || 10000000 || 25000000 || || 6 || 5000000 || 10000000 || || 7 || 2500000 || 5000000 || || 8 || 2000000 || 2500000 || || 9 || 1000000 || 2000000 || || 10 || 500000 || 1000000 || || 11 || 250000 || 500000 || || 12-22 || n/a || 250000 || ==== WFS ==== If you are displaying a complex dataset at zoomed-out resolutions, then you will want to have simplified views. e.g. Hospitals aren't shown at all at low zooms, are shown as Points at medium zooms & shown as Polygons at high zooms. Scale-dependent styling using SLD in !GeoServer: * http://ian01.geog.psu.edu/geoserver_docs/data/naturalearth/naturalearth_physical.html Scale-dependent styling in !OpenLayers: * http://docs.openlayers.org/library/feature_styling.html#custom-rules Simplifying Polygons in PostGIS: * http://linfiniti.com/2011/06/scale-dependent-generalization-in-postgis-and-qgis/ Showing the different layers at different zooms using !GeoServer: * http://docs.geoserver.org/stable/en/user/tutorials/feature-pregeneralized/feature-pregeneralized_tutorial.html {{{ cd wget http://kent.dl.sourceforge.net/project/geoserver/GeoServer%20Extensions/2.1.0/geoserver-2.1.0-feature-pregeneralized-plugin.zip cd /var/lib/tomcat6/webapps/geoserver/WEB-INF/lib/ unzip ~/geoserver-2.1.0-feature-pregeneralized-plugin.zip /etc/init.d/tomcat6 restart }}} ==== Add WMS Layer to Sahana Eden ==== * ''tbc'' === WMS Reprojection === * Have a remote WMS source that you want to access? * Have a desire to keep !OpenStreetMap/Google/Bing layers? * WMS source server doesn't support the 900913 projection? e.g. TRMM Rainfall Monitoring Solution: [wiki:InstallationGuidelinesGISDataLinux#ConfigurationforTRMM MapProxy] === Grid === We have a 'Coordinate Grid' Layer available by default. Other options: * [wiki:BluePrintGISGrid] === Topographic Maps === ==== WMS ==== Topography can be rendered as WMS using e.g. !GeoServer Download the SRTMs in GeoTIFF format from ftp://xftp.jrc.it/pub/srtmV4/tiff * [http://eden.sahanafoundation.org/attachment/wiki/UserGuidelinesGISData/get.sh get.sh] can assist with this * Beware this is a *lot* of data! (At least 60Gb for a global dataset) * The GeoTIFFs are already well [http://linfiniti.com/2011/05/gdal-efficiency-of-various-compression-algorithms/ compressed] * Partial datasets are, of course, possible (@!ToDo: A script to select an area & download just that area) {{{ mkdir /tmp/SRTMv4 cd /tmp/SRTMv4 sh get.sh }}} Unzip the data into a folder called 'SRTMv4' in the !GeoServer 'coverages' folder (or use a symlink): {{{ cd /var/lib/tomcat6/webapps/geoserver/data/coverages mkdir SRTMv4 unzip -o /tmp/SRTMv4/\*.zip rm /var/lib/tomcat6/webapps/geoserver/data/coverages/SRTMv4/*.hdr rm /var/lib/tomcat6/webapps/geoserver/data/coverages/SRTMv4/*.tfw rm /var/lib/tomcat6/webapps/geoserver/data/coverages/SRTMv4/readme.txt }}} Give Tomcat permission to the folder: {{{ chown tomcat6 /var/lib/tomcat6/webapps/geoserver/data/coverages/SRTMv4 }}} Configure !GeoServer by adding a new Store using the [http://docs.geoserver.org/stable/en/user/tutorials/image_mosaic_plugin/imagemosaic.html Image mosaicking plugin] * URL: file:coverages/SRTMv4 Publish (defaults OK) Styling: * [http://eden.sahanafoundation.org/attachment/wiki/UserGuidelinesGISData/srtm.sld srtm.sld] 'official' * [http://eden.sahanafoundation.org/attachment/wiki/UserGuidelinesGISData/topography.sld topography.sld] 'common usage' Test out using the direct WMS URL: * http://host.domain/geoserver/service/wms Once happy then start using the !GeoCache URL (but don't do this too early as otherwise you have to invalidate the cache to see your changes): * http://host.domain/geoserver/gwc/service/wms ==== !OpenStreetMap ==== Contours can be rendered using OSM tools: * [wiki:InstallationGuidelinesGISDataLinux#Contours] * http://wiki.openstreetmap.org/wiki/Contours * Uses [http://wiki.openstreetmap.org/wiki/SRTM SRTM] ([http://wiki.openstreetmap.org/wiki/ASTER ASTER] is a future possibility) * Alternate approach: [http://wiki.openstreetmap.org/wiki/Srtm2Osm SRTM 2 OSM] === Old Printed Maps === Old Printed Maps can be 'Rectified' to be overlaid on the base maps: * [wiki:BluePrintGISRectifier] == !OpenStreetMap == === 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) * [wiki:BluePrintGISOSMLayers] === Import === We have an XSLT [http://eden.sahanafoundation.org/browser/static/formats/osm/import.xsl stylesheet] to import .osm files e.g for hospitals and clinics: {{{ osmosis --read-xml country.osm --tf accept-nodes amenity=hospital,clinic --tf reject-ways --tf reject-relations --write-xml nodes.osm osmosis --read-xml country.osm --tf reject-relations --tf accept-ways amenity=hospital,clinic --used-node --write-xml ways.osm osmosis --rx nodes.osm --rx ways.osm --merge --wx country_hospitals.osm http://myhost.com/eden/hms/hospital/create.osm?filename=country_hospitals.osm }}} This needs more work to understand the admin hierarchy properly to be able to import Places. * http://wiki.openstreetmap.org/wiki/Map_Features#Places * http://wiki.openstreetmap.org/wiki/Placename_hierachies is_in tag Geofabrik have updated extracts daily for Pakistan: * http://download.geofabrik.de/osm/asia/pakistan.osm.bz2 Otherwise pull a BBOX directly using Osmosis: * http://wiki.openstreetmap.org/wiki/Osmosis Osmosis requires Java. Python options for filtering based on tag, which would be more suitable for integration within Sahana, however we need to add Polygon filtering using Shapely: * http://dev.omniscale.net/imposm.parser/ * [http://pbf.raggedred.net ParsePBF] * http://blog.lifeeth.in/2011/02/extract-pois-from-osm-pbf.html Ruby script to generate KML of recently-added locations by a group of users: * http://github.com/vertis/osm_export/tree/master === Basemap for Garmin GPS === * [wiki:UserGuidelinesGISDataOpenStreetMapGarmin] == PostgreSQL management == * [wiki:InstallationGuidelinesPostgreSQL#Maintenance] === PostGIS functions === * Centroids {{{ SELECT name, iso2, asText(ST_Transform(ST_Centroid(the_geom), 4326)) AS centroid FROM countries; }}} == Data Sources == * Admin 0 & 1, Hydro features, Raster & Vector: http://www.naturalearthdata.com/ === L0 === * http://www.gadm.org * http://www.naturalearthdata.com/ * VMap0: http://en.wikipedia.org/wiki/Vector_Map * http://barendgehrels.blogspot.com/2010/12/free-shapefile-of-countries-of-world.html * http://barendgehrels.blogspot.com/2010/12/free-shapefiles-of-of-world-2.html * http://barendgehrels.blogspot.com/2010/12/free-shapefiles-of-of-world-3.html * http://barendgehrels.blogspot.com/2011/01/free-shapefiles-of-countries-of-world-4.html * http://thematicmapping.org/downloads/world_borders.php * UN (North Africa): http://unosat-sdn.web.cern.ch/unosat-sdn/northafrica/region/ungiwg_level0_region.zip === L1 === * http://www.gadm.org * http://www.naturalearthdata.com/ * http://geonames.org * US: http://www.mapcruzin.com/free-united-states-arcgis-maps-shapefiles.htm === L2 === * SALB (High-quality, country-verified, but not all countries): http://www.unsalb.org/ * http://www.gadm.org * http://geonames.org * California: http://swdb.igs.berkeley.edu/pub/data/GEOGRAPHY/DECENNIAL2010/state_county_2010_shp.zip === OGC (WMS/WFS) === * http://geonetwork-opensource.org/gallery.html#geonetwork-nodes * http://www.ogc-services.net * !BlueMarble & Mosaic (!LandSat7): http://onearth.jpl.nasa.gov/ * Hazard Layers: http://preview.grid.unep.ch:8080/geoserver/ows?service=WMS&request=GetCapabilities * Hazard Layers: http://www.pdc.org/mde/services.jsp * Massachusetts: http://lyceum.massgis.state.ma.us/wiki/doku.php ---- [wiki:GIS]