Hey Remi,
I don't quite get what the query you gave does to be honest. But
working with some of the ideas and notions you gave me I have put the
below together. The final bit of the code is the key query. The tables
of NS and EW lines were done very quickly. Nice. But now doing the
'intersects within polygon' is taking some time so I'll see how it
gets on when I get in to work tomorrow morning:
DROP TABLE IF EXISTS north_to_south;
DROP TABLE IF EXISTS east_to_west;
-- Make a table of north to south lines
CREATE TABLE north_to_south tablespace jamestabs AS
( SELECT st_setsrid(st_makeline(st_makepoint(x, 7780), st_makepoint(x,
1226580)),27700) as the_geom
FROM generate_series(53320::int, 667380::int, 20) as x);
-- Add an index
CREATE INDEX north_to_south_geom_index ON north_to_south USING GIST (
the_geom );
-- Make a table of east to west lines
CREATE TABLE east_to_west tablespace jamestabs AS
( SELECT st_setsrid(st_makeline(st_makepoint(53320, y),
st_makepoint(667380, y)),27700) as the_geom
FROM generate_series(7780::int, 1226580::int, 20) as y);
-- Add an index
CREATE INDEX east_to_west_geom_index ON east_to_west USING GIST ( the_geom );
-- Import the Road Buffer file using the pg_loader interface
-- Update the geometry field as the loader didn't seem to do this.
SELECT UpdateGeometrySRID('ukmajrdbuffer','geom',27700);
-- Merge the road buffer polygons into one big polygon
-- Should maybe consider leaving them as they are, but am merging for now.
SELECT st_union(geom) as geom INTO union_roads FROM ukmajrdbuffer;
-- The unioned roads file isn't valid geom. So I simplify it a little
to make it valid.
-- We simplify with a 70 metres factor. Geom is now valid.
SELECT ST_SimplifyPreserveTopology(geom, 70) AS geom INTO
buff_union_roads FROM union_roads;
-- Now calculate the points where the lines intersect and also where
they are within the polygon.
CREATE TABLE gridpoints tablespace jamestabs
AS (SELECT ST_Intersection(east_to_west.the_geom, north_to_south.the_geom)
FROM east_to_west, north_to_south, buff_union_roads
WHERE st_within(buff_union_roads.geom,
ST_Intersection(east_to_west.the_geom, north_to_south.the_geom)) =
TRUE);
Thanks
James