Skip to content

Instantly share code, notes, and snippets.

@ploscri
Last active February 2, 2018 17:49
Show Gist options
  • Save ploscri/8759651 to your computer and use it in GitHub Desktop.
Save ploscri/8759651 to your computer and use it in GitHub Desktop.
shp -> geojson -> topoJson

#Test Archivo shp convertido a geojson y topojson sin usar linea de comando. Usando Qgis para pasar el shp a geojson y Mapshaper para convertir el geojson a topojson (barriosTopo.json). Fuente del shp Buenos Aires Data.

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.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v0.min.js"></script>
<style type="text/css">
</style>
</head>
<body>
<script type="text/javascript">
//Width and height
var w = 900;
var h = 500;
//Define map projection
var projection = d3.geo.transverseMercator()
.center([0, -34.61])
.rotate([58.38, 0])
.scale((h * 56.5) / 0.2);
//Define path generator
var path = d3.geo.path()
.projection(projection);
//Create SVG element
var svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
//Load in topojson data
d3.json("barriosTopo.json", function(error, topology) {
svg.selectAll("path")
.data(topojson.object(topology, topology.objects.barrios).geometries)
.enter()
.append("path")
.attr("d", path)
.style("stroke", "steelblue");
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment