Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Openlayers 5 使用OpenLayers 5显示地理参考图像_Openlayers 5 - Fatal编程技术网

Openlayers 5 使用OpenLayers 5显示地理参考图像

Openlayers 5 使用OpenLayers 5显示地理参考图像,openlayers-5,Openlayers 5,我正在尝试制作一个应用程序,用户可以对扫描的地图进行地理参考。您可以在此处查看一个示例: 有两幅图像: -不旋转 -轮换 第一个图像已正确加载到地图上,但带有旋转的图像未正确加载 我找不到有关OpenLayers 5是否可以使用存储在world文件中的变换参数处理图像的信息。可能我错过了什么但弄不清是什么 这就是我的逻辑工作原理: 使用4个点的仿射变换计算变换参数。您可以在Affine.js文件中看到逻辑。从源图像和地图中至少拾取4个点。然后利用这4个点计算变换参数。然后我计算图像的范围:

我正在尝试制作一个应用程序,用户可以对扫描的地图进行地理参考。您可以在此处查看一个示例: 有两幅图像:

  • -不旋转
  • -轮换
第一个图像已正确加载到地图上,但带有旋转的图像未正确加载

我找不到有关OpenLayers 5是否可以使用存储在world文件中的变换参数处理图像的信息。可能我错过了什么但弄不清是什么

这就是我的逻辑工作原理:

使用4个点的仿射变换计算变换参数。您可以在Affine.js文件中看到逻辑。从源图像和地图中至少拾取4个点。然后利用这4个点计算变换参数。然后我计算图像的范围:

width = image.width in pixels
height = image.height in pixels
width *= Math.sqrt(Math.pow(parameters.A, 2) + Math.pow(parameters.D, 2));
height *= Math.sqrt(Math.pow(parameters.B, 2) + Math.pow(parameters.E, 2));

// then the extent in projection units is
extent = [parameters.C, parameters.F - height, parameters.C + width, parameters.F];
世界文件参数按定义计算

问题可能是,在OpenLayers 5中加载为静态图像时,带旋转的图像没有旋转,但找不到旋转的方法。

我尝试在QGIS和ArcMap中加载这两个图像,并使用计算出的参数,并且两个图像都已正确加载。您可以看到第二张图片的结果:

您可以在此处看到每个图像的参数:

Image: test.png
Calculated extent: [436296.79726721847, 4666723.973240128, 439864.3389057907, 4669253.416495154]
Calculated parameters (for world file):
3.8359372067274027
-0.03146800786355865
-0.03350636818089405
-3.820764346376064
436296.79726721847
4669253.416495154

Image: test_rotation.png
Calculated extent: [437178.8291026594, 4667129.767589236, 440486.91675884253, 4669768.939256327]
Calculated parameters (for world file):
3.506332904308879
-1.2831186688536016
-1.3644002712982917
-3.7014921022625864
437178.8291026594
4669768.939256327

我意识到我的方法是错误的。在地图投影中,不需要计算图像的范围并在图层中设置它。我可以简单地添加一个转换函数,负责在图像投影和地图投影之间转换坐标。这样,图像层总是将其投影设置为图像投影,并将范围设置为图像的大小(以像素为单位)

转换函数是这样添加的:

import { addCoordinateTransforms } from 'ol/proj.js';

addCoordinateTransforms(
  mapProjection,
  imageProjection,
  coords => {
    // forward
    return Affine.transform(coords);
  },
  coords => {
    // inverse
  }
)
仿射参数再次从至少3个点计算:

// mapPoints - coordinates in map projection
// imagePoints - coordinates in image projection
Affine.calculate(mapPoints, imagePoints);
你可以在这里看到一个完整的例子-