Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using post-gis to create a polyline that describes the flow direction of water in a landscape/catchment, to use in a hydrological model. To do that I start with a regular grid (as polygon) and connect the centre of each cell to the centre each of the 8 cells around it, using ST_Intersect. (afterwards I delete the irrelevant lines, based on the elevation of the grid). When I do this, most connections are made as I want, except that only half of the diagonal connections are made:

enter image description here

In the figure the green squares is my grid, and the white lines are the output polyline

here is a code sample I use:

INSERT INTO test_olaf.olafmain(id,id_in,id_out,ngf_in,ngf_out,the_geom,geom_in,geom_out SELECT DISTINCT ON (ST_Intersection(parcel_a.the_geom,parcel_b.the_geom) CAST(CAST( as TEXT)||CAST( as TEXT) as INTEGER), 

FROM test_olaf.grid as parcel_a, test_olaf.grid as parcel_b -- test_olaf.grid is my grid (based on a DEM, converted into a polygon)
WHERE ST_Intersects(parcel_a.the_geom,parcel_b.the_geom)


Does anyone know how I can connect my cell-centre to all the cells around it, or why the ST_intersect function does not work for all the cells?

thanks! Annette

share|improve this question
up vote 0 down vote accepted

Try adding a small buffer to one of the polygons to avoid floating-point errors.

If the units are degrees, 0.00001 will buffer by a meter or two. If the units are meters, use 1.0 or 0.1.

ST_Intersection(ST_Buffer(parcel_a.the_geom, 0.00001),parcel_b.the_geom)

share|improve this answer
that solved it, thanks a lot! – Annette Jun 26 '13 at 13:37

Your Answer


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.