Skip to content

Commit

Permalink
filter out images w/out spatial info
Browse files Browse the repository at this point in the history
ref #10
  • Loading branch information
maxgrossman committed Sep 2, 2018
1 parent ae31a54 commit ece0419
Show file tree
Hide file tree
Showing 7 changed files with 611 additions and 74 deletions.
39 changes: 17 additions & 22 deletions adapters/sequence/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,30 @@ class Sequence {
const radDiffLon = this.toRadian(nextLoc.lon - loc.lon);

const a = Math.sin(radDiffLat/2) * Math.sin(radDiffLat/2) +
Math.cos(radLat1) * Math.cos(radLat2) *
Math.cos(radLat1) * Math.cos(radLat2) *
Math.sin(radDiffLon/2) * Math.sin(radDiffLon/2);

const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return R * c;
}

cut(images, params) {
return Promise
.map(images, (image) => this.meta(image))
.then(metas => this.split(metas, params))
let metas = [];
return Promise.each(images, (image) => {
return exif.read(image).then(tags => {
const spatial = tags.hasOwnProperty('GPSLongitude') && tags.hasOwnProperty('GPSLatitude');
if (spatial) {
metas.push({
image: image,
loc: this.makeLoc(tags),
timestamp: this.makeDate(tags),
id: uuidv4()
});
}
})
.catch(err => { throw err; });
})
.then(() => this.split(metas, params))
}

fromSource(source, type) {
Expand All @@ -89,27 +102,9 @@ class Sequence {
}
}

meta(image) {
return exif.read(image).then(tags => {
const spatial = !tags.hasOwnProperty('GPSLongitude') && !tags.hasOwnProperty('GPSLatitude');
if (spatial) {
return {
image: image,
loc: this.makeLoc(tags),
timestamp: this.makeDate(tags),
id: uuidv4()
}
} else {
return {}
}
})
.catch(err => { throw err; });
}

toRadian(coord) {
return coord * (Math.PI / 180)
}

split(metas, params) {
metas = metas.sort((a, b) => a.timestamp - b.timestamp);
const sequences = [];
Expand Down
4 changes: 2 additions & 2 deletions db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Database {
'${index}',
'${sequenceId}',
'${userId}',
GeomFromText('POINT(${image.loc.lat} ${image.loc.lon})', 4326)
GeomFromText('POINT(${image.loc.lon} ${image.loc.lat})', 4326)
)`
}).join(',');
const sql = `INSERT INTO Images VALUES ${images}`;
Expand All @@ -94,7 +94,7 @@ class Database {
}
getSequence(id) {
const sql = `
SELECT AsGeoJSON(loc), seqId
SELECT AsGeoJSON(loc), id, seqId
FROM Images
WHERE seqId='${id}';
`;
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const server = Hapi.server({
const initServer = async () => {
await server.register(require('inert'));
server.route(routes)
await server.start();
console.log(`Server running at: ${server.info.uri}`);
}

process.on('unhandledRejection', (err) => {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"migrate:up": "./node_modules/.bin/migrate up --state-file db/migrations/.migrate --migrations-dir db/migrations",
"migrate:down": "migrate down --state-file db/migrations/.migrate --migrations-dir db/migrations",
"seed": "node db/seeds/index.js",
"migrate:up:seed": "npm run migrate:up && npm run seed"
"migrate:up:seed": "npm run migrate:up && npm run seed",
"start": "nodemon index.js"
},
"dependencies": {
"bluebird": "^3.5.1",
Expand All @@ -36,6 +37,7 @@
"devDependencies": {
"async": "^2.6.1",
"geojson-validation": "^0.2.1",
"nodemon": "^1.18.4",
"turf-feature": "^1.0.0",
"turf-featurecollection": "^1.0.1"
}
Expand Down
58 changes: 22 additions & 36 deletions test/sequence/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@ describe('sequence', () => {
expect(dist).to.not.be.null
})
})
it('meta reads then selializes an image\'s exif metadata', async () => {
try {
const image = './testData/exif-gps-samples/DSCN0010.JPG';
const metadata = await Sequence.meta(image)
const validation = Joi.validate(metadata, metadataSchema);

expect(validation.value).to.be.eql(metadata);
expect(validation.error).to.be.null;
return;
} catch (e) {
console.error(e);

}
})
it ('given a path of images sufficiently close together in space in time, returns sequence of same length', async () => {
try {
const paths = [ '/testData/danbjoseph2' ].map(p => process.cwd() + p);
Expand All @@ -54,28 +40,28 @@ describe('sequence', () => {

}
})
// it('given path with images less than max size, makes one big sequence', async () => {
// try {
// const paths = ['/testData/100MSDCF'].map(p => process.cwd() + p);
// const sequences = await Sequence.build(paths, 'directory', uuidv4(), { maxSize: 10000 });
// expect(sequences.length).to.eql(1);
// } catch (e) {
// console.log(e);
// }
// })
// .timeout(10000000)
// it('given multiple image paths, makes multiple sequenecs', async () => {
// try {
// const paths = ['/testData/100MSDCF', '/testData/103MSDCF'].map(p => process.cwd() + p);
// const sequences = await Sequence.build(paths, 'directory', uuidv4(), { maxSize: 1000 });
// const validation = Joi.validate(sequences, sequencesSchema);
it('given path with images less than max size, makes one big sequence', async () => {
try {
const paths = ['/testData/100MSDCF'].map(p => process.cwd() + p);
const sequences = await Sequence.build(paths, 'directory', uuidv4(), { maxSize: 10000 });
expect(sequences.length).to.eql(1);
} catch (e) {
console.log(e);
}
})
.timeout(10000000)
it('given multiple image paths, makes multiple sequenecs', async () => {
try {
const paths = ['/testData/100MSDCF', '/testData/103MSDCF'].map(p => process.cwd() + p);
const sequences = await Sequence.build(paths, 'directory', uuidv4(), { maxSize: 1000 });
const validation = Joi.validate(sequences, sequencesSchema);

// expect(validation.value).to.be.eql(sequences)
// expect(validation.error).to.be.null;
expect(validation.value).to.be.eql(sequences)
expect(validation.error).to.be.null;

// } catch (e) {
// console.log(e);
// }
// })
// .timeout(10000000)
} catch (e) {
console.log(e);
}
})
.timeout(10000000)
})
2 changes: 1 addition & 1 deletion test/sequence/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

module.exports = {
// handlerSpec: require('./handler'),
handlerSpec: require('./handler'),
adapterSpec: require('./adapter')
}
Loading

0 comments on commit ece0419

Please sign in to comment.