# Grid Analysis from samples data

I'm trying to analyze set of samples into vector grids in order to generate average data in corresponding grid.I'm working with 50m separated grids but the size of grid may change over time.That's why we need to generate grids on the fly.There is a snapshot of data distribution below.

There are two important things for us,one of which creating grid,as you may know we can create grid from minimum bounding rectangle (MBR) of our data.The trick is let say we have 1000 rows of distributed samples (points) for a large area,then the processing of this MBR plus dividing into grids will be too long.Since,what we want is intersecting grids alone,we must generate them from samples which means we must count as the length of our sample data.That's what I'm asking,is there an easy way to do it without processing all grids?

The other is bound to first where our samples contain various data that we should aggregate into the single grid.How can we do it with or without processing grid at the same time ?

NOTE: This question may require programming or querying which we are wiling to migrate to solution in any ways.Our samples are in text format that we can transform them to any other solutions you can suggest.

You don't have to create the grid at all: to aggregate the points, you only need to know into which cell any given point falls. For a grid with origin coordinates (x0,y0) and cellsize c, compute the row and column coordinates for a point located at (x,y) as

row = floor((y-y0)/c),
col = floor((x-x0)/c).

Those can be assembled into a single cell id. A universal way is to convert them to strings and concatenate them (with a non-numeric separator). In many cases it's a little easier to multiply row by the number of columns needed to span your area and add col to that.

In any event, once you have computed a cell id for each point--a process whose effort is proportional only to the number of points, not the grid size--simply perform a database summary using the cell id as the key.

(In effect, this is an implementation of a sparse array.)

• for (x0,y0) is it min(x,y) of points (minimum coordinates of mbr) ? – Myra Dec 17 '12 at 20:12
• You may choose practically anything for the origin. To minimize roundoff error, it's best to keep the origin within or close to the grid. Many people choose an origin that makes all row and column indexes positive (or at least nonnegative). I frequently round the corner of the MBR down to a nice multiple of the units of measure, such as the nearest 100, 1000, or 10000 meters, depending on the size and scale of the study area: this provides coordinates that are easy to check mentally and allows a border to expand into to compensate for edge effects in analyses. – whuber Dec 18 '12 at 8:18
• For Example,for point (3657664.6769,4854362.786) in meters and for 50 meter cells to the origin (0,0) in your formula => col = 73153 & row = 97087.If I set origin to nearest number (3m,4m) then col&row numbers become even more smaller.That's true to easily check,so all i need is to choose minimum corner for all my samples and they become unity.About the single cell id,i will need them to become single rectangle for visualization.I have to use metric coordinate system for this right ? – Myra Dec 19 '12 at 10:15
• I am afraid I do not understand your question about a "single rectangle for visualization," nor how it is related to cell ids or a "metric coordinate system" (whatever that may be). Let's get back on track: the answer I supplied works--I use it all the time--so I would like to know whether you have actually tested it out with your data. It takes only a minute or two with a field calculation (or its equivalent), so there's no practical barrier to trying it out. – whuber Dec 19 '12 at 16:24
• Is this solution also possible for hexagon grids,if so how ? – Myra Mar 22 '13 at 13:25