2017-02-16 61 views
0

我有兩個包含兩個多邊形實際座標的csv文件。我需要將csv文件的內容複製到名爲'sample'的PostGIS表中。我需要找到兩個多邊形和相交區域的交集。 enter image description here將csv文件複製到PostGIS表中

我是PostGIS中的新成員。請幫幫我。

+0

是一個很廣泛的話題......你什麼都已經嘗試過?你讀過這個了嗎? https://www.postgresql.org/docs/9.6/static/sql-copy.html –

回答

3

假設WGS84:

第一創建表

create table sample (lat float, lon float); 

然後將CSV到表(可能需要用定界符一些調整)。

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); 

然後通過首先創建線串,則多邊形創建從點表中的多邊形。確保線串已關閉,這意味着第一個點必須等於最後一個點!

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' 
+0

我在第一個csv文件中插入了一個新字段「文件名」,並將其值作爲「part1」輸入,之後(第二個csv文件)由'part2'表示。我根據它的'文件名'聚集表項。我需要找到part1簇和part2簇的交集區域。 – Aami

+0

我添加了一個部分來到達兩個多邊形的交集區域。 – kdd

相關問題