{"id":15557649,"url":"https://github.com/icholy/postgis-raster-examples","last_synced_at":"2026-01-05T12:50:15.335Z","repository":{"id":14876358,"uuid":"17599886","full_name":"icholy/postgis-raster-examples","owner":"icholy","description":null,"archived":false,"fork":false,"pushed_at":"2014-03-10T17:09:03.000Z","size":164,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-30T03:13:14.371Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/icholy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-10T16:37:22.000Z","updated_at":"2014-03-10T17:09:04.000Z","dependencies_parsed_at":"2022-08-03T00:30:52.547Z","dependency_job_id":null,"html_url":"https://github.com/icholy/postgis-raster-examples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icholy%2Fpostgis-raster-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icholy%2Fpostgis-raster-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icholy%2Fpostgis-raster-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icholy%2Fpostgis-raster-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icholy","download_url":"https://codeload.github.com/icholy/postgis-raster-examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245372367,"owners_count":20604490,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T15:19:44.597Z","updated_at":"2026-01-05T12:50:15.295Z","avatar_url":"https://github.com/icholy.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"Postgis Raster Examples\n=======================\n\n\n## Create Raster\n\n* [ST_MakeEmptyRaster](http://postgis.net/docs/RT_ST_MakeEmptyRaster.html)\n\n``` sql\nSELECT ST_MakeEmptyRaster(\n  3, 3,  -- width, height\n  0, 0,  -- origin (top-left corner)\n  1, -1, -- scalex, scaley (pixel size, negative pixel size?)\n  0, 0,  -- skewx, skewy\n  0      -- srid coordinate system (0 = None)\n)\n```\n\n| st_makeemptyraster |\n| -------------------|\n| 0100000000000000000000F03F000000000000F0BF00000000000000000000000000000000000000000000000000000000000000000000000003000300 |\n\n\n* [ST_MetaData](http://postgis.net/docs/RT_ST_MetaData.html)\n\n\n``` sql\nSELECT * FROM\n  ST_MetaData(\n    ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0) -- raster\n  )\n```\n\nupperleftx | upperlefty | width | height | scalex | scaley | skewx | skewy | srid | numbands\n-----------|------------|-------|--------|--------|--------|-------|-------|------|----------\n0 | 0 | 3 | 3 | 1 | -1 | 0 | 0 | 0 | 0\n\n\n* [ST_PixelAsPolygons](http://postgis.net/docs/RT_ST_PixelAsPolygons.html)\n\n``` sql\nSELECT x, y, ST_AsEWKT(geom)\nFROM\n  ST_PixelAsPolygons(\n    ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0) -- raster\n  )\n```\n\n x | y | st_askewkt\n---|---|---------------------------------------\n 1 | 1 | POLYGON((0 0,1 0,1 -1,0 -1,0 0))\n 1 | 2 | POLYGON((0 -1,1 -1,1 -2,0 -2,0 -1))\n 1 | 3 | POLYGON((0 -2,1 -2,1 -3,0 -3,0 -2)) \n 2 | 1 | POLYGON((1 0,2 0,2 -1,1 -1,1 0))\n 2 | 2 | POLYGON((1 -1,2 -1,2 -2,1 -2,1 -1))\n 2 | 3 | POLYGON((1 -2,2 -2,2 -3,1 -3,1 -2))\n 3 | 1 | POLYGON((2 0,3 0,3 -1,2 -1,2 0))\n 3 | 2 | POLYGON((2 -1,3 -1,3 -2,2 -2,2 -1))\n 3 | 3 | POLYGON((2 -2,3 -2,3 -3,2 -3,2 -2)) \n\n## Add Band to Raster\n\n* [ST_AddBand](http://postgis.net/docs/RT_ST_AddBand.html)\n* [Don't know what a band is?](http://edndoc.esri.com/arcsde/9.2/concepts/rasters/entities/rasterbands.htm)\n\n``` sql\nSELECT ST_AddBand(\n  ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0), -- the raster\n  '4BUI'::text,                                   -- pixel type (http://postgis.net/docs/RT_ST_BandPixelType.html)\n  5,                                              -- initial value\n  NULL                                            -- nodata value (could be 0)\n)\n```\n\n| st_addband |\n|------------|\n| 0100000100000000000000F03F000000000000F0BF000000000000000000000000000000000000000000000000000000000000000000000000030003000200050505050505050505 |\n\n \n``` sql\nSELECT *\nFROM\n  ST_MetaData(\n    ST_AddBand(\n      ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0),\n      '4BUI'::text, 5, NULL\n    )\n  )\n```\n\nupperleftx | upperlefty | width | height | scalex | scaley | skewx | skewy | srid | numbands\n-----------|------------|-------|--------|--------|--------|-------|-------|------|----------\n 0 | 0 | 3 | 3 | 1 | -1 | 0 | 0 | 0 | 1\n \n \n\n``` sql\nSELECT x, y, val\nFROM\n  ST_PixelAsPolygons(\n    ST_AddBand(\n      ST_MakeEmptyRaster(3, 3, 0, 0, 1, -1, 0, 0, 0),\n      '4BUI'::text, 5, NULL\n    )\n  )\n```\n\n x | y | val\n---|---|-----\n1 | 1 | 5\n1 | 2 | 5\n1 | 3 | 5\n2 | 1 | 5\n2 | 2 | 5\n2 | 3 | 5\n3 | 1 | 5\n3 | 2 | 5\n3 | 3 | 5\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficholy%2Fpostgis-raster-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficholy%2Fpostgis-raster-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficholy%2Fpostgis-raster-examples/lists"}