[Users] GeoJSON vs WKT

Knut Staring knutst at gmail.com
Mon May 24 15:48:38 CEST 2010


Dear list,

I was wondering if there are any criteria for choosing between GeoJSON
or WKT when feeding GeoExt from the database? I care about both
transmission size (since many users will have low bandwidth) and
processing (users may have low spec hardware, and even the latest
Chrome and Opera struggle with too large geometries).

WKT looks more compact, in that there are much fewer square brackets.
But since browsers speak javascript, it may be heavier to process?

I've written some PHP to generate GeoJSON, like this:
http://109.74.202.200/ke/geojson.php, which feeds into
http://109.74.202.200/ke/feature-grid.html in the following way:

protocol: new OpenLayers.Protocol.HTTP({
                url: "geojson.php",
		format: new OpenLayers.Format.GeoJSON()
            })

However, looking at http://waterandhealth.eu/, I notice that WKT is
used rather than GeoJSON:
http://waterandhealth.eu/php/geometries.php

Here is a snippet from the javascript:

Atlas.data.store.GeometryStore = Ext.extend(Ext.data.JsonStore, {
    features: [],
    countryRoot: null,
    constructor: function (a) {
        Ext.apply(this, a);
        Atlas.data.store.GeometryStore.superclass.constructor.call(this,
Ext.apply({
            proxy: new Ext.data.HttpProxy({
                url: "php/geometries.php",
                method: "POST"
            }),
            root: "geometries",
            fields: ["fid", "geom", "country_id", "country_name"]
        }, a));
        this.addEvents("featureLoad");
        this.on("load", function () {
            this.data.each(function (e, b, f) {
                var d = OpenLayers.Geometry.fromWKT(e.get("geom"));
                var c = new OpenLayers.Feature.Vector(d, {
                    id: e.get("fid"),
                    countryId: e.get("country_id"),
                    countryName: e.get("country_name"),
                    value: -1
                });
                this.features.push(c)
            }, this);
            this.fireEvent("featureLoad")
        })
    },
    getFeatures: function () {
        var c = this.features;
        var d = [];
        for (var b = 0; b < c.length; b++) {
            var a = c[b].clone();
            d.push(a)
        }
        return d
    }
});

Grateful for any guidance.

Cheers,
Knut


More information about the Users mailing list