Shapefile to TopoJSON conversion problems

2019-08-03 16:33发布

问题:

I'm trying to convert a shapefile to GeoJSON and then to TopoJSON as described in Let's Make a Map. Somewhere along the chain, something gets corrupted and my resulting image looks like below:

My workflow is as follows:

  1. Download shapefile from: http://vcgi.vermont.gov/warehouse/search_tools - I am working with the Master Town Boundary data, specifically, the "Boundary_BNDHASH_region_towns.shp" file.
  2. Convert shapefile to GeoJSON

    ogr2ogr -f GeoJSON vt_towns.json Boundary_BNDHASH_region_towns.shp
    
  3. Convert GeoJSON to TopoJSON

    topojson -p TOWNNAME -p CNTY -o vt.json vt_towns.json
    
  4. Plug into basic template with some minor modifications to Mike Bostock's example

    <!DOCTYPE html>
    <meta charset="utf-8">
    <style>
    
    /* CSS goes here. */
    
    </style>
    <body>
    <script src="http://d3js.org/d3.v3.min.js"></script>
    <script src="http://d3js.org/topojson.v1.min.js"></script>
    <script>
    
        var width = 960,
            height = 1160;
    
        var svg = d3.select("body").append("svg")
            .attr("width", width)
            .attr("height", height);
    
        var projection = d3.geo.transverseMercator()
                .rotate([72.57, -44.20])
                .translate([175,185])
                .scale([100]);
    
        // Define path generator
        var path = d3.geo.path()
            .projection(projection);
    
        d3.json("vt.json", function(error, vt) {
    
            var vermont = topojson.feature(vt, vt.objects.vt_towns);
    
            svg.append("path")
                .datum(vermont)
                .attr("d", path);
    
        });
    
    </script>
    

This is not my first d3 map (it's my second!) but I am very much at a loss as to what is going wrong. My best guess is that it has something to do with the unzipped dataset containing many shapefiles and their accompanying files.

回答1:

It seems that your file uses the gridded coordinate system, use the option -t_srs EPSG:4326 to get latitude and longitude:

ogr2ogr -f GeoJSON -t_srs EPSG:4326 vt_towns.json Boundary_BNDHASH_region_towns.shp

And then continue with your workflow.