GithubHelp home page GithubHelp logo

luissevillano / es-atlas Goto Github PK

View Code? Open in Web Editor NEW

This project forked from martgnz/es-atlas

0.0 0.0 0.0 80 KB

Pre-built TopoJSON from the Spanish National Geographic Institute.

License: MIT License

Shell 57.47% JavaScript 42.53%

es-atlas's Introduction

Spain Atlas TopoJSON

This repository provides a simple script to generate TopoJSON files from the Spanish National Geographic Institute’s National Reference Geographic Equipment vector data.

Usage

You can see an interactive example in this Observable notebook.

For the browser with d3-geo and SVG:

<!DOCTYPE html>
<svg width="960" height="500"></svg>
<script src="https://d3js.org/d3.v6.min.js"></script>
<script src="https://d3js.org/topojson.v3.min.js"></script>
<script src="https://unpkg.com/[email protected]"></script>
<script>

const svg = d3.select("svg");
const projection = d3.geoConicConformalSpain();
const path = d3.geoPath(projection);

d3.json("https://unpkg.com/es-atlas/es/municipalities.json")
  .catch(err => console.warn(err))
  .then(es => {
    svg
      .append('path')
      .attr('d', path(topojson.mesh(es)))
      .attr('fill', 'none')
      .attr('stroke', 'black');

    svg
      .append('path')
      .attr('d', projection.getCompositionBorders())
      .attr('fill', 'none')
      .attr('stroke', 'black');
  })
</script>

In Node (using d3-geo and node-canvas):

const fs = require('fs');
const d3_composite = require('d3-composite-projections');
const d3 = require('d3-geo');
const topojson = require('topojson-client');
const Canvas = require('canvas');
const es = require('./node_modules/es-atlas/es/municipalities.json');

const canvas = new Canvas(960, 500);
const context = canvas.getContext('2d');
const projection = d3_composite.geoConicConformalSpain();
const path = d3.geoPath(projection, context);

context.beginPath();
path(topojson.mesh(es));
context.stroke();

canvas.pngStream().pipe(fs.createWriteStream('preview.png'));

I highly recommend using Roger Veciana’s d3-composite-projections with these files. Using a geoConicConformalSpain projection will ensure that the Canary Islands are painted closer to the mainland and even add a border to mark the projection zone.

Generating the files

Clone or download the repo, start a terminal and run npm install in the folder. This command will run the script and move the generated files to the es folder.

If you need to make further adjustments (simplification, quantization) you can change the package.json config and run npm install again.

Reference

# simplification

Removes points to reduce the file size. Set to 1e-4 by default.

# quantization

Removes information by reducing the precision of each coordinate. Set to 1e4 by default.

# autonomous_regions

Filters the result by the given autonomous region id separated by comma.

File Reference

# es/municipalities.json · Download

A TopoJSON which contains four objects: municipalities, provinces, autonomous regions and border. Every city, province and region has its corresponding National Statistics Institute identifier and name, so it's easy to get started.

# es.objects.municipalities

# es.objects.provinces

# es.objects.autonomous_regions

# es.objects.border

# es/provinces.json · Download

This file provides provinces and autonomous regions, to keep a smaller footprint on less detailed maps.

# es/autonomous_regions.json · Download

This file only provides autonomous regions, to keep a smaller footprint on less detailed maps.

Data license

The shapefiles have a CC-BY 4.0 license. You need to accept the terms before using the files.

Inspiration

The original idea and implementation comes from Mike Bostock’s us-atlas and world-atlas.

es-atlas's People

Contributors

martgnz avatar luissevillano avatar ale0xb avatar brauliodiez avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.