Archive

Author Archives: underdark

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

Martin Dobias’ weekly reports on his project to speed up QGIS [1] are being published on QGIS wiki.

Currently, we’re in week #4 and things look good! Thumbs up!

[1] http://blog.qgis.org/node/144

It sounds incredible, but it’s true: OGC Filter Encoding in it’s current version 1.1 lacks an IN operator [1]. Combining multiple PropertyIsEqualTo using ORs performs really badly both on Arcgis Server [2] and Geoserver [3]. That calls for the implementation of this standard-exceeding IN operator. Maybe PropertyIsIn?

[1] http://www.opengeospatial.org/standards/filter
[2] http://viswaug.wordpress.com/2009/01/20/filter-encoding-standard-11-and-the-curious-case-of-the-missing-in-operator/
[3] https://underdark.wordpress.com/2010/06/10/dynamic-styling-and-filtering-of-a-geoserver-wms-using-openlayers-layer-wms-post/

There is a new layer class in OpenLayers API: OpenLayers.Layer.WMS.Post [1]. – Great work!

While the “normal” OpenLayers.Layer.WMS class requests maps via HTTP GET, this new class sends the request via HTTP POST. This way, we can now send big client-side created SLD files in our GetMap requests that used to exceed size limits of GET.

This code snippet shows the basic use of OpenLayers.Layer.WMS.Post with a client-side created SLD. You’ll need at least OpenLayers 2.9 to test this on your server. (A full example can be found at http://www.openlayers.org/dev/examples/wms-long-url.html)

var sld = 'define your SLD here';

wms = new OpenLayers.Layer.WMS.Post(
  "name",
  "http://localhost:8080/geoserver/wms",
  {
    'layers': 'myNs:layername',
    format: 'image/jpeg',
    sld_body: sld
  },
  {
    unsupportedBrowsers: []
  }
);

Setting unsupportedBrowsers to an empty list is important! This list by default contains [“mozilla”, “firefox”, “opera”]. These browsers support long GET requests so the developers argued that these browsers wouldn’t need to use POST. Well, turns out that they do ;)

I performed a small stress test using an SLD with approximately 1,000 rules being applied on a big city road network. While my browser would willingly send a GET request of that size, Apache doesn’t want to accept it. So, I tried the POST way and it turns out that it really works! (But it’s slow, very slow …)

Thanks to the developers for yet another great feature!

[1] http://trac.openlayers.org/ticket/2224

During this year’s Google Summer of Code Martin Dobias will work on speeding up QGIS [1]. His goals are:

  1. Introduce parallelism into rendering
  2. Improve user experience when browsing map
  3. Optimization of map rendering
  4. Miscellaneous optimizations

[1] http://blog.qgis.org/node/144