将 csv 文件复制到 PostGIS table
COPY csv file into PostGIS table
我有两个包含两个多边形实际坐标的 csv 文件。我需要将 csv 文件的内容复制到名为 'sample' 的 PostGIS table 中。我需要找到两个多边形的交集和交集的面积。 enter image description here
我是 PostGIS 新手。请帮助我。
假设 WGS84:
首先创建 table
create table sample (lat float, lon float);
然后将 csv 插入 table(可能需要使用分隔符进行一些调整)。
copy sample from 'path_to_csv' delimiter ';' csv;
然后将经纬度转换为点(因此假设 WGS84,SRID 4326):
alter table sample add column geom geometry(point, 4326)
using st_setsrid(st_makepoint(lon, lat),4326);
然后从点 table 创建多边形,方法是首先创建线串,然后创建多边形。确保线串闭合,这意味着第一个点必须等于最后一个点!
select st_makepolygon(st_makeline(geom)) geom
into polygon1
from sample;
获取两个多边形的交集面积:
select filename, st_makepolygon(st_makeline(geom)) geom
into polygons
from sample
group by filename;
select st_area(st_intersection(a.geom,b.geom))
from polygons a, polygons b
where a.filename == 'part1' and b.filename == 'part2'
我有两个包含两个多边形实际坐标的 csv 文件。我需要将 csv 文件的内容复制到名为 'sample' 的 PostGIS table 中。我需要找到两个多边形的交集和交集的面积。 enter image description here
我是 PostGIS 新手。请帮助我。
假设 WGS84:
首先创建 table
create table sample (lat float, lon float);
然后将 csv 插入 table(可能需要使用分隔符进行一些调整)。
copy sample from 'path_to_csv' delimiter ';' csv;
然后将经纬度转换为点(因此假设 WGS84,SRID 4326):
alter table sample add column geom geometry(point, 4326)
using st_setsrid(st_makepoint(lon, lat),4326);
然后从点 table 创建多边形,方法是首先创建线串,然后创建多边形。确保线串闭合,这意味着第一个点必须等于最后一个点!
select st_makepolygon(st_makeline(geom)) geom
into polygon1
from sample;
获取两个多边形的交集面积:
select filename, st_makepolygon(st_makeline(geom)) geom
into polygons
from sample
group by filename;
select st_area(st_intersection(a.geom,b.geom))
from polygons a, polygons b
where a.filename == 'part1' and b.filename == 'part2'