Convert .shp file to .mat file

7 views (last 30 days)
SUSHMA MB
SUSHMA MB on 26 Mar 2015
Commented: guodong zhao on 6 Nov 2022
How can i convert a shape file into a matlab file?

Answers (1)

Danhay
Danhay on 23 May 2016
Hello Sushma, I am not sure if you still need this, but this is what I use:
%%
% Read the shapefile into matlab as well as the boundaries
shp_res = shaperead(data.shp);
x1 = round(shp_res.BoundingBox(1,1))-1;
x2 = round(shp_res.BoundingBox(2,1))+1;
y1 = round(shp_res.BoundingBox(1,2))-1;
y2 = round(shp_res.BoundingBox(2,2))+1;
%%
% get the length of the lon lat using a resolution of 0.1
[lon, lat]=meshgrid(x1:0.1:x2,y1:0.1:y2);
lon1(:,1) = lon(1,:); lat1(:,1) = lat(:,1);
x4 = length(lon1); y4 = length(lat1);
Z = randn(x4,y4);
%%
% create the mat file
R = makerefmat('RasterSize',size(Z'),'Lonlim',[a1 a2],'Latlim',[b1 b2]);
mat_data = vec2mtx(shp_res.Y,shp_res.X,Z',R,'filled');
  1 Comment
guodong zhao
guodong zhao on 6 Nov 2022
you are welcome!thanks,he maybe not liv.... but i need

Sign in to comment.

Categories

Find more on Oceanography and Hydrology in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!