目前在d3中,如果您要绘制一个geoJSON对象,则必须对其进行缩放并对其进行翻译,以使其达到所需大小并将其翻译以使其居中.这是一个非常乏味的反复试验,我想知道是否有人知道更好的方法来获得这些价值观?
所以,例如,如果我有这个代码
var path, vis, xy;
xy = d3.geo.mercator().scale(8500).translate([0, -1200]);
path = d3.geo.path().projection(xy);
vis = d3.select("#vis").append("svg:svg").attr("width", 960).attr("height", 600);
d3.json("../../data/ireland2.geojson", function(json) {
return vis.append("svg:g")
.attr("class", "tracts")
.selectAll("path")
.data(json.features).enter()
.append("svg:path")
.attr("d", path)
.attr("fill", "#85C3C0")
.attr("stroke", "#222");
});
Run Code Online (Sandbox Code Playgroud)
到底如何获得.scale(8500)和.translate([0,-1200]),而一点一点去?
GeoJSON和TopoJSON之间的区别是什么?我何时使用另一个?
GitHub上TopoJSON的描述意味着TopoJSON文件缩小了80%.那么为什么不一直只使用TopoJSON呢?
如何在地图标签上施加力排斥,以便他们自动找到合适的位置?
Mike Bostock的Let's Make a Map(截图如下).默认情况下,标签放在点的坐标处,多边形/多边形的path.centroid(d)
+左边或右边的简单对齐,因此它们经常进入冲突状态.
我遇到的一项改进需要添加人为IF
修复,并添加所需数量,例如:
.attr("dy", function(d){ if(d.properties.name==="Berlin") {return ".9em"} })
Run Code Online (Sandbox Code Playgroud)
随着要重新调整的标签数量增加,整体变得越来越脏:
//places's labels: point objects
svg.selectAll(".place-label")
.data(topojson.object(de, de.objects.places).geometries)
.enter().append("text")
.attr("class", "place-label")
.attr("transform", function(d) { return "translate(" + projection(d.coordinates) + ")"; })
.attr("dy", ".35em")
.text(function(d) { if (d.properties.name!=="Berlin"&&d.properties.name!=="Bremen"){return d.properties.name;} })
.attr("x", function(d) { return d.coordinates[0] > -1 ? 6 : -6; })
.style("text-anchor", function(d) { return d.coordinates[0] > -1 ? "start" : "end"; });
//districts's labels: polygons objects.
svg.selectAll(".subunit-label") …
Run Code Online (Sandbox Code Playgroud) 我一直在寻找答案,我无法弄明白.
quantization
和之间有什么区别simplification
?量化是另一种简化方式吗?在某些情况下使用量化是否更好?或者我应该使用两者的组合?
给定一个data.tsv文件:
id code name
1 AL Alabama
2 AK Alaska
4 AZ Arizona
5 AR Arkansas
6 CA California
... ... ...
Run Code Online (Sandbox Code Playgroud)
给定topojson.json文件:(结构正确,数值是随机的)
{
"type":"Topology",
"transform":
{
"scale": [0.0015484881821515486,0.0010301030103010299],
"translate":[-5.491666666666662,41.008333333333354]
},
"objects":
{
"states":
{
"type":"GeometryCollection",
"geometries":
[
{"type":"Polygon","arcs":[[0]],"properties":{"code_2":"AL"}},
{"type":"Polygon","arcs":[[1]],"properties":{"code_2":"AK"}}
]
}
},
"arcs":
[
[[2466,9916],[-25,-5],[3,-13]],
[[2357,9852],[1,-2],[1,-2]]
]
}
Run Code Online (Sandbox Code Playgroud)
如何使用公共字段(1)将其他字段(2)的值注入json文件?
1]:data.txt#code
和topojson.txt.objects.states.geometries.properties.code_2
2]: data.txt#name
最终结果应包含:
{"type":"Polygon","arcs":[[0]],"properties":{"code_2":"AL", "name":"Alabama" }},
{"type":"Polygon","arcs":[[1]],"properties":{"code_2":"AK", "name":"Alaska" }},
Run Code Online (Sandbox Code Playgroud)
编辑:接受的答案:
topojson -o final.json -e data.tsv --id-property=code_2,code -p code_2,state=name -- topojson.json
Run Code Online (Sandbox Code Playgroud) topoJSON
geoJSON
在互联网上绘制地图时,文件非常常见.是否可以导入它们R
来绘制等值区域图?
是否可以使用JavaScript(通过d3,topojson或任何其他方式)确定给定lat,lon中的GeoJSON点是否位于给定的GeoJSON多边形内?
例如,我可以根据这里的教程绘制一张显示英国国家的地图.
然后我有一些点有坐标但没有迹象表明它们在哪个国家.
我想显示每个国家的总点数.
我可以确定哪个国家/地区包含浏览器中的每个点,或者我是否需要使用PostGIS或类似方法在服务器上预处理我的点数据?
我需要将geojson文件转换为topojson并可能简化topojson文件.我已经设法安装Node.js和topojson包.但我不知道如何运行topojson.
维基列出了一堆命令行选项,但是我在哪里运行这些命令?我已经尝试在命令提示符和节点shell中运行它们.Node,GDAL,ogr2ogr和TopoJSON都是我的新概念,所以我有点困惑和不知所措.
顺便说一下,我在Windows上运行.
编辑
我升级了节点并运行了"npm install -g contextify"看起来它安装得很好(没有错误),但输入"which contextify"什么都不返回.安装contextify时的消息:
npm http GET https://registry.npmjs.org/contextify
npm http 304 https://registry.npmjs.org/contextify
npm http GET https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/bindings
> contextify@0.1.6 install /usr/local/share/npm/lib/node_modules/contextify
> node-gyp rebuild
CXX(target) Release/obj.target/contextify/src/contextify.o
SOLINK_MODULE(target) Release/contextify.node
SOLINK_MODULE(target) Release/contextify.node: Finished
contextify@0.1.6 /usr/local/share/npm/lib/node_modules/contextify
??? bindings@1.1.1
Run Code Online (Sandbox Code Playgroud)
原版的
我在使用npm安装contextify时遇到问题:
npm install -g contextify
Run Code Online (Sandbox Code Playgroud)
并获取以下错误消息:
npm http GET https://registry.npmjs.org/contextify
npm http 304 https://registry.npmjs.org/contextify
npm http GET https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/bindings
> contextify@0.1.6 install /usr/local/share/npm/lib/node_modules/contextify
> node-gyp rebuild
CXX(target) Release/obj.target/contextify/src/contextify.o
SOLINK_MODULE(target) Release/contextify.node
SOLINK_MODULE(target) Release/contextify.node: Finished
/usr/local/Cellar/node/0.10.1/lib/node_modules/npm/bin/node-gyp-bin/node-gyp: line 2: …
Run Code Online (Sandbox Code Playgroud) topojson ×10
d3.js ×6
geojson ×5
gis ×2
javascript ×2
json ×2
node.js ×2
cartography ×1
contextify ×1
force-layout ×1
maps ×1
node-gyp ×1
r ×1