필터 지우기
필터 지우기

create grid of squares over map using mapping toolbox

조회 수: 15 (최근 30일)
Amir
Amir 2016년 3월 1일
댓글: Jos (10584) 2016년 3월 2일
Hi,
I am working on a project where i have specific locations (latitude/longitude) and need to create a type of heat-map which represents how populated each region.
I would like to create a grid of squares over the map (which i have created using the mapping toolbox) and color each square based on the number of points registered inside it. I have done a similar thing using circles, where i verify if the point is inside each circle using the "inpoly" function. However, i am finding it challenging to do the same using squares. I guess as long as i know the corner points of each square, i would still be able to follow the same approach.
I have attached a sample image to show you the type of grid i am looking for. Ideally, i would like to be able to specify the size of each of the squares in for example km. The map was produced using the following code (the grids were overlaid in paint):
figure(1);
f=worldmap([33 68],[-15 37]);
geoshow('landareas.shp', 'FaceColor', [1 1 1],'DefaultEdgeColor', 'b')
Thank you very much for you help in advance.

답변 (1개)

Jos (10584)
Jos (10584) 2016년 3월 1일
You can add a grid like this:
f=worldmap([33 68],[-15 37]);
geoshow('landareas.shp', 'FaceColor', [1 1 1],'DefaultEdgeColor', 'b')
AxisHandle = gca ;
GridHandle = gridxy(linspace(AxisHandle.XLim(1),AxisHandle.XLim(2),25), ...
linspace(AxisHandle.YLim(1),AxisHandle.YLim(2),25)) ;
set(GridHandle,'color',[.6 .6 .6],'LineWidth',.5) ;
uistack(GridHandle,'top')
My function GRIDXY is available at the Matlab File Exchange and can be downloaded here: http://www.mathworks.com/matlabcentral/fileexchange/9973
  댓글 수: 4
Amir
Amir 2016년 3월 1일
Jos,
Yes it does provide the points, but i would need to have the coordinates in latitude/longitude. Also, the "25" in that lines specifies the number of squares generated over the plot. However, i need to specify the size of each of the squares instead. so for example, the side length of each square to be 25km.
Jos (10584)
Jos (10584) 2016년 3월 2일
I am not sure about the units of the axes, but you can create these points using colon notation (start:step:end) So if the units are kilometers, this would do, I think:
Xpoints = AxisHandle.XLim(1):25:AxisHandle.XLim(2)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by