Create an empty tiled raster table in PostGIS
<p>I am new to postgres/postgis and am trying to figure out how to make an empty tiled raster with postgis. </p>

<p>I would like to generate an empty raster containing 5000 X 2000 cells, which I would like to query later to find a specific cell at location x/y or add a cell value at location x/y. I will basically add individual cell values to the empty raster in the future (e.g. report animal sightings in cells over time).</p>

<p>I found out that most of this this is possible by first creating a raster table: </p>

<pre><code>CREATE TABLE myRasterTable(rid serial primary key, rast raster);
</code></pre>

<p>and then adding an empty raster:</p>

<pre><code>INSERT INTO myRasterTable(rid,rast)
VALUES(1, ST_MakeEmptyRaster( 5000, 2000, 2485869.5728, 1299941.7864, 100, 100, 0, 0, 2056) );
</code></pre>

<p>(Reference: <a href="http://suite.opengeo.org/docs/latest/dataadmin/pgGettingStarted/raster2pgsql.html" rel="noreferrer">http://suite.opengeo.org/docs/latest/dataadmin/pgGettingStarted/raster2pgsql.html</a>) </p>

<p>I have also added a band and added a value to one of the raster cells:</p>

<pre><code>UPDATE myRasterTable SET rast = ST_AddBand(rast, 1, '32BF'::text, 0);
UPDATE myRasterTable SET rast = ST_SetValue(rast, 1,ST_Transform(ST_SetSRID(ST_MakePoint(7.5,48.5),4326),2056),987.654321)
</code></pre>

<p>(Reference: <a href="https://gis.stackexchange.com/questions/14960/postgis-raster-value-of-a-lat-lon-point">https://gis.stackexchange.com/questions/14960/postgis-raster-value-of-a-lat-lon-point</a>)</p>

<p>I can now query the value of the raster cell I have set:</p>

<pre><code>// Location with value
SELECT rid, ST_Value(rast, ST_Transform(ST_SetSRID(ST_MakePoint(7.5,48.5),4326),2056),false) val FROM myRasterTable
// Return = 987.654296875 in 0.5224609375 Seconds

// Location without value:
SELECT rid, ST_Value(rast, ST_Transform(ST_SetSRID(ST_MakePoint(7.0,48.5),4326),2056),false) val FROM myRasterTable
// Return =  0 in 0.51311993598938 Seconds
</code></pre>

<p>I have found numerous posts saying, that for larger rasters, it is essential in regards to query performance, that rasters are tiled with extents of about 100X100 cells per tile (references: <a href="http://postgis.17.x6.nabble.com/raster-loading-and-ST-Value-performance-td4999924.html" rel="noreferrer">http://postgis.17.x6.nabble.com/raster-loading-and-ST-Value-performance-td4999924.html</a> AND <a href="https://duncanjg.wordpress.com/2013/09/21/effect-of-tile-size-and-data-storage-on-postgis-raster-query-times/" rel="noreferrer">https://duncanjg.wordpress.com/2013/09/21/effect-of-tile-size-and-data-storage-on-postgis-raster-query-times/</a> )</p>

<p>Now I do not know: </p>

<ol>
<li>How to create tiles out of my large raster in PostGIS or how I could create a tiled raster from the start with PostGIS? In other words: What query do I need to use to create a raster tile collection covering a 5000X2000 raster with tiles of an extent of 100X100 cells containing multiple bands?</li>
<li>Once the tiles are created, do I need to create a seperate spatial index or is that done automatically?</li>
<li>And lastly: how do I then perform a query of what cell value a specific location has after the raster has been tiled?</li>
</ol>

<p>Any help would be appreciated!</p>