Archive

Tag Archives: GIS

Adding a unique ID to an (editable) layer in QGIS is easy:

  1. Turn editing on and
  2. go to field calculator, there you can
  3. add a new column and
  4. populate it using “rownum”

QGIS Field Calculator Operators incl. "rownum"

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!

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).

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

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

%d bloggers like this: