2014-01-23 18 views
2

我使用的是postgresql版本: 「在x86_64-unknown-linux-gnu上的PostgreSQL 9.3.1,由gcc(GCC)編譯4.6.3 20120306(Red Hat 4.6.3-2) ,64位「st_intersect()在postgresql中不起作用

我創建了2個表A和B,其中點和多邊形作爲數據類型。 現在我想知道點是否在多邊形內。 爲此,我試圖使用ST_Intersect(A.point_LatLong,B.polygon_abc); 我的查詢是:

SELECT A.id 
FROM A, B 
WHERE A.name = 'callifornia' 
AND ST_Intersect(A.point_LatLong , B.polygon_abc); 

這裏point_latLongpolygon_abc是具有表A的數據類型點和多邊形B.

列名,但此查詢給出了一個錯誤:

ERROR: function st_intersect(point, polygon) does not exist
LINE 3: WHERE city.city_name = 'callifornia' AND ST_intersect(city.c...
HINT: No function matches the given name and argument types. You might need to add
explicit type casts.


我該如何解決這個問題?我甚至無法在postgresql中使用任何其他空間方法,如st_contains()等讓我知道你是否有任何解決方案。

+1

'st_intersect()'是PostGIS的功能,它聽起來好像你沒有安裝PostGIS。 –

回答

5

您試圖將PostgreSQL的內置(有限但有用)幾何類型與PostGIS函數混合使用。這聽起來像你還沒有安裝PostGIS。你還輸入了函數名稱,它是ST_Intersects而不是ST_Intersect

首先,如果你想使用的PostGIS,確保它的安裝,然後:

CREATE EXTENSION postgis; 

接下來,你可能會發現,你不能真正稱之爲ST_Intersectspointpolygon。 PostGIS可以使用它自己的geometry類型。它有一些PostgreSQL內部類型的轉換器,但它們只是有限的。因此,與原始幾何類型調用PostGIS的功能可能會導致像錯誤:

postgres=# SELECT ST_Intersects(polygon(box(point(0,0), point(10,10))), point(5,5)); 
ERROR: function st_intersects(polygon, point) does not exist 
LINE 1: SELECT ST_Intersects(polygon(box(point(0,0), point(10,10))... 
      ^
HINT: No function matches the given name and argument types. You might need to add explicit type casts. 

您通常必須將它們轉換爲PostGIS的自己geometry型。 PostGIS的提供了一些這方面的顯式轉換爲大多數類型,例如:

postgres=# SELECT ST_Intersects(
    polygon(box(point(0,0), point(10,10)))::geometry, 
    point(5,5)::geometry 
); 
st_intersects 
--------------- 
t 
(1 row) 
在查詢

所以,這會是:

ST_Intersects(A.point_LatLong::geometry , B.polygon_abc::geometry); 
+0

謝謝克雷格林格 現在我已經安裝了postgis,並在所有的設置。現在查詢st_intersects()對我來說工作正常。 – virtual

相關問題