Skip to content
This repository has been archived by the owner on Jun 6, 2019. It is now read-only.

Commit

Permalink
Fix for #3 Add support for additional geom data types.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjohare committed Jan 29, 2016
1 parent 5de421d commit 99f3381
Show file tree
Hide file tree
Showing 6 changed files with 332 additions and 2 deletions.
48 changes: 46 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ ONA.parse = function(input, cadasta_data, cb) {
//For each geolocation property, replace it with valid geojson snippet
input.forEach(function(item){
if(item._geolocation){
item._geolocation = replaceYXWithGeoJSON(item._geolocation);
//item._geolocation = replaceYXWithGeoJSON(item._geolocation);
item._geolocation = processGeolocation(item);
}
});

Expand Down Expand Up @@ -319,7 +320,8 @@ function filterFreshData(uuidHash, onaData) {
var obj = onaData[i];
// if we dont currently have data with this uuid
if (!uuidHash[obj._uuid]) {
obj._geolocation = replaceYXWithGeoJSON(obj._geolocation);
//obj._geolocation = replaceYXWithGeoJSON(obj._geolocation);
obj._geolocation = processGeolocation(obj);
filteredData.push(obj);
}
}
Expand Down Expand Up @@ -487,6 +489,48 @@ function replaceYXWithGeoJSON(input){
return (!input[1] && !input[0]) ? null : {"type":"Point","coordinates":[input[1],input[0]]};
}

/**
* Takes the value of the _geolocation or geo_location properties
* and returns a GeoJSON encoded point, line or polygon.
*
* @param item the survey data
* @return GeoJSON of type point, line or polygon
*/
function processGeolocation(item){
// pull out both geom properties
var _geolocation = item._geolocation;
var geo_location = item.geo_location;

// check for point data
if (_geolocation[1] && _geolocation[0]){
return {"type":"Point","coordinates":[_geolocation[1],_geolocation[0]]};
}
else {
points = geo_location.split(';');
coords = [];
points.forEach(function(point, idx){
// ignore extraneous 0.0 and empty coordinate values
coord = point.split(' ').slice(0, 2);
if (coord[0] != ''){
coords.push(coord);
}
})
// check for polygon type
var start = coords[0];
var end = coords[coords.length -1];
var polygon = (start[0] === end[0] && start[1] === end[1]);
if (polygon) {
// return GeoJSON Polygon
return {"type": "Polygon", "coordinates": [coords]};
}
else{
// return GeoJSON LineString
return {"type": "LineString", "coordinates": coords};
}
}
return null;
}

function httpOrHttps(port) {
if (port === 443) {
return 'https://';
Expand Down
29 changes: 29 additions & 0 deletions test/data/shapesurvey-geotrace-geo-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[{
"_notes": [],
"_bamboo_dataset_id": "",
"_tags": [],
"surveyor": "ianroll",
"_xform_id_string": "ShapeSurveyGeoTrace",
"_geolocation": [null, null],
"_duration": 137.0,
"land_type": "sacred_area",
"end": "2016-01-28T13:52:26.004Z",
"date_land_possession": "2016-01-28T13:52:00.000Z",
"party_type": "individual",
"applicant_name_full": "Bjohare",
"start": "2016-01-28T13:50:09.092Z",
"geo_location": "52.947525 -8.033709 0 43.0;52.944655 -8.034825 0 13.0;52.942792999999995 -8.037271 0 15.0;52.938009 -8.030147 0 14.0;",
"_attachments": [],
"_status": "submitted_via_web",
"today": "2016-01-28",
"meta/instanceID": "uuid:8d331320-9889-408e-8fd0-9066ae7158a6",
"_uuid": "8d331320-9889-408e-8fd0-9066ae7158a6",
"means_of_acquire": "Gifted",
"_submitted_by": null,
"formhub/uuid": "aebff060bbca47efb3171d2b091405c4",
"_submission_time": "2016-01-28T13:54:31",
"_version": "201601281351",
"tenure_type": "joint_tenancy",
"deviceid": "359149062988565",
"_id": 65
}]
1 change: 1 addition & 0 deletions test/data/shapesurvey-geotrace-geo-form.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"default_language": "default", "id_string": "ShapeSurveyGeoTrace", "children": [{"name": "start", "type": "start"}, {"name": "end", "type": "end"}, {"name": "today", "type": "today"}, {"name": "deviceid", "type": "deviceid"}, {"name": "title", "label": "Cadasta Platform - UAT Survey", "type": "note"}, {"children": [{"name": "theaaldridge", "label": "Thea Aldridge"}, {"name": "katechapman", "label": "Kate Chapman"}, {"name": "alexisfranklin", "label": "Alexis Franklin"}, {"name": "chandralash", "label": "Chandra Lash"}, {"name": "frankpichel", "label": "Frank Pichel"}, {"name": "oliverroick", "label": "Oliver Roick"}, {"name": "ianroll", "label": "Ian Ross"}, {"name": "noeltaylor", "label": "Noel Taylor"}, {"name": "boriszamyatin", "label": "Boris Zamyatin"}], "name": "surveyor", "label": "Surveyor Name", "type": "select one"}, {"children": [{"name": "group", "label": "Group"}, {"name": "individual", "label": "Individual"}], "name": "party_type", "label": "Party Classification", "type": "select one"}, {"name": "applicant_name_full", "bind": {"relevant": "${party_type}='individual'"}, "label": "Applicant Full Name", "type": "text"}, {"name": "applicant_name_group", "bind": {"relevant": "${party_type}='group'"}, "label": "Applicant Group Name", "type": "text"}, {"name": "geo_location", "label": "Location of Parcel", "type": "geotrace"}, {"name": "date_land_possession", "label": "Date and Time of Land Possession", "type": "dateTime"}, {"name": "means_of_acquire", "label": "How did you acquire the land?", "type": "text"}, {"children": [{"name": "indigenous_land_rights", "label": "Indigenous land rights"}, {"name": "joint_tenancy", "label": "Joint tenancy"}, {"name": "tenancy_in_common", "label": "Tenancy in common"}, {"name": "undivided_co_ownership", "label": "Undivided co-ownership (general term covering strata title and condominiums)"}, {"name": "easment", "label": "Easement"}, {"name": "equitable_servitude", "label": "Equitable servitude"}, {"name": "mineral_rights", "label": "Mineral rights (includes oil & gas)"}, {"name": "water_rights", "label": "Water rights (collective term for bundle of rights possible)"}, {"name": "concessionary_rights", "label": "Concessionary rights (non-mineral)"}, {"name": "carbon_rights", "label": "Carbon rights"}, {"name": "freehold", "label": "Freehold"}, {"name": "long_term_leasehold", "label": "Long term leasehold (10+ years)"}, {"name": "leasehold", "label": "Leasehold"}, {"name": "customary_rights", "label": "Customary Rights"}, {"name": "occupancy", "label": "Occupancy (no documented rights)"}, {"name": "tenancy", "label": "Tenancy (documented sub-lease)"}, {"name": "hunting_fishing_harvest_rights", "label": "Hunting/Fishing/Harvest Rights"}, {"name": "grazing_rights", "label": "Grazing Rights"}], "name": "tenure_type", "label": "What is the social tenure type?", "type": "select one"}, {"children": [{"name": "sacred_area", "label": "Sacred Area"}, {"name": "common_grazing", "label": "Common Grazing Area"}, {"name": "sacred_site", "label": "Sacred Site"}, {"name": "community_meeting_hall", "label": "Community Meeting Hall"}, {"name": "graveyard", "label": "Graveyard"}], "name": "land_type", "label": "What is the land feature?", "type": "select one"}, {"control": {"bodyless": true}, "children": [{"name": "instanceID", "bind": {"readonly": "true()", "calculate": "concat('uuid:', uuid())"}, "type": "calculate"}], "name": "meta", "type": "group"}], "version": "201601281351", "type": "survey", "name": "ShapeSurveyGeoTrace", "sms_keyword": "ShapeSurveyGeoTrace", "title": "ShapeSurveyGeoTrace"}
29 changes: 29 additions & 0 deletions test/data/shapesurvey-polygon-geo-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[{
"_notes": [],
"_bamboo_dataset_id": "",
"_tags": [],
"surveyor": "ianroll",
"_xform_id_string": "ShapeSurvey",
"_geolocation": [null, null],
"_duration": 150.0,
"land_type": "sacred_area",
"end": "2016-01-26T19:19:24.924Z",
"date_land_possession": "2016-01-26T19:18:00.000Z",
"party_type": "individual",
"applicant_name_full": "Bjohare",
"start": "2016-01-26T19:16:54.051Z",
"geo_location": "52.94417 -8.041144 0.0 0.0;52.946013 -8.041241 0.0 0.0;52.946808 -8.040018 0.0 0.0;52.946776 -8.038837 0.0 0.0;52.946498 -8.037668 0.0 0.0;52.947162999999996 -8.03682 0.0 0.0;52.94717 -8.035973 0.0 0.0;52.946335999999995 -8.03549 0.0 0.0;52.945488999999995 -8.034438999999999 0.0 0.0;52.944227999999995 -8.034964 0.0 0.0;52.944325 -8.036069 0.0 0.0;52.944196 -8.037014 0.0 0.0;52.943439999999995 -8.037636 0.0 0.0;52.943400999999994 -8.038504999999999 0.0 0.0;52.942947999999994 -8.038848 0.0 0.0;52.942980999999996 -8.039309 0.0 0.0;52.943556 -8.039287999999999 0.0 0.0;52.943737 -8.040103 0.0 0.0;52.944157 -8.041144 0.0 0.0;52.94417 -8.041144 0.0 0.0;",
"_attachments": [],
"_status": "submitted_via_web",
"today": "2016-01-26",
"meta/instanceID": "uuid:8b30cfa2-6dbe-4e8c-91cc-20d6662eee8d",
"_uuid": "8b30cfa2-6dbe-4e8c-91cc-20d6662eee8d",
"means_of_acquire": "Test",
"_submitted_by": null,
"formhub/uuid": "ab1537fec2024a8580831ba878304a01",
"_submission_time": "2016-01-26T19:21:30",
"_version": "201601131904",
"tenure_type": "undivided_co_ownership",
"deviceid": "359149062988565",
"_id": 64
}]
188 changes: 188 additions & 0 deletions test/data/shapesurvey-polygon-geo-form.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
{
"default_language": "default",
"id_string": "ShapeSurvey",
"children": [{
"name": "start",
"type": "start"
}, {
"name": "end",
"type": "end"
}, {
"name": "today",
"type": "today"
}, {
"name": "deviceid",
"type": "deviceid"
}, {
"name": "title",
"label": "Cadasta Platform - UAT Survey",
"type": "note"
}, {
"children": [{
"name": "theaaldridge",
"label": "Thea Aldridge"
}, {
"name": "katechapman",
"label": "Kate Chapman"
}, {
"name": "alexisfranklin",
"label": "Alexis Franklin"
}, {
"name": "chandralash",
"label": "Chandra Lash"
}, {
"name": "frankpichel",
"label": "Frank Pichel"
}, {
"name": "oliverroick",
"label": "Oliver Roick"
}, {
"name": "ianroll",
"label": "Ian Ross"
}, {
"name": "noeltaylor",
"label": "Noel Taylor"
}, {
"name": "boriszamyatin",
"label": "Boris Zamyatin"
}],
"name": "surveyor",
"label": "Surveyor Name",
"type": "select one"
}, {
"children": [{
"name": "group",
"label": "Group"
}, {
"name": "individual",
"label": "Individual"
}],
"name": "party_type",
"label": "Party Classification",
"type": "select one"
}, {
"name": "applicant_name_full",
"bind": {
"relevant": "${party_type}='individual'"
},
"label": "Applicant Full Name",
"type": "text"
}, {
"name": "applicant_name_group",
"bind": {
"relevant": "${party_type}='group'"
},
"label": "Applicant Group Name",
"type": "text"
}, {
"name": "geo_location",
"label": "Location of Parcel",
"type": "geoshape"
}, {
"name": "date_land_possession",
"label": "Date and Time of Land Possession",
"type": "dateTime"
}, {
"name": "means_of_acquire",
"label": "How did you acquire the land?",
"type": "text"
}, {
"children": [{
"name": "indigenous_land_rights",
"label": "Indigenous land rights"
}, {
"name": "joint_tenancy",
"label": "Joint tenancy"
}, {
"name": "tenancy_in_common",
"label": "Tenancy in common"
}, {
"name": "undivided_co_ownership",
"label": "Undivided co-ownership (general term covering strata title and condominiums)"
}, {
"name": "easment",
"label": "Easement"
}, {
"name": "equitable_servitude",
"label": "Equitable servitude"
}, {
"name": "mineral_rights",
"label": "Mineral rights (includes oil & gas)"
}, {
"name": "water_rights",
"label": "Water rights (collective term for bundle of rights possible)"
}, {
"name": "concessionary_rights",
"label": "Concessionary rights (non-mineral)"
}, {
"name": "carbon_rights",
"label": "Carbon rights"
}, {
"name": "freehold",
"label": "Freehold"
}, {
"name": "long_term_leasehold",
"label": "Long term leasehold (10+ years)"
}, {
"name": "leasehold",
"label": "Leasehold"
}, {
"name": "customary_rights",
"label": "Customary Rights"
}, {
"name": "occupancy",
"label": "Occupancy (no documented rights)"
}, {
"name": "tenancy",
"label": "Tenancy (documented sub-lease)"
}, {
"name": "hunting_fishing_harvest_rights",
"label": "Hunting/Fishing/Harvest Rights"
}, {
"name": "grazing_rights",
"label": "Grazing Rights"
}],
"name": "tenure_type",
"label": "What is the social tenure type?",
"type": "select one"
}, {
"children": [{
"name": "sacred_area",
"label": "Sacred Area"
}, {
"name": "common_grazing",
"label": "Common Grazing Area"
}, {
"name": "sacred_site",
"label": "Sacred Site"
}, {
"name": "community_meeting_hall",
"label": "Community Meeting Hall"
}, {
"name": "graveyard",
"label": "Graveyard"
}],
"name": "land_type",
"label": "What is the land feature?",
"type": "select one"
}, {
"control": {
"bodyless": true
},
"children": [{
"name": "instanceID",
"bind": {
"readonly": "true()",
"calculate": "concat('uuid:', uuid())"
},
"type": "calculate"
}],
"name": "meta",
"type": "group"
}],
"version": "201601131904",
"type": "survey",
"name": "bolinas_exercise",
"sms_keyword": "ShapeSurvey",
"title": "ShapeSurvey"
}
39 changes: 39 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,45 @@ describe('ONA Suite', function () {

})

/**
* Test Polygon ingestion
*/
it('should load an ONA file with geo_location polygon data', function(done){
var url = path.join(__dirname + '/data/shapesurvey-polygon-geo-data.json');
ona_provider.load(url, function(err, response){
(response).should.have.property('cadasta_id');
(response).should.have.property('operation');
(response).should.have.property('version');
(response).should.have.property('data');
assert.typeOf(response.data, 'array', 'data should be an array of objects.');
(response.data[0]._geolocation).should.have.property('type');
assert.equal(response.data[0]._geolocation.type, 'Polygon', 'type should be Polygon');
assert.typeOf(response.data[0]._geolocation.coordinates, 'array', 'data should be an array of objects.');
console.log(JSON.stringify(response.data[0]._geolocation))
done();
})
})

/**
* Test LineString ingestion
*/
it('should load an ONA file with geo_location linestring data', function(done){
var url = path.join(__dirname + '/data/shapesurvey-geotrace-geo-data.json');
ona_provider.load(url, function(err, response){
(response).should.have.property('cadasta_id');
(response).should.have.property('operation');
(response).should.have.property('version');
(response).should.have.property('data');
assert.typeOf(response.data, 'array', 'data should be an array of objects.');
(response.data[0]._geolocation).should.have.property('type');
assert.equal(response.data[0]._geolocation.type, 'LineString', 'type should be Polygon');
assert.typeOf(response.data[0]._geolocation.coordinates, 'array', 'data should be an array of objects.');
console.log(JSON.stringify(response.data[0]._geolocation))
done();
})
})


})


Expand Down

0 comments on commit 99f3381

Please sign in to comment.