起飞就起飞

使用postgresql-postgis实现多边形取交集

Posted on By baixiao

交集表结构为

postgres=# \d route_intersects_polygon Table “public.route_intersects_polygon” Column | Type | Modifiers
———+———-+———————————————————————– id | bigint | not null default nextval(‘route_intersects_polygon_id_seq’::regclass) polygon | geometry | Indexes: “route_intersects_polygon_pkey” PRIMARY KEY, btree (id)

代码为

INSERT INTO route_intersects_polygon(polygon) SELECT * FROM
(SELECT ST_Intersection(a.polygon, b.polygon) As intersect_ab
FROM route_track_polygon a, route_challenge_polygon b
WHERE ST_Intersects(a.polygon, b.polygon)) sq;

结果为:

polygon_intersection