create grid of squares over map using mapping toolbox

37 views (last 30 days)
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.

Answers (1)

Jos (10584)
Jos (10584) on 1 Mar 2016
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 Comments
Amir
Amir on 1 Mar 2016
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) on 2 Mar 2016
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)

Sign in to comment.

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!