tif 高程_DEM数据如何生成高程点

这次给大家介绍一个arcgis里的实用功能:通过地形数据提取高程点。

首先做好准备工作:

1.地形数据下载获取

可以看一下我之前写的帖子,介绍了如何下载地形数据。

用Arcgis配出一张DEM专题图​zhuanlan.zhihu.com

2.辅助数据下载

县级行政边界:链接: https://pan.baidu.com/s/1ZBBHoN2PiTiJJeFyYH6LgQ 提取码: k6sy

地形数据下载完成后,通过矢量边界数据裁剪得到了下图的地形数据,

c9638395248f45087275b9274fbf84d5.png

找到arctoolbox->3d analyst工具->转换->栅格转多点功能,如下图:

c99a34f363bc07dd6dee2ae2609b8309.png

弹出功能对话框后,依次输入栅格,输出要素类,在输出要素类时直接加上后缀,比如Point.shp。在取点的方法上,可以参照对话框右侧的帮助,介绍的十分详细&#x

  • 2
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用GDAL库中的GDALRasterBand类来实现这个功能。以下是一个简单的示例代码: ```c++ #include <iostream> #include "gdal_priv.h" #include "cpl_conv.h" // for CPLMalloc() int main() { // Open the DEM file GDALAllRegister(); GDALDataset *pDataset = (GDALDataset *) GDALOpen("dem.tif", GA_ReadOnly); if (pDataset == NULL) { std::cerr << "Failed to open DEM file!" << std::endl; return 1; } // Get the raster band GDALRasterBand *pBand = pDataset->GetRasterBand(1); // Get the geo-transform double adfGeoTransform[6]; pDataset->GetGeoTransform(adfGeoTransform); // Define the point to query double x = 123.45; double y = 67.89; // Convert the point to pixel coordinates int nPixel, nLine; pBand->GetGeoTransform(adfGeoTransform, x, y, &nPixel, &nLine); // Read the pixel value float fValue; pBand->RasterIO(GF_Read, nPixel, nLine, 1, 1, &fValue, 1, 1, GDT_Float32, 0, 0); // Print the pixel value std::cout << "Pixel value at (" << x << ", " << y << ") is " << fValue << std::endl; // Close the dataset GDALClose(pDataset); return 0; } ``` 该示例代码首先打开了DEM文件,然后获取了第一个波段(假设DEM只有一个波段)。接下来,它获取了DEM的地理变换,用于将坐标转换为像素坐标。然后,它读取了像素值,并将其输出到控制台。 如果要找到离查询最近的已知高程,您可以在DEM中查询一系列,并找到其中距离查询最近的。以下是一个示例代码: ```c++ #include <iostream> #include "gdal_priv.h" #include "cpl_conv.h" // for CPLMalloc() #include <vector> #include <cmath> struct Point { double x; double y; float z; }; int main() { // Open the DEM file GDALAllRegister(); GDALDataset *pDataset = (GDALDataset *) GDALOpen("dem.tif", GA_ReadOnly); if (pDataset == NULL) { std::cerr << "Failed to open DEM file!" << std::endl; return 1; } // Get the raster band GDALRasterBand *pBand = pDataset->GetRasterBand(1); // Get the geo-transform double adfGeoTransform[6]; pDataset->GetGeoTransform(adfGeoTransform); // Define the query point double x = 123.45; double y = 67.89; // Convert the query point to pixel coordinates int nPixel, nLine; pBand->GetGeoTransform(adfGeoTransform, x, y, &nPixel, &nLine); // Define the search radius in pixels int nRadius = 10; // Define the search area in pixels int nLeft = nPixel - nRadius; int nTop = nLine - nRadius; int nWidth = 2 * nRadius + 1; int nHeight = 2 * nRadius + 1; // Read the pixel values in the search area std::vector<float> vecValues(nWidth * nHeight); pBand->RasterIO(GF_Read, nLeft, nTop, nWidth, nHeight, &vecValues[0], nWidth, nHeight, GDT_Float32, 0, 0); // Convert the search area to geographic coordinates std::vector<Point> vecPoints(nWidth * nHeight); for (int i = 0; i < nWidth; ++i) { for (int j = 0; j < nHeight; ++j) { int nIndex = i * nHeight + j; double x = adfGeoTransform[0] + (nLeft + i) * adfGeoTransform[1] + (nTop + j) * adfGeoTransform[2]; double y = adfGeoTransform[3] + (nLeft + i) * adfGeoTransform[4] + (nTop + j) * adfGeoTransform[5]; vecPoints[nIndex].x = x; vecPoints[nIndex].y = y; vecPoints[nIndex].z = vecValues[nIndex]; } } // Find the point closest to the query point Point closestPoint; closestPoint.z = std::numeric_limits<float>::max(); for (const auto &point : vecPoints) { double dx = point.x - x; double dy = point.y - y; double distance = std::sqrt(dx*dx + dy*dy); if (distance < nRadius && point.z < closestPoint.z) { closestPoint = point; } } // Print the closest point std::cout << "Closest point to (" << x << ", " << y << ") is (" << closestPoint.x << ", " << closestPoint.y << ", " << closestPoint.z << ")" << std::endl; // Close the dataset GDALClose(pDataset); return 0; } ``` 该示例代码首先定义了要查询的,并将其转换为像素坐标。然后,它定义了一个搜索半径,并使用该半径在DEM中查询像素值。接下来,它将搜索区域中的每个像素转换为地理坐标,并将其保存在一个向量中。然后,它找到最靠近查询,并将其输出到控制台。 请注意,此示例代码仅在搜索区域内搜索。如果您需要在整个DEM中搜索,则需要更改搜索区域并读取整个DEM,这可能会非常耗时。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值