当前位置:   article > 正文

第四节.postgis空间函数的运用_怎么在postgis中使用函数

怎么在postgis中使用函数

具体请看如下文章

https://blog.csdn.net/qq_34748010/article/details/126920098

实战经验如下:

  1. 计算面积
  2. st_area ( ST_Transform (geometry, 4527 ))
  3. 是否绝对包含
  4. SELECT ST_Contains(p1.geometry, p2.geometry) AS baohanFROM t_base_wuran_fqjstc AS p2,t_base_wuran_mdkxx AS p1where p1.wai_id=58 and p2.tudi_bian=58
  5. 是否相交 ST_NumGeometries(ST_Intersection(p1.geometry, p2.geometry))>0,
  6. 相交的面ST_AsText(ST_Intersection(p1.geometry, p2.geometry))
  7. SELECT ST_NumGeometries(ST_Intersection(p1.geometry, p2.geometry))>0 as xiangjiao,ST_AsText(ST_Intersection(p1.geometry, p2.geometry)) as mianFROM t_base_wuran_fqjstc AS p2,t_base_wuran_mdkxx AS p1where p1.wai_id=58 and p2.tudi_bian=58
  8. 是否分离
  9. st_disjoint ( p1.geometry, p2.geometry )
  10. SELECT p2.id,ST_AsText(ST_SymDifference(p1.geometry, p2.geometry)) as non_intersecting_geom
  11. FROM t_base_wuran_mdkxx AS p2, t_base_wuran_fqjstc AS p1
  12. WHERE p2.wai_id=58 and p1.id=12
  13. 包含 相交 分离 初掉面积 第一建设图形的面积
  14. SELECT
  15. p1.id as cid,
  16. p2.id as fid,
  17. p2.NAME,
  18. p2.beu_zhu,
  19. p1.NAME AS dname,
  20. ST_AsText(p1.geometry) as chumian,
  21. ST_AsText(p2.geometry) as fmian,
  22. ST_Contains ( p1.geometry, p2.geometry ) AS baohan,
  23. ST_NumGeometries ( ST_Intersection ( p1.geometry, p2.geometry ) ) > 0 AS xiangjiao,
  24. st_disjoint ( p1.geometry, p2.geometry ) AS fenli
  25. FROM
  26. t_base_wuran_mdkxx AS p1,
  27. t_base_wuran_fqjstc AS p2
  28. WHERE p1.wai_id=58 and p2.id=12
  29. SELECT
  30. ST_AsText ( ST_Intersection ( p1.geometry, p2.geometry ) ) AS xiangmian ,ST_AsText(ST_SymDifference(p1.geometry, p2.geometry)) as feixiang
  31. FROM
  32. t_base_wuran_mdkxx AS p1,
  33. t_base_wuran_fqjstc AS p2
  34. WHERE
  35. p1.wai_id = 58
  36. AND p2.id = 12
  37. select * from t_base_wuran_fqjstc
  38. SELECT ST_Area(geometry) FROM t_base_wuran_fqjstc WHERE id=12;
  39. NOT ST_Intersects(p1.geometry, p2.geometry);
  40. select * from t_base_wuran_mdkxx
  41. t_base_wuran_dkjc
  42. SELECT p1.id as cid, p2.id as fid, p2.NAME, p2.beu_zhu, p1.NAME AS dname, ST_AsText(p1.geometry) as chumian, ST_AsText(p2.geometry) as fmian, ST_Contains ( p1.geometry, p2.geometry ) AS baohan, ST_NumGeometries ( ST_Intersection ( p1.geometry, p2.geometry ) ) > 0 AS xiangjiao, st_disjoint ( p1.geometry, p2.geometry ) AS fenli FROM t_base_wuran_mdkxx AS p1, t_base_wuran_fqjstc AS p2 WHERE p1.wai_id = 58 AND p2.id = 11
  43. SELECT ST_Area(geometry) FROM t_base_wuran_mdkxx
  44. SELECT st_area ( ST_Transform (geometry, 4527 )) as area FROM t_base_wuran_mdkxx where id=40
  45. select * from t_base_wuran_xxdcdkxx
  46. SELECT
  47. p1.id AS cid,
  48. p2.id AS fid,
  49. p2.NAME,
  50. p2.beu_zhu,
  51. p1.NAME AS dname,
  52. ST_AsText ( p1.geometry ) AS chumian,
  53. ST_AsText ( p2.geometry ) AS fmian,
  54. ST_Contains ( p1.geometry, p2.geometry ) AS baohan,
  55. ST_NumGeometries ( ST_Intersection ( p1.geometry, p2.geometry ) ) > 0 AS xiangjiao,
  56. st_disjoint ( p1.geometry, p2.geometry ) AS fenli ,
  57. st_area ( ST_Transform (p1.geometry, 4527 )) as mianji,
  58. st_area ( ST_Transform (p2.geometry, 4527 )) as fmianji
  59. FROM
  60. t_base_wuran_xxdcdkxx AS p1,
  61. t_base_wuran_fqjstc AS p2
  62. WHERE
  63. p1.wai_id = 58
  64. AND p2.id = 11
  65. SELECT st_area ( ST_Transform (ST_Intersection ( p1.geometry, p2.geometry ), 4527 )) as xiangmianji, ST_AsText ( ST_Intersection ( p1.geometry, p2.geometry ) ) AS xiangmian ,ST_AsText(ST_SymDifference(p1.geometry, p2.geometry)) as feixiang FROM t_base_wuran_mdkxx AS p1, t_base_wuran_fqjstc AS p2 WHERE p1.wai_id = 58 AND p2.id = 12
  66. 创建的扩展语句
  67. CREATE EXTENSION postgis;
  68. CREATE EXTENSION postgis_topology;
  69. CREATE EXTENSION postgis_sfcgal;
  70. CREATE EXTENSION fuzzystrmatch;
  71. CREATE EXTENSION address_standardizer;
  72. CREATE EXTENSION address_standardizer_data_us;
  73. CREATE EXTENSION postgis_tiger_geocoder;
  74. CREATE EXTENSION pgrouting;
  75. -- 创建完毕用户后 postgres用户下执行如上语句
  76. SELECT name, ST_AsText(geomline) as geom FROM "AA"
  77. 最近设施
  78. where+=" ORDER BY geom <-> GeomFromEWKT('SRID=4326;"+postdata.getString("geoTxt2")+"') limit 5";
  79. INSERT INTO "AA" (name,geom) VALUES ('基站1001',GeomFromEWKT('SRID=4326;POINT(121.50 31.22)'));
  80. SELECT name, ST_AsText(geom) as geom FROM "geo_sfz_point"
  81. where 1=1 ORDER BY geom <-> GeomFromEWKT('SRID=4326;POINT(121.50 31.22)') limit 5;
  82. SELECT ST_AsText(geom) as geom FROM geo_zyzx_polygon LIMIT 10 OFFSET 0
  83. 转载自:http://www.jsjtt.com/shujuku/postgresql/31.html
  84. 1.OGC标准函数
  85. 管理函数:
  86. 添加几何字段 AddGeometryColumn(, , , , , )
  87. 删除几何字段 DropGeometryColumn(, , )
  88. 检查数据库几何字段并在geometry_columns中归档 Probe_Geometry_Columns()
  89. 给几何对象设置空间参考(在通过一个范围做空间查询时常用) ST_SetSRID(geometry, integer)
  90. 几何对象关系函数 :
  91. 获取两个几何对象间的距离 ST_Distance(geometry, geometry)
  92. 如果两个几何对象间距离在给定值范围内,则返回TRUE ST_DWithin(geometry, geometry, float)
  93. 判断两个几何对象是否相等
  94. (比如LINESTRING(0 0, 2 2)和LINESTRING(0 0, 1 1, 2 2)是相同的几何对象) ST_Equals(geometry, geometry)
  95. 判断两个几何对象是否分离 ST_Disjoint(geometry, geometry)
  96. 判断两个几何对象是否相交 ST_Intersects(geometry, geometry)
  97. 判断两个几何对象的边缘是否接触 ST_Touches(geometry, geometry)
  98. 判断两个几何对象是否互相穿过 ST_Crosses(geometry, geometry)
  99. 判断A是否被B包含 ST_Within(geometry A, geometry B)
  100. 判断两个几何对象是否是重叠 ST_Overlaps(geometry, geometry)
  101. 判断A是否包含B ST_Contains(geometry A, geometry B)
  102. 判断A是否覆盖 B ST_Covers(geometry A, geometry B)
  103. 判断A是否被B所覆盖 ST_CoveredBy(geometry A, geometry B)
  104. 通过DE-9IM 矩阵判断两个几何对象的关系是否成立 ST_Relate(geometry, geometry, intersectionPatternMatrix)
  105. 获得两个几何对象的关系(DE-9IM矩阵) ST_Relate(geometry, geometry)
  106. 几何对象处理函数:
  107. 获取几何对象的中心 ST_Centroid(geometry)
  108. 面积量测 ST_Area(geometry)
  109. 长度量测 ST_Length(geometry)
  110. 返回曲面上的一个点 ST_PointOnSurface(geometry)
  111. 获取边界 ST_Boundary(geometry)
  112. 获取缓冲后的几何对象 ST_Buffer(geometry, double, [integer])
  113. 获取多几何对象的外接对象 ST_ConvexHull(geometry)
  114. 获取两个几何对象相交的部分 ST_Intersection(geometry, geometry)
  115. 将经度小于0的值加360使所有经度值在0-360间 ST_Shift_Longitude(geometry)
  116. 获取两个几何对象不相交的部分(A、B可互换) ST_SymDifference(geometry A, geometry B)
  117. 从A去除和B相交的部分后返回 ST_Difference(geometry A, geometry B)
  118. 返回两个几何对象的合并结果 ST_Union(geometry, geometry)
  119. 返回一系列几何对象的合并结果 ST_Union(geometry set)
  120. 用较少的内存和较长的时间完成合并操作,结果和ST_Union相同 ST_MemUnion(geometry set)
  121. 几何对象存取函数:
  122. 获取几何对象的WKT描述 ST_AsText(geometry)
  123. 获取几何对象的WKB描述 ST_AsBinary(geometry)
  124. 获取几何对象的空间参考ID ST_SRID(geometry)
  125. 获取几何对象的维数 ST_Dimension(geometry)
  126. 获取几何对象的边界范围 ST_Envelope(geometry)
  127. 判断几何对象是否为空 ST_IsEmpty(geometry)
  128. 判断几何对象是否不包含特殊点(比如自相交) ST_IsSimple(geometry)
  129. 判断几何对象是否闭合 ST_IsClosed(geometry)
  130. 判断曲线是否闭合并且不包含特殊点 ST_IsRing(geometry)
  131. 获取多几何对象中的对象个数 ST_NumGeometries(geometry)
  132. 获取多几何对象中第N个对象 ST_GeometryN(geometry,int)
  133. 获取几何对象中的点个数 ST_NumPoints(geometry)
  134. 获取几何对象的第N个点 ST_PointN(geometry,integer)
  135. 获取多边形的外边缘 ST_ExteriorRing(geometry)
  136. 获取多边形内边界个数 ST_NumInteriorRings(geometry)
  137. 同上 ST_NumInteriorRing(geometry)
  138. 获取多边形的第N个内边界 ST_InteriorRingN(geometry,integer)
  139. 获取线的终点 ST_EndPoint(geometry)
  140. 获取线的起始点 ST_StartPoint(geometry)
  141. 获取几何对象的类型 GeometryType(geometry)
  142. 类似上,但是不检查M值,即POINTM对象会被判断为point ST_GeometryType(geometry)
  143. 获取点的X坐标 ST_X(geometry)
  144. 获取点的Y坐标 ST_Y(geometry)
  145. 获取点的Z坐标 ST_Z(geometry)
  146. 获取点的M值 ST_M(geometry)
  147. 几何对象构造函数 :
  148. 参考语义:
  149. Text:WKT
  150. WKB:WKB
  151. Geom:Geometry
  152. M:Multi
  153. Bd:BuildArea
  154. Coll:Collection ST_GeomFromText(text,[])
  155. ST_PointFromText(text,[])
  156. ST_LineFromText(text,[])
  157. ST_LinestringFromText(text,[])
  158. ST_PolyFromText(text,[])
  159. ST_PolygonFromText(text,[])
  160. ST_MPointFromText(text,[])
  161. ST_MLineFromText(text,[])
  162. ST_MPolyFromText(text,[])
  163. ST_GeomCollFromText(text,[])
  164. ST_GeomFromWKB(bytea,[])
  165. ST_GeometryFromWKB(bytea,[])
  166. ST_PointFromWKB(bytea,[])
  167. ST_LineFromWKB(bytea,[])
  168. ST_LinestringFromWKB(bytea,[])
  169. ST_PolyFromWKB(bytea,[])
  170. ST_PolygonFromWKB(bytea,[])
  171. ST_MPointFromWKB(bytea,[])
  172. ST_MLineFromWKB(bytea,[])
  173. ST_MPolyFromWKB(bytea,[])
  174. ST_GeomCollFromWKB(bytea,[])
  175. ST_BdPolyFromText(text WKT, integer SRID)
  176. ST_BdMPolyFromText(text WKT, integer SRID)
  177. 2. PostGIS扩展函数
  178. 管理函数:
  179. 删除一个空间表(包括geometry_columns中的记录) DropGeometryTable([], )
  180. 更新空间表的空间参考 UpdateGeometrySRID([], , , )
  181. 更新空间表的统计信息 update_geometry_stats([, ])
  182. 参考语义:
  183. Geos:GEOS库
  184. Jts:JTS库
  185. Proj:PROJ4库 postgis_version()
  186. postgis_lib_version()
  187. postgis_lib_build_date()
  188. postgis_script_build_date()
  189. postgis_scripts_installed()
  190. postgis_scripts_released()
  191. postgis_geos_version()
  192. postgis_jts_version()
  193. postgis_proj_version()
  194. postgis_uses_stats()
  195. postgis_full_version()
  196. 几何操作符:
  197. A范围=B范围 A = B
  198. A范围覆盖B范围或A范围在B范围左侧 A &<> B
  199. A范围在B范围左侧 A <<>> B
  200. A范围覆盖B范围或A范围在B范围下方 A &<| B A范围覆盖B范围或A范围在B范围上方 A |&> B
  201. A范围在B范围下方 A <<| B A范围在B范围上方 A |>> B
  202. A=B A ~= B
  203. A范围被B范围包含 A @ B
  204. A范围包含B范围 A ~ B
  205. A范围覆盖B范围 A && B
  206. 几何量测函数:
  207. 量测面积 ST_Area(geometry)
  208. 根据经纬度点计算在地球曲面上的距离,单位米,地球半径取值6370986米 ST_distance_sphere(point, point)
  209. 类似上,使用指定的地球椭球参数 ST_distance_spheroid(point, point, spheroid)
  210. 量测2D对象长度 ST_length2d(geometry)
  211. 量测3D对象长度 ST_length3d(geometry)
  212. 根据经纬度对象计算在地球曲面上的长度 ST_length_spheroid(geometry,spheroid)
  213. ST_length3d_spheroid(geometry,spheroid)
  214. 量测两个对象间距离 ST_distance(geometry, geometry)
  215. 量测两条线之间的最大距离 ST_max_distance(linestring,linestring)
  216. 量测2D对象的周长 ST_perimeter(geometry)
  217. ST_perimeter2d(geometry)
  218. 量测3D对象的周长 ST_perimeter3d(geometry)
  219. 量测两点构成的方位角,单位弧度 ST_azimuth(geometry, geometry)
  220. 几何对象输出:
  221. 参考语义:
  222. NDR:Little Endian
  223. XDR:big-endian
  224. HEXEWKB:Canonical
  225. SVG:SVG 格式
  226. GML:GML 格式
  227. KML:KML 格式
  228. GeoJson:GeoJson 格式
  229. ST_AsBinary(geometry,{‘NDR’|’XDR’})
  230. ST_AsEWKT(geometry)
  231. ST_AsEWKB(geometry, {‘NDR’|’XDR’})
  232. ST_AsHEXEWKB(geometry, {‘NDR’|’XDR’})
  233. ST_AsSVG(geometry, [rel], [precision])
  234. ST_AsGML([version], geometry, [precision])
  235. ST_AsKML([version], geometry, [precision])
  236. ST_AsGeoJson([version], geometry, [precision], [options])
  237. 几何对象创建:
  238. 参考语义:
  239. Dump:转储 ST_GeomFromEWKT(text)
  240. ST_GeomFromEWKB(bytea)
  241. ST_MakePoint(, , [], [])
  242. ST_MakePointM(, , )
  243. ST_MakeBox2D(, )
  244. ST_MakeBox3D(, )
  245. ST_MakeLine(geometry set)
  246. ST_MakeLine(geometry, geometry)
  247. ST_LineFromMultiPoint(multipoint)
  248. ST_MakePolygon(linestring, [linestring[]])
  249. ST_BuildArea(geometry)
  250. ST_Polygonize(geometry set)
  251. ST_Collect(geometry set)
  252. ST_Collect(geometry, geometry)
  253. ST_Dump(geometry)
  254. ST_DumpRings(geometry)
  255. 几何对象编辑:
  256. 给几何对象添加一个边界,会使查询速度加快 ST_AddBBOX(geometry)
  257. 删除几何对象的边界 ST_DropBBOX(geometry)
  258. 添加、删除、设置点 ST_AddPoint(linestring, point, [])
  259. ST_RemovePoint(linestring, offset)
  260. ST_SetPoint(linestring, N, point)
  261. 几何对象类型转换 ST_Force_collection(geometry)
  262. ST_Force_2d(geometry)
  263. ST_Force_3dz(geometry), ST_Force_3d(geometry),
  264. ST_Force_3dm(geometry)
  265. ST_Force_4d(geometry)
  266. ST_Multi(geometry)
  267. 将几何对象转化到指定空间参考 ST_Transform(geometry,integer)
  268. 3D几何对象作仿射变化 ST_Affine(geometry, float8, float8, float8, float8, float8, float8, float8, float8, float8, float8, float8, float8)
  269. 2D几何对象作仿射变化 ST_Affine(geometry, float8, float8, float8, float8, float8, float8)
  270. 对几何对象作偏移 ST_Translate(geometry, float8, float8, float8)
  271. 对几何对象作缩放 ST_Scale(geometry, float8, float8, float8)
  272. 3D几何对象作旋转 ST_RotateZ(geometry, float8)
  273. ST_RotateX(geometry, float8)
  274. ST_RotateY(geometry, float8)
  275. 2D对象作偏移和缩放 ST_TransScale(geometry, float8, float8, float8, float8)
  276. 反转 ST_Reverse(geometry)
  277. 转化到右手定则 ST_ForceRHR(geometry)
  278. 参考IsSimple函数
  279. 使用Douglas-Peuker算法 ST_Simplify(geometry, tolerance)
  280. ST_SimplifyPreserveTopology(geometry, tolerance)
  281. 讲几何对象顶点捕捉到网格 ST_SnapToGrid(geometry, originX, originY, sizeX, sizeY)
  282. ST_SnapToGrid(geometry, sizeX, sizeY), ST_SnapToGrid(geometry, size)
  283. 第二个参数为点,指定原点坐标 ST_SnapToGrid(geometry, geometry, sizeX, sizeY, sizeZ, sizeM)
  284. 分段 ST_Segmentize(geometry, maxlength)
  285. 合并为线 ST_LineMerge(geometry)
  286. 线性参考:
  287. 根据location0-1)获得该位置的点 ST_line_interpolate_point(linestring, location)
  288. 获取一段线 ST_line_substring(linestring, start, end)
  289. 根据点获取location0-1) ST_line_locate_point(LineString, Point)
  290. 根据量测值获得几何对象 ST_locate_along_measure(geometry, float8)
  291. 根据量测值区间获得几何对象集合 ST_locate_between_measures(geometry, float8, float8)
  292. 杂项功能函数:
  293. 几何对象的摘要 ST_Summary(geometry)
  294. 几何对象的边界 ST_box2d(geometry)
  295. ST_box3d(geometry)
  296. 多个几何对象的边界 ST_extent(geometry set)
  297. 0=2d, 1=3dm, 2=3dz, 3=4d ST_zmflag(geometry)
  298. 是否包含Bounding Box ST_HasBBOX(geometry)
  299. 几何对象的维数:234 ST_ndims(geometry)
  300. 子对象的个数 ST_nrings(geometry)
  301. ST_npoints(geometry)
  302. 对象是否验证成功 ST_isvalid(geometry)
  303. 扩大几何对象 ST_expand(geometry, float)
  304. 计算一个空间表的边界范围 ST_estimated_extent([schema], table, geocolumn)
  305. 获得空间参考 ST_find_srid(, , )
  306. 几何对象使用的内存大小,单位byte ST_mem_size(geometry)
  307. 点是否在圆上 ST_point_inside_circle(,,,)
  308. 获取边界的X、Y、Z ST_XMin(box3d)
  309. ST_YMin(box3d)
  310. ST_ZMin(box3d)
  311. ST_XMax(box3d)
  312. ST_YMax(box3d)
  313. ST_ZMax(box3d)
  314. 构造一个几何对象的数组 ST_Accum(geometry set)
  315. 长事务支持:
  316. 启用/关闭长事务支持,重复调用无副作用 EnableLongTransactions()
  317. DisableLongTransactions()
  318. 检查对行的update和delete操作是否已授权 CheckAuth([],
  319. , )
  320. 锁定行 LockRow([], , , , [])
  321. 解锁行 UnlockRows()
  322. 在当前事务中添加授权ID AddAuth()
  323. 其他的函数可到官网进行查看: http://postgis.net/docs/reference.html

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号