-
-
Save saleiva/3721907 to your computer and use it in GitHub Desktop.
Rasters to polygons for CartoDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Upload your new raster data | |
--In my case the data goes into a table, night_light | |
--In some cases, I find it useful to downsample the total number of variables in a band, or in some cases merge data from multiple bands into one. | |
--Here is an example how one such process would work | |
UPDATE night_light SET rast = ST_MapAlgebraExpr(rast,'8BUI','CASE WHEN [rast] = 0 THEN 10 WHEN [rast] = 255 THEN 11 ELSE floor([rast]/32)::int END'); | |
--Create a new table, light_polygons | |
--Add a numeric column called, rast_value | |
--Add a numeric column called, band | |
--Bin raster data by value and store it in your new table | |
SET statement_timeout TO 0; INSERT INTO light_polygons (the_geom, rast_value, band) (select st_multi(st_makevalid((geomval).geom)) as the_geom, (geomval).val as rast_value, 1 as band from (select ST_DumpAsPolygons(rast) as geomval from night_light) f ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment