PostGIS中的常用函數(shù)

2018-08-02 17:01 更新

PostGIS中的常用函數(shù)

首先需要說(shuō)明一下,這里許多函數(shù)是以ST_[X]yyy形式命名的,事實(shí)上很多函數(shù)也可以通過(guò)xyyy的形式訪問(wèn),在PostGIS的函數(shù)庫(kù)中我們可以看到這兩種函數(shù)定義完全一樣。

1. OGC標(biāo)準(zhǔn)函數(shù)

管理函數(shù):

添加幾何字段 AddGeometryColumn(, , , , , ) 刪除幾何字段 DropGeometryColumn(, , ) 檢查數(shù)據(jù)庫(kù)幾何字段并在geometry_columns中歸檔 Probe_Geometry_Columns() 給幾何對(duì)象設(shè)置空間參考(在通過(guò)一個(gè)范圍做空間查詢時(shí)常用) ST_SetSRID(geometry, integer)

幾何對(duì)象關(guān)系函數(shù):

獲取兩個(gè)幾何對(duì)象間的距離 ST_Distance(geometry, geometry) 如果兩個(gè)幾何對(duì)象間距離在給定值范圍內(nèi),則返回TRUE ST_DWithin(geometry, geometry, float) 判斷兩個(gè)幾何對(duì)象是否相等 (比如LINESTRING(0 0, 2 2)和LINESTRING(0 0, 1 1, 2 2)是相同的幾何對(duì)象) ST_Equals(geometry, geometry) 判斷兩個(gè)幾何對(duì)象是否分離 ST_Disjoint(geometry, geometry) 判斷兩個(gè)幾何對(duì)象是否相交 ST_Intersects(geometry, geometry) 判斷兩個(gè)幾何對(duì)象的邊緣是否接觸 ST_Touches(geometry, geometry) 判斷兩個(gè)幾何對(duì)象是否互相穿過(guò) ST_Crosses(geometry, geometry) 判斷A是否被B包含 ST_Within(geometry A, geometry B) 判斷兩個(gè)幾何對(duì)象是否是重疊 ST_Overlaps(geometry, geometry) 判斷A是否包含B ST_Contains(geometry A, geometry B) 判斷A是否覆蓋 B ST_Covers(geometry A, geometry B) 判斷A是否被B所覆蓋 ST_CoveredBy(geometry A, geometry B) 通過(guò)DE-9IM 矩陣判斷兩個(gè)幾何對(duì)象的關(guān)系是否成立 ST_Relate(geometry, geometry, intersectionPatternMatrix) 獲得兩個(gè)幾何對(duì)象的關(guān)系(DE-9IM矩陣) ST_Relate(geometry, geometry)

幾何對(duì)象處理函數(shù):

獲取幾何對(duì)象的中心 ST_Centroid(geometry) 面積量測(cè) ST_Area(geometry) 長(zhǎng)度量測(cè) ST_Length(geometry) 返回曲面上的一個(gè)點(diǎn) ST_PointOnSurface(geometry) 獲取邊界 ST_Boundary(geometry) 獲取緩沖后的幾何對(duì)象 ST_Buffer(geometry, double, [integer]) 獲取多幾何對(duì)象的外接對(duì)象 ST_ConvexHull(geometry) 獲取兩個(gè)幾何對(duì)象相交的部分 ST_Intersection(geometry, geometry) 將經(jīng)度小于0的值加360使所有經(jīng)度值在0-360間 ST_Shift_Longitude(geometry) 獲取兩個(gè)幾何對(duì)象不相交的部分(A、B可互換) ST_SymDifference(geometry A, geometry B) 從A去除和B相交的部分后返回 ST_Difference(geometry A, geometry B) 返回兩個(gè)幾何對(duì)象的合并結(jié)果 ST_Union(geometry, geometry) 返回一系列幾何對(duì)象的合并結(jié)果 ST_Union(geometry set) 用較少的內(nèi)存和較長(zhǎng)的時(shí)間完成合并操作,結(jié)果和ST_Union相同 ST_MemUnion(geometry set)

幾何對(duì)象存取函數(shù):

