[OSM-dev] Grid lines
Gregory Williams
gregory.williams at purplegeodesoftware.co.uk
Mon Jan 17 17:24:14 GMT 2011
> -----Original Message-----
> From: Jan-Benedict Glaw [mailto:jbglaw at lug-owl.de]
> Sent: 17 January 2011 15:45
> To: Steve Hill
> Cc: dev at openstreetmap.org
> Subject: Re: [OSM-dev] Grid lines
>
> On Mon, 2011-01-17 15:31:43 +0000, Steve Hill <steve at nexusuk.org>
> wrote:
> > On Mon, 17 Jan 2011, Andy Allan wrote:
> > > My approach would be to generate a table with the gridlines in it,
> but
> > > I haven't tried.
> >
> > I was starting to think that might be the way, but was just curious
> if
> > anyone had come up with a better programmatic method (e.g. a fancy
> select
> > sql statement that generates the appropriate geometries on-the-fly or
> > similar, since they are regular repeating geometries - this should be
> > reasonably easy for lat/lon grids but the other types aren't quite as
> > regular so would require some thought)
>
> It's probably not that hard to use PostgreSQL's generate_series() to
> build the grid lines. But OTOH, I'd somehow expect the map drawing
> application (or library) to generate them. There, you'd probably
> better decide what kind of grid to use (eg. lon/lat, which
> granularity, or the A/B/C/D 1/2/3/4 grid you often find on printed
> city maps).
I use exactly that for generating some town-scale maps with a grid. The grid lines are actually generated as appropriately-sized boxes at regular intervals thanks to generate_series(). I use the same squares to generate the street name and misc feature index for each map too.
Here's the code as it stands at present, but I know it needs tidying to not have a hard-coded box size in it:
insert into grid (map, "column", row, way)
SELECT
'Canterbury',
chr(65 + x_series) AS column,
y_series + 1 AS row,
translate(way, 113562 + (x_series * 1603), 6666524 + (y_series * 1603)) AS way
from generate_series(0, 11) as x_series,
generate_series(0, 7) as y_series,
(
SELECT GeomFromText('POLYGON((0 0, 0 1603, 1603 1603, 1603 0, 0 0))',900913) as way
) as one_grid
union all
<...other towns...>
More information about the dev
mailing list