简单说明:代码C++,配置GDAL环境(必须),ArcMap
附一个配置GDAL环境的教程,感谢这位大佬
VS2017编译配置GDAL库

输入流向数据的 asc文件,附网盘测试链接
链接:https://pan.baidu.com/s/1-Q35OktO8dOPbjdkI1XC8w
提取码:p2ap

代码如下:

#include <iostream>
#include <fstream>
#include <string>
#include <string.h>
#include <sstream>
#include "ogrsf_frmts.h"
#include "gdal.h"
#include "gdal_priv.h"
#include "gdal_alg.h"
using namespace std;//ToString该函数转载自他人
template<typename T> string toString(const T& t)
{ostringstream oss;  //创建一个格式化输出流oss << t;             //把值传递如流中return oss.str();
}
void Draw_arrow(int fd, int row, int col, int fd_row, int fd_col, double fd_xll, double fd_yll, double fd_res, double &x1, double &x2, double &y1, double &y2);void main()
{int i, j, k;int fd_row = 359;int fd_col = 719;double fd_xll = 112.6;double fd_yll = 32.500277777778;double fd_res = 0.00027777777799999;string flow_path_file = "E:\\arcgis\\fdr.asc";string line_shp_path = "E:\\arcgis\\fdr.shp";string flow_file_path;int **fd_value = new int*[fd_row*fd_col];for (i = 0; i < fd_row*fd_col; i++){fd_value[i] = new int[8];}int **order = new int*[fd_row*fd_col];for (i = 0; i < fd_row; i++){order[i] = new int[fd_col];}for (i = 0; i < fd_row*fd_col; i++)for (j = 0; j < 8; j++)fd_value[i][j] = 0;ifstream FDR(flow_path_file.c_str());if (!FDR){cout << "no in FDR" << endl;system("pause");}string str;for (i = 0; i < 6; i++)getline(FDR, str);//cout << "1" << endl;//system("pause");int tmp;for (i = 0; i < fd_row; i++){for (j = 0; j < fd_col; j++){FDR >> tmp;if (tmp == -9999 || tmp == 0){continue;}// 这里根据ArcGIS的D8算法流向修改了一下,不过问题不大,个人比较喜欢这么计算if (tmp == 32){fd_value[i*fd_col + j][0] = 1;}else if (tmp == 64){fd_value[i*fd_col + j][1] = 1;}else if (tmp == 128){fd_value[i*fd_col + j][2] = 1;}else if (tmp == 16){fd_value[i*fd_col + j][3] = 1;}else if (tmp == 1){fd_value[i*fd_col + j][4] = 1;}else if (tmp == 8){fd_value[i*fd_col + j][5] = 1;}else if (tmp == 4){fd_value[i*fd_col + j][6] = 1;}else if (tmp == 2){fd_value[i*fd_col + j][7] = 1;}}}GDALAllRegister();const char * pFileName = line_shp_path.c_str();const char * pszDriverName = "ESRI Shapefile";GDALDriver * poDriver = GetGDALDriverManager()->GetDriverByName(pszDriverName);if (poDriver == NULL)return;GDALDataset * poDs = poDriver->Create(pFileName, 0, 0, 0, GDT_Unknown, NULL);if (poDs == NULL)return;//wkbPolygon表示绘制多边形;wkbLinearRing表示绘制线环OGRLayer * poLayer = poDs->CreateLayer("ring", NULL, wkbLineString, NULL);//不删if (poLayer == NULL){return;}int line_num;int count_line;double x1, x2, y1, y2;//   system("pause");for (i = 0; i < fd_row; i++){for (j = 0; j < fd_col; j++){count_line = 0;for (k = 0; k < 8; k++){if (fd_value[i*fd_col + j][k] == 1)count_line++;}if (count_line == 0)continue;if (count_line == 1){for (k = 0; k < 8; k++){if (fd_value[i*fd_col + j][k] == 1){Draw_arrow(k + 1, i, j, fd_row, fd_col, fd_xll, fd_yll, fd_res, x1, x2, y1, y2);OGRFeature * poFeature = OGRFeature::CreateFeature(poLayer->GetLayerDefn());OGRLineString line;line.setNumPoints(2);line.setPoint(0, x1, y1, 0);//第一个输入变量是序号,第二、三、四分别是线XYZ坐标line.setPoint(1, x2, y2, 0);poFeature->SetGeometry(&line);if (poLayer->CreateFeature(poFeature) != OGRERR_NONE){return;}OGRFeature::DestroyFeature(poFeature);}}}else if (count_line > 1){for (k = 0; k < 8; k++){if (fd_value[i*fd_col + j][k] == 1){    // k+1Draw_arrow(k + 1 + 8, i, j, fd_row, fd_col, fd_xll, fd_yll, fd_res, x1, x2, y1, y2);OGRFeature * poFeature = OGRFeature::CreateFeature(poLayer->GetLayerDefn());OGRLineString line;line.setNumPoints(2);line.setPoint(0, x1, y1, 0);//第一个输入变量是序号,第二、三、四分别是线XYZ坐标line.setPoint(1, x2, y2, 0);poFeature->SetGeometry(&line);if (poLayer->CreateFeature(poFeature) != OGRERR_NONE){return;}OGRFeature::DestroyFeature(poFeature);}}}}}GDALClose(poDs);OGRCleanupAll();for (i = 0; i < fd_row; i++)delete[]fd_value[i];delete[]fd_value;cout << "***** Finished *****" << endl;//system("pause");
}void Draw_arrow(int fd, int row, int col, int fd_row, int fd_col, double fd_xll, double fd_yll, double fd_res, double &x1, double &x2, double &y1, double &y2)
{int i = row;int j = col;if (fd == 1){x1 = fd_xll + (j + 1)* fd_res;x2 = fd_xll + (j)*fd_res;y1 = fd_yll + (fd_row - i - 1)*fd_res;y2 = fd_yll + (fd_row - i) * fd_res;}else if (fd == 2){x1 = fd_xll + (2 * j + 1)* fd_res / 2.0;x2 = fd_xll + (2 * j + 1)*fd_res / 2.0;y1 = fd_yll + (fd_row - i - 1)*fd_res;y2 = fd_yll + (fd_row - i) * fd_res;}else if (fd == 3){x1 = fd_xll + (j)* fd_res;x2 = fd_xll + (j + 1)*fd_res;y1 = fd_yll + (fd_row - i - 1)*fd_res;y2 = fd_yll + (fd_row - i) * fd_res;}else if (fd == 4){x1 = fd_xll + (j)*fd_res;x2 = fd_xll + (j + 1)* fd_res;y1 = fd_yll + (fd_row - (2 * i + 1) / 2.0)*fd_res;y2 = fd_yll + (fd_row - (2 * i + 1) / 2.0) * fd_res;}else if (fd == 8){x1 = fd_xll + (j + 1)* fd_res;x2 = fd_xll + (j)*fd_res;y1 = fd_yll + (fd_row - (2 * i + 1) / 2.0)*fd_res;y2 = fd_yll + (fd_row - (2 * i + 1) / 2.0) * fd_res;}else if (fd == 5){x1 = fd_xll + (j)*fd_res;x2 = fd_xll + (j + 1)* fd_res;y1 = fd_yll + (fd_row - i) * fd_res;y2 = fd_yll + (fd_row - i - 1)*fd_res;}else if (fd == 6){x1 = fd_xll + (2 * j + 1)*fd_res / 2.0;x2 = fd_xll + (2 * j + 1)* fd_res / 2.0;y1 = fd_yll + (fd_row - i) * fd_res;y2 = fd_yll + (fd_row - i - 1)*fd_res;}else if (fd == 7){x1 = fd_xll + (j + 1)*fd_res;x2 = fd_xll + (j)* fd_res;y1 = fd_yll + (fd_row - i) * fd_res;y2 = fd_yll + (fd_row - i - 1)*fd_res;}//以下是别的,可忽略;else if (fd == 9){x1 = fd_xll + (j + 1)* fd_res - 0.5*fd_res;x2 = fd_xll + (j)*fd_res;y1 = fd_yll + (fd_row - (i + 1))*fd_res + 0.5*fd_res;y2 = fd_yll + (fd_row - i) * fd_res;}else if (fd == 10){x1 = fd_xll + (2 * j + 1)* fd_res / 2.0;x2 = fd_xll + (2 * j + 1)*fd_res / 2.0;y1 = fd_yll + (fd_row - (i + 1))*fd_res + 0.5*fd_res;y2 = fd_yll + (fd_row - i) * fd_res;}else if (fd == 11){x1 = fd_xll + (j)* fd_res + 0.5*fd_res;x2 = fd_xll + (j + 1)*fd_res;y1 = fd_yll + (fd_row - i - 1)*fd_res + 0.5*fd_res;y2 = fd_yll + (fd_row - i) * fd_res;}else if (fd == 12){x1 = fd_xll + (j)*fd_res + 0.5*fd_res;x2 = fd_xll + (j + 1)* fd_res;y1 = fd_yll + (fd_row - (2 * i + 1) / 2.0)*fd_res;y2 = fd_yll + (fd_row - (2 * i + 1) / 2.0) * fd_res;}else if (fd == 16){x1 = fd_xll + (j + 1)* fd_res - 0.5*fd_res;x2 = fd_xll + (j)*fd_res;y1 = fd_yll + (fd_row - (2 * i + 1) / 2.0)*fd_res;y2 = fd_yll + (fd_row - (2 * i + 1) / 2.0) * fd_res;}else if (fd == 13){x1 = fd_xll + (j)*fd_res + 0.5*fd_res;x2 = fd_xll + (j + 1)* fd_res;y1 = fd_yll + (fd_row - i) * fd_res - 0.5*fd_res;y2 = fd_yll + (fd_row - i - 1)*fd_res;}else if (fd == 14){x1 = fd_xll + (2 * j + 1)*fd_res / 2.0;x2 = fd_xll + (2 * j + 1)* fd_res / 2.0;y1 = fd_yll + (fd_row - i) * fd_res - 0.5*fd_res;y2 = fd_yll + (fd_row - i - 1)*fd_res;}else if (fd == 15){x1 = fd_xll + (j + 1)*fd_res - 0.5*fd_res;x2 = fd_xll + (j)* fd_res;y1 = fd_yll + (fd_row - i) * fd_res - 0.5*fd_res;y2 = fd_yll + (fd_row - i - 1)*fd_res;}
}

