2

Is there a way to get or generate a tile matrix set geometry grid in any format like shapefile, geopackage, postgis, ... ?

EDIT

I've tried to create a set of grid polygons with postgis to generate tile matrix set geometries similar to the following worldwind structure, i.e. 5 rows by 10 columns 36 degrees tiles at level 0 based on EPSG:4326 full extent with bottom-left orgin
https://www.microimages.com/documentation/TechGuides/78Worldwind.pdf

I've tried using ST_SquareGrid function like

CREATE TABLE worldwind_z0 AS 
  SELECT 0 AS zoom_level,
    (ST_SquareGrid(36, ST_Transform(ST_GeomFromText('POLYGON((-180 -90,180 -90,180 90,-180 90,-180 -90))', 4326), 4326))).i AS col,
    (ST_SquareGrid(36, ST_Transform(ST_GeomFromText('POLYGON((-180 -90,180 -90,180 90,-180 90,-180 -90))', 4326), 4326))).j AS row,
    (ST_SquareGrid(36, ST_Transform(ST_GeomFromText('POLYGON((-180 -90,180 -90,180 90,-180 90,-180 -90))', 4326), 4326))).geom AS geom;

but the created grid origin is at the coord (0,0) for SRID 4326, and I would need the grid origin to be at the bottom left (-180,-90).

SOLUTION

For those interested I've used the ST_CreateFishnet function from this post
Creating regular polygon grid in PostGIS
modified as follows to start row & column numbering at 0

CREATE OR REPLACE FUNCTION ST_CreateFishnet(
        nrow integer, ncol integer,
        xsize float8, ysize float8,
        x0 float8 DEFAULT 0, y0 float8 DEFAULT 0,
        OUT "row" integer, OUT col integer,
        OUT geom geometry)
    RETURNS SETOF record AS
$$
SELECT i AS row, j AS col, ST_Translate(cell, j * $3 + $5, i * $4 + $6) AS geom
FROM generate_series(0, $1 - 1) AS i,
     generate_series(0, $2 - 1) AS j,
(
SELECT ('POLYGON((0 0, 0 '||$4||', '||$3||' '||$4||', '||$3||' 0,0 0))')::geometry AS cell
) AS foo;
$$ LANGUAGE sql IMMUTABLE STRICT;

To get what I want I just have to use
SELECT * FROM ST_CreateFishnet(5, 10, 36, 36, -180, -90)

7
  • The answer is "yes", using some fairly simple mathematics - just divide the EPSG 3857 coordinates into parts. Do you want to do this from some programming language, for some range of coordinates and zoom levels?
    – Spacedman
    Mar 30 at 9:23
  • I'm trying to create world coverage grids for zoom level 0 to 10 based on the worldwind tile matrix set (microimages.com/documentation/TechGuides/78Worldwind.pdf), i.e. 5 rows x 10 columns at level 0, origin bottom left in EPSG:4326 Mar 30 at 9:29
  • Simple mathematics again, except in degrees. What have you tried? They could be created with PostGIS SQL, or Python code, or any other language with some geospatial features, or even in Excel which could create the WKT for each tile polygon
    – Spacedman
    Mar 30 at 11:24
  • Quick calc tells me a full set of polygons down to level 10 is 16 million polygons. Is that useful?
    – Spacedman
    Mar 30 at 11:27
  • yes I'm looking into postgis ST_SquareGrid function but the output grid is centered on the coord (0,0) of the SRID, I would need the grid origin at the bottom left Mar 30 at 12:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.