獲取幾何對(duì)象的WKT描述 ST_AsText(geometry) 獲取幾何對(duì)象的WKB描述 ST_AsBinary(geometry) 獲取幾何對(duì)象的空間參考ID ST_SRID(geometry) 獲取幾何對(duì)象的維數(shù) ST_Dimension(geometry) 獲取幾何對(duì)象的邊界范圍 ST_Envelope(geometry) 判斷幾何對(duì)象是否為空 ST_IsEmpty(geometry) 判斷幾何對(duì)象是否不包含特殊點(diǎn)(比如自相交) ST_IsSimple(geometry) 判斷幾何對(duì)象是否閉合 ST_IsClosed(geometry) 判斷曲線是否閉合并且不包含特殊點(diǎn) ST_IsRing(geometry) 獲取多幾何對(duì)象中的對(duì)象個(gè)數(shù) ST_NumGeometries(geometry) 獲取多幾何對(duì)象中第N個(gè)對(duì)象 ST_GeometryN(geometry,int) 獲取幾何對(duì)象中的點(diǎn)個(gè)數(shù) ST_NumPoints(geometry) 獲取幾何對(duì)象的第N個(gè)點(diǎn) ST_PointN(geometry,integer) 獲取多邊形的外邊緣 ST_ExteriorRing(geometry) 獲取多邊形內(nèi)邊界個(gè)數(shù) ST_NumInteriorRings(geometry) 同上 ST_NumInteriorRing(geometry) 獲取多邊形的第N個(gè)內(nèi)邊界 ST_InteriorRingN(geometry,integer) 獲取線的終點(diǎn) ST_EndPoint(geometry) 獲取線的起始點(diǎn) ST_StartPoint(geometry) 獲取幾何對(duì)象的類型 GeometryType(geometry) 類似上,但是不檢查M值,即POINTM對(duì)象會(huì)被判斷為point ST_GeometryType(geometry) 獲取點(diǎn)的X坐標(biāo) ST_X(geometry) 獲取點(diǎn)的Y坐標(biāo) ST_Y(geometry) 獲取點(diǎn)的Z坐標(biāo) ST_Z(geometry) 獲取點(diǎn)的M值 ST_M(geometry)

幾何對(duì)象構(gòu)造函數(shù):

參考語(yǔ)義: Text:WKT WKB:WKB Geom:Geometry M:Multi Bd:BuildArea Coll:Collection ST_GeomFromText(text,[])

ST_PointFromText(text,[]) ST_LineFromText(text,[]) ST_LinestringFromText(text,[]) ST_PolyFromText(text,[]) ST_PolygonFromText(text,[]) ST_MPointFromText(text,[]) ST_MLineFromText(text,[]) ST_MPolyFromText(text,[]) ST_GeomCollFromText(text,[]) ST_GeomFromWKB(bytea,[]) ST_GeometryFromWKB(bytea,[]) ST_PointFromWKB(bytea,[]) ST_LineFromWKB(bytea,[]) ST_LinestringFromWKB(bytea,[]) ST_PolyFromWKB(bytea,[]) ST_PolygonFromWKB(bytea,[]) ST_MPointFromWKB(bytea,[]) ST_MLineFromWKB(bytea,[]) ST_MPolyFromWKB(bytea,[]) ST_GeomCollFromWKB(bytea,[]) ST_BdPolyFromText(text WKT, integer SRID) ST_BdMPolyFromText(text WKT, integer SRID)

  1. PostGIS擴(kuò)展函數(shù)

    管理函數(shù):

刪除一個(gè)空間表(包括geometry_columns中的記錄) DropGeometryTable([], ) 更新空間表的空間參考 UpdateGeometrySRID([], , , ) 更新空間表的統(tǒng)計(jì)信息 update_geometry_stats([, ])

參考語(yǔ)義: Geos:GEOS庫(kù) Jts:JTS庫(kù) Proj:PROJ4庫(kù) postgis_version()

postgis_lib_version() postgis_lib_build_date() postgis_script_build_date() postgis_scripts_installed() postgis_scripts_released() postgis_geos_version() postgis_jts_version() postgis_proj_version() postgis_uses_stats() postgis_full_version()

幾何操作符:

