Openlayers 3圆半径,以米为单位 [英] Openlayers 3 Circle radius in meters

查看:1926
本文介绍了Openlayers 3圆半径,以米为单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取以米为单位的半径 可能这是现有的问题,但是我没有得到正确的结果.我正在尝试在半径和&相同的Postgis中创建Polygon;中心从openlayers圈子获取.

要获取以米为单位的半径,我遵循了链接.

var radiusInMeters = circleRadius * ol.proj.METERS_PER_UNIT['m'];

获得中心后,半径(以米为单位)我试图使用postgis(服务器作业)&在地图上绘制该功能,例如.

select st_astext(st_buffer('POINT(79.25887485937808 17.036647682474722 0)'::geography, 365.70644956827164));

但是两者都没有覆盖相同的区域.任何人都可以让我知道我做错了什么.

基本上,我到Circle的输入/输出仅以米为单位.

解决方案

ol.geom.Circle可能不表示圆圈

OpenLayers圆的几何形状在投影平面上定义.这意味着它们在地图上始终是圆形的,但是覆盖的区域可能并不代表地球上的实际圆.圆圈所覆盖区域的实际形状和大小将取决于所使用的投影.

这可以通过天梭的指示器可视化,该指示器显示了投影到飞机上时地球上的圆形区域是如何变形的.使用投影EPSG:3857,它看起来像:

图片来自 OpenLayer 3的Tissot示例,并显示了全部半径为80万米.如果将这些圆绘制为半径为800000的ol.geom.Circle(使用EPSG:3857),则它们在地图上的大小都是相同的,但是更靠近两极的直径将表示地球面积小得多.

对于大多数使用OpenLayers几何图形的事物来说都是如此.几何的半径,长度或面积都在投影平面中报告.

因此,如果您有ol.geom.Circle,则获取实际表面半径将取决于投影和特征位置.对于某些投影(例如EPSG:4326),由于几何形状甚至不能表示圆形区域,因此无法给出准确的答案.

但是,假设您使用的是EPSG:3857,并且没有画出很大的圆或非常靠近两极,那么圆"将很好地表示圆形区域.

ol.proj.METERS_PER_UNIT

ol.proj.METERS_PER_UNIT只是米和某些其他单位之间的转换表. ol.proj.METERS_PER_UNIT['m']将始终返回1,因为单位'm'是米. EPSG:3857以米为单位,但请注意,它们向两极变形.

解决方案(在阅读并理解上述内容后使用)

要获取ol.geom.Circle的实际地面半径,必须找到圆心与边缘点之间的距离.可以使用 ol.Sphere :

完成

var center = geometry.getCenter()
var radius = geometry.getRadius()
var edgeCoordinate = [center[0] + radius, center[1]];
var wgs84Sphere = new ol.Sphere(6378137);
var groundRadius = wgs84Sphere.haversineDistance(
    ol.proj.transform(center, 'EPSG:3857', 'EPSG:4326'), 
    ol.proj.transform(edgeCoordinate, 'EPSG:3857', 'EPSG:4326')
);

更多选项

如果要添加表示地球上圆形区域的几何图形,则应考虑使用上述天梭示例中使用的方法.也就是说,定义一个具有足够点以显示平滑的规则多边形.这将使它可以在投影之间转换,并且似乎就是您在服务器端所做的事情. OpenLayers 3通过 ol.geom.Polygon.circular :

var circularPolygon = ol.geom.Polygon.circular(wgs84Sphere, center, radius, 64);

还有 ol.geom.Polygon.fromCircle ,它使用ol.geom.Circle并将其转换为表示相同区域的Polygon.

How to get Circle radius in meters May be this is existing question, but i am not getting proper result. I am trying to create Polygon in postgis with same radius & center getting from openlayers circle.

To get radius in meters I followed this. Running example link.

var radiusInMeters = circleRadius * ol.proj.METERS_PER_UNIT['m'];

After getting center, radius (in meters) i am trying to generate Polygon(WKT) with postgis (server job) & drawing that feature in map like this.

select st_astext(st_buffer('POINT(79.25887485937808 17.036647682474722 0)'::geography, 365.70644956827164));

But both are not covering same area. Can any body please let me know where i am doing wrong.

Basically my input/output to/from Circle will be in meters only.

解决方案

ol.geom.Circle might not represent a circle

OpenLayers Circle geometries are defined on the projected plane. This means that they are always circular on the map, but the area covered might not represent an actual circle on earth. The actual shape and size of the area covered by the circle will depend on the projection used.

This could be visualized by Tissot's indicatrix, which shows how circular areas on the globe are transformed when projected onto a plane. Using the projection EPSG:3857, this would look like:

The image is from OpenLayer 3's Tissot example and displays areas that all have a radius of 800 000 meters. If these circles were drawn as ol.geom.Circle with a radius of 800000 (using EPSG:3857), they would all be the same size on the map but the ones closer to the poles would represent a much smaller area of the globe.

This is true for most things with OpenLayers geometries. The radius, length or area of a geometry are all reported in the projected plane.

So if you have an ol.geom.Circle, getting the actual surface radius would depend on the projection and features location. For some projections (such as EPSG:4326), there would not be an accurate answer since the geometry might not even represent a circular area.

However, assuming you are using EPSG:3857 and not drawing extremely big circles or very close to the poles, the Circle will be a good representation of a circular area.

ol.proj.METERS_PER_UNIT

ol.proj.METERS_PER_UNIT is just a conversion table between meters and some other units. ol.proj.METERS_PER_UNIT['m'] will always return 1, since the unit 'm' is meters. EPSG:3857 uses meters as units, but as noted they are distorted towards the poles.

Solution (use after reading and understanding the above)

To get the actual on-the-ground radius of an ol.geom.Circle, you must find the distance between the center of the circle and a point on it's edge. This could be done using ol.Sphere:

var center = geometry.getCenter()
var radius = geometry.getRadius()
var edgeCoordinate = [center[0] + radius, center[1]];
var wgs84Sphere = new ol.Sphere(6378137);
var groundRadius = wgs84Sphere.haversineDistance(
    ol.proj.transform(center, 'EPSG:3857', 'EPSG:4326'), 
    ol.proj.transform(edgeCoordinate, 'EPSG:3857', 'EPSG:4326')
);

More options

If you wish to add a geometry representing a circular area on the globe, you should consider using the method used in the Tissot example above. That is, defining a regular polygon with enough points to appear smooth. That would make it transferable between projections, and appears to be what you are doing server side. OpenLayers 3 enables this by ol.geom.Polygon.circular:

var circularPolygon = ol.geom.Polygon.circular(wgs84Sphere, center, radius, 64);

There is also ol.geom.Polygon.fromCircle, which takes an ol.geom.Circle and transforms it into a Polygon representing the same area.

这篇关于Openlayers 3圆半径,以米为单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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