Spatial Clustering of Introduction to postgis (Introduction to st_snaptogrid)

Source: Internet
Author: User
Tags postgis

Clustering: Indicates clustering and classification. This word is involved in postgis. Although the two terms use the same term, they indicate different meanings. One is index clustering, and the other is spatial clustering.

Spatial Clustering: This is usually used in the point type. It can aggregate some points through the closeness or other features. The st_snaptogrid method is used to achieve this. The following describes st_snaptogrid:

The following methods are used:

Boolean st_overlaps (geometry A, geometry B); it is not completely included to determine whether a Ries intersection exists.

Boolean st_touches (geometry G1, geometry G2); determines that there is at least one common point between geometries and there is no internal intersection.

Geometry st_translate (geometry G1, float deltax, float deltay); ry is converted to a new location.

Geometry st_snaptogrid (geometry geoma, float size); snap all points of the input geometry to the grid defined by its origin and cell size. remove consecutive points falling on the same cell, eventually returning null if output points are not enough to define a geometry of the given type. collapsed geometries in a collection are stripped from it. (I will not translate ENGLISH)

Create tables first:

-- Create the translate_polygons table
Create Table translate_polygons (
"ID" Serial not null primary key,
"Name" char (1) not null,
"The_geom" geometry not null
);
-- Add data
Insert into translate_polygons (name, the_geom) values (
'A', 'polygon (2 1, 0 3, 2 3, 2 1) ': Geometry
),(
'B', 'polygon (0 3, 2 5, 2 3, 0 3) ': Geometry
),(
'C', 'polygon (2 5, 4 3, 2 3, 2 5) ': Geometry
),(
'D', 'polygon (4 3, 2 1, 2 3, 4 3) ': Geometry
);

Open in qgis and edit the style as follows:

SELECT t1.name || ' overlaps ' || t2.name || ' = ' || ST_Overlaps(t1.the_geom, t2.the_geom)::text AS overlap_test,
t1.name || ' touches ' || t2.name || ' = ' || ST_Touches(t1.the_geom, t2.the_geom)::text AS touch_test
FROM translate_polygons AS t1,
translate_polygons AS t2
WHERE t1.name <> t2.name
ORDER BY t1.name, t2.name;

View intersection information:

Use st_translate to move two triangles (A and C ):

-- A and C move to the lower left corner

Update translate_polygons
Set the_geom = st_translate (the_geom,-0.4,-0.2)
Where name = 'a ';

Update translate_polygons
Set the_geom = st_translate (the_geom,-0.1,-0.4)
Where name = 'C ';

View intersection information:

Graphic Display:

Use st_snaptogrid:

UPDATE translate_polygons
SET the_geom = ST_SnapToGrid(the_geom, 1)

 

If you change the distance from A to the left to 0.6, then run st_snaptogrid:

-- A and C move to the lower left corner

Update translate_polygons
Set the_geom = st_translate (the_geom,-0.6,-0.2)
Where name = 'a ';

Update translate_polygons
Set the_geom = st_translate (the_geom,-0.1,-0.4)
Where name = 'C ';

I have a rough understanding of st_snaptogrid, and I will use it in the next study.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.