Here's a first go. A few things to note. First, this requires Manifold 9 >= 9.0.167.6, released today. Secondly, the source data type is hard coded (here INT32X3, e.g. standard RGB or RGB). This needs to be adjusted (in three places) for other data types. I think that's currently unavoidable (unless we wrap in a script). Third, there is a Rect filter, commented out. So all pixels from all tiles are returned, including those falling outside the image Rect. Uncomment the filter to remove peripheral cells for pixels that don't show. Lastly, I don't think there is anything here that would benefit from multiple threads, but I haven't tested that yet. Execution time isn't bad. For an image 5761 x 8505px, I get a time of 16 minutes on this i7 laptop, producing 49,397,760 cells (pixel areas). --SQL9 -- source/target vector type is hardcoded (see notes) -- Rect filter inactive (see WHERE clause) -- -- source table and image VALUE @table TABLE = [BA32_GRIDLESS_GeoTifv1-06 Tiles]; VALUE @image TABLE = [BA32_GRIDLESS_GeoTifv1-06]; -- NB image qua TABLE -- -- image metadata VALUE @field NVARCHAR = ComponentProperty(@image, 'FieldTile'); VALUE @dimXY INT32X2 = CAST(ComponentProperty(@table, 'FieldTileSize.' + @field) AS INT32X2); VALUE @dimX INT32 = VectorValue(@dimXY, 0); VALUE @dimY INT32 = VectorValue(@dimXY, 1); VALUE @rect INT32X4 = CAST(ComponentProperty(@image, 'Rect') AS INT32X4); VALUE @minX INT32 = CAST(VectorValue(@rect, 0) AS INT32); VALUE @minY INT32 = CAST(VectorValue(@rect, 1) AS INT32); VALUE @maxX INT32 = CAST(VectorValue(@rect, 2) AS INT32); VALUE @maxY INT32 = CAST(VectorValue(@rect, 3) AS INT32); VALUE @cs NVARCHAR = ComponentProperty(@table, 'FieldCoordSystem.' + @field); -- -- target table CREATE TABLE [Grid Table] ( [tileX] INT32, [tileY] INT32, [pixelX] INT32, [pixelY] INT32, [imageX] INT32, [imageY] INT32, [Cell] GEOM, [Value] UINT8X3, -- source data type (restored) INDEX [Y_X_x] BTREE ([imageY], [imageX]), -- same order as image INDEX [Cell_x] RTREE ([Cell]), PROPERTY 'FieldCoordSystem.Cell' @cs -- same as image ); -- target drawing CREATE DRAWING [Grid] ( PROPERTY 'FieldGeom' 'Cell', PROPERTY 'Table' '[Grid Table]' ); -- INSERT INTO [Grid table] ( [tileX], [tileY], [pixelX], [pixelY], [imageX], [imageY], [Cell], [Value] ) SELECT [tileX], [tileY], [pixelX], [pixelY], [imageX], [imageY], GeomMakeRect( VectorMakeX4([imageX], [imageY], [imageX] + 1, [imageY] + 1) ) AS [Cell], --[Value] -- FLOAT64XN CAST([Value] AS INT32X3) -- restore source data type FROM ( SELECT [tileX], [tileY], [X] AS [pixelX], [Y] AS [pixelY], [tileX] * @dimX + [X] AS [imageX], [tileY] * @dimY + [Y] AS [imageY], [Value] FROM ( SELECT [X] AS [tileX], [Y] AS [tileY], SPLIT CALL TileToValuesX3([Tile]) --> X, Y, Value (always FLOAT64XN) FROM @table ) ) -- exclude pixels outside image Rect --WHERE [imageX] BETWEEN @minX AND @maxX --AND [imageY] BETWEEN @minY AND @maxY ; Attachments: Extract cells and values (int32x3) forum.sql
|