From 9c4917789aba9f4dd1817340bd15bb8fec1713ce Mon Sep 17 00:00:00 2001 From: ajturner Date: Sat, 2 Sep 2017 07:04:14 -0400 Subject: [PATCH 1/3] Changed passthrough to process geojson --- model.js | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/model.js b/model.js index ee4e5c8..9366c6d 100644 --- a/model.js +++ b/model.js @@ -35,6 +35,7 @@ Model.prototype.getData = function (req, callback) { geojson.metadata.title = "Koop GeoJSON" geojson.metadata.description = `Data from ${url}`; + console.log("Geojson", geojson) // hand off the data to Koop callback(null, geojson) }) @@ -43,9 +44,11 @@ Model.prototype.getData = function (req, callback) { // GeoJSON to GeoJSON function translate (input) { + // console.log("input", input) // GeoJSON can just be the geometry if( input.type === undefined || input.type === null || input.type != "FeatureCollection" ) { + console.log("input", input.type) let geometry = 'Point'; switch(input.type) { case 'LineString': @@ -60,28 +63,48 @@ function translate (input) { return { type: 'FeatureCollection', - features: [ formatFeature(input) ], + features: [formatFeature(input)], metadata: { geometryType: geometry } } } else { - + const features = []; + input.features.map((feature) => { + features.push(formatFeature(feature)) + }) // Or it's a feature collection - return input; + return { + type: 'FeatureCollection', + features: [features] + } } } -function formatFeature (geometry) { - - const feature = { - type: 'Feature', - properties: { - "type": geometry.type - }, - geometry: geometry +function formatFeature (input) { + let feature = {}; + if(input.type == "Feature") { + feature = input; + if(feature.geometry === undefined || feature.geometry === null) { + feature.geometry = { + type: "Point", + coordinates: [ 0, 0] + } + } + } else { + feature = { + type: 'Feature', + properties: { + type: 'no location' + } + } + if(input !== undefined && input !== null) { + feature.properties.type = input.type; + feature.geometry = geometry; + } } + return feature } From 26816c5db34ffc73376b7328c8b90938a3a5b707 Mon Sep 17 00:00:00 2001 From: ajturner Date: Sat, 2 Sep 2017 07:15:32 -0400 Subject: [PATCH 2/3] Changed to return features --- model.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/model.js b/model.js index 9366c6d..1a09724 100644 --- a/model.js +++ b/model.js @@ -35,7 +35,6 @@ Model.prototype.getData = function (req, callback) { geojson.metadata.title = "Koop GeoJSON" geojson.metadata.description = `Data from ${url}`; - console.log("Geojson", geojson) // hand off the data to Koop callback(null, geojson) }) @@ -44,11 +43,9 @@ Model.prototype.getData = function (req, callback) { // GeoJSON to GeoJSON function translate (input) { - // console.log("input", input) // GeoJSON can just be the geometry if( input.type === undefined || input.type === null || input.type != "FeatureCollection" ) { - console.log("input", input.type) let geometry = 'Point'; switch(input.type) { case 'LineString': @@ -73,10 +70,12 @@ function translate (input) { input.features.map((feature) => { features.push(formatFeature(feature)) }) + + // Or it's a feature collection return { type: 'FeatureCollection', - features: [features] + features: features } } } From 60592f04ef63a9681bf4a4ec5084bfe550979e00 Mon Sep 17 00:00:00 2001 From: ajturner Date: Sat, 2 Sep 2017 20:57:23 -0400 Subject: [PATCH 3/3] Added aws-serverless-express npm --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43fc2e9..efbfb2a 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,6 @@ "test": "standard && tape test/*.js | tap-spec" }, "dependencies": { - "aws-serverless-express": "^3.0.2", "config": "^1.25.1", "koop": "^3.4.0", "request": "^2.79.0" @@ -19,6 +18,7 @@ "author": "Daniel Fenton", "license": "Apache-2.0", "devDependencies": { + "aws-serverless-express": "^3.0.2", "nock": "^9.0.2", "standard": "^10.0.0", "tap-spec": "^4.1.1",