How to crop the area outside the shaperfile on a map

Technical Source
2 min readDec 25, 2023

--

Dear,

I have a .txt file with three columns: longitude, latitude and another variable (i.e. altitude, temperature, precipitation), the data are from weather stations, I have a value per station.

As the seasons are sparse I used the griddata function to interpolate the values and then plotted a shaperfile over the image.

The generated figure is as follows::

And the script I used is as follows:

clear all
close all
load dados_dd.txt
d = (dados_dd);
lat = 0 - d(:,2); %negative because I am in the southern hemisphere
lon = 0 - d(:,1);
cota = d(:,3);
N = 1000;
[Xi, Yi] = meshgrid(linspace(-49,-44,N),linspace(-24,-20,N));
Ci = griddata(lon, lat, cota, Xi, Yi);
imagesc(linspace(-49,-44,N),linspace(-24,-20,N),Ci);xlabel('Longitude');
ylabel('Latitude');
colorbarS = shaperead('shaperfile.shp')
geoshow(S)

I would like to know if there is a way to remove the parts that are outside the shaperfile

I do not understand much of interpolation, is it possible to interpolate the data so that they fill the entire Shaperfile?

Sorry for the inconvenience, but I really need help.

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

Have a look on inpolygon. This will give you the indices, which are lying inside the given polygon (shape file here). From this, you can add NaN to the points lying outside and plot. This will solve your purpose.

Or have a look on _ScatteredInterpolant, here you can specify not to extrapolation. YOu will get only the region lying inside the closed region.

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

Responses (1)