2011-06-22 40 views
1

我使用PostGIS地理定義了以下表格。在PostGIS中投射地理類型

CREATE TABLE test_geog (
    id SERIAL PRIMARY KEY, 
    boundary GEOGRAPHY(Polygon) 
); 

我增加了以下測試多邊形表:

INSERT INTO test_geog VALUES (ST_GeographyFromText('SRID=4326;POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))')); 

我試圖確定一個點是否位於內的任何此表中的多邊形。我有這個疑問:

SELECT ST_ContainsProperly(ST_GeographyFromText('Point(2 2)'), area) 
FROM (SELECT boundary FROM test_geog) AS area; 

我們得到以下錯誤:

ERROR: function st_containsproperly(geography, record) does not exist 
LINE 1: SELECT ST_ContainsProperly(ST_GeographyFromText('Point(2 2)'... 
      ^
HINT: No function matches the given name and argument types. You might need to add explicit type casts. 

如何轉換這個 「紀錄」 爲POLYGON?我很困惑,因爲它似乎已經聲明只有POLYGON類型的列,但出於某種原因,我不是從數據庫中提取的。

我試圖記錄轉換爲POLYGON這樣的:

SELECT ST_ContainsProperly(ST_GeographyFromText('Point(2 2)'), CAST (boundary AS POLYGON)) 
FROM (SELECT boundary FROM source_imagery) AS nitf_area; 

但是,這給了我這個錯誤:

ERROR: cannot cast type record to polygon 
LINE 1: ...tainsProperly(ST_GeographyFromText('Point(2 2)'), CAST (boun... 

什麼我不理解嗎?

回答

1

我的問題在GIS論壇上得到了回答。我犯了一個愚蠢的錯誤,認爲ST_Contains可以用於地理,當它實際上僅支持幾何。我也不需要我試圖做的多餘的子查詢。

所以這裏是我的解決方案。我轉而使用ST_Covers,而不是我想要的並支持Geography。這避免了轉換爲幾何體。以下是可用的代碼:

SELECT ST_Covers(
    boundary, 
    ST_GeographyFromText('Point(2 2)') 
) 
FROM source_imagery