1

I'm trying to convert official boundaries of administrative regions of Poland from official governmental site (codgik.gov.pl). I want to use those data because they are official ones, and set contains additional levels of borders of that I cannot find in other data sets (such as Natural Earth).

I use approach similar to How to create a GeoJSON that works with D3?. However when I'm trying to use conversion ogr2ogr and plot the results using d3.js I fail. Data seems to be incorrectly translated giving essentially gibberish.

The same approach worked just fine w Natural Earth shapefiles.

By playing around with SVG (deleting paths) I can see that path overlaps and hugely and result in just black square.

Java GeoTools [quickstart tutorial] shows this shapefile without any problem, so I'm guessing mine conversions are off.

Shapefile set is available here (5.5MB)

JavaScript code:

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

var projection = d3.geo.mercator()
//    .center([171677, 133223])
//    .scale(69)
    .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");

Content of .PRJ file:

PROJCS["ETRS89 / Poland CS92", 
  GEOGCS["ETRS89", 
    DATUM["European Terrestrial Reference System 1989", 
      SPHEROID["GRS 1980", 6378137.0, 298.257222101], 
      TOWGS84[0,0,0]
    ], 
    PRIMEM["Greenwich", 0.0], 
    UNIT["Decimal Degree", 0.017453292519943295]
  ], 
  PROJECTION["Transverse_Mercator"], 
  PARAMETER["latitude_of_origin", 0.0], 
  PARAMETER["central_meridian", 18.999999999999982], 
  PARAMETER["scale_factor", 0.9993], 
  PARAMETER["false_easting", 500000.0], 
  PARAMETER["false_northing", -5300000.0], 
  UNIT["Meter", 1.0], 
  AUTHORITY["EPSG", 2180]
]

I'm very new to cartography.

3
  • 2
    Did you use ogr2ogr as ogr2ogr -f GeoJSON -s_srs epsg:2180 -t_srs epsg:4326 output.json input.shp ?
    – user30184
    Commented Aug 18, 2015 at 4:54
  • Welcome to GIS SE! As a new user be sure to take the Tour
    – TsvGis
    Commented Aug 18, 2015 at 5:36
  • Thank you this finally did the trick, I've tried different combination of source and target srs but not this one.
    – czyzu
    Commented Aug 19, 2015 at 17:57

1 Answer 1

1

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");
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.