[GIS] Extracting Earthquake Depth from the USGS GeoJson Earthquake Feed for use with Openlayers

geojsonopenlayers-2

I have some GeoJson from the USGS as follows:

{"type":"Feature","properties":{"mag":4.3,"place":"30km ESE of Jarm, Afghanistan","time":1382069641720,"updated":1382071013039,"tz":270,"url":"http://earthquake.usgs.gov/earthquakes/eventpage/usb000kg6q","detail":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/usb000kg6q.geojson","felt":0,"cdi":1,"mmi":null,"alert":null,"status":"reviewed","tsunami":null,"sig":284,"net":"us","code":"b000kg6q","ids":",usb000kg6q,","sources":",us,","types":",cap,dyfi,general-link,geoserve,nearby-cities,origin,phase-data,tectonic-summary,","nst":null,"dmin":2.372,"rms":0.49,"gap":112,"magType":"mb","type":"earthquake","title":"M 4.3 - 30km ESE of Jarm, Afghanistan"},"geometry":{"type":"Point","coordinates":[71.1215,36.7111,215.63]},"id":"usb000kg6q"},

The geometry contains 3 dimensional data, where it is necessary to set the GeoJSON.ignoreExtraDims parameter to true to ignore that third dimension to load the Geojson into a Vector Layer

This third dimension appears to be the depth of the Earthquake! How can i get access to this if it does not appear in the data in the Vector Layer (It does not, I have checked, it is just ignored)

Best Answer

I feel that it is possible to process the data on the client side itself. In your previous question, you have indicated that you are using a handler for the get request. In the handler, you could process the data received, and add the depth value as an attribute in the properties of each feature.

I would use something like this:

function handler(request) {

var geojson_format = new OpenLayers.Format.GeoJSON({
    'internalProjection': map.baseLayer.projection,
    'externalProjection': new OpenLayers.Projection("EPSG:4326")
});
geojson_format.ignoreExtraDims=true;
var processedData=ExtractZvalue(request.responseText) //this is the addition
vectorLayer.addFeatures(geojson_format.read(processedData));
}


function ExtractZvalue(ob){
    var features=ob["features"];
    var featCount=features.length;

    //iterate over each feature
    for(var i=0;i<featCount;i++){
        var f=features[i];
        var geom=f["geometry"];
        var coordinates=geom["coordinates"];
        var dep=coordinates[2]; //third coordinate
        var prop=f["properties"];
        prop["depth"]=dep;
    }

    return ob;
}

Another Alternative is that you could edit the parseFeature Function of the OpenLayers.Format.GeoJSON class, to do something similar.