使用d3-geo-projection命令行工具设置自定义投影 [英] Setting a custom projection using d3-geo-projection command line tool

查看:447
本文介绍了使用d3-geo-projection命令行工具设置自定义投影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用geoproject在geojson文件上设置投影。具体来说,我正在尝试将投影设置为BCalbers( http://spatialreference.org/ref/epsg / 3005 /

I'm trying to use geoproject to set the projection on a geojson file. Specifically I'm trying to set the projection to BCalbers (http://spatialreference.org/ref/epsg/3005/)

我看到geoproject有许多投影选项,即

I see geoproject has a number of projections options i.e.

geoproject 'd3.geoAlbersUsa()' us.json \
  > us-albers.json

但是可以使用命令行工具设置自定义投影吗?我希望这样的事情是可能的:

but it is possible to set a custom projection using the command line tool? I was hoping something like this would be possible:

geoproject '+proj=aea +lat_1=50 +lat_2=58.5 +lat_0=45 +lon_0=-126 +x_0=1000000 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs' build/airzones.geojson \
  > bc-albers.json

但没有骰子。这适用于ogr2ogr

but no dice. This works with ogr2ogr

ogr2ogr -f GeoJSON -t_srs "+proj=aea +lat_1=50 +lat_2=58.5 +lat_0=45 +lon_0=-126 +x_0=1000000 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs  " \


推荐答案

D3地理投影支持一系列常规投影(和自定义投影),通常可以重新创建任何给定的特定投影。但是,在重新创建投影时,d3投影不会复制地图单位*。 D3投影在svg坐标空间中创建单位(投影的坐标将从 [0,0] (位于左上角)开始)。这样可以跳过投影数据的步骤(通常使用d3进行实时处理),然后重新缩放并转换它以显示地图。

D3 geo projections support a range of generic projections (and custom projections), recreating any given specific projection is generally possible. However, when re-creating a projection, d3 projections don't replicate map units*. D3 projections create units in svg coordinate space (the projected coordinates will start from [0,0] which is the top left corner). This allows skipping the step of projecting data (often on the fly with d3), and then rescaling and translating it to show a map.

比较:使用引用的 d3.geoAlbersUsa(),如果使用默认比例尺,则d3将沿x轴将数据投影到大约960个像素上。非常适合在SVG中未经修改地使用-坐标可用作直接SVG坐标。在ArcGIS或QGIS中使用BC Albers可以在数百万米的范围内投影数据。

Compare: Using the referenced d3.geoAlbersUsa(), d3 will project data across roughly 960 pixels along the x axis if using the default scale. Perfect for unmodified use in an SVG - coordinates could be used as straight SVG coordinates. Using a BC Albers in ArcGIS or QGIS will project data across millions of meters.

除了单位以外,您还可以按比例重新创建BC Albers,以保留Web形状,常规BC Albers的距离,方向和面积。但是,由于d3不使用.prj文件之类的投影定义或其他定义,因此您需要使用d3的投影方法和适当的参数。

Units aside, however, you can recreate a BC Albers proportionally scaled for web preserving the shape, distance, direction, and area of a regular BC Albers. But as d3 doesn't take projection definitions such as .prj files or other definitions, you need to use a d3's projection methods and the appropriate parameters.

对于BC Albers,您的平行度是:50和58.5,中心经度是-126,投影类型是Albers。这就是您所需要的-(错误的)东/北参考是重新创建地图单位-在Web场景中通常不需要(如果需要,则使用更完整的GIS平台会更合适)。

For a BC Albers your parallels are: 50 and 58.5, your central longitude is -126, and your projection type is an Albers. This is all you need - the (false) easting/northing reference is to recreate map units - which should not generally be needed in a web scenario (if you do, using a more complete GIS platform would be more appropriate).

因此,要设置投影,您将使用:

So, to set the projection, you would use:

d3.geoAlbers()
  .center([0,y])
  .rotate([-x,0])
  .parallels([a,b])
  .scale(k)

其中

x = center longitude (negative because we rotate the globe under the map)

a, b = standard parallels

k = scale factor(for a d3.geoAlbers(): whole world is 960 px across with a scale of 1070, the default scale, larger numbers expand this/zoom in)

y = centering latitude.

注意:y不会改变投影,它只会翻译它-BC Albers的y参考位于不列颠哥伦比亚省以南,仅作为北向参考,因为它对地图的形状,区域,距离或方向没有影响。对于不列颠哥伦比亚省的阿尔伯斯,我可能会选择50.5,因为它位于育空地区和华盛顿边境之间的中间位置,后者是不列颠哥伦比亚省的北部和南部边界(嗯,除了温哥华岛和某些海湾群岛,所以说50度北方,对不起,我忘记了你维多利亚州。)

Note: y does not alter the projection, it merely translates it - the y reference for a BC Albers is south of BC, it is just a reference for northings, as it has no impact on map shape, area, distance, or direction. For a BC Albers, I would probably choose 50.5 as it is half way between the Yukon border and the Washington border which are the northern and southern limits of BC (well, excepting Vancouver Island and some of the Gulf Islands, so let's say 50 degrees north, sorry I forgot about you Victoria).

还请记住,d3的投影功能假定未投影的数据(或WGS84中的已投影)由长数据组成

Also remember the the projection functionality of d3 assumes data that is unprojected (or "projected" in WGS84), consisting of long lat pairs.

您可以在命令行制图文章此处

You can see how Mike Bostock uses these methods in his command line cartography article here:

geoproject 'd3.geoConicEqualArea().parallels([34, 40.5]).rotate([120, 0]).fitSize([960, 960], d)' < ca.json > ca-albers.json

fitSize 在此示例中缩放并转换要素到指定的边界框-此转换和缩放不会更改投影参数,就像 center 方法中的y坐标一样,不会更改距离,面积,形状或角度(井,距离和面积仍与适当的BC Albers成比例)。

fitSize in this exmaple scales and translates the features to the specified bounding box - this translate and scale does not alter the projection parameters, and like the y coordinate in the center method, does not alter distance, area, shape, or angle (well, distance and area remain proportional to a proper BC Albers).

*您可以重新创建地图单位(错误的东/北可能需要一些自定义投影工作),但这并不是真正的平台,使用许多其他平台会更容易。

*You could recreate map units (false eastings/northings might require some custom projection work), but this is not the platform for it really, it would be easier to use many other platforms.

另请参阅以下问题和答案:将EPSG投影范围转换为D3。 js

See also this question and answer:Converting EPSG projection bounds to a D3.js.

这篇关于使用d3-geo-projection命令行工具设置自定义投影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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