所有美国城市的TopoJSON数据

TopoJSON data for all US Cities

本文关键字:TopoJSON 数据 城市 美国      更新时间:2023-09-26

我一直在寻找一个好的数据来投影D3中的美国州和城市边界(类似于所有著名的例子中的县/州边界)。我正在寻找这个能够地图数据我有一个城市的水平。

到目前为止,我想到的最好的数据是来自美国人口普查局的数据位于这里:http://www.census.gov/cgi-bin/geo/shapefiles2013/main(从下拉菜单中选择地点)

我下载了每个州的所有单独文件,并使用ogr2ogr将它们转换为GeoJSON,然后使用TopoJSON库将它们转换为TopoJSON。下面是我使用的命令:

ogr2ogr -f GeoJSON -s_srs EPSG:4269 cities.geojson tl_2011_37_place.shp
topojson -s 7e-9 --id-property=+GEOID -o cities.json -- cities.geojson

然后我使用D3来映射,但我没有得到寄宿者…更确切地说,它看起来像一般的形状是正确的,但边界线似乎已经削减/褪色的所有地方。有人能帮我指出我做错了什么吗?

谢谢!

南卡罗来纳州:

下面是我用来映射数据的代码:

    queue()
    .defer(d3.json, "/shapefile/cities/cities.json")
    .defer(d3.tsv, "tsentiment.tsv", function(d) { countySentiment.set(d.id, +d.sentiment); })
    .await(ready);
/*
This function is used to initially draw of the US map with the initial data set
*/
function ready(error, cities) 
{
//setup your SVG
  svg = d3.select("#map_svg").append("svg")
    .attr("width", width)
    .attr("height", height);
//Draw the city lines
  svg.append("g")
        .attr("class", "uscities")
        .selectAll("path")
        .data(topojson.feature(cities, cities.objects.cities).features)
        .enter().append("path")
        .attr("d", path);
}

看看这是否对你有帮助

var group = svg.selectAll("g")
    .data(features)
    .enter()
    .append("g");
var areas = group.append("path")
        .attr("d", path)
        .attr("class", "area")
        .attr("fill", "#DCDCDC")
        .attr("stroke", "#FFFFFF");