Skip to content
forked from martgnz/es-atlas

Pre-built TopoJSON from the Spanish National Geographic Institute.

License

Notifications You must be signed in to change notification settings

miguelfg/es-atlas

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

In a browser (using d3-geo and Canvas):

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

var context = d3.select("canvas").node().getContext("2d"),
  projection = d3.geoConicConformalSpain(),
  path = d3.geoPath(projection, context);

d3.json("https://unpkg.com/[email protected]/es/municipalities.json", function(error, es) {
  if (error) throw error;

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

  context.stroke(new Path2D(projection.getCompositionBorders()));
});

</script>

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

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

var canvas = new Canvas(960, 500),
  context = canvas.getContext('2d'),
  projection = d3_composite.geoConicConformalSpain(),
  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 ConicConformalSpain 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.

You can also run the script with inline arguments:

npm run prepare --es-atlas:simplification=1e3

Reference

# with-names

Adds a name property to the generated files with the feature name. Set to false by default.

# 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.

npm run prepare --es-atlas:autonomous-regions=09,10,14,04

File Reference

# es/municipalities.json <>

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

# es.objects.municipalities

# es.objects.provinces

# es.objects.autonomous_regions

# es.objects.border

# es/provinces.json <>

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

# es/autonomous_regions.json <>

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.

About

Pre-built TopoJSON from the Spanish National Geographic Institute.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 100.0%