Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a vector file containing points with an attributed value (no. of employes at that location). I need to create a hectare raster with the sum of employes for each grid cell. I'm using QGIS and have so far played around with gdal_rasterize gdal_grid but with no success. I'm not even sure if I'm looking at the right tool. Can anyone give me a hint?

share|improve this question
add comment

2 Answers

Assuming you know how to create the hectare sized grid (using the Vector->Research tools->Vector grid) then you can import both the point shapefile and the grid polygons into SpatiaLite and with an aggregate query get the totals as an attribute column in each grid sqare. For example if you have an id column in the grid polygon layer, and a num_employees column in the points layer, then:

Using spatialite, import the two shapefiles:

.loadshp employee_points points utf-8 4326
.loadshp grid grid utf-8 4326

Add new columns in the grid layer for the totals. You can also get averages, etc while you're at it...

ALTER TABLE grid ADD COLUMN ttl_employees INTEGER;
ALTER TABLE grid ADD COLUMN avg_employees INTEGER;
ALTER TABLE grid ADD COLUMN cnt_pts INTEGER;

Now do the UPDATE to populate those columns with a SELECT query that uses the SQL aggregate "SUM" and the ST_Contains() function. The second part of the WHERE clause matches each select to the correct row in the outer UPDATE statement:

UPDATE grid SET ttl_employees=(
SELECT SUM(p.num_employees) 
FROM points AS p, grid AS g
WHERE ST_Contains(g.Geometry, p.Geometry) AND
g.id = grid.id
);
UPDATE grid SET avg_employees=(
SELECT AVG(p.num_employees) 
FROM points AS p, grid AS g
WHERE ST_Contains(g.Geometry, p.Geometry) AND
g.id = grid.id
);
UPDATE grid SET cnt_pts=(
SELECT COUNT(p.id) 
FROM points AS p, grid AS g
WHERE ST_Contains(g.Geometry, p.Geometry) AND
g.id = grid.id
);
share|improve this answer
    
I got the data from the provider in a hectar raster. Therefor I haven't tried your solution yet. But as it's a quite common problem, I will surely get to it in another project soon. Thanks anyway! –  Pascal Mages Jun 10 '13 at 10:26
add comment

It depends on your initial projection, but lets assume its distance units are meters.

  • You create a vector grid with QGIS using the standard vector tools or mmqgis. 1ha equals 10,000 m², therefore you need to specify your grid size (ratio) according to that.
  • After you have created the grid, just conduct a spatial join which sums up the number of employees per vector grid cell.
  • Then use the gdal_rasterize command to rasterize your vector grid
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.