Convert .shp file to .mat file
7 views (last 30 days)
Show older comments
How can i convert a shape file into a matlab file?
0 Comments
Answers (1)
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
See Also
Categories
Find more on Oceanography and Hydrology 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!