将shp转换为topoJSON失败 [英] convert shp to topoJSON failing

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

问题描述

GIS到Topojson:



我使用 DIVA-gis.org 为我的数据源。我已经下载了亚美尼亚行政区的数据。这个下载会产生一个.shp文件。我试图直接传递给topoJSON,我得到一个json文件如下

 对象{
type:Topology,
objects:Object,
arcs:Array [1],
transform:Object
}
/ pre>

Topojson到SVG:



.armenia其中包含我的geometries属性。问题是,geometries属性包含一个为0的数组。现在在我的topoJSON的亚美尼亚,我看到一个arcs属性数组包含相当大的数组值...我试着指向我的d3代码到元素但我仍然得不到任何东西。
除此之外,我还使用QGIS将我的.shp文件转换为geoJSON,他们使用topoJSON从geoJSON从topoJSON ...但仍然没有。
我的d3代码如下

  var width = 960,
height = 500;

var projection = d3.geo.mercator()
.scale(1000)
.translate([width / 2,height / 2]);

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

var mapContainer = d3.select(#armenia)。append(svg)
.attr(width,width)
.attr ,height);

d3.json(/ ARM_adm / output.json,function(error,country){
console.log(country,country)
mapContainer.insert path,.graticule)
.datum(topojson.feature(country,country.armenia))
.attr(class,land)
.attr d,path);
});

我只是得到一个空路径...任何帮助将是非常遗憾。

解决方案

作为一个windows用户我不经常使用topojson,当我使用虚拟机时,所以我不会评论topojson过程。我倾向于做的是使用一些在线topojson转换器进行快速转换。有多种服务可用,例如:





所有这些都有正面和负面。



我从DIVA下载了您提到的数据,并使用Shape Escape转换为Topojson。使用Shape Escape需要注意的一点是,它可以为对象提供一些愚蠢的名字。只需打开下载的topojson文件,并将名称更改为有用的东西。



然后我使用你的代码来映​​射它,第一件事是检查数据是否正常,但没有显示地图。这有两个原因。第一个是解压缩

中的topojson。

  .datum(topojson.feature(country,country.arcs [0]) )

行。你要求D3映射弧而不是几何。如果你看看console.log并深入到对象,你会看到几何。所以如果你指向topojson几何D3将有一些工作。因此,基准线变为:

  .datum(topojson.feature(country,country.objects.states))

您也使用了Albers投影,这往往最适合美国的数据,所以我改变了墨卡托,关于与规模和中心和一切都很好。投影结果是:

  var projection = d3.geo.mercator()
.scale(5000)
.center([45.55,40.5])
.translate([width / 2,height / 2]);


GIS to Topojson:

I'm using DIVA-gis.org for my data source. I've downloaded the data for Armenias administrative areas. This dowload produces a .shp file. I've tried to pass it directly to topoJSON and I get a json file as follows

Object {
  type: "Topology", 
  objects: Object, 
  arcs: Array[1], 
  transform: Object
} 

Topojson to SVG:

I'm pointing d3 to objects.armenia which contains my geometries property. The problem is that that geometries property contains an array of arcs which is 0. Now within my topoJSON of armenia I do see an arcs property array that contains quite a big array of values... I've tried pointing my d3 code to that element but I still get nothing.
Aside from that I've also used QGIS to convert my .shp file into geoJSON and them use topoJSON to go from geoJSON from topoJSON... but still nothing. My d3 code is as follows

var width = 960,
height = 500;

var projection = d3.geo.mercator()
.scale(1000)
.translate([width / 2, height / 2]);

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

var mapContainer = d3.select("#armenia").append("svg")
.attr("width", width)
.attr("height", height);

d3.json("/ARM_adm/output.json", function(error, country) {
console.log("country",country)
mapContainer.insert("path", ".graticule")
  .datum(topojson.feature(country, country.armenia))
  .attr("class", "land")
  .attr("d", path);
});

I simply get an empty path... any help would be much apreciated.

解决方案

Being a windows user I don't use topojson all that often and when I do I use a virtual machine, so I won't comment on the topojson process. What I tend to do instead is to use some online topojson converters for quick conversion. There are a number services available such as:

All of which have the positives and negatives.

I downloaded the data you mentioned above from DIVA and used Shape Escape to translate into Topojson. One thing to note with Shape Escape is that it can give you some silly names for the objects. Just open the downloaded topojson file and change the names to something useful.

I then used your code to map it, the first thing was to check the data which was all fine but no map was being displayed. There were two reasons for this. The first was the unpacking of the topojson in the

.datum(topojson.feature(country, country.arcs[0]))

line. You were asking D3 to map the arcs not the geometry. If you have a look at the console.log and dig down into the objects you'll see the geometry there. So if you point topojson at the geometry D3 will have something to work. So the datum line becomes:

.datum(topojson.feature(country, country.objects.states))

You were also using an Albers projection, this tends to work best with US data, so I changed that to Mercator and played about with the scale and center and everything was fine. The Projection ended up being:

var projection = d3.geo.mercator()
    .scale(5000)
    .center([45.55, 40.5])
    .translate([width / 2, height / 2]);

这篇关于将shp转换为topoJSON失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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