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:
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(parcel_a.id as TEXT)||CAST(parcel_b.id as TEXT) as INTEGER), nextval('olaf_s2s_id'), parcel_a.id, parcel_b.id, parcel_a.elevation, parcel_b.elevation, ST_MakeLine(ST_centroid(parcel_a.the_geom),ST_centroid(parcel_b.the_geom)), parcel_a.the_geom, parcel_b.the_geom 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?