Removing Steps in Gridded Vector Data – SmoothGrid for Oracle
Many vector datasets are created from remote sensed imagery. If the conversion processes does not remove the “steps” in the boundaries of the created polygons the data can not only look “unreal” it can also greatly increase the complexity of the resultant polygons (and thus the number of vertices and size of the stored object) if no attempt is made to “smooth” or “de-Step” the data.
Here is an example, test multipolygon that is in need of “smoothing”:
I have created a PL/SQL function called “smoothGrid” (As I can’t think of another name that would be more grammatical – try UnStepGriddedPolygon – I think not) that smooths the multipolygon’s edges:
CREATE OR REPLACE FUNCTION GRIDSMOOTH ( P_GEOMETRY IN MDSYS.SDO_GEOMETRY ) RETURN mdsys.sdo_geometry deterministic
That when applied to the gridded data above produces the following result.
select gridSmooth(geom) as geom from (select MDSYS.SDO_GEOMETRY('MULTIPOLYGON(((-250.0 3850.0, 750.0 3850.0,1750.0 3850.0,1750.0 2850.0,2750.0 2850.0,3750.0 2850.0, 3750.0 1850.0,2750.0 1850.0,2750.0 850.0,1750.0 850.0,1750.0 -150.0, 2750.0 -150.0,3750.0 -150.0,4750.0 -150.0,5750.0 -150.0,5750.0 850.0, 6750.0 850.0,6750.0 1850.0,6750.0 2850.0,5750.0 2850.0,5750.0 3850.0, 4750.0 3850.0,4750.0 4850.0,4750.0 5850.0,5750.0 5850.0,6750.0 5850.0, 6750.0 4850.0,7750.0 4850.0,7750.0 3850.0,7750.0 2850.0,9750.0 2850.0, 9750.0 3850.0,9750.0 4850.0,9750.0 5850.0,8750.0 5850.0,8750.0 6850.0, 7750.0 6850.0,7750.0 7850.0,6750.0 7850.0,6750.0 8850.0,6750.0 9850.0, 5750.0 9850.0,4750.0 9850.0,4750.0 8850.0,3750.0 8850.0,3750.0 7850.0, 2750.0 7850.0,2750.0 6850.0,1750.0 6850.0,1750.0 5850.0,750.0 5850.0, 750.0 4850.0,-250.0 4850.0,-250.0 3850.0),(1250.0 4350.0,1250.0 5350.0, 2250.0 5350.0,2250.0 6350.0,3250.0 6350.0,3250.0 7350.0,4250.0 7350.0, 4250.0 8350.0,5250.0 8350.0,5250.0 7350.0,5250.0 6350.0,4250.0 6350.0, 4250.0 5350.0,3250.0 5350.0,3250.0 4350.0,2250.0 4350.0,1250.0 4350.0)), ((-500.0 5100.0,500.0 5100.0,500.0 6100.0,1500.0 6100.0,1500.0 7100.0, 2500.0 7100.0,2500.0 8100.0,3500.0 8100.0,3500.0 9100.0,2500.0 9100.0, 1500.0 9100.0,1500.0 8100.0,500.0 8100.0,500.0 7100.0,-500.0 7100.0, -500.0 6100.0,-500.0 5100.0)))',null) as geom from dual);
The savings in the number of stored points can be generated as follows:
select geomSmoothCount,original_count,ROUND( (geomSmoothCount / original_count) * 100,0) as saving from ( select mdsys.sdo_util.getNumVertices(gridSmooth(geom)) as geomSmoothCount, mdsys.sdo_util.getNumVertices(geom) as original_count from (select MDSYS.SDO_GEOMETRY('MULTIPOLYGON(((-250.0 3850.0, 750.0 3850.0,1750.0 3850.0,1750.0 2850.0,2750.0 2850.0,3750.0 2850.0, 3750.0 1850.0,2750.0 1850.0,2750.0 850.0,1750.0 850.0,1750.0 -150.0, 2750.0 -150.0,3750.0 -150.0,4750.0 -150.0,5750.0 -150.0,5750.0 850.0, 6750.0 850.0,6750.0 1850.0,6750.0 2850.0,5750.0 2850.0,5750.0 3850.0, 4750.0 3850.0,4750.0 4850.0,4750.0 5850.0,5750.0 5850.0,6750.0 5850.0, 6750.0 4850.0,7750.0 4850.0,7750.0 3850.0,7750.0 2850.0,9750.0 2850.0, 9750.0 3850.0,9750.0 4850.0,9750.0 5850.0,8750.0 5850.0,8750.0 6850.0, 7750.0 6850.0,7750.0 7850.0,6750.0 7850.0,6750.0 8850.0,6750.0 9850.0, 5750.0 9850.0,4750.0 9850.0,4750.0 8850.0,3750.0 8850.0,3750.0 7850.0, 2750.0 7850.0,2750.0 6850.0,1750.0 6850.0,1750.0 5850.0,750.0 5850.0, 750.0 4850.0,-250.0 4850.0,-250.0 3850.0),(1250.0 4350.0,1250.0 5350.0, 2250.0 5350.0,2250.0 6350.0,3250.0 6350.0,3250.0 7350.0,4250.0 7350.0, 4250.0 8350.0,5250.0 8350.0,5250.0 7350.0,5250.0 6350.0,4250.0 6350.0, 4250.0 5350.0,3250.0 5350.0,3250.0 4350.0,2250.0 4350.0,1250.0 4350.0)), ((-500.0 5100.0,500.0 5100.0,500.0 6100.0,1500.0 6100.0,1500.0 7100.0, 2500.0 7100.0,2500.0 8100.0,3500.0 8100.0,3500.0 9100.0,2500.0 9100.0, 1500.0 9100.0,1500.0 8100.0,500.0 8100.0,500.0 7100.0,-500.0 7100.0, -500.0 6100.0,-500.0 5100.0)))',null) as geom from dual) );
GEOMSMOOTHCOUNT | ORIGINAL_COUNT | SAVING |
---|---|---|
39 | 88 | 44 |
If anyone is interested in this function, contact me.