A范圍=B范圍 A = B A范圍覆蓋B范圍或A范圍在B范圍左側(cè) A &<> B A范圍在B范圍左側(cè) A <<>> B A范圍覆蓋B范圍或A范圍在B范圍下方 A &<| B A范圍覆蓋B范圍或A范圍在B范圍上方 A |&> B A范圍在B范圍下方 A <<| B A范圍在B范圍上方 A |>> B A=B A ~= B A范圍被B范圍包含 A @ B A范圍包含B范圍 A ~ B A范圍覆蓋B范圍 A && B

幾何量測(cè)函數(shù):

量測(cè)面積 ST_Area(geometry) 根據(jù)經(jīng)緯度點(diǎn)計(jì)算在地球曲面上的距離,單位米,地球半徑取值6370986米 ST_distance_sphere(point, point) 類似上,使用指定的地球橢球參數(shù) ST_distance_spheroid(point, point, spheroid) 量測(cè)2D對(duì)象長(zhǎng)度 ST_length2d(geometry) 量測(cè)3D對(duì)象長(zhǎng)度 ST_length3d(geometry) 根據(jù)經(jīng)緯度對(duì)象計(jì)算在地球曲面上的長(zhǎng)度 ST_length_spheroid(geometry,spheroid) ST_length3d_spheroid(geometry,spheroid) 量測(cè)兩個(gè)對(duì)象間距離 ST_distance(geometry, geometry) 量測(cè)兩條線之間的最大距離 ST_max_distance(linestring,linestring) 量測(cè)2D對(duì)象的周長(zhǎng) ST_perimeter(geometry) ST_perimeter2d(geometry) 量測(cè)3D對(duì)象的周長(zhǎng) ST_perimeter3d(geometry) 量測(cè)兩點(diǎn)構(gòu)成的方位角,單位弧度 ST_azimuth(geometry, geometry)

幾何對(duì)象輸出:

參考語(yǔ)義: NDR:Little Endian XDR:big-endian HEXEWKB:Canonical SVG:SVG 格式 GML:GML 格式 KML:KML 格式 GeoJson:GeoJson 格式

ST_AsBinary(geometry,{'NDR'|'XDR'}) ST_AsEWKT(geometry) ST_AsEWKB(geometry, {'NDR'|'XDR'}) ST_AsHEXEWKB(geometry, {'NDR'|'XDR'}) ST_AsSVG(geometry, [rel], [precision]) ST_AsGML([version], geometry, [precision]) ST_AsKML([version], geometry, [precision]) ST_AsGeoJson([version], geometry, [precision], [options])

幾何對(duì)象創(chuàng)建:

參考語(yǔ)義: Dump:轉(zhuǎn)儲(chǔ) ST_GeomFromEWKT(text)

ST_GeomFromEWKB(bytea) ST_MakePoint(, , [], []) ST_MakePointM(, , ) ST_MakeBox2D(, ) ST_MakeBox3D(, ) ST_MakeLine(geometry set) ST_MakeLine(geometry, geometry) ST_LineFromMultiPoint(multipoint) ST_MakePolygon(linestring, [linestring[]]) ST_BuildArea(geometry) ST_Polygonize(geometry set) ST_Collect(geometry set) ST_Collect(geometry, geometry) ST_Dump(geometry) ST_DumpRings(geometry)

幾何對(duì)象編輯:

