Skip to content

Instantly share code, notes, and snippets.

@macbre
Last active November 5, 2018 11:47
Show Gist options
  • Save macbre/daf47d229cb2e40f4a139f4e4c379888 to your computer and use it in GitHub Desktop.
Save macbre/daf47d229cb2e40f4a139f4e4c379888 to your computer and use it in GitHub Desktop.
Farerskie Kadry - GeoJSON
node_modules/
*.swp
do:
npm start && git add . && git commit -m 'Update' && git push origin
{
"name": "faroje-geojson",
"version": "1.0.0",
"description": "* https://www.googleapis.com/blogger/v3/blogs/1945893211430914339/posts?maxResults=500&fetchBodies=true&fetchImages=true&key=AIzaSyAJO5J-pRCaGOIeRLIJfvAPwxpMLKvwebU",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+ssh://[email protected]/daf47d229cb2e40f4a139f4e4c379888.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://gist.github.com/daf47d229cb2e40f4a139f4e4c379888"
},
"homepage": "https://gist.github.com/daf47d229cb2e40f4a139f4e4c379888",
"dependencies": {
"debug": "^2.6.1",
"fetch": "^1.1.0",
"geojson": "^0.4.1"
}
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
// @se https://www.npmjs.com/package/fetch
const debug = require('debug')('fetch'),
fetchUrl = require('fetch').fetchUrl,
fs = require('fs'),
GeoJSON = require('geojson'),
URL = 'https://www.googleapis.com/blogger/v3/blogs/1945893211430914339/posts?maxResults=500&fetchBodies=true&fetchImages=true&key=AIzaSyAJO5J-pRCaGOIeRLIJfvAPwxpMLKvwebU';
debug(`Fetching ${URL}`);
fetchUrl(URL, (err, meta, body) => {
if (err) throw err;
debug(`Response code: ${meta.status}`);
// get posts locations
const posts = JSON.parse(body).items,
locations = posts.
filter(item => {
return (typeof item.location !== 'undefined') && (item.location.lat > 58) && (item.location.lng > -10);
}).
map(item => {
return {
'lat': item.location.lat,
'lng': item.location.lng,
'title': item.location.name,
'url': item.url,
// add marker customization
"marker-symbol": "circle", // https://www.mapbox.com/maki-icons/
'marker-size': "small",
"marker-color": "#62a9f0"
};
});
debug(`Points: ${locations.length}`);
// now turn them into GeoJSON
const geo = GeoJSON.parse(locations, {Point: ['lat', 'lng']});
// save the result
fs.writeFileSync('posts.geojson', JSON.stringify(geo, null, 2));
debug('GeoJSON file saved');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment