3.8 Generating and Setting Spatial Extents
When a GeoRaster object is created, its spatial extent (spatialExtent
attribute, described in spatialExtent Attribute) is not necessarily the enclosing geometry in its model space coordinate system. The spatial extent (footprint) geometry might initially be null, or it might reflect the cell space coordinate system or some other coordinate system. The ability to generate and set spatial extents is useful for building large GeoRaster databases of a global or large regional scope, in which the spatial extents are in one global geodetic coordinate system while the GeoRaster objects (imagery, DEMs, and so on) are in different projected coordinate systems. In such a case, you can create a spatial (R-tree) index on the spatial extents, which requires that all spatial extent geometries have the same SRID value.
To ensure that the spatial extent geometry of each GeoRaster object in a table is correct for its model space coordinate system (or for any other coordinate system that you may want to use), you must set the spatial extent. Moreover, to use a spatial index on the spatial extent geometries (described in Indexing GeoRaster Objects), all indexed geometries must be based on the same coordinate system (that is, have the same SRID value).
You can set the spatial extent in any of the following ways: specify
spatialExtent=TRUE
as a storage parameter to the GeoRaster client-side
loader (described in GeoRaster Tools: Viewer_
Loader_ Exporter), use the SQL UPDATE statement, or set the spatial extent during
loading with GDAL. If you use the loaders, the SRID cannot be null or 0 (zero), and if there
is an R-tree index on the GeoRaster spatial extent, the SRID of the spatial extent must match
the SRID of the existing spatial index; otherwise, the spatial extent is set to a null
value.
In addition, if you do not already have the spatial extent geometry, you can generate it using the SDO_GEOR.generateSpatialExtent function, and use that geometry to update the GeoRaster object. The following example updates the spatial extent geometry of a specified GeoRaster object in the CITY_IMAGES table (created in Example 3-1 in Creating a GeoRaster Table) to the generated spatial extent (reflecting the model coordinate system) of that object:
UPDATE city_images c SET c.image.spatialExtent = sdo_geor.generateSpatialExtent(image) WHERE c.image_id = 100; COMMIT;
The following example updates the spatial extent geometry of all GeoRaster objects in the CITY_IMAGES table to the generated spatial extent (reflecting the model coordinate system) of that object:
UPDATE city_images c SET c.image.spatialExtent = sdo_geor.generateSpatialExtent(image) WHERE c.image.spatialExtent is null; COMMIT;
If you already know the spatial extent geometry for a GeoRaster object, or if you want the spatial extent geometry to be based on a coordinate system other than the one for the model space, construct the SDO_GEOMETRY object or select it from a table, and then update the GeoRaster object to set its spatial extent attribute to that geometry, as shown in the following example:
DECLARE geom sdo_geometry; BEGIN -- Set geom to an SDO_GEOMETRY object that covers the spatial extent -- of the desired GeoRaster object. If necessary, perform coordinate -- system transformation before setting geom. -- geom := sdo_geometry(...); UPDATE city_images c SET c.image.spatialExtent = geom WHERE c.image_id = 100; COMMIT; END;
Parent topic: GeoRaster Database Creation and Management
3.8.1 Special Considerations if the GeoRaster Table Has a Spatial Index
If you create a spatial R-tree index on the GeoRaster spatial extents (as described in Indexing GeoRaster Objects), all spatial extent geometries must have the same SRID value. However, the GeoRaster objects may have different model SRIDs, and most GeoRaster operations automatically generate a spatial extent for the output GeoRaster objects based on the model SRID of the source GeoRaster object or objects. This can cause problems when the resulting GeoRaster object with a spatial extent is updated into a GeoRaster table, which might already have a spatial index built on its spatialExtent
attribute but using a different SRID.
In such cases, you must transform the spatial extent to the same SRID as that of the spatial index before the insert or update operation. The following example performs a mosaic operation, but then transforms the spatial extent of the resulting GeoRaster object to SRID 4326 before updating the GeoRaster table with that object.
DECLARE
gr sdo_georaster;
BEGIN
SELECT georaster INTO gr FROM mosaic_test WHERE georid=1 FOR UPDATE;
sdo_geor.mosaic('mosaic_data', 'georaster', gr, 'blocking=OPTIMALPADDING,
blocksize=(512,512)');
-- Transform the spatial extent geometry, if ncessary.
-- In this example example, the modelSRID of the mosaic is 27302,
-- but the SRID of the spatial index on mosaic_test is 4326.
gr.spatialExtent := sdo_cs.transform(gr.spatialExtent, 4326);
UPDATE mosaic_test SET georaster=gr WHERE georid=1;
END;
/
If a spatial R-tree index exists, a commit operation after an insert or update operation causes the index to be updated if the inserted or updated GeoRaster object has a spatial extent geometry. This could slow some operations if you perform a commit after each operation, particularly for batch jobs such as batch image loading. It is usually more efficient to balance the performance of index updates with GeoRaster operations, and to commit only in batches after the operations.
Parent topic: Generating and Setting Spatial Extents