diff --git a/README.md b/README.md index 27a8893..9a2d3c9 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,42 @@ See [sources](https://librarymap.hugh.run/sources). See [contributing](https://librarymap.hugh.run/contributing/), especially *[which files to update](https://librarymap.hugh.run/contributing/#which-files-to-update)*. +<<<<<<< HEAD +## Deployment + +The website for this project uses [git-webhooks](https://git.suboptimal.solutions/hugh/git-webhooks) with a customisation to run the `process.js` file that is found in this repository on each pull. The file is stored with the webhooks files so that everything can be `npm install`ed together. + +This `process.js` file syncs any changes from the csv files into the topojson attributes (e.g. when a library changes their ILS). + +## Updating the topojson + +### Update boundaries + +* make a copy of `/public_library_map/boundaries.geo.json` +* update in `qgis` +* save the copied file + +### Simplify to reduce the file size + +#### Option 1 + +* upload to https://mapshaper.org/ and 'simplify' the boundaries +* download the simplified version +* replace `/public_library_map/boundaries.geo.json` + +#### Option 2 + +```bash +sudo npm install -g mapshaper +mapshaper boundaries.geo.json snap -clean -o force precision=0.0001 format=geojson boundaries.geo.json +``` +### Turn it into `topojson`: + +```bash +sudo npm install -g topojson-server +geo2topo boundaries.geo.json -q 50000 > website/data/boundaries.topo.json +``` + ## Contributing To contribute to the map data you can contact Hugh at librarymap [at] hugh.run. If necessary, I will add an account for you on `git.suboptimal.solutions` if you want to contribute to the code. diff --git a/process.js b/process.js new file mode 100644 index 0000000..da505f5 --- /dev/null +++ b/process.js @@ -0,0 +1,35 @@ +import csv from 'csv-parser' +import fs from 'fs' + +const data_directory = '/srv/public_library_map/website/data' +// read json file into memory +const mapData = fs.readFileSync(`${data_directory}/boundaries.topo.json`) +let data = JSON.parse(mapData) +let geometries = data.objects['boundaries.geo'].geometries + +// read csv file +// 'data' should be a single line (excl headers) +fs.createReadStream(`${data_directory}/library_services_information.csv`) + .pipe(csv()) + .on('data', (data) => { + for (let feature in geometries) { + if (geometries[feature].properties.name == data.name) { + for (let k in data) { + if (k != "long_name" && k != "") { + geometries[feature].properties[k] = data[k] + } + } + } + } + }) + .on('end', () => { + // write back to object + data.objects['boundaries.geo'].geometries = geometries + // write back to file + try { + fs.writeFileSync(`${data_directory}/boundaries.topo.json`, JSON.stringify(data)) + } catch (err) { + console.err('ERROR writing topo file') + } + console.log('topo updated') + }) diff --git a/website/about/index.html b/website/about/index.html index 3582ce9..3fa27be 100644 --- a/website/about/index.html +++ b/website/about/index.html @@ -23,7 +23,7 @@
  • About
  • Acknowledgements
  • Contribute
  • -
  • Code
  • +
  • Code
  • diff --git a/website/contributing/index.html b/website/contributing/index.html index b1fbe0e..2ddf6aa 100644 --- a/website/contributing/index.html +++ b/website/contributing/index.html @@ -23,7 +23,7 @@
  • About
  • Acknowledgements
  • Contribute
  • -
  • Code
  • +
  • Code
  • @@ -33,16 +33,14 @@

    I’d love your help to make Library Map as accurate and useful as possible.

    How to contribute your idea, bug report or improvement

      -
    1. Look at the current GitHub issues tagged help wanted to see if you can help. Most of these will be to do with updating data, like finding street addresses or other information.
    2. -
    3. You can create a new issue on GitHub.
    4. -
    5. You can send a pull request — though it is strongly preferred that you either ask to be assigned to an existing issue (so everyone knows you’re working on it), or create a new issue, first.
    6. -
    7. You can just send an email to librarymap@hugh.run and ask me to fix/add something.
    8. +
    9. Look at the current issues tagged help wanted to see if you can help. Most of these will be to do with updating data, like finding street addresses or other information.
    10. +
    11. Email librarymap@hugh.run and ask me to open a git.suboptimal.solutions account for you, or just request that I fix/add something.
    -

    If you have not used Git or GitHub before

    -

    There is a class outline for an introduction to Git and GitHub aimed at librarians at librarycarpentry.org. This assumes you are using the command line. If you create or already have a GitHub account, you can also edit files directly in the browser, or use GitHub Desktop - both of which are probably less intimidating options if you don’t have any desire to learn how to use a command line/shell interface, or just want to make a single minor update.

    +

    If you have not used Git before

    +

    There is a class outline for an introduction to Git and GitHub aimed at librarians at librarycarpentry.org. This assumes you are using the command line.

    Which files to update

    -

    To update information about library services (e.g. fines info, loan period etc) you should edit website/data/library_services_information.csv.

    -

    To update information about library locations (e.g. street address, phone number, coordinates) you should edit the relevant csv location file:

    +

    To update information about library services (e.g. fines info, loan period etc) you should edit website/data/library_services_information.csv.

    +

    To update information about library locations (e.g. street address, phone number, coordinates) you should edit the relevant csv location file:

    diff --git a/website/index.html b/website/index.html index 86e97ac..6ccec03 100644 --- a/website/index.html +++ b/website/index.html @@ -25,7 +25,7 @@
  • About
  • Acknowledgements
  • Contribute
  • -
  • Code
  • +
  • Code
  • diff --git a/website/sources/index.html b/website/sources/index.html index 0fa13c1..e31cdb2 100644 --- a/website/sources/index.html +++ b/website/sources/index.html @@ -23,7 +23,7 @@
  • About
  • Acknowledgements
  • Contribute
  • -
  • Code
  • +
  • Code
  • diff --git a/website/who-else/index.html b/website/who-else/index.html index 69d602d..69313a6 100644 --- a/website/who-else/index.html +++ b/website/who-else/index.html @@ -23,7 +23,7 @@
  • About
  • Acknowledgements
  • Contribute
  • -
  • Code
  • +
  • Code