4

I have a street layer of a city. I want to create a hexagon gridwithin the streets. I buffered the streets with 20m, I unionized them. The next step would be creating hexagons within the streets. However, my result is rather strange. I get a straight line

straight line.

I'd expect a hexagon grid with the layout of a streetnetwork.

WITH baseStreet AS (
    SELECT 
        ST_Union(
            ST_Buffer(geom , 20, 'endcap=round join=round')
        ) AS geom
    FROM all_streets
), hexagons AS (
    SELECT 
        ST_HexagonGrid(5, baseStreet.geom) AS hex
    FROM baseStreet
) SELECT (hex).* FROM hexagons LIMIT 100;

Or is that not possible, and I have to make an envelope of the streetnetwork, create a hexagon grid within this envelop and then do a clip or intersect to identify the hexagons that are of relevance?

1
  • 1
    Hexagonal grids and clipping such is a topic that comes up from from time to time, there are already a few questions that are fairly close. Although I'm not an expert with PostGIS the part that sticks out to me is the LIMIT 100, it's possible that all your hexagons are being created but you're only seeing the first 100 generated. I would also expect that the grid is generated over the entire extent of baseStreet.geom even if there are no geometries that intersect all the hexagons, you'll probably need to do a geometry selection if you want just the hexagons that intersect your streets. Oct 27 at 0:29
1

Indeed, I ended up doing this

WITH baseStreet AS (
    SELECT 
        ST_Union(
            ST_Buffer(geom , 20, 'endcap=round join=round')
        ) AS geom
    FROM all_streets
), bbox AS (
    SELECT ST_Envelope(geom) AS geom FROM baseStreet 
), hexagons AS (
    SELECT ST_HexagonGrid(5, bbox) AS hex FROM baseStreet
), hexOnStreets AS (
    SELECT (hex).geom FROM hexagons 
    JOIN all_streets
        ON ST_Intersects((hex).geom, baseStreet.geom)
) SELECT * FROM hexOnStreets;

Create a bbox of the street network, fill it with a hexagon grid and then perform a spatial Join on the hexagons and streets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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