To rasterize polygons without using GUI

5 visualizaciones (últimos 30 días)
SChow
SChow el 22 de En. de 2020
Editada: Lan Wang Erlandsson el 18 de Feb. de 2021
Hi, I am trying to rasterize a feature (POP2005) of a shapefile containing 246 countries.
I need to manually point the cursor to each of the 246 countries, which is a difficult task(considering some of the 246 countries are too small to be seen on a regular map.
I need help to rasterize the feature in polygons without using GUI ****I could not use the example in https://de.mathworks.com/help/map/vector-to-raster-data-conversion.html . as I found that it works for just one country and all the countries need to be processed separately.
The shapefile is attached
  3 comentarios
SChow
SChow el 22 de En. de 2020
Thanks for your reply,
I have tried to loop for each closed region. It doesnot work out
clc
clear
states=shaperead('Z:\shpfiles\TM_WORLD_BORDERS_SIMPL-0.3.shp');
meLat = [states.Y];
meLon = [states.X];
[meGrid, meRefVec] = vec2mtx(meLat, meLon, 2);
figure
axesm eqdcyl
geoshow(meLat, meLon, 'Color', 'black');
for i=1:246;
swlat=[states(i).Y]';
swlon=[states(i).X]';
den = 2;
[swgrid,swrv] = vec2mtx(swlat,swlon,den);
axesm eqdcyl
meshm(swgrid,swrv)
swpt (i,:) = [round(size(swgrid)./2), [states(i).POP2005]] %%%obtaining the seeds for all the closed regions
end;
row=swpt(:,1);
col=swpt(:,2);
vec=swpt(:,3);
cegrid5 = encodem(meGrid,[row col vec],1);
clma
meshm(cegrid5,meRefVec)
Lan Wang Erlandsson
Lan Wang Erlandsson el 18 de Feb. de 2021
Editada: Lan Wang Erlandsson el 18 de Feb. de 2021
Chad Greene's response to this thread might be useful (use inpolygon instead of vec2mtx/encodem etc ):

Iniciar sesión para comentar.

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by