Skip to main content
added complete script
Source Link
cengel
  • 3.3k
  • 2
  • 19
  • 30

As @user30184 suggests, convert your shapefile to json and at the same time reproject it to WGS84 with:

ogr2ogr -f GeoJSON -s_srs epsg:2180 -t_srs epsg:4326 wojeowdztwa.json wojewodztwa.shp 

Then, define the projection in your script like this:

var projection = d3.geo.mercator()
    .center([21, 52])
    .scale(2000)
    .translate([width / 2, height / 2]);

You then should see this:

enter image description here

Complete script:

var width = 600,
    height = 600;

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

d3.json("wojeowdztwa.json", function(error, map) {
  if (error) return console.error(error);

var projection = d3.geo.mercator()
    .center([21, 52])
    .scale(2000)
    .translate([width / 2, height / 2]);

var path = d3.geo.path()
    .projection(projection);

svg.append("g").attr("id", "polska")
    .selectAll("path")
      .data(map.features)
      .enter()
        .append("path")
        .attr("id", function(d) { return d.id; })
        .attr("d", path)
        .attr("class", "wojewodztwo");
});

As @user30184 suggests, convert your shapefile to json and at the same time reproject it to WGS84 with:

ogr2ogr -f GeoJSON -s_srs epsg:2180 -t_srs epsg:4326 wojeowdztwa.json wojewodztwa.shp 

Then, define the projection in your script like this:

var projection = d3.geo.mercator()
    .center([21, 52])
    .scale(2000)
    .translate([width / 2, height / 2]);

You then should see this:

enter image description here

As @user30184 suggests, convert your shapefile to json and at the same time reproject it to WGS84 with:

ogr2ogr -f GeoJSON -s_srs epsg:2180 -t_srs epsg:4326 wojeowdztwa.json wojewodztwa.shp 

Then, define the projection in your script like this:

var projection = d3.geo.mercator()
    .center([21, 52])
    .scale(2000)
    .translate([width / 2, height / 2]);

You then should see this:

enter image description here

Complete script:

var width = 600,
    height = 600;

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

d3.json("wojeowdztwa.json", function(error, map) {
  if (error) return console.error(error);

var projection = d3.geo.mercator()
    .center([21, 52])
    .scale(2000)
    .translate([width / 2, height / 2]);

var path = d3.geo.path()
    .projection(projection);

svg.append("g").attr("id", "polska")
    .selectAll("path")
      .data(map.features)
      .enter()
        .append("path")
        .attr("id", function(d) { return d.id; })
        .attr("d", path)
        .attr("class", "wojewodztwo");
});
Source Link
cengel
  • 3.3k
  • 2
  • 19
  • 30

As @user30184 suggests, convert your shapefile to json and at the same time reproject it to WGS84 with:

ogr2ogr -f GeoJSON -s_srs epsg:2180 -t_srs epsg:4326 wojeowdztwa.json wojewodztwa.shp 

Then, define the projection in your script like this:

var projection = d3.geo.mercator()
    .center([21, 52])
    .scale(2000)
    .translate([width / 2, height / 2]);

You then should see this:

enter image description here