城市需求显示在地图上(附MATLAB程序)

我们显示很多城市信息时, 有时候需要把各地人口数量, 各地城市对某种货物的需求量呈现到地图上, 可以用以下代码实现:

程序结果:

% 画中国地图

clc;close all;clear all;

%%曲面拟合

warning off;%禁止显示警告信息

% load lonlatdata.mat;

lonlatdata=xlsread('工作簿1.xls','D2:F301');%载入xls的数据

x=lonlatdata(:,1);%载入经度

y=lonlatdata(:,2);%载入纬度

z=lonlatdata(:,3);%载入需求

%设置拟合参数

xmin=min(lonlatdata(:,1));

xmax=max(lonlatdata(:,1));

ymin=min(lonlatdata(:,2));

ymax=max(lonlatdata(:,2));

xstep=(xmax-xmin)/100;

ystep=(ymax-ymin)/100;

gx=xmin:xstep:xmax;

gy=ymin:ystep:ymax;

g=gridfit(x,y,z,gx,gy);

%%----------------数据拟合开始--------------------

position01=-100000;%用于调整Z轴比例,绝对值越小,曲面越曲

%%----------------数据拟合结束--------------------

figure;

colormap(hot(256));

mesh(gx,gy,g);

camlight right;

lighting phong;

shading interp

hold on;

map_path = shaperead('bou2_4l.shp');% 省级行政区划

map_X = [map_path(:).X];

map_Y = [map_path(:).Y];

ax=length(map_X);

ay=length(map_Y);

map_Z=ones(ax,1)*(position01);

plot3(map_X,map_Y,map_Z);

hold on;

map_path = shaperead('diquJie_polyline.shp');% 地级行政区划

map_X = [map_path(:).X];

map_Y = [map_path(:).Y];

ax=length(map_X);

ay=length(map_Y);

map_Z=ones(ax,1)*(position01);

plot3(map_X,map_Y,map_Z);

hold on;

%%画城市点

x=lonlatdata(:,1);

y=lonlatdata(:,2);

acity=length(x);

z0=ones(acity,1)*(position01);

plot3(x,y,z0,'r.');

hold on;

%画城市线

for i=1:acity

plot3([x(i),x(i)],[y(i),y(i)],[z0(i),z(i)],'r:');

hold on;

end

xlabel('经度');

ylabel('纬度');

zlabel('需求(元)');

title('需求拟合');

完整代码见: https://download.csdn.net/download/corn1949/88774936

需要讨论可加Q1579325979

相关推荐
一个很帅的帅哥6 分钟前
JavaScript事件循环
开发语言·前端·javascript
驰羽7 分钟前
[GO]gin框架:ShouldBindJSON与其他常见绑定方法
开发语言·golang·gin
程序员大雄学编程13 分钟前
「用Python来学微积分」5. 曲线的极坐标方程
开发语言·python·微积分
Jose_lz1 小时前
C#开发学习杂笔(更新中)
开发语言·学习·c#
一位代码1 小时前
python | requests爬虫如何正确获取网页编码?
开发语言·爬虫·python
看到我,请让我去学习1 小时前
Qt 控件 QSS 样式大全(通用属性篇)
开发语言·c++·qt
筱砚.2 小时前
【STL——vector容器】
开发语言·c++
lly2024062 小时前
数据访问对象模式(Data Access Object Pattern)
开发语言
std860212 小时前
Rust 与 Python – 这是未来的语言吗?
开发语言·python·rust
2503_930123932 小时前
Kubernetes (六)调度策略详解:从节点匹配到Pod调度全流程
java·开发语言