将代码生成的fdr.shp加载入ArcMap

对其形状标志选择向右的箭头

放大看就完成了

生成有箭头的流向Line.shp 并通过ArcMap绘制带箭头的图,根据D8算法,输入Flow Direction相关推荐

  1. Matlab如何绘制带箭头图形

    Matlab如何绘制带箭头图形 带箭头坐标轴 带箭头曲线 实例演示 例1 带箭头曲线 例2 带箭头曲线+带箭头坐标轴 联系作者 带箭头坐标轴 前段时间推出了绘制箭头坐标轴曲线的方法,许多网友联系我索取 ...

  2. Echarts绘制带箭头的线

    Echarts绘制带箭头的线 这个图主要参考echarts官网的关系图绘制的,难点在于去掉其余导向图的箭头,只保留最后一个节点的箭头,以及处理值为null时箭头的指向问题,代码如下: <temp ...

  3. R语言使用rnorm函数生成正太分布数据、使用plot函数可视化折线图、使用arrows函数在可视化图像中绘制箭头曲线、绘制带箭头线段,可以设置箭头角度,有几个箭头(1起点箭头、2终点箭头,3双箭头)

    R语言使用rnorm函数生成正太分布数据.使用plot函数可视化折线图.使用arrows函数在可视化图像中绘制箭头曲线.绘制带箭头线段,可以设置箭头角度,有几个箭头(1起点箭头.2终点箭头,3双箭头) ...

  4. Android Canvas绘制带箭头的直线

    先看下效果图: 下面我们直接看代码 我自定义了一个View,代码如下: package com.davis.drawtrangle;import android.content.Context; im ...

  5. Matlab任意两点之间绘制带箭头的直线

    Matlab任意两点之间绘制带箭头的直线 简单绘制任意两点之间.本来不想自己写的,可是网上的代码用起来不舒服,所以简单看看原理,原来就是个坐标变换而已.索性自己写了一份,分享如下: function ...

  6. WebGL绘制带箭头贴图的线

    示例 在讲述本文内容之前,我希望读者先具备以下知识点: 了解WebGL的基本知识,懂得调用自定义的Shader程序: 基本的数学基础和空间几何知识: 明白GPU的渲染管线流程: 因为,本文内容主要讲述 ...

  7. opencv之绘制带箭头的线段---arrowedLine

    核心函数 arrowedLine(img, pt1, pt2, color, thickness=None, line_type=None, shift=None, tipLength=None) i ...

  8. 为图片绘制带箭头的坐标轴

    需求说明 有时候,我们需要对一张图片进行坐标轴绘制,直观观察图片的长宽分布,并根据坐标轴中心点的选取来实现不同位置的坐标轴. 常见需求: 中心点自定义 坐标间隔自定义 坐标轴颜色自定义 透明度自定义 ...

  9. Canvas 教程:如何绘制带箭头的曲线

    这篇文章要解决一个问题,就是给定 HTML 中任意一个点(起点)和另一个点(终点),绘制一条带箭头的曲线. 废话不多说,直奔主题. 我们只有两个点的相对偏移量(offset),思路就是以这两个点作为对 ...

