addgeometrycolumn(<schema_name>, <table_name>,<column_name>, <srid>, <type>, <dimension>)
給一個已存在屬性資料表增加一個幾何字段(geomtrycolumn)。schema_name 指表的模式的名字,srid 必須是一個整數指對應于 spatial_ref_sys 表,type必須是一個大寫的字元串,用來描述幾何類型,例如:'polygon' 或者 'multilinestring'。
dropgeometrycolumn(<schema_name>, <table_name>,<column_name>)
從一個空間資料表中删除一個幾何字段。
st_setsrid(geometry, integer)
給一個幾何對象(geometry)設定一個整型的srid,對于在一個範圍内的查詢非常有用。
st_distance(geometry, geometry)
傳回兩個幾何對象的距離(笛卡兒距離),不使用索引。
st_dwithid(geometry, geometry, float)
如果一個幾何對象(geometry)在另一個幾何對象描述的距離(float)内,傳回true。如果有索引,會用到索引。
st_equals(geometry, geometry)
如果兩個空間對象相等,則傳回true。用這個函數比用“=”更好,例如:
equals('linestring(0 0, 10 10)','linestring(0 0, 5 5, 10 10)') 傳回 true。
st_disjoint(geometry, geometry)
如果兩個對象不相連,則傳回true。不要使用geometrycollection作為參數。
st_intersects(geometry, geometry)
判斷兩個幾何空間資料是否相交,如果相交傳回true,不要使用geometrycollection作為參數。
intersects(g1, g2 ) --> not (disjoint(g1, g2 ))
不使用索引可以用_st_intersects.
st_touches(geometry, geometry)
如果兩個幾何空間對象存在接觸,則傳回true。不要使用geometrycollection作為參數。
a.touches(b) -> (i(a) intersection i(b) = {empty set} ) and (a intersectionb) not empty
不使用索引可以用_st_touches.
st_crosses(geometry, geometry)
如果兩個幾何空間對象存在交叉,則傳回true。不要使用geometrycollection作為參數。
不使用索引可以用_st_crosses.
st_within(geometry a, geometry b)
如果幾何空間對象a存在空間對象b中,則傳回true,不要使用geometrycollection作為參數。
不使用索引可以用_st_within
st_overlaps(geometry, geometry)
如果兩個幾何空間資料存在交疊,則傳回 true,不要使用geometrycollection作為參數。
不使用索引可以用_st_overlaps.
st_contains(geometry a, geometry b)
如果幾何空間對象a包含空間對象b,則傳回 true,不要使用geometrycollection作為參數。
這個函數類似于st_within(geometry b, geometrya)
不使用索引可以用_st_contains.
st_covers(geometry a, geometry b)
如果幾何空間對象b中的所有點都在空間對象a中,則傳回 true。
不要使用geometrycollection作為參數。
不使用索引可以用_st_covers.
st_coveredby(geometry a, geometry b)
如果幾何空間對象a中的所有點都在空間對象b中,則傳回 true。
幾何空間資料處理函數
st_centroid(geometry)
傳回質心點,就是根據幾何空間資料,活動該幾何空間資料的中心點,傳回一個空間點資料.
st_area(geometry)
如果幾何空間資料為多邊形,或者多多邊形,則傳回空間資料的外圍(傳回類型double precision) ;
st_length(geometry)
這個曲線在其相關的空間參考長度(傳回類型double precision) ;
st_pointonsurface(geometry)
一定在幾何空間線資料上的點,傳回一個資料點
st_buffer(geometry, double, [integer])
buffer操作一個很有用函數,
這個函數的第一個參數是要操作的空間幾何資料,第二個參數長度(距離),第三個參數為一個整型,
這個函數傳回一個空間資料類型,以目前第一個參數空間幾何資料為參考點,傳回小于等于距離的空間
幾何資料點,最後由這些點組成一個多邊形空間資料,最後一個參數表示
在組成一個1/4圓的有幾個點分隔。也就是說如果最好一個參數為8那麼這個最後組成的多邊形就是32邊
的多邊形,如果不指定這個參數,系統預設的是8
注意:第二個參數,距離它的機關為空間資料機關(度),在運算時需要進行機關換算,最後轉換成度
,機關的換算關系如下:
1英裡= 63360 米
1米=1/1852 海裡
1海裡= 1/60度
如果要進行具體的運算,需要進行一下機關換算,比如要求一個500米的範圍,那麼應該是
500*1/1852*1/60(度)
st_envelope(geometry)
這個函數可以傳回mbr(空間最小外包矩形),傳入參數可以是point line polygon。
st_extent(geometry set)
這個函數可以對一個空間資料集進行操作,傳回一個最小包含矩形(mbr).
如:select extent(geom) fromgeomtable group by category
st_difference(geometry a, geometry b)
傳回一個幾何空間資料a不同于空間資料b的幾何空間資料類型,不要使用geometrycollection作為參數。
也就是說,如果a為一個line,b也為一個line,那麼他們傳回的類型就是b把a分割的多線。
如:
select st_asewkt(st_difference(geomfromtext('linestring(1 1,2 3,3 4,31)'),geomfromtext('linestring(2 0,2 2,5 2,3 1)')))
傳回的multilinestring((1 1,2 3,3 4,32),(3 2,3 1))
如果是a和b都是一個polygon多邊形,那麼傳回的就是多多邊形,如果相交,那麼傳回的就是b把a分割,并且不再b中的多多邊形。
select st_asewkt(st_difference(geomfromtext('polygon((1 1,2 3,3 4,3 1,11))'),geomfromtext('polygon((2 0,2 2,5 2,1 3,2 0))')))
st_union(geometry, geometry)
傳回一個合并的幾何空間資料,将兩個幾何空間資料合并為一個幾何空間資料,或者geometrycollection,不要使用geometrycollection作為參數。
st_linemerge(geometry)
合并為線
st_astext(geometry)
将幾何空間資料,轉換成容易了解的空間資料文本格式,
例如:
(0,0 0,1 1,1 1,0 0,0)
轉換後應該是這樣的結果 polygon(0 0,0 1,1 1,1 0,0 0)
st_srid(geometry)
傳回目前幾何空間資料的srid值
st_isclosed(geometry)
判斷幾何空間資料是否是閉合,就是判斷起始點和終點坐标是相同的,如果是相同的傳回true,否則傳回false.
st_isring(geometry)
這個函數參數的對象是line,判斷起始點和終點坐标是否相同,
如果閉合(這個曲線除了起始點和終點相同外,沒有其他相交點)怎傳回true,否則false,
st_numpoints(geometry)
傳回幾何空間資料linestring上的第一條線上點的個數。
geometrytype(geometry)
判斷幾何空間資料的類型。
例如
select geometrytype(geomfromtext('multilinestring((1 1,2 3,3 4,3 1,2 1,1 1),(12,2 3,4 5))'))
傳回的類型為 multilinestring。
關于每個polygon過大,緻使程式處理超級慢的問題解決:
用geometry st_scale(geometry geoma, float xfactor, float yfactor);函數,對原始geometry切割,插入到新的資料表中,這樣就變成了對小polygon的處理