create grid of squares over map using mapping toolbox

13 views (last 30 days)
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):
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) ;
My function GRIDXY is available at the Matlab File Exchange and can be downloaded here:
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.

Community Treasure Hunt

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

Start Hunting!