給幾何對(duì)象添加一個(gè)邊界,會(huì)使查詢速度加快 ST_AddBBOX(geometry) 刪除幾何對(duì)象的邊界 ST_DropBBOX(geometry) 添加、刪除、設(shè)置點(diǎn) ST_AddPoint(linestring, point, []) ST_RemovePoint(linestring, offset) ST_SetPoint(linestring, N, point) 幾何對(duì)象類型轉(zhuǎn)換 ST_Force_collection(geometry) ST_Force_2d(geometry) ST_Force_3dz(geometry), ST_Force_3d(geometry), ST_Force_3dm(geometry) ST_Force_4d(geometry) ST_Multi(geometry) 將幾何對(duì)象轉(zhuǎn)化到指定空間參考 ST_Transform(geometry,integer) 對(duì)3D幾何對(duì)象作仿射變化 ST_Affine(geometry, float8, float8, float8, float8, float8, float8, float8, float8, float8, float8, float8, float8) 對(duì)2D幾何對(duì)象作仿射變化 ST_Affine(geometry, float8, float8, float8, float8, float8, float8) 對(duì)幾何對(duì)象作偏移 ST_Translate(geometry, float8, float8, float8) 對(duì)幾何對(duì)象作縮放 ST_Scale(geometry, float8, float8, float8) 對(duì)3D幾何對(duì)象作旋轉(zhuǎn) ST_RotateZ(geometry, float8) ST_RotateX(geometry, float8) ST_RotateY(geometry, float8) 對(duì)2D對(duì)象作偏移和縮放 ST_TransScale(geometry, float8, float8, float8, float8) 反轉(zhuǎn) ST_Reverse(geometry) 轉(zhuǎn)化到右手定則 ST_ForceRHR(geometry) 參考IsSimple函數(shù) 使用Douglas-Peuker算法 ST_Simplify(geometry, tolerance) ST_SimplifyPreserveTopology(geometry, tolerance) 講幾何對(duì)象頂點(diǎn)捕捉到網(wǎng)格 ST_SnapToGrid(geometry, originX, originY, sizeX, sizeY) ST_SnapToGrid(geometry, sizeX, sizeY), ST_SnapToGrid(geometry, size) 第二個(gè)參數(shù)為點(diǎn),指定原點(diǎn)坐標(biāo) ST_SnapToGrid(geometry, geometry, sizeX, sizeY, sizeZ, sizeM) 分段 ST_Segmentize(geometry, maxlength) 合并為線 ST_LineMerge(geometry)

線性參考:

根據(jù)location(0-1)獲得該位置的點(diǎn) ST_line_interpolate_point(linestring, location) 獲取一段線 ST_line_substring(linestring, start, end) 根據(jù)點(diǎn)獲取location(0-1) ST_line_locate_point(LineString, Point) 根據(jù)量測(cè)值獲得幾何對(duì)象 ST_locate_along_measure(geometry, float8) 根據(jù)量測(cè)值區(qū)間獲得幾何對(duì)象集合 ST_locate_between_measures(geometry, float8, float8)

雜項(xiàng)功能函數(shù):

幾何對(duì)象的摘要 ST_Summary(geometry) 幾何對(duì)象的邊界 ST_box2d(geometry) ST_box3d(geometry) 多個(gè)幾何對(duì)象的邊界 ST_extent(geometry set) 0=2d, 1=3dm, 2=3dz, 3=4d ST_zmflag(geometry) 是否包含Bounding Box ST_HasBBOX(geometry) 幾何對(duì)象的維數(shù):2、3、4 ST_ndims(geometry) 子對(duì)象的個(gè)數(shù) ST_nrings(geometry) ST_npoints(geometry) 對(duì)象是否驗(yàn)證成功 ST_isvalid(geometry) 擴(kuò)大幾何對(duì)象 ST_expand(geometry, float) 計(jì)算一個(gè)空間表的邊界范圍 ST_estimated_extent([schema], table, geocolumn) 獲得空間參考 ST_find_srid(, , ) 幾何對(duì)象使用的內(nèi)存大小,單位byte ST_mem_size(geometry) 點(diǎn)是否在圓上 ST_point_inside_circle(,,,) 獲取邊界的X、Y、Z ST_XMin(box3d) ST_YMin(box3d) ST_ZMin(box3d) ST_XMax(box3d) ST_YMax(box3d) ST_ZMax(box3d) 構(gòu)造一個(gè)幾何對(duì)象的數(shù)組 ST_Accum(geometry set)

長(zhǎng)事務(wù)支持:

啟用/關(guān)閉長(zhǎng)事務(wù)支持,重復(fù)調(diào)用無(wú)副作用 EnableLongTransactions() DisableLongTransactions() 檢查對(duì)行的update和delete操作是否已授權(quán) CheckAuth([],, ) 鎖定行 LockRow([],, , , []) 解鎖行 UnlockRows() 在當(dāng)前事務(wù)中添加授權(quán)ID AddAuth()

其它還有SQL-MM和ArcSDE樣式的函數(shù)支持,可以參考http://postgis.refractions.net/documentation/manual-1.3/ch06.html#id2750611,這里就不詳細(xì)列了。

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)