Archive

Author Archives: underdark

gis.stackexchange.com (not live yet) could soon be the new Q&A site for anyone interested in GIS. The technology is based on Stack Overflow, meaning that users can rate answers to the questions so that the best one shows up first. If you would like to see this happen, support the proposal here: http://area51.stackexchange.com/proposals/1425/geographic-information-systems?referrer=gnmvpv_s0afgMMEpzVsZAg2.

Update: gis.stackexchange.com is now in Private Beta!

SpatiaLite Manger in QGIS 1.5

SpatiaLite Manager connected to example database (additional data from Natural Earth)

SpatiaLite Manager is a plugin for QGIS for managing spatial data in SpatiaLite databases. It’s based on the PostGIS Manager plugin that provides equal functionality for PostGIS.

In the database view, all tables are listed and it’s easy to distinguish between tables, views and spatial tables of different geometry types. On the right, different tabs show table meta data, table and a map preview for geometry tables.

Additionally, there is an SQL window that allows execution of statements from inside QGIS.

While there’s certainly room for additional functions, this is a great start and facilitates working with SpatiaLite databases considerably. Possible enhancements could be:

  • Functionality to create new layers from within SpatiaLite Manager (now only available through “Add new layer”).
  • SPIT-like importer for shapefiles

Based on QGIS libraries, Marco Hugentobler an his team are developing a QGIS webserver. It’s a WMS server aiming at ease of use and cartographic richness. The project home page can be found at http://karlinapp.ethz.ch/qgis_wms/index.html.

QGIS libraries are used for the underlying GIS logic and map rendering. QGIS Mapserver supports Linux, WinXP and MacOSX and is licensed under GPL.

While some countries give away geographic data for free, in other parts of the world geodata is either expensive or non-existent. Still there are sources that can help you get started with your work or even just provide a base for your GIS experiments.

OpenStreetMap

Probably the best source for road data and other infrastructure data: http://www.openstreetmap.org/.

Natural Earth

Natural Earth is a public domain map dataset available at 1:10m, 1:50m, and 1:110 million scales. (See http://www.naturalearthdata.com/.) You can find a big amount of raster and vector datasets covering the whole world there.

FreeGIS.org

FreeGIS.org is another great source both for GIS software news and data. They host a database linking to many useful sources (http://freegis.org/database/?cat=1).

Looking for a complete list of functions supported by SpatiaLite 2.3.1? Here it is: SpatiaLite 2.3.1 – SQL functions reference list This is a great place to get a feeling for just how powerful SpatiaLite is.

One nice convenience function listed is MakePoint(). It’s a nice alternative to GeomFromText as described in SpatiaLite GeomFromText() for Points. The syntax is:
MakePoint( x Double precision , y Double precision , [ , SRID Integer] ) : Geometry

SpatiaLite supports a number of SQL functions that test spatial relationships both on MBRs and actual geometries: Equals, Disjoint, Touches, Within, Overlaps, Crosses, Intersects, Contains, and Relate. Of course you can also calculate distances between geometries. Furthermore, SpatiaLite supports the following spatial operators: Intersection, Difference, Union (called GUnion()), SymDifference, Buffer, and ConvexHull.


14NewLayerOriginally uploaded by linfiniti.com

A new great feature for QGIS 1.5: You can create new layers in SpatiaLite!

Ooop, there’s not even an English Wikipedia article on SpatiaLite … Well, SpatiaLite is the spatial extension for SQLite, like PostGIS is the extension for PostgreSQL. SpatiaLite makes data exchange so much easier. Just copy the database file to some other location and use it there. The database can contain any number of spatial tables, all neatly packaged in one file. No more Shapefiles without .prj or .dbf file. *dream* :)

Also check out Tim’s other latest screenshots: http://www.flickr.com/photos/linfiniti/

Will we really live to see the end of the Shapefile? One can always hope …

Assuming you already have a table containing x and y coordinates (WGS84) as integers:

spatialite> SELECT AddGeometryColumn('tablename','Geometry',4326,'POINT',2);
spatialite> UPDATE tablename SET Geometry = GeomFromText('POINT('||x||' '||y||')',4326);

SpatiaLite doesn’t need to be installed [1], just get SpatiaLite and unpack it in – for example – ~/apps (tested on Ubuntu 9.4):

~$ mkdir apps
~$ cd apps
~/apps$ wget http://www.gaia-gis.it/spatialite/spatialite-tools-linux-x86-2.3.1.tar.gz
~/apps$ tar xvfz spatialite-tools-linux-x86-2.3.1.tar.gz

Now you should be able to run it. Let’s create a test database:

~/apps$ cd ~/temp
~/temp$ ~/apps/spatialite-tools-linux-x86-2.3.1/bin/spatialite testdb.sqlite

Then we have to initialize the new database with some metadata. We need a script called init_spatialite-2.3.sql (get it from http://www.gaia-gis.it/spatialite-2.3.1/resources.html). It will create the tables “geometry_columns” and “spatial_ref_sys”.

spatialite> .read '~/init_spatialite-2.3.sql' ASCII

For testing purposes, we’ll now load a shapefile into our new database. I used a Teleatlas street graph (attribute encoding iso-8859-15) and created a “streets” table:

spatialite> .loadshp ~/maps/streetgraph streets iso-8859-15

Finally, we register the geometry columns … pretty similar to PostGIS:

spatialite> UPDATE streets SET Geometry = SetSrid(Geometry,4326);
spatialite> SELECT RecoverGeometryColumn('streets','Geometry',4326,'LINESTRING',2);

Done! That’s it. Now we can view our test data in QGIS. For a longer Tutorial check http://www.gaia-gis.it/spatialite/spatialite-tutorial-2.3.1.html

[1] http://www.gaia-gis.it/spatialite/install-linux.html

For all of us who can’t remember OSM’s tags by heart there is help out there: The OpenStreetMap Cheat Sheet summarizes all OSM tags on just one page. Great!

The OGC filter encoding standard – for whatever reason – lacks the useful IN operator we know and love from other languages like SQL [1]. Geoserver developers have therefore implemented this functionality as a non-standard SLD function [2]. Unfortunately this implementation requires prior knowledge of the number of arguments in the IN clause and it’s limited to 10 arguments.

An example filter would look like this:

<ogc:Filter>
   <ogc:PropertyIsEqualsTo>
       <ogc:Function name="in3">
          <ogc:PropertyName>first_name</ogc:PropertyName>
          <ogc:Literal>Paul</ogc:Literal>
          <ogc:Literal>Mary</ogc:Literal>
          <ogc:Literal>Luke</ogc:Literal>
       </ogc:Function>
       <ogc:Literal>true</ogc:Literal>
   </ogc:PropertyIsEqualsTo>
</ogc:Filter>

[1] https://underdark.wordpress.com/2010/06/14/the-missing-in-operator-ogc-filter-standards/
[2] http://docs.geoserver.org/stable/en/user/styling/sld-tipstricks/mixed-geometries.html#using-non-standard-sld-functions