block by hugolpz 6279966

France_topographic_map.svg

Full Screen

Step 2: Topographic map. final_topo_France.json (topojson) created using makefile.

Attempt to programmatically generate geolocalized France_topographic_map.svg (focus: France, type: topographic map, geolocalised yet light, printable) following existing Wikipedia’s guidelines.

Meta: v13.08.22. Makefile: Make4b. Focus: India. Type: topographic_map.

With: topography.

This code is part of the Wikimaps team push for better wikipedia maps. An efforts for both GIS data collection and map generation for the purpose of encyclopedic cartography and free knowledge.

Sources:

1a. Base introduction to Makefile Why Use Make by Mike Bostock

1b. In practice (shorter): Austria D3 TopoJSON

2a. wikimaps’ guidelines: Wikipedia:WikiProject_Maps/Conventions

To do: 1. Simplify to get lighter svg.

index.html

<!DOCTYPE html>
<!--    //bost.ocks.org/mike/map/-->
<meta charset="utf-8">
v. 08/20. Last version on codio.com<br />
<style>
svg { border: 5px solid #333; background-color: #C6ECFF;}

/* TOPO */
path.Topo_1 { fill:#ACD0A5; stroke: #0978AB; stroke-width: 1px; }
path.Topo_50 {fill: #94BF8B; }
path.Topo_100 {fill: #BDCC96; }
path.Topo_200 {fill: #E1E4B5; }
path.Topo_500 {fill: #DED6A3; }
path.Topo_1000 {fill:#CAB982 ; }
path.Topo_2000 {fill: #AA8753; }
path.Topo_3000 {fill: #BAAE9A; }
path.Topo_4000 {fill: #F5F4F2 ; }
</style>
<body>
<script src="//code.jquery.com/jquery-2.0.2.min.js"></script>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/topojson.v0.min.js"></script>
<script>
// -------------- SETTINGS ------------- //
// HTML frame: dimensions & colors
var width  = 630,
    height = 630,
    color = d3.scale.category10(); // d3.scale.ordinal().domain(["000000", "FFFFFF", "baz"]).range(colorbrewer.RdBu[9]);

// Projection: New projection, center coord, scale(?):
var projection = d3.geo.mercator()
    .center([2.2, 46.4]) // jap: [139, 35.4]
    .scale(2400) // behavioral definition welcome
    .translate([width / 2, height / 2]); //??

// SVG injection:
var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height);

// Path
var path = d3.geo.path()
    .projection(projection)
    .pointRadius(4);

// Data (getJSON: TopoJSON)
d3.json("final_topo_France.json", showData);

// ---------- FUNCTION ------------- //
function showData(error, fra) {

// var #Coord: projection formerly here

// var #Path: formerly here
    var Levels = topojson.object(fra, fra.objects.levels);

//Append Topo polygons
    svg.append("path")
        .datum(Levels)
        .attr("d", path)
    svg.selectAll(".levels")
        .data(topojson.object(fra, fra.objects.levels).geometries)
      .enter().append("path")
        .attr("class", function(d) { return "Topo_" + d.properties.name; })
        .attr("data-elev", function(d) { return d.properties.name; })
        .attr("d", path)

// Function Click > Console
    function click(a){
        console.log(a.properties.name);}

}
</script>
<br />
<div>
    <a class="download ac-icon-download" href="javascript:javascript: (function () { var e = document.createElement('script'); if (window.location.protocol === 'https:') { e.setAttribute('src', 'https://raw.github.com/NYTimes/svg-crowbar/gh-pages/svg-crowbar.js'); } else { e.setAttribute('src', '//nytimes.github.com/svg-crowbar/svg-crowbar.js'); } e.setAttribute('class', 'svg-crowbar'); document.body.appendChild(e); })();"><!--⤋--><big></big> Download</a> -- Works on Chrome. Feedback me for others web browsers ?
</div>
<br />
</body>
</html>

makefile

#make v.5!
# topojsoning: 
final.json:  levels.json
	topojson --id-property none -p name=elev -o final.json -- levels.json 

## shp2jsoning:
levels.json: levels.shp
	ogr2ogr -f GeoJSON -where "elev < 10000" levels.json levels.shp

## merge
levels.shp: level0001.shp level0050.shp level0100.shp level0200.shp level0500.shp level1000.shp level2000.shp level3000.shp level4000.shp
	ogr2ogr levels.shp level0001.shp
	ogr2ogr -update -append levels.shp level0050.shp
	ogr2ogr -update -append levels.shp level0100.shp
	ogr2ogr -update -append levels.shp level0200.shp
	ogr2ogr -update -append levels.shp level0500.shp
	ogr2ogr -update -append levels.shp level1000.shp
	ogr2ogr -update -append levels.shp level2000.shp
	ogr2ogr -update -append levels.shp level3000.shp
	ogr2ogr -update -append levels.shp level4000.shp

# Polygonize slices:
level0001.shp: level0001.tif
	gdal_polygonize.py level0001.tif -f "ESRI Shapefile" level0001.shp level_0001 elev
level0050.shp: level0050.tif
	gdal_polygonize.py level0050.tif -f "ESRI Shapefile" level0050.shp level_0050 elev
level0100.shp: level0100.tif
	gdal_polygonize.py level0100.tif -f "ESRI Shapefile" level0100.shp level_0100 elev
level0200.shp: level0200.tif
	gdal_polygonize.py level0200.tif -f "ESRI Shapefile" level0200.shp level_0200 elev
level0500.shp: level0500.tif
	gdal_polygonize.py level0500.tif -f "ESRI Shapefile" level0500.shp level_0500 elev
level1000.shp: level1000.tif
	gdal_polygonize.py level1000.tif -f "ESRI Shapefile" level1000.shp level_1000 elev
level2000.shp: level2000.tif
	gdal_polygonize.py level2000.tif -f "ESRI Shapefile" level2000.shp level_2000 elev
level3000.shp: level3000.tif
	gdal_polygonize.py level3000.tif -f "ESRI Shapefile" level3000.shp level_3000 elev
level4000.shp: level4000.tif
	gdal_polygonize.py level4000.tif -f "ESRI Shapefile" level4000.shp level_4000 elev


# Raster slicing:
level0001.tif: crop.tif
	gdal_calc.py -A crop.tif --outfile=level0001.tif --calc="1*(A>0)"       --NoDataValue=0
level0050.tif: crop.tif
	gdal_calc.py -A crop.tif --outfile=level0050.tif --calc="50*(A>50)"      --NoDataValue=0
level0100.tif: crop.tif
	gdal_calc.py -A crop.tif --outfile=level0100.tif --calc="100*(A>100)"     --NoDataValue=0
level0200.tif: crop.tif
	gdal_calc.py -A crop.tif --outfile=level0200.tif --calc="200*(A>200)"     --NoDataValue=0
level0500.tif: crop.tif
	gdal_calc.py -A crop.tif --outfile=level0500.tif --calc="500*(A>500)"     --NoDataValue=0
level1000.tif: crop.tif
	gdal_calc.py -A crop.tif --outfile=level1000.tif --calc="1000*(A>1000)"     --NoDataValue=0
level2000.tif: crop.tif
	gdal_calc.py -A crop.tif --outfile=level2000.tif --calc="2000*(A>2000)"     --NoDataValue=0
level3000.tif: crop.tif
	gdal_calc.py -A crop.tif --outfile=level3000.tif --calc="3000*(A>3000)"     --NoDataValue=0
level4000.tif: crop.tif
	gdal_calc.py -A crop.tif --outfile=level4000.tif --calc="4000*(A>4000)"     --NoDataValue=0


# boxing: 
crop.tif: ETOPO1_Ice_g_geotiff.tif
	gdal_translate -projwin -005.50 051.30 10.00 041.00 ETOPO1_Ice_g_geotiff.tif crop.tif
	# ulx uly lrx lry  // W N E S // -005.50 051.30 010.00 041.00

# unzip:
ETOPO1_Ice_g_geotiff.tif: ETOPO1.zip
	unzip ETOPO1.zip
	touch ETOPO1_Ice_g_geotiff.tif

# download:
ETOPO1.zip:
	curl -o ETOPO1.zip 'http://www.ngdc.noaa.gov/mgg/global/relief/ETOPO1/data/ice_surface/grid_registered/georeferenced_tiff/ETOPO1_Ice_g_geotiff.zip'

clean:
	rm `ls | grep -v 'zip' | grep -v 'Makefile'`