Polygon bounding box

I have about 40,000 polygons stored in my geometry. Now I want to create a spatial index in this geometry column. When creating a spatial index, it asks me for the values ​​of the Bounding box. Could you please help me on how to find my limit. to get my bounding box i need to find my xmin, ymin, xmax, ymax.

thanks

+6
source share
1 answer

EDIT: you can use EnvelopeAggregate instead of UnionAggregate and STEnvelope, of course ...


You can execute UnionAggregate on all polygons, put STEnvelope around it and visually select the values ​​XMin, YMin, XMax, YMax. Of course, you can do some TSQL manipulations with the STAsText bounding box, but I will leave this as a manual exercise.

This gives you a field that covers your existing polygons, but you should think about how many indents you need or what borders are needed for future data.

Example:

 use tempdb; create table GeometryTest( id int identity primary key, geom Geometry ); insert GeometryTest values ( 'POLYGON((-130 54, -130 23, -60 23, -60 54, -130 54))' ); insert GeometryTest values ( 'POLYGON((1 0, 0 0, 0 1, 1 1, 3 5, 1 0))' ); insert GeometryTest values ( 'POLYGON((0 0, -100 5, 0 60, 70 70, 3 5, 0 0))' ); select geometry::UnionAggregate ( geom ).STEnvelope().STAsText() from GeometryTest; --------------------------------------------------------------- POLYGON ((-130 0, 70 0, 70 70, -130 70, -130 0)) --------------------------------------------------------------- create spatial index six_GeometryTest_geom on GeometryTest(geom) WITH (BOUNDING_BOX = (-130, 0, 70, 70)); 
+7
source

Source: https://habr.com/ru/post/944408/


All Articles