Question

I would like to convert a shape file to raster grid using matlab. First I tried to do it in Python but I have faced some difficulties and my superior recommended me to use MATLAB. I use matlab randomly and I am pro in it.

The data I have is an ASCII file with a set of points with their coordinates and I want to create a raster grid from them.

I was thinking i can read the data, create an empty matrix with the size of (xmin,ymin,xmax,ymax) from data. Then I should assign the z value to each grid cell based on the coordinate of the corresponding point.

The grid size should be 0.5m . I have copied a part of data for your consideration. I would be thankful if somebody help me to find the right way of thinking for this application.

32511632.00 5402000.00 354.29 17.50
32511632.50 5402000.00 354.29 17.50
32511633.00 5402000.00 354.35 18.00
32511633.50 5402000.00 354.52 15.75
32511634.00 5402000.00 354.70 12.37
32511634.50 5402000.00 354.61 10.62
32511635.00 5402000.00 354.11 8.50
32511635.50 5402000.00 353.43 9.50
32511636.00 5402000.00 352.72 14.25
32511636.50 5402000.00 352.22 17.62

(the first column is X, the second is Y, the third is Z and the last in an attribute)

Was it helpful?

Solution

isize = floor((ymax - ymin) / 0.5) + 1;
jsize = floor((xmax - xmin) / 0.5) + 1
M=zeros(isize, jsize);

Then for each input line:

i = floor((y - ymin) / 0.5) + 1;
j = floor((x - xmin) / 0.5) + 1;
M(i, j) = z;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top