最新文章

  1. 六年级小学python第四讲_python第四讲
  2. js---PC端滑动进度条
  3. tinymce 设置和获取编辑器的内容
  4. 区块链共识机制分析——论PoW,PoS,DPos和DAG的优缺点
  5. plsqldev远程连接mysql_PLSQL Developer连接远程Oracle数据库
  6. 如何分析SAP UI5应用的undefined is not a function错误
  7. 一个程序员的逗逼瞬间(一)
  8. OWASP-ZAP扫描器的使用(攻击)
  9. 程序员画图工具Draw.io
  10. 矩阵分析 (七) 矩阵特征值的估计
  11. 什么是JDK JRE JVM?
  12. CasADi——数据类型详解与基本操作介绍
  13. 糗事百科李威: 如何基于数据构建推荐系统,助力精细化运营?
  14. Stairway to T-SQL: Beyond The Basics Level 4: Using Views to Simplify Your Query - SQLServerCentral
  15. Mini-CEX在神经内科住院医师临床能力培养中的应用
  16. Pycharm、Vscode设置美女背景【内附20张高清图片】
  17. Google Earth Engine (GEE)——awesome-gee-community-catalog
  18. “被骗”的1600万,QQ飞车多久能赚回来?
  19. 高校被盗邮箱处置的运维经验分享-清华大学
  20. java环境搭建及概述

热门文章

  1. 省一级计算机ppt,江苏省计算机一级要点.ppt
  2. linux系统LAMP的实战应用
  3. Python实现因子分析(附案例实战)
  4. {Samsung K9F1208U0B,NAND_MFR_SAMSUNG, 0x76, 26, 0, 3, 0x4000, 0}的分析
  5. MSF模块爆破SSH
  6. 嵌入式Linux下基于FFmpeg的视频硬件编解码
  7. 家庭网络组网技术介绍
  8. 猜猜这是经过了多少次加密?
  9. oracle 磁带 恢复,NBU Oracle 异机恢复磁带备份测试-有catalog
  10. c语言程序设计课程技能点,C语言程序设计课程标准.doc