Shapefile到TopoJSON转换问题 [英] Shapefile to TopoJSON conversion problems

查看:1156
本文介绍了Shapefile到TopoJSON转换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将shapefile转换为GeoJSON,然后转换为TopoJSON,如 -
我使用< a href =http://maps.vcgi.org/gisdata/vcgi/packaged_zips/BoundaryOther_BNDHASH.zip =nofollow noreferrer> Master Town Boundary 数据,特别是Boundary_BNDHASH_region_towns.shp文件。

  • 将shapefile转换为GeoJSON

      ogr2ogr -f GeoJSON vt_towns.json Boundary_BNDHASH_region_towns .shp 


  • 将GeoJSON转换为TopoJSON

      topojson -p TOWNNAME -p CNTY -o vt.json vt_towns.json 


  • 插入基本模板,对Mike Bostock的例子稍作修改

     <!DOCTYPE html> ; 
    < meta charset =utf-8>
    < style>

    / * CSS在这里。 * /

    < / 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高度);

    var projection = d3.geo.transverseMercator()
    .rotate([72.57,-44.20])
    .translate([175,185])
    .scale [100]);

    //定义路径生成器
    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>


  • 这不是我的第一张d3地图我的第二个!),但我非常失落,什么是错的。我最好的猜测是,它与包含许多shapefile及其附带文件的解压缩数据集有关。

    解决方案

    您的文件使用网格坐标系统,使用选项 -t_srs EPSG:4326 获取纬度和经度:

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

    然后继续使用您的工作流程。


    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.

    解决方案

    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.

    这篇关于Shapefile到TopoJSON转换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