{"id":938,"date":"2022-05-29T21:43:51","date_gmt":"2022-05-29T13:43:51","guid":{"rendered":"https:\/\/blog.frost-s.com\/?p=938"},"modified":"2022-07-26T15:15:40","modified_gmt":"2022-07-26T07:15:40","slug":"postgis%e6%80%bb%e7%bb%93","status":"publish","type":"post","link":"https:\/\/blog.frost-s.com\/index.php\/2022\/05\/29\/postgis%e6%80%bb%e7%bb%93\/","title":{"rendered":"POSTGIS \u603b\u7ed3"},"content":{"rendered":"\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<div class='github-info-card github-info-card-full card shadow-sm' data-author='postgis' data-project='postgis' githubinfo-card-id='9913160949' data-getdata='frontend' data-description='' data-stars='' data-forks=''><div class='github-info-card-header'><a href='https:\/\/github.com\/' ref='nofollow' target='_blank' title='Github' no-pjax><span><i class='fa fa-github'><\/i> GitHub<\/span><\/a><\/div><div class='github-info-card-body'>\r\n\t\t\t<div class='github-info-card-name-a'>\r\n\t\t\t\t<a href='https:\/\/github.com\/postgis\/postgis' target='_blank' no-pjax>\r\n\t\t\t\t\t<span class='github-info-card-name'>postgis\/postgis<\/span>\r\n\t\t\t\t<\/a>\r\n\t\t\t\t<\/div>\r\n\t\t\t<div class='github-info-card-description'><\/div>\r\n\t\t<\/div><div class='github-info-card-bottom'>\r\n\t\t\t\t<span class='github-info-card-meta github-info-card-meta-stars'>\r\n\t\t\t\t\t<i class='fa fa-star'><\/i> <span class='github-info-card-stars'><\/span>\r\n\t\t\t\t<\/span>\r\n\t\t\t\t<span class='github-info-card-meta github-info-card-meta-forks'>\r\n\t\t\t\t\t<i class='fa fa-code-fork'><\/i> <span class='github-info-card-forks'><\/span>\r\n\t\t\t\t<\/span>\r\n\t\t\t<\/div><\/div>\n\n\n\n<ul><li><a href=\"https:\/\/www.cnblogs.com\/yjh1995\/p\/13893272.html\">PostGreSQL\uff08\u4e09\uff09PostGIS<\/a><\/li><li><a href=\"https:\/\/www.cnblogs.com\/yjh1995\/p\/13893286.html\">PostGreSQL\uff08\u56db\uff09PostGIS-\u7a7a\u95f4\u6570\u636e\u5b58\u50a8<\/a><\/li><li><a href=\"https:\/\/www.cnblogs.com\/yjh1995\/p\/13893295.html\">PostGreSQL\uff08\u4e94\uff09PostGIS-\u5e38\u7528\u51fd\u6570<\/a><\/li><li><a href=\"https:\/\/www.cnblogs.com\/yjh1995\/p\/13893306.html\">PostGreSQL\uff08\u516d\uff09PostGIS-\u7a7a\u95f4\u8fde\u63a5\u548c\u7a7a\u95f4\u7d22\u5f15<\/a><\/li><li><a href=\"https:\/\/www.cnblogs.com\/yjh1995\/p\/13893355.html\">PostGreSQL\uff08\u4e03\uff09PostGIS-\u51e0\u4f55\u56fe\u5f62\u521b\u5efa\u51fd\u6570<\/a><\/li><li><a href=\"https:\/\/www.cnblogs.com\/yjh1995\/p\/13893363.html\">PostGreSQL\uff08\u516b\uff09PostGIS-\u56fe\u5f62\u6709\u6548\u6027\u548c\u7b80\u5355\u6027<\/a><\/li><li><a href=\"https:\/\/www.cnblogs.com\/yjh1995\/p\/13893374.html\">PostGreSQL\uff08\u4e5d\uff09PostGIS-\u51e0\u4f55\u56fe\u5f62\u7684\u76f8\u7b49<\/a><\/li><li><a href=\"https:\/\/www.cnblogs.com\/yjh1995\/p\/13893384.html\">PostGreSQL\uff08\u5341\uff09PostGIS-\u6700\u8fd1\u9886\u57df\u641c\u7d22<\/a><\/li><li><a href=\"https:\/\/www.cnblogs.com\/yjh1995\/p\/13893398.html\">PostGreSQL\uff08\u5341\u4e00\uff09PostGIS-\u5176\u4ed6\u51fd\u6570<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4e00\u3001postgis\u4ecb\u7ecd\">\u4e00\u3001PostGIS\u4ecb\u7ecd<\/h2>\n\n\n\n<p><strong>PostGIS<\/strong>\u662f\u4e00\u4e2a<strong>\u7a7a\u95f4\u6570\u636e\u5e93<\/strong>\uff0c<strong>\u7a7a\u95f4\u6570\u636e\u5e93\u50cf\u5b58\u50a8\u548c\u64cd\u4f5c\u6570\u636e\u5e93\u4e2d\u5176\u4ed6\u4efb\u4f55\u5bf9\u8c61\u4e00\u6837\u53bb\u5b58\u50a8\u548c\u64cd\u4f5c\u7a7a\u95f4\u5bf9\u8c61<\/strong>\u3002<\/p>\n\n\n\n<p><strong>\u7a7a\u95f4\u6570\u636e\u5e93<\/strong>\u5c06<strong>\u7a7a\u95f4\u6570\u636e<\/strong>\u548c<strong>\u5bf9\u8c61\u5173\u7cfb\u6570\u636e\u5e93<\/strong>\uff08Object Relational database\uff09\u5b8c\u5168\u96c6\u6210\u5728\u4e00\u8d77\u3002\u5b9e\u73b0\u4ece\u4ee5GIS\u4e3a\u4e2d\u5fc3\u5411\u4ee5\u6570\u636e\u5e93\u4e3a\u4e2d\u5fc3\u7684\u8f6c\u53d8\u3002<\/p>\n\n\n\n<p>PostGIS\u901a\u8fc7\u5411<a href=\"https:\/\/so.csdn.net\/so\/search?q=PostgreSQL&amp;spm=1001.2101.3001.7020\">PostgreSQL<\/a>\u6dfb\u52a0\u5bf9<strong>\u7a7a\u95f4\u6570\u636e\u7c7b\u578b<\/strong>\u3001**\u7a7a\u95f4\u7d22\u5f15(R-Tree)<strong>\u548c<\/strong>\u7a7a\u95f4\u51fd\u6570<strong>\u7684\u652f\u6301\uff0c\u5c06PostgreSQL\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\u8f6c\u6362\u4e3a<\/strong>\u7a7a\u95f4\u6570\u636e\u5e93**\uff0c\u53ef\u4ee5\u8bf4PostGIS\u4ec5\u4ec5\u53ea\u662fPostgreSQL\u7684\u4e00\u4e2a\u63d2\u4ef6\uff0c\u4f46\u662f\u5b83\u5c06PostgreSQL\u53d8\u6210\u4e86\u4e00\u4e2a\u5f3a\u5927\u7684\u7a7a\u95f4\u6570\u636e\u5e93\uff01<\/p>\n\n\n\n<p>\u6700\u91cd\u8981\u7684\u53ea\u8981\u63a5\u89e6\u8fc7SQL\u8bed\u8a00\uff0c\u5c31\u53ef\u4ee5\u5229\u7528PostGIS\u7684SQL\u8bed\u6cd5\u4fbf\u6377\u7684\u64cd\u7eb5\u88c5\u8f7d\u7740\u7a7a\u95f4\u4fe1\u606f\u7684\u6570\u636e\u6846\uff08\u6570\u636e\u8868\uff09\uff0c\u8fd9\u4e9b\u4e8c\u7ef4\u8868\u9664\u4e86\u88ab\u8bbe\u5b9a\u4e86\u4e00\u4e2a\u7279\u6b8a\u7684\u7a7a\u95f4\u5730\u7406\u4fe1\u606f\u5b57\u6bb5\uff08\u5e26\u6709\u7a7a\u95f4\u6295\u5f71\u4fe1\u606f\u3001\u7ecf\u7eac\u5ea6\u4fe1\u606f\u7b49\uff09\u4e4b\u5916\uff0c\u4e0e\u4e3b\u6d41\u6570\u636e\u7ba1\u7406\u7cfb\u7edf\u6240\u5b9a\u4e49\u7684\u5404\u79cd\u5b57\u6bb5\u5e76\u65e0\u4e24\u6837\u3002<\/p>\n\n\n\n<p>PostGIS\u5b89\u88c5\u4e0d\u4ec5\u4f9d\u8d56\u4e8ePostgreSQL\uff0c\u8fd8\u4f9d\u8d56\u4e8e\u5f88\u591a\u63d2\u4ef6\uff1a<\/p>\n\n\n\n<ul><li>GEOS\u51e0\u4f55\u5bf9\u8c61\u5e93<\/li><li>GDAL\u6805\u683c\u529f\u80fd<\/li><li>LibXML2<\/li><li>LIBJSON<\/li><\/ul>\n\n\n\n<p>PostGIS\u7684\u7279\u70b9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul><li>PostGIS\u652f\u6301\u6240\u6709\u7684\u7a7a\u95f4\u6570\u636e\u7c7b\u578b\uff0c\u8fd9\u4e9b\u7c7b\u578b\u5305\u62ec\uff1a\u70b9\uff08POINT\uff09\u3001\u7ebf\uff08LINESTRING\uff09\u3001\u9762\uff08POLYGON\uff09\u3001\u591a\u70b9 \uff08MULTIPOINT\uff09\u3001\u591a\u7ebf\uff08MULTILINESTRING\uff09\u3001\u591a\u9762\uff08MULTIPOLYGON\uff09\u548c\u51e0\u4f55\u96c6\u5408 \uff08GEOMETRYCOLLECTION\uff09\u7b49\u3002PostGIS\u652f\u6301\u6240\u6709\u7684\u5bf9\u8c61\u8868\u8fbe\u65b9\u6cd5\uff0c\u6bd4\u5982WKT\u548cWKB\u3002<\/li><li>PostGIS\u652f\u6301\u6240\u6709\u7684\u6570\u636e\u5b58\u53d6\u548c\u6784\u9020\u65b9\u6cd5\uff0c\u5982GeomFromText()\u3001AsBinary()\uff0c\u4ee5\u53caGeometryN()\u7b49\u3002<\/li><li>PostGIS\u63d0\u4f9b\u7b80\u5355\u7684\u7a7a\u95f4\u5206\u6790\u51fd\u6570\uff08\u5982Area\u548cLength\uff09\u540c\u65f6\u4e5f\u63d0\u4f9b\u5176\u4ed6\u4e00\u4e9b\u5177\u6709\u590d\u6742\u5206\u6790\u529f\u80fd\u7684\u51fd\u6570\uff0c\u6bd4\u5982Distance\u3002<\/li><li>PostGIS\u63d0\u4f9b\u4e86\u5bf9\u4e8e\u5143\u6570\u636e\u7684\u652f\u6301\uff0c\u5982GEOMETRY_COLUMNS\u548cSPATIAL_REF_SYS\u3002\u540c\u65f6\uff0cPostGIS\u4e5f\u63d0\u4f9b\u4e86\u76f8\u5e94\u7684\u652f\u6301\u51fd\u6570\uff0c\u5982AddGeometryColumn\u548cDropGeometryColumn\u3002<\/li><li>PostGIS\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u7684\u4e8c\u5143\u8c13\u8bcd\uff08\u5982Contains\u3001Within\u3001Overlaps\u548cTouches\uff09\u7528\u4e8e\u68c0\u6d4b\u7a7a\u95f4\u5bf9\u8c61\u4e4b\u95f4\u7684\u7a7a\u95f4\u5173\u7cfb\uff0c\u540c\u65f6\u8fd4\u56de\u5e03\u5c14\u503c\u6765\u8868\u5f81\u5bf9\u8c61\u4e4b\u95f4\u7b26\u5408\u8fd9\u4e2a\u5173\u7cfb\u3002<\/li><li>PostGIS\u63d0\u4f9b\u4e86\u7a7a\u95f4\u64cd\u4f5c\u7b26\uff08\u5982Union\u548cDifference\uff09\u7528\u4e8e\u7a7a\u95f4\u6570\u636e\u64cd\u4f5c\u3002<\/li><li>\u6570\u636e\u5e93\u5750\u6807\u53d8\u6362<\/li><li>\u7403\u4f53\u957f\u5ea6\u8fd0\u7b97<\/li><li>\u4e09\u7ef4\u7684\u51e0\u4f55\u7c7b\u578b<\/li><li>\u7a7a\u95f4\u805a\u96c6\u51fd\u6570<\/li><li>\u6805\u683c\u6570\u636e\u7c7b\u578b<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"11-\u7a7a\u95f4\u6570\u636e\u7c7b\u578b\">1.1 \u7a7a\u95f4\u6570\u636e\u7c7b\u578b<\/h3>\n\n\n\n<ul><li><strong>\u7a7a\u95f4\u6570\u636e\u7c7b\u578b<\/strong>\u7528\u4e8e\u6307\u5b9a\u56fe\u5f62\u4e3a<strong>\u70b9<\/strong>\uff08point\uff09\u3001<strong>\u7ebf<\/strong>\uff08line\uff09\u548c<strong>\u9762<\/strong>\uff08polygon\uff09<ul><li><strong>\u666e\u901a\u6570\u636e\u5e93<\/strong>\u62e5\u6709<strong>\u5b57\u7b26\u4e32<\/strong>\uff08string\uff09\u3001<strong>\u6570\u503c<\/strong>\uff08number\uff09\u548c<strong>\u65e5\u671f<\/strong>\uff08date\uff09\u8fd9\u4e9b\u6570\u636e\u7c7b\u578b\uff0c<strong>\u7a7a\u95f4\u6570\u636e\u5e93<\/strong>\u6dfb\u52a0\u4e86\u989d\u5916\u7684\u6570\u636e\u7c7b\u578b\uff08\u7a7a\u95f4\u6570\u636e\u7c7b\u578b\uff09\u4ee5\u7528\u4e8e\u8868\u8fbe<strong>\u5730\u7406\u7279\u5f81<\/strong>\uff08geographic features\uff09\u3002 \u8fd9\u4e9b<strong>\u7a7a\u95f4\u6570\u636e\u7c7b\u578b<\/strong>\u62bd\u8c61\u5e76\u5c01\u88c5\u4e86\u8bf8\u5982<strong>\u8fb9\u754c<\/strong>\uff08boundary\uff09\u548c<strong>\u7ef4\u5ea6<\/strong>\uff08dimension\uff09\u7b49\u7a7a\u95f4\u7ed3\u6784\u3002 \u5728\u8bb8\u591a\u65b9\u9762\uff0c<strong>\u7a7a\u95f4\u6570\u636e\u7c7b\u578b<\/strong>\u53ef\u4ee5\u7b80\u5355\u7684\u7406\u89e3\u4e3a<strong>\u5f62\u72b6<\/strong>\uff08shape\uff09<\/li><\/ul><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"12-\u7a7a\u95f4\u7d22\u5f15\u548c\u8fb9\u754c\u6846\">1.2 \u7a7a\u95f4\u7d22\u5f15\u548c\u8fb9\u754c\u6846<\/h3>\n\n\n\n<ul><li>\u591a\u7ef4\u5ea6<strong>\u7a7a\u95f4\u7d22\u5f15<\/strong>\u88ab\u7528\u4e8e\u8fdb\u884c\u7a7a\u95f4\u64cd\u4f5c\u7684\u9ad8\u6548\u5904\u7406\uff08\u6ce8\u610f\u662f\u591a\u7ef4\u5ea6\u54e6\uff0c\u800c\u4e0d\u662f\u53ea\u6709\u9488\u5bf9\u4e8c\u7ef4\u7a7a\u95f4\u6570\u636e\u7684\u7d22\u5f15\uff09<\/li><li>\u7531\u4e8e<strong>\u591a\u8fb9\u5f62<\/strong>\uff08Polygon\uff09\u53ef\u4ee5\u91cd\u53e0\uff0c\u53ef\u4ee5\u76f8\u4e92\u5305\u542b\uff0c\u5e76\u4e14\u53ef\u4ee5\u6392\u5217\u5728\u4e8c\u7ef4\uff08\u6216\u66f4\u591a\u7ef4\u6570\uff09\u7a7a\u95f4\u4e2d\uff0c\u56e0\u6b64\u65e0\u6cd5\u4f7f\u7528<strong>B\u6811\u7d22\u5f15<\/strong>\u6709\u6548\u5730\u7d22\u5f15\u5b83\u4eec\u3002 <strong>\u7a7a\u95f4\u6570\u636e\u5e93<\/strong>\u63d0\u4f9b\u4e86\u4e00\u4e2a\u201c<strong>\u7a7a\u95f4\u7d22\u5f15<\/strong>\uff08spatial index\uff09\u201d\uff0c\u5b83\u56de\u7b54\u4e86\u201c\u54ea\u4e9b\u5bf9\u8c61\u5728\u8fd9\u4e2a\u7279\u5b9a\u7684\u8fb9\u754c\u6846\u5185\uff1f\u201d\u8fd9\u4e2a\u95ee\u9898\u3002 <strong>\u8fb9\u754c\u6846<\/strong>\uff08bounding box\uff09\u662f\u5e73\u884c\u4e8e\u5750\u6807\u8f74\u4e14\u5305\u542b\u7ed9\u5b9a\u5730\u7406<strong>\u8981\u7d20<\/strong>\uff08feature\uff09\u7684\u6700\u5c0f\u7684\u77e9\u5f62\u3002<\/li><li><strong>\u7a7a\u95f4\u7d22\u5f15<\/strong>\u4e0d\u50cf<strong>B\u6811\u7d22\u5f15<\/strong>\u90a3\u6837\u63d0\u4f9b\u7cbe\u786e\u7684\u7ed3\u679c\uff0c\u800c\u662f\u63d0\u4f9b\u8fd1\u4f3c\u7684\u7ed3\u679c\u3002<\/li><li>\u5404\u79cd\u6570\u636e\u5e93\u5b9e\u9645\u5b9e\u73b0\u7684<strong>\u7a7a\u95f4\u7d22\u5f15<\/strong>\u5dee\u5f02\u5f88\u5927\uff0c\u6700\u5e38\u89c1\u7684\u5b9e\u73b0\u662f<a href=\"https:\/\/link.zhihu.com\/?target=http%3A\/\/en.wikipedia.org\/wiki\/R-tree\">R-tree<\/a>\uff08\u5728PostGIS\u4e2d\u4f7f\u7528\uff09\uff0c\u4f46\u5728\u5176\u4ed6<strong>\u7a7a\u95f4\u6570\u636e\u5e93<\/strong>\u4e2d\u4e5f\u6709\u57fa\u4e8e<a href=\"https:\/\/link.zhihu.com\/?target=http%3A\/\/en.wikipedia.org\/wiki\/Quadtree\">\u56db\u53c9\u6811<\/a>\uff08Quadtrees\uff09\u7684\u5b9e\u73b0\u548c<a href=\"https:\/\/link.zhihu.com\/?target=http%3A\/\/en.wikipedia.org\/wiki\/Grid_%28spatial_index%29\">\u57fa\u4e8e\u7f51\u683c\u7684\u7d22\u5f15<\/a>\uff08grid-based indexes\uff09\u7684\u5b9e\u73b0<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"13-\u7a7a\u95f4\u51fd\u6570\">1.3 \u7a7a\u95f4\u51fd\u6570<\/h3>\n\n\n\n<p><strong>\u7a7a\u95f4\u51fd\u6570<\/strong>\u6784\u5efa\u4e8eSQL\u8bed\u8a00\u4e2d\uff0c\u7528\u4e8e\u8fdb\u884c\u7a7a\u95f4\u5c5e\u6027\u548c\u7a7a\u95f4\u5173\u7cfb\u7684\u67e5\u8be2\uff0c<strong>\u7a7a\u95f4\u51fd\u6570<\/strong>\u4e2d\u7684\u5927\u90e8\u5206\u53ef\u4ee5\u88ab\u5f52\u7eb3\u4e3a\u4ee5\u4e0b\u4e94\u7c7b\uff1a<\/p>\n\n\n\n<ul><li>\u8f6c\u6362 \u2014\u2014 \u5728geometry\uff08PostGIS\u4e2d\u5b58\u50a8\u7a7a\u95f4\u4fe1\u606f\u7684\u683c\u5f0f\uff09\u548c\u5916\u90e8\u6570\u636e\u683c\u5f0f\u4e4b\u95f4\u8fdb\u884c\u8f6c\u6362\u7684\u51fd\u6570<\/li><li>\u7ba1\u7406 \u2014\u2014 \u7ba1\u7406\u5173\u4e8e\u7a7a\u95f4\u8868\u548cPostGIS\u7ec4\u7ec7\u7684\u4fe1\u606f\u7684\u51fd\u6570<\/li><li>\u68c0\u7d22 \u2014\u2014 \u68c0\u7d22\u51e0\u4f55\u56fe\u5f62\u7684\u5c5e\u6027\u548c\u7a7a\u95f4\u4fe1\u606f\u6d4b\u91cf\u7684\u51fd\u6570<\/li><li>\u6bd4\u8f83 \u2014\u2014 \u6bd4\u8f83\u4e24\u79cd\u51e0\u4f55\u56fe\u5f62\u7684\u7a7a\u95f4\u5173\u7cfb\u7684\u51fd\u6570<\/li><li>\u751f\u6210 \u2014\u2014 \u57fa\u4e8e\u5176\u4ed6\u51e0\u4f55\u56fe\u5f62\u751f\u6210\u65b0\u56fe\u5f62\u7684\u51fd\u6570<\/li><\/ul>\n\n\n\n<p>\u53c2\u8003\uff1a\u3000\u3000<a href=\"https:\/\/zhuanlan.zhihu.com\/p\/67232451\">https:\/\/zhuanlan.zhihu.com\/p\/67232451<\/a><\/p>\n\n\n\n<ul><li><a href=\"https:\/\/www.cnblogs.com\/yjh1995\/p\/13893286.html\">\u7a7a\u95f4\u6570\u636e\u5b58\u50a8<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4e8c\u3001\u7a7a\u95f4\u6570\u636e\u5b58\u50a8\">\u4e8c\u3001\u7a7a\u95f4\u6570\u636e\u5b58\u50a8<\/h2>\n\n\n\n<p>\u4f7f\u7528<strong>geography<\/strong>\u8fd9\u79cd\u6570\u636e\u7c7b\u578b\u65f6\uff0cPostGIS\u7684\u5185\u90e8\u8ba1\u7b97\u662f\u57fa\u4e8e<strong>\u5b9e\u9645\u5730\u7403\u7403\u4f53<\/strong>\u6765\u8ba1\u7b97\u7684\uff1b<\/p>\n\n\n\n<p>\u800c\u4f7f\u7528<strong>geometry<\/strong>\u8fd9\u79cd\u6570\u636e\u7c7b\u578b\u65f6\uff0cPostGIS\u7684\u5185\u90e8\u8ba1\u7b97\u662f<strong>\u57fa\u4e8e\u5e73\u9762<\/strong>\u6765\u8ba1\u7b97\u7684\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"21-\u51e0\u4f55\u7c7b\u578b\uff08geometry-type\uff09\">2.1 \u51e0\u4f55\u7c7b\u578b\uff08Geometry Type\uff09<\/h3>\n\n\n\n<p>Geometry\uff08\u51e0\u4f55\u5bf9\u8c61\u7c7b\u578b\uff09\u662fPG\u7684\u4e00\u4e2a\u57fa\u672c\u5b58\u50a8\u7c7b\u578b\uff0cPostGIS\u7684\u7a7a\u95f4\u6570\u636e\u90fd\u4f1a\u4ee5Geometry\u7684\u5f62\u5f0f\u5b58\u50a8\u5728PostgreSQL\u91cc\uff0c\u672c\u8d28\u662f\u4e2a\u4e8c\u8fdb\u5236\u5bf9\u8c61\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"211-ogc\u7684wkb\u548cwkt\u683c\u5f0f\">2.1.1 OGC\u7684WKB\u548cWKT\u683c\u5f0f<\/h4>\n\n\n\n<p>PostGIS\u57fa\u4e8eOGC\u7684\u201cSimple Feature for Specification for SQL\u201d\u89c4\u8303\uff0c\u5728Geometry\u5bf9\u8c61\u4e0a\u5b9e\u73b0\u4e86\u4e00\u7cfb\u5217\u7684GIS Object\uff08\u5730\u7269\u5bf9\u8c61\uff09\uff0c\u4f7f\u7528\u4e86OGC\u63a8\u8350\u7684WKT\uff08Well-Known Text\uff09\u548cWKB\uff08Well-Known Binary\uff09\u683c\u5f0f\u8fdb\u884c\u63cf\u8ff0\uff0c\u5927\u5e45\u589e\u52a0\u4e86\u6613\u7528\u6027\uff0c\u4f8b\u5982WKT\u76847\u4e2a\u57fa\u672c\u7c7b\u578b\uff1a<\/p>\n\n\n\n<p>\u70b9\uff1aPOINT(0 0) \u7ebf\uff1aLINESTRING(0 0,1 1,1 2) \u9762(\u591a\u8fb9\u5f62)\uff1aPOLYGON((0 0,4 0,4 4,0 4,0 0)) \u7b80\u5355\u591a\u8fb9\u5f62 POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1, 2 1, 2 2, 1 2,1 1)) \u591a\u8fb9\u5f62\u6709\u4e00\u4e2a\u5185\u90e8\u7684\"\u5b54\u6d1e\uff08hole\uff09\" \u591a\u70b9\uff1aMULTIPOINT((0 0),(1 2)) \u591a\u7ebf\uff1aMULTILINESTRING((0 0,1 1,1 2),(2 3,3 2,5 4)) \u591a\u9762\uff1aMULTIPOLYGON(((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1)), ((-1 -1,-1 -2,-2 -2,-2 -1,-1 -1))) \u51e0\u4f55\u96c6\u5408\uff1aGEOMETRYCOLLECTION(POINT(2 3),LINESTRING(2 3,3 4))<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"212-ewkt\u3001ewkb\u548ccanonical\u683c\u5f0f\">2.1.2 EWKT\u3001EWKB\u548cCanonical\u683c\u5f0f<\/h4>\n\n\n\n<p>PostGIS\u81ea\u8eab\u53c8\u5728WKT\u548cWKB\u57fa\u7840\u4e0a\u6269\u5c55\u5b9e\u73b0\u4e86EWKT\u548cEWKB\u6765\u6ee1\u8db3\u66f4\u590d\u6742\u7684\u573a\u666f\u9700\u6c42\uff0cEWKT\u548cEWKB\u76f8\u6bd4OGC WKT\u548cWKB\u683c\u5f0f\u4e3b\u8981\u7684\u6269\u5c55\u67093DZ\u30013DM\u30014D\u5750\u6807\u548c\u5185\u5d4c\u7a7a\u95f4\u53c2\u8003\u652f\u6301\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"213-sql-mm\u683c\u5f0f\">2.1.3 SQL-MM\u683c\u5f0f<\/h4>\n\n\n\n<p>SQL-MM\u683c\u5f0f\u5b9a\u4e49\u4e86\u4e00\u4e9b\u63d2\u503c\u66f2\u7ebf\uff0c\u8fd9\u4e9b\u63d2\u503c\u66f2\u7ebf\u548cEWKT\u6709\u70b9\u7c7b\u4f3c\uff0c\u4e5f\u652f\u63013DZ\u30013DM\u30014D\u5750\u6807\uff0c\u4f46\u662f\u4e0d\u652f\u6301\u5d4c\u5165\u7a7a\u95f4\u53c2\u8003\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"22-\u5730\u7406\u7c7b\u578b\uff08geography-type\uff09\">2.2 \u5730\u7406\u7c7b\u578b\uff08Geography Type\uff09<\/h3>\n\n\n\n<p>\u5730\u7406\u7c7b\u578b\u63d0\u4f9b\u652f\u6301\u672c\u5730\u7a7a\u95f4\u7279\u6027\u7684\u201c\u5730\u7406\u201d\u5750\u6807(\u6709\u65f6\u79f0\u4e3a\u201c\u5927\u5730\u201d\u5750\u6807,\u6216\u201c\u7eac\u5ea6\/\u7ecf\u5ea6\u201d,\u6216\u201c\u7ecf\u5ea6\/\u7eac\u5ea6\u201d)\u3002\u5b83\u7684\u51e0\u4f55\u57fa\u7840\u662f\u7403\u9762\u3002<\/p>\n\n\n\n<p>\u8ba1\u7b97\u4e24\u70b9\u95f4\u7684\u8ddd\u79bb\u76f8\u5f53\u4e8e\u8ba1\u7b97\u5706\u5f27\u7684\u8ddd\u79bb\uff0c\u4e0d\u80fd\u4f7f\u7528\u5e73\u9762\u51e0\u4f55\u539f\u7406\uff0c\u9700\u8981\u901a\u8fc7\u5176\u4ed6\u53c2\u8003\u65b9\u6cd5\u8ba1\u7b97\u3002<\/p>\n\n\n\n<p>\u7531\u4e8e\u5e95\u5c42\u7b97\u6cd5\u590d\u6742\uff0c\u5b9a\u4e49\u7684\u5730\u7406\u7c7b\u578b\u6bd4\u7a7a\u95f4\u7c7b\u578b\u5c11\u5f88\u591a\uff0c\u968f\u4e4b\u7b97\u6cd5\u7684\u589e\u52a0\uff0c\u5c06\u51fa\u73b0\u65b0\u7684\u5730\u7406\u7c7b\u578b\u3002<\/p>\n\n\n\n<p>PostGresSQL8.3\u63a8\u51fa\u4e00\u5f20\u8868\u8f85\u52a9\u7a7a\u95f4\u53c2\u8003\u8868\uff1aspatial_ref_sys\u8868\uff0c\u5b83\u5b58\u653e\u7684\u662fOGC\u89c4\u8303\u7684\u7a7a\u95f4\u53c2\u8003\u3002\u8f85\u52a9\u8f6c\u5316\u3002<\/p>\n\n\n\n<p>\u5730\u7406\u7c7b\u578b\u53ea\u652f\u6301\u7b80\u5355\u7684\u7b80\u5355\u7684\u5143\u7d20\u3002<strong>\u6807\u51c6\u51e0\u4f55\u7c7b\u578b\u6570\u636e\u5c06\u81ea\u52a8\u8f6c\u6362\u5230\u5730\u7406WGS84\u5750\u6807<\/strong>\u3002\u8fd8\u53ef\u4ee5\u4f7f\u7528EWKT\u548cEWKB\u7ea6\u5b9a\u6765\u63d2\u5165\u6570\u636e\u3002<\/p>\n\n\n\n<p>patial_ref_sys\u8868\uff0c\u5b83\u5b58\u653e\u7684\u662fOGC\u89c4\u8303\u7684\u7a7a\u95f4\u53c2\u8003\u3002\u6211\u4eec\u53d6\u6211\u4eec\u6700\u719f\u6089\u76844326\u53c2\u8003\u770b\u4e00\u4e0b\uff1a<\/p>\n\n\n\n<p>\u5b83\u7684srid\u5b58\u653e\u7684\u5c31\u662f\u7a7a\u95f4\u53c2\u8003\u7684Well-Known ID\uff0c\u5bf9\u8fd9\u4e2a\u7a7a\u95f4\u53c2\u8003\u7684\u5b9a\u4e49\u4e3b\u8981\u5305\u62ec\u4e24\u4e2a\u5b57\u6bb5\uff0csrtext\u5b58\u653e\u7684\u662f\u4ee5\u5b57\u7b26\u4e32\u63cf\u8ff0\u7684\u7a7a\u95f4\u53c2\u8003\uff0cproj4text\u5b58\u653e\u7684\u5219\u662f\u4ee5\u5b57\u7b26\u4e32\u63cf\u8ff0\u7684PROJ.4 \u6295\u5f71\u5b9a\u4e49\uff08PostGIS\u4f7f\u7528PROJ.4\u5b9e\u73b0\u6295\u5f71\uff09<\/p>\n\n\n\n<p>SRID 4326\u58f0\u660e\u4e86\u5730\u7406\u7a7a\u95f4\u53c2\u8003\u7cfb\u7edf<\/p>\n\n\n\n<p>\u5982\u4e0b\u521b\u5efa\u8868\uff1a<\/p>\n\n\n\n<p>CREATE TABLE global_points ( id SERIAL PRIMARY KEY, name VARCHAR(64), location GEOGRAPHY(POINT,4326) );<\/p>\n\n\n\n<p>\u63d2\u5165\u6570\u636e\uff1a<\/p>\n\n\n\n<p>INSERT INTO global_points (name, location) VALUES ('London', ST_GeographyFromText('SRID=4326; POINT(-72.1235 42.3521)'));<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"23-postgis\u5bf9\u51e0\u4f55\u4fe1\u606f\u7684\u68c0\u67e5\">2.3 PostGIS\u5bf9\u51e0\u4f55\u4fe1\u606f\u7684\u68c0\u67e5<\/h3>\n\n\n\n<p>PostGIS\u53ef\u4ee5\u68c0\u67e5\u51e0\u4f55\u4fe1\u606f\u7684\u6b63\u786e\u6027\uff0c\u8fd9\u4e3b\u8981\u662f\u901a\u8fc7IsValid\u51fd\u6570\u5b9e\u73b0\u7684\u3002 \u4ee5\u4e0b\u8bed\u53e5\u5206\u8fa8\u68c0\u67e5\u4e862\u4e2a\u51e0\u4f55\u5bf9\u8c61\u7684\u6b63\u786e\u6027\uff0c\u663e\u7136\uff0c(0, 0)\u70b9\u548c(1,1)\u70b9\u53ef\u4ee5\u6784\u6210\u4e00\u6761\u7ebf\uff0c\u4f46\u662f(0, 0)\u70b9\u548c(0, 0)\u70b9\u5219\u4e0d\u80fd\u6784\u6210\uff0c\u8fd9\u4e2a\u8bed\u53e5\u6267\u884c\u4ee5\u540e\u7684\u5f97\u51fa\u7684\u7ed3\u679c\u662fTRUE,FALSE\u3002<\/p>\n\n\n\n<p>select IsValid('LINESTRING(0 0, 1 1)'), IsValid('LINESTRING(0 0,0 0)')<\/p>\n\n\n\n<p>\u9ed8\u8ba4PostGIS\u5e76\u4e0d\u4f1a\u4f7f\u7528IsValid\u51fd\u6570\u68c0\u67e5\u7528\u6237\u63d2\u5165\u7684\u65b0\u6570\u636e\uff0c\u56e0\u4e3a\u8fd9\u4f1a\u6d88\u8017\u8f83\u591a\u7684CPU\u8d44\u6e90\uff08\u7279\u522b\u662f\u590d\u6742\u7684\u51e0\u4f55\u5bf9\u8c61\uff09\u3002\u5f53\u4f60\u9700\u8981\u4f7f\u7528\u8fd9\u4e2a\u529f\u80fd\u7684\u65f6\u5019\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\u4e3a\u8868\u65b0\u5efa\u4e00\u4e2a\u68c0\u67e5\u7ea6\u675f\uff1a<\/p>\n\n\n\n<p>ALTER TABLE cities ADD CONSTRAINT geometry_valid CHECK (IsValid(shape))<\/p>\n\n\n\n<p>\u8fd9\u65f6\u5f53\u6211\u4eec\u5f80\u8fd9\u4e2a\u8868\u8bd5\u56fe\u63d2\u5165\u4e00\u4e2a\u9519\u8bef\u7684\u7a7a\u95f4\u5bf9\u8c61\u7684\u65f6\u5019\uff0c\u4f1a\u5f97\u5230\u4e00\u4e2a\u9519\u8bef\uff1a<\/p>\n\n\n\n<p>INSERT INTO test.cities ( shape, name ) VALUES ( GeomFromText('LINESTRING(0 0,0 0)', 4326), '\u5317\u4eac'); ERROR: new row for relation \"cities\" violates check constraint \"geometry_valid\" SQL \u72b6\u6001: 23514<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4e09\u3001postgis\u4e2d\u7684\u5e38\u7528\u51fd\u6570\">\u4e09\u3001PostGIS\u4e2d\u7684\u5e38\u7528\u51fd\u6570<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"31-\u56fe\u5f62\u548c\u5730\u7406\u4f4d\u7f6e\">3.1 \u56fe\u5f62\u548c\u5730\u7406\u4f4d\u7f6e<\/h3>\n\n\n\n<ul><li><strong>ST_GeometryType(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56de\u51e0\u4f55\u56fe\u5f62\u7684\u7c7b\u578b<\/li><li><strong>ST_Transform(geometry, srid)<\/strong>\u2014\u2014\u5c06\u51e0\u4f55\u56fe\u5f62\u6295\u5f71\u4e3a\u5730\u7406\u5750\u6807\u6570\u636e \u6216 \u8f6c\u6362\u4e3a\u4e0d\u540csrid\u5750\u6807\u7cfb\u7edf\u7684\u5750\u6807\u6570\u636e<\/li><li><strong>Geography(geometry)<\/strong>\u2014\u2014\u5c06\u57fa\u4e8eEPSG:4326(srid=4326)\u7684geometry\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u4e3ageography\u6570\u636e\u7c7b\u578b<\/li><li><strong>ST_NDims(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56de\u51e0\u4f55\u56fe\u5f62\u7684\u7ef4\u6570<\/li><li><strong>ST_SRID(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56de\u51e0\u4f55\u56fe\u5f62\u7684\u7a7a\u95f4\u53c2\u8003\u6807\u8bc6\u7801 srid<\/li><li><strong>ST_SetSRID(geometry\uff0cSRID\uff09<\/strong>\u2014\u2014\u8bbe\u7f6esrid<\/li><li><strong>sum(expression)<\/strong>&nbsp;\u2014\u2014\u8fd4\u56de\u4e00\u4e2a\u8ba1\u7b97\u5f0f\/\u8868\u8fbe\u5f0f\u7684\u548c<\/li><li><strong>count(expression)<\/strong>&nbsp;\u2014\u2014\u8fd4\u56de\u4e00\u4e2a\u8868\u8fbe\u5f0f\u4e2d\u7684\u6b21\u6570<\/li><\/ul>\n\n\n\n<p>PS : geometry\uff0c\u662f\u51e0\u4f55\u7c7b\u578b\u7684\u5217\u7684\u5217\u540d<\/p>\n\n\n\n<p>srid\uff0c\u4e0d\u540c\u7684srid\u5c31\u662f\u4e0d\u540c\u6807\u51c6\u7684\u5750\u6807\u7cfb<\/p>\n\n\n\n<p><strong>\u70b9\u7a7a\u95f4\u51fd\u6570<\/strong>\uff1a<\/p>\n\n\n\n<ul><li><strong>ST_X(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56deX\u5750\u6807<\/li><li><strong>ST_Y(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56deY\u5750\u6807<\/li><\/ul>\n\n\n\n<p><strong>\u7ebf\u4e32\u7a7a\u95f4\u51fd\u6570<\/strong>\uff1a<\/p>\n\n\n\n<ul><li><strong>ST_Length(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56de\u7ebf\u4e32\u7684\u957f\u5ea6<\/li><li><strong>ST_StartPoint(geometry)<\/strong>&nbsp;\u2014\u2014 \u5c06\u7ebf\u4e32\u7684\u7b2c\u4e00\u4e2a\u5750\u6807\u4f5c\u4e3a\u70b9\u8fd4\u56de<\/li><li><strong>ST_EndPoint(geometry\uff09<\/strong>&nbsp;\u2014\u2014 \u5c06\u7ebf\u4e32\u7684\u6700\u540e\u4e00\u4e2a\u5750\u6807\u4f5c\u4e3a\u70b9\u8fd4\u56de<\/li><li><strong>ST_NPoints(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56de\u7ebf\u4e32\u7684\u5750\u6807\u6570\u91cf<\/li><\/ul>\n\n\n\n<p><strong>\u591a\u8fb9\u5f62\u7a7a\u95f4\u51fd\u6570<\/strong>\uff1a<\/p>\n\n\n\n<ul><li><strong>ST_Area(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56de\u591a\u8fb9\u5f62\u7684\u9762\u79ef<\/li><li><strong>ST_NRings(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56de\u591a\u8fb9\u5f62\u4e2d\u73af\u7684\u6570\u91cf\uff08\u901a\u5e38\u4e3a1\u4e2a\uff0c\u5176\u4ed6\u662f\u5b54\uff09<\/li><li><strong>ST_ExteriorRing(geometry)<\/strong>&nbsp;\u2014\u2014 \u4ee5\u7ebf\u4e32\u7684\u5f62\u5f0f\u8fd4\u56de\u591a\u8fb9\u5f62\u6700\u5916\u9762\u7684\u73af<\/li><li><strong>ST_InteriorRingN(geometry, n)<\/strong>&nbsp;\u2014\u2014 \u4ee5\u7ebf\u4e32\u5f62\u5f0f\u8fd4\u56de\u6307\u5b9a\u7684\u5185\u90e8\u73af<\/li><li><strong>ST_Perimeter(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56de\u6240\u6709\u73af\u7684\u957f\u5ea6<\/li><\/ul>\n\n\n\n<p><strong>\u96c6\u5408\u7a7a\u95f4\u51fd\u6570<\/strong>(\u591a\u70b9\u3001\u591a\u7ebf\u3001\u591a\u9762\u3001\u4efb\u610f\u56fe\u5f62\u7ec4\u5408)\uff1a<\/p>\n\n\n\n<ul><li><strong>ST_NumGeometries(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56de\u96c6\u5408\u4e2d\u7684\u7ec4\u6210\u90e8\u5206\u7684\u6570\u91cf<\/li><li><strong>ST_GeometryN(geometry, n)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56de\u96c6\u5408\u4e2d\u6307\u5b9a\u7684\u7ec4\u6210\u90e8\u5206<\/li><li><strong>ST_Area(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56de\u96c6\u5408\u4e2d\u6240\u6709\u591a\u8fb9\u5f62\u7ec4\u6210\u90e8\u5206\u7684\u603b\u9762\u79ef<\/li><li><strong>ST_Length(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56de\u6240\u6709\u7ebf\u6bb5\u7ec4\u6210\u90e8\u5206\u7684\u603b\u957f\u5ea6<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"32-\u51e0\u4f55\u56fe\u5f62\u8f93\u5165\u548c\u8f93\u51fa\">3.2 \u51e0\u4f55\u56fe\u5f62\u8f93\u5165\u548c\u8f93\u51fa<\/h3>\n\n\n\n<p>\u5728\u6570\u636e\u5e93\u4e2d\uff0c<strong>\u51e0\u4f55\u56fe\u5f62<\/strong>\uff08Geometry\uff09\u4ee5\u4ec5\u4f9bPostGIS\u4f7f\u7528\u7684\u683c\u5f0f\u5b58\u50a8\u5728\u78c1\u76d8\u4e0a\u3002\u4e3a\u4e86\u8ba9\u5916\u90e8\u7a0b\u5e8f\u63d2\u5165\u548c\u68c0\u7d22\u6709\u7528\u7684<strong>\u51e0\u4f55\u56fe\u5f62<\/strong>\u4fe1\u606f\uff0c\u9700\u8981\u5c06\u5b83\u4eec\u8f6c\u6362\u4e3a\u5176\u4ed6\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u7406\u89e3\u7684\u683c\u5f0f\u3002<\/p>\n\n\n\n<p>\u2460Well-known text\uff08<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/postgis.net\/workshops\/postgis-intro\/glossary.html%23term-wkt\">WKT<\/a>\uff09<\/p>\n\n\n\n<ul><li><strong>ST_GeomFromText(text, srid)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56degeometry\uff0c\u9664\u975e\u6307\u5b9aSRID\uff0c\u5426\u5219\u5c06\u5f97\u5230\u4e00\u4e2a\u5305\u542b\u672a\u77e5SRID\u7684<strong>\u51e0\u4f55\u56fe\u5f62<\/strong><\/li><li><strong>ST_GeographyFromText(text)<\/strong>\u2014\u2014\u8fd4\u56deGeography<\/li><li><strong>ST_AsText(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56detext<\/li><li><strong>ST_AsEWKT(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56detext<\/li><\/ul>\n\n\n\n<p>\u2461Well-known binary\uff08<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/postgis.net\/workshops\/postgis-intro\/glossary.html%23term-wkb\">WKB<\/a>\uff09<\/p>\n\n\n\n<ul><li><strong>ST_GeomFromWKB(bytea)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56degeometry<\/li><li><strong>ST_AsBinary(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56debytea<\/li><li><strong>ST_AsEWKB(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56debytea<\/li><\/ul>\n\n\n\n<p>\u2462Geographic Mark-up Language\uff08<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/postgis.net\/workshops\/postgis-intro\/glossary.html%23term-gml\">GML<\/a>\uff09<\/p>\n\n\n\n<ul><li><strong>ST_GeomFromGML(text)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56degeometry<\/li><li><strong>ST_ASGML(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56detext<\/li><\/ul>\n\n\n\n<p>\u2463Keyhole Mark-up Language\uff08<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/postgis.net\/workshops\/postgis-intro\/glossary.html%23term-kml\">KML<\/a>\uff09<\/p>\n\n\n\n<ul><li><strong>ST_GeomFromKML(text)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56degeometry<\/li><li><strong>ST_ASKML(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56detext<\/li><\/ul>\n\n\n\n<p>\u2464<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/postgis.net\/workshops\/postgis-intro\/glossary.html%23term-geojson\">GeoJson<\/a><\/p>\n\n\n\n<ul><li><strong>ST_AsGeoJSON(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56detext<\/li><\/ul>\n\n\n\n<p>\u2465Scalable Vector Graphics(<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/postgis.net\/workshops\/postgis-intro\/glossary.html%23term-svg\">SVG<\/a>\uff09<\/p>\n\n\n\n<ul><li><strong>ST_AsSVG(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56detext<\/li><\/ul>\n\n\n\n<p>\u4ee5\u4e0a\u51fd\u6570\u6700\u5e38\u89c1\u7684\u7528\u6cd5\u662f\u5c06<strong>\u51e0\u4f55\u56fe\u5f62<\/strong>\u7684<strong>\u6587\u672c<\/strong>\uff08text\uff09\u8868\u793a\u5f62\u5f0f\u8f6c\u6362\u4e3a\u5185\u90e8\u8868\u793a\u5f62\u5f0f<\/p>\n\n\n\n<p>\u8bf7\u6ce8\u610f\uff0c\u9664\u4e86\u5177\u6709<strong>\u51e0\u4f55\u56fe<\/strong>\u5f62\u8868\u793a\u5f62\u5f0f\u7684<strong>\u6587\u672c<\/strong>\u53c2\u6570\u5916\uff0c\u8fd8\u53ef\u4ee5\u6307\u5b9a\u4e00\u4e2a\u63d0\u4f9b\u51e0\u4f55\u56fe\u5f62<strong>SRID<\/strong>\u7684\u6570\u5b57\u53c2\u6570\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"33-\u56fe\u5f62\u5173\u7cfb\">3.3 \u56fe\u5f62\u5173\u7cfb<\/h3>\n\n\n\n<p><strong>ST_Equals(geometry A, geometry B)<\/strong><\/p>\n\n\n\n<ul><li>\u7528\u4e8e\u6d4b\u8bd5\u4e24\u4e2a\u56fe\u5f62\u7684\u7a7a\u95f4\u76f8\u7b49\u6027\u3002<\/li><li>\u5982\u679c\u4e24\u4e2a\u76f8\u540c\u7c7b\u578b\u7684\u51e0\u4f55\u56fe\u5f62\u5177\u6709\u76f8\u540c\u7684x\u3001y\u5750\u6807\u503c\uff0c\u5373\u5982\u679c\u7b2c\u4e8c\u4e2a\u56fe\u5f62\u4e0e\u7b2c\u4e00\u4e2a\u56fe\u5f62\u7684\u5750\u6807\u4fe1\u606f\u76f8\u7b49\uff08\u76f8\u540c\uff09\uff0c\u5219ST_Equals()\u8fd4\u56deTRUE\u3002<\/li><\/ul>\n\n\n\n<p><strong>ST_Intersects\u3001ST_Disjoint\u3001ST_Crosses\u548cST_Overlaps<\/strong><\/p>\n\n\n\n<ul><li><strong>ST_Intersects<\/strong>\u3001<strong>ST_Crosses<\/strong>\u548c<strong>ST_Overlaps<\/strong>\u6d4b\u8bd5\u51e0\u4f55\u56fe\u5f62\u662f\u5426\u76f8\u4ea4\u3002<\/li><li>\u5982\u679c<strong>\u4e24\u4e2a\u56fe\u5f62\u6709\u91cd\u5408\u7684\u90e8\u5206\uff0c\u5373\u5982\u679c\u5b83\u4eec\u7684\u8fb9\u754c\u6216\u5185\u90e8\u76f8\u4ea4<\/strong>\uff0c\u5219**ST_Intersects(geometry A, geometry B)**\u8fd4\u56deTRUE<\/li><li><strong>ST_Disjoint(geometry A, geometry B)<\/strong>\uff0c\u5982\u679c\u4e24\u4e2a\u51e0\u4f55\u56fe\u5f62\u6ca1\u6709\u91cd\u5408\u7684\u90e8\u5206\uff0c\u5219\u5b83\u4eec\u4e0d\u76f8\u4ea4\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002\u4e8b\u5b9e\u4e0a\u6d4b\u8bd5\"not intersect\"\u901a\u5e38\u6bd4\u6d4b\u8bd5\"disjoint\"\u66f4\u6709\u6548\uff0c\u56e0\u4e3aintersect\u6d4b\u8bd5\u53ef\u4ee5\u4f7f\u7528<strong>\u7a7a\u95f4\u7d22\u5f15<\/strong><\/li><li>\u5bf9\u4e8emultipoint\/polygon\u3001multipoint\/linestring\u3001linestring\/linestring\u3001linestring\/polygon\u548clinestring\/multipolygon\u7684\u6bd4\u8f83\uff0c<strong>\u5982\u679c\u76f8\u4ea4\u751f\u6210\u7684\u51e0\u4f55\u56fe\u5f62\u7684\u7ef4\u5ea6\u5c0f\u4e8e\u4e24\u4e2a\u6e90\u51e0\u4f55\u56fe\u5f62\u7684\u6700\u5927\u7ef4\u5ea6\uff0c\u4e14\u76f8\u4ea4\u96c6\u4f4d\u4e8e\u4e24\u4e2a\u6e90\u51e0\u4f55\u56fe\u5f62\u7684\u5185\u90e8<\/strong>\uff0c\u5219**ST_Crosses(geometry A, geometry B)**\u5c06\u8fd4\u56deTRUE\u3002<\/li><li>**ST_Overlaps(geometry A, geometry B)<strong>\u6bd4\u8f83\u4e24\u4e2a<\/strong>\u76f8\u540c\u7ef4\u5ea6**\u7684\u51e0\u4f55\u56fe\u5f62\uff0c<strong>\u5982\u679c\u5b83\u4eec\u7684\u7ed3\u679c\u96c6\u4e0e\u4e24\u4e2a\u6e90\u51e0\u4f55\u56fe\u5f62\u90fd\u4e0d\u540c\u4f46\u5177\u6709\u76f8\u540c\u7ef4\u5ea6<\/strong>\uff0c\u5219\u8fd4\u56deTRUE\u3002<\/li><\/ul>\n\n\n\n<p><strong>ST_Touches()<\/strong><\/p>\n\n\n\n<ul><li>\u6d4b\u8bd5\u4e24\u4e2a\u51e0\u4f55\u56fe\u5f62\u662f\u5426\u5728\u5b83\u4eec\u7684\u8fb9\u754c\u4e0a\u63a5\u89e6\uff0c\u4f46\u5728\u5b83\u4eec\u7684\u5185\u90e8\u4e0d\u76f8\u4ea4<\/li><li>\u5982\u679c\u4e24\u4e2a\u51e0\u4f55\u56fe\u5f62\u7684<strong>\u8fb9\u754c\u76f8\u4ea4<\/strong>\uff0c\u6216\u8005\u53ea\u6709\u4e00\u4e2a\u51e0\u4f55\u56fe\u5f62\u7684\u5185\u90e8\u4e0e\u53e6\u4e00\u4e2a\u51e0\u4f55\u56fe\u5f62\u7684\u8fb9\u754c\u76f8\u4ea4\uff0c\u5219**ST_Touches(geometry A, geometry B)**\u5c06\u8fd4\u56deTRUE<\/li><\/ul>\n\n\n\n<p><strong>ST_Within\u548cST_Contains<\/strong><\/p>\n\n\n\n<ul><li>ST_Within()\u548cST_Contains()\u6d4b\u8bd5\u4e00\u4e2a\u51e0\u4f55\u56fe\u5f62\u662f\u5426\u5b8c\u5168\u4f4d\u4e8e\u53e6\u4e00\u4e2a\u51e0\u4f55\u56fe\u5f62\u5185<\/li><li>\u5982\u679c\u7b2c\u4e00\u4e2a\u51e0\u4f55\u56fe\u5f62\u5b8c\u5168\u4f4d\u4e8e\u7b2c\u4e8c\u4e2a\u51e0\u4f55\u56fe\u5f62\u5185\uff0c\u5219ST_Within(geometry A, geometry B)\u8fd4\u56deTRUE\uff0cST_Within()\u6d4b\u8bd5\u7684\u7ed3\u679c\u4e0eST_Contains()\u5b8c\u5168\u76f8\u53cd<\/li><li>\u5982\u679c\u7b2c\u4e8c\u4e2a\u51e0\u4f55\u56fe\u5f62\u5b8c\u5168\u5305\u542b\u5728\u7b2c\u4e00\u4e2a\u51e0\u4f55\u56fe\u5f62\u5185\uff0c\u5219ST_Contains(geometry A, geometry B)\u8fd4\u56deTRUE<\/li><\/ul>\n\n\n\n<p><strong>ST_Distance\u548cST_DWithin<\/strong><\/p>\n\n\n\n<ul><li>**ST_Distance(geometry A, geometry B)**\u8ba1\u7b97\u4e24\u4e2a\u51e0\u4f55\u56fe\u5f62\u4e4b\u95f4\u7684\u6700\u77ed\u8ddd\u79bb\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u6d6e\u70b9\u6570\u8fd4\u56de\u3002\u8fd9\u5bf9\u4e8e\u5b9e\u9645\u62a5\u544a\u51e0\u4f55\u56fe\u5f62\u4e4b\u95f4\u7684\u8ddd\u79bb\u975e\u5e38\u6709\u7528<\/li><li><strong>ST_DWithin()<\/strong>\uff0c\u6d4b\u8bd5\u4e24\u4e2a\u51e0\u4f55\u56fe\u5f62\u4e4b\u95f4\u7684\u8ddd\u79bb\u662f\u5426\u5728\u67d0\u4e2a\u8303\u56f4\u4e4b\u5185\uff0c<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"34-geography\u7c7b\u578b\">3.4 geography\u7c7b\u578b<\/h3>\n\n\n\n<ul><li><strong>ST_AsText(geography)<\/strong>&nbsp;returns&nbsp;<code>text<\/code><\/li><li><strong>ST_GeographyFromText(text)<\/strong>&nbsp;returns&nbsp;<code>geography<\/code><\/li><li><strong>ST_AsBinary(geography)<\/strong>&nbsp;returns&nbsp;<code>bytea<\/code><\/li><li><strong>ST_GeogFromWKB(bytea)<\/strong>&nbsp;returns&nbsp;<code>geography<\/code><\/li><li><strong>ST_AsSVG(geography)<\/strong>&nbsp;returns&nbsp;<code>text<\/code><\/li><li><strong>ST_AsGML(geography)<\/strong>&nbsp;returns&nbsp;<code>text<\/code><\/li><li><strong>ST_AsKML(geography)<\/strong>&nbsp;returns&nbsp;<code>text<\/code><\/li><li><strong>ST_AsGeoJson(geography)<\/strong>&nbsp;returns&nbsp;<code>text<\/code><\/li><li><strong>ST_Distance(geography, geography)<\/strong>&nbsp;returns&nbsp;<code>double<\/code><\/li><li><strong>ST_DWithin(geography, geography, float8)<\/strong>&nbsp;returns&nbsp;<code>boolean<\/code><\/li><li><strong>ST_Area(geography)<\/strong>&nbsp;returns&nbsp;<code>double<\/code><\/li><li><strong>ST_Length(geography)<\/strong>&nbsp;returns&nbsp;<code>double<\/code><\/li><li><strong>ST_Covers(geography, geography)<\/strong>&nbsp;returns&nbsp;<code>boolean<\/code><\/li><li><strong>ST_CoveredBy(geography, geography)<\/strong>&nbsp;returns&nbsp;<code>boolean<\/code><\/li><li><strong>ST_Intersects(geography, geography)<\/strong>&nbsp;returns&nbsp;<code>boolean<\/code><\/li><li><strong>ST_Buffer(geography, float8)<\/strong>&nbsp;returns&nbsp;<code>geography<\/code><a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/postgis.net\/workshops\/postgis-intro\/geography.html%23casting-note\">[1]<\/a><\/li><li><strong>ST_Intersection(geography, geography)<\/strong>&nbsp;returns&nbsp;<code>geography<\/code><a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/postgis.net\/workshops\/postgis-intro\/geography.html%23casting-note\">[1]<\/a><\/li><\/ul>\n\n\n\n<p><strong>geography\u8f6c\u6362\u4e3ageometry<\/strong><\/p>\n\n\n\n<p>PostgreSQL\u7684\u7c7b\u578b\u8f6c\u6362\u8bed\u6cd5\u662f\u5c06&nbsp;<strong>::typename<\/strong>&nbsp;\u9644\u52a0\u5230\u5e0c\u671b\u8f6c\u6362\u7684\u503c\u7684\u672b\u5c3e\u3002\u56e0\u6b64\uff0c2::text\u5c06\u6570\u5b572\u8f6c\u6362\u4e3a\u6587\u672c\u5b57\u7b26\u4e32\"2\"\uff1b\u2018POINT(0 0)\u2019 :: geometry\u5c06\u70b9\u7684\u6587\u672c\u8868\u793a\u5f62\u5f0f\u8f6c\u6362\u4e3ageometry\u70b9<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u56db\u3001\u7a7a\u95f4\u8fde\u63a5\">\u56db\u3001\u7a7a\u95f4\u8fde\u63a5<\/h2>\n\n\n\n<p><strong>\u7a7a\u95f4\u8fde\u63a5<\/strong>\uff08spatial joins\uff09\u662f<strong>\u7a7a\u95f4\u6570\u636e\u5e93<\/strong>\u7684\u4e3b\u8981\u7ec4\u6210\u90e8\u5206\uff0c\u5b83\u4eec\u5141\u8bb8\u4f60\u4f7f\u7528<strong>\u7a7a\u95f4\u5173\u7cfb<\/strong>\u4f5c\u4e3a<strong>\u8fde\u63a5\u952e<\/strong>\uff08join key\uff09\u6765\u8fde\u63a5\u6765\u81ea\u4e0d\u540c<strong>\u6570\u636e\u8868<\/strong>\u7684\u4fe1\u606f\uff0c\u5982\uff1a<\/p>\n\n\n\n<p>SELECT subways.name AS subway_name, neighborhoods.name AS neighborhood_name, neighborhoods.boroname AS borough FROM nyc_neighborhoods AS neighborhoods JOIN nyc_subway_stations AS subways ON ST_Contains(neighborhoods.geom, subways.geom) WHERE subways.name = 'Broad St';<\/p>\n\n\n\n<p>\u4efb\u4f55\u5728\u4e24\u4e2a\u8868\u4e4b\u95f4\u63d0\u4f9btrue\/false\u5173\u7cfb\u7684\u51fd\u6570\u90fd\u53ef\u4ee5\u7528\u6765\u9a71\u52a8<strong>\u7a7a\u95f4\u8fde\u63a5<\/strong>\uff0c\u4f46\u6700\u5e38\u7528\u7684\u51fd\u6570\u662f\uff1a<\/p>\n\n\n\n<p><strong>ST_Intersects\u3001ST_Contains\u548cST_DWithin<\/strong><\/p>\n\n\n\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6570\u636e\u5e93\u4f7f\u7528\u7684\u662f<strong>INNER JOIN<\/strong>\u8fde\u63a5\u7c7b\u578b\uff0c\u8fd8\u53ef\u4ee5\u7528 LEFT OUTER JOIN\u3001RIGHT OUTER JOIN<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4e94\u3001\u7a7a\u95f4\u7d22\u5f15\">\u4e94\u3001\u7a7a\u95f4\u7d22\u5f15<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"51-\u521b\u5efa\u548c\u4f7f\u7528\u7d22\u5f15\">5.1 \u521b\u5efa\u548c\u4f7f\u7528\u7d22\u5f15<\/h3>\n\n\n\n<p>\u5982\u4e0b\u521b\u5efa\u4e00\u4e2a\u7a7a\u95f4\u7d22\u5f15\uff1a<\/p>\n\n\n\n<p>CREATE INDEX nyc_census_blocks_geom_idx ON nyc_census_blocks USING GIST (geom)<\/p>\n\n\n\n<p><strong>USING GIST<\/strong>\u5b50\u53e5\u544a\u8bc9PostgreSQL\u5728\u6784\u5efa\u7d22\u5f15\u65f6\u4f7f\u7528generic index structure\uff08<strong>GIST-\u901a\u7528\u7d22\u5f15\u7ed3\u6784<\/strong>\uff09<\/p>\n\n\n\n<p>PostGIS\u4f7f\u7528\"<strong>R-Tree<\/strong>\"\u7a7a\u95f4\u7d22\u5f15\u7ed3\u6784\u3002R-Tree\u5c06\u6570\u636e\u5206\u89e3\u4e3a<strong>\u77e9\u5f62<\/strong>\uff08rectangle\uff09\u3001<strong>\u5b50\u77e9\u5f62<\/strong>\uff08sub-rectangle\uff09\u548c<strong>\u5b50-\u5b50\u77e9\u5f62<\/strong>\uff08sub-sub rectangle\uff09\u7b49\u3002\u5b83\u662f\u4e00\u79cd\u53ef\u81ea\u52a8\u5904\u7406\u53ef\u53d8\u6570\u636e\u7684\u5bc6\u5ea6\u548c\u5bf9\u8c61\u5927\u5c0f\u7684\u81ea\u8c03\u4f18\uff08self-tuning\uff09\u7d22\u5f15\u7ed3\u6784\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u5927\u7684\u6570\u636e\u8868\u6765\u8bf4\uff0c\u5148\u8ba1\u7b97\u51fa\u8fd1\u4f3c\u7ed3\u679c\uff0c\u7136\u540e\u8fdb\u884c\u7cbe\u786e\u6d4b\u8bd5\u7684\"\u4e24\u904d\"\u673a\u5236\u53ef\u4ee5\u4ece\u6839\u672c\u4e0a\u51cf\u5c11\u8ba1\u7b97\u91cf\u3002\uff08\u8fd9\u79cd\u601d\u60f3\u5c31\u662f<strong>\u7c97\u8c03\u548c\u7cbe\u8c03<\/strong>\u7684\u601d\u60f3\uff0c\u5c31\u50cf\u663e\u5fae\u955c\u4e00\u6837\u6709\u7c97\u7c92\u5ea6\u7684\u8c03\u6574\u548c\u7ec6\u7c92\u5ea6\u7684\u8c03\u6574\u3002\u5f88\u591a\u4e8b\u7269\u90fd\u6d89\u53ca\u5230\u8fd9\u4e2a\u601d\u60f3\uff0c\u5b83\u7684\u4f5c\u7528\u5c31\u662f\u51cf\u5c11\u4e86\u8017\u8d39\u7684\u4ee3\u4ef7\uff09<\/p>\n\n\n\n<figure class=\"wp-block-image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/img-blog.csdnimg.cn\/img_convert\/b222418813fe00dba6b3781da6361729.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/img-blog.csdnimg.cn\/img_convert\/b222418813fe00dba6b3781da6361729.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"img\"\/><\/div><\/figure>\n\n\n\n<p>\u4f7f\u7528\u7d22\u5f15\uff1a<\/p>\n\n\n\n<ul><li><strong>\u7eaf\u7d22\u5f15\u67e5\u8be2<\/strong>\uff1a\u4f7f\u7528\"<strong>&amp;&amp;<\/strong>\u201c\u8fd0\u7b97\u7b26\u3002\u5bf9\u4e8e\u51e0\u4f55\u56fe\u5f62\uff0c&amp;&amp;\u8fd0\u7b97\u7b26\u8868\u793a\"\u8fb9\u754c\u6846\u91cd\u53e0\u6216\u63a5\u89e6\u201d\uff08\u7eaf\u7d22\u5f15\u67e5\u8be2\uff09\uff0c\u5c31\u50cf\u5bf9\u4e8e\u6570\u5b57\uff0c\"<strong>=<\/strong>\u201c\u8fd0\u7b97\u7b26\u8868\u793a\"\u503c\u76f8\u540c\u201d\u3002<\/li><\/ul>\n\n\n\n<p>SELECT Sum(popn_total)FROM nyc_neighborhoods neighborhoodsJOIN nyc_census_blocks blocksON neighborhoods.geom &amp;&amp; blocks.geomWHERE neighborhoods.name = 'West Village';<\/p>\n\n\n\n<ul><li>PostGIS\u4e2d\u6700\u5e38\u7528\u7684\u51fd\u6570\uff08ST_Contains\u3001ST_Intersects\u3001ST_DWithin\u7b49\uff09\u90fd\u5305\u542b<strong>\u81ea\u52a8\u7d22\u5f15\u8fc7\u6ee4\u5668<\/strong><\/li><li>\u6709\u4e9b\u51fd\u6570\uff08\u5982ST_Relate\uff09\u4e0d\u5305\u62ec<strong>\u7d22\u5f15\u8fc7\u6ee4\u5668<\/strong><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"52-\u5206\u6790\uff08analyze\uff09\">5.2 \u5206\u6790\uff08ANALYZE\uff09<\/h3>\n\n\n\n<p>PostgreSQL\u67e5\u8be2\u89c4\u5212\u5668\uff08query planner\uff09\u667a\u80fd\u5730\u9009\u62e9\u4f55\u65f6\u4f7f\u7528\u6216\u4e0d\u4f7f\u7528<strong>\u7a7a\u95f4\u7d22\u5f15<\/strong>\u6765\u8ba1\u7b97\u67e5\u8be2\u3002\u4e0e\u76f4\u89c9\u76f8\u53cd\uff0c\u6267\u884c<strong>\u7a7a\u95f4\u7d22\u5f15<\/strong>\u641c\u7d22\u5e76\u4e0d\u603b\u662f\u66f4\u5feb\uff1a\u5982\u679c\u641c\u7d22\u5c06\u8fd4\u56de\u8868\u4e2d\u7684\u6bcf\u6761\u8bb0\u5f55\uff0c\u5219\u904d\u5386\u7d22\u5f15\u6811\u4ee5\u83b7\u53d6\u6bcf\u6761\u8bb0\u5f55\u5b9e\u9645\u4e0a\u6bd4\u4ece\u4e00\u5f00\u59cb\u7ebf\u6027\u8bfb\u53d6\u6574\u4e2a\u8868\u8981\u6162\uff08\u6ce8\u610f\u8fd9\u53e5\u8bdd\uff09\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u5f04\u6e05\u695a\u8981\u5904\u7406\u7684\u6570\u636e\u7684\u5927\u6982\u5185\u5bb9\uff08\u8bfb\u53d6\u8868\u7684\u4e00\u5c0f\u90e8\u5206\u4fe1\u606f\uff0c\u800c\u4e0d\u662f\u8bfb\u53d6\u8868\u7684\u5927\u90e8\u5206\u4fe1\u606f\uff09\uff0cPostgreSQL\u4fdd\u5b58\u6bcf\u4e2a\u7d22\u5f15\u5217\u4e2d\u6570\u636e\u5206\u5e03\u7684<strong>\u7edf\u8ba1\u4fe1\u606f<\/strong>\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cPostgreSQL\u5b9a\u671f\u6536\u96c6\u7edf\u8ba1\u4fe1\u606f\u3002\u4f46\u662f\uff0c\u5982\u679c\u4f60\u5728\u77ed\u65f6\u95f4\u5185\u66f4\u6539\u4e86\u8868\u7684\u6784\u6210\uff0c\u5219\u7edf\u8ba1\u6570\u636e\u5c06\u4e0d\u4f1a\u662f\u6700\u65b0\u7684\u3002<\/p>\n\n\n\n<p>\u4e3a\u786e\u4fdd\u7edf\u8ba1\u4fe1\u606f\u4e0e\u8868\u5185\u5bb9\u5339\u914d\uff0c\u660e\u667a\u7684\u505a\u6cd5\u662f\u5728\u8868\u4e2d\u52a0\u8f7d\u548c\u5220\u9664\u5927\u5bb9\u91cf\u6570\u636e\u540e\u624b\u52a8\u8fd0\u884c<strong>ANALYZE\u547d\u4ee4<\/strong>\u3002\u8fd9\u5c06\u5f3a\u5236\u7edf\u8ba1\u7cfb\u7edf\u6536\u96c6\u6240\u6709\u7d22\u5f15\u5217\u7684\u7edf\u8ba1\u4fe1\u606f\u3002<\/p>\n\n\n\n<p>ANALYZE\u547d\u4ee4\u8981\u6c42PostgreSQL\u904d\u5386\u8be5\u8868\u5e76\u66f4\u65b0\u7528\u4e8e\u67e5\u8be2\u64cd\u4f5c\u800c\u4f30\u7b97\u7684\u5185\u90e8\u7edf\u8ba1\u4fe1\u606f\u3002<\/p>\n\n\n\n<p>ANALYZE nyc_census_blocks;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"53-\u6e05\u7406\uff08vacuum\uff09\">5.3 \u6e05\u7406\uff08VACUUM\uff09<\/h3>\n\n\n\n<p>\u503c\u5f97\u5f3a\u8c03\u7684\u662f\uff0c\u4ec5\u4ec5\u521b\u5efa<strong>\u7a7a\u95f4\u7d22\u5f15<\/strong>\u4e0d\u8db3\u4ee5\u8ba9PostgreSQL\u6709\u6548\u5730\u4f7f\u7528\u5b83\u3002\u6bcf\u5f53\u521b\u5efa\u65b0\u7d22\u5f15\u6216\u5bf9\u8868\u5927\u91cf\u66f4\u65b0\u3001\u63d2\u5165\u6216\u5220\u9664\u540e\uff0c\u90fd\u5fc5\u987b\u6267\u884c<strong>\u6e05\u7406\uff08VACUUMing\uff09<\/strong>\u3002<strong>VACUUM<\/strong>\u547d\u4ee4\u8981\u6c42PostgreSQL\u56de\u6536\u8868\u9875\u9762\u4e2d\u56e0\u8bb0\u5f55\u7684\u66f4\u65b0\u6216\u5220\u9664\u800c\u7559\u4e0b\u7684\u4efb\u4f55\u672a\u4f7f\u7528\u7684\u7a7a\u95f4\u3002<\/p>\n\n\n\n<p><strong>\u6e05\u7406<\/strong>\u5bf9\u4e8e\u6570\u636e\u5e93\u7684\u9ad8\u6548\u8fd0\u884c\u975e\u5e38\u5173\u952e\uff0c\u56e0\u6b64\uff0cPostgreSQL\u63d0\u4f9b\u4e86\u4e00\u4e2a\u201c<strong>\u81ea\u52a8\u6e05\u7406<\/strong>\uff08autovacuum\uff09\"\u9009\u9879\u3002<\/p>\n\n\n\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c<strong>\u81ea\u52a8\u6e05\u7406\u673a\u5236<\/strong>\u4f1a\u6839\u636e\u6d3b\u52a8\u7ea7\u522b\u786e\u5b9a\u7684\u5408\u7406\u65f6\u95f4\u95f4\u9694\u81ea\u52a8\u6e05\u7406\uff08\u6062\u590d\u7a7a\u95f4\uff09\u548c\u5206\u6790\uff08\u66f4\u65b0\u7edf\u8ba1\u4fe1\u606f\uff09\u3002\u867d\u7136\u8fd9\u5bf9\u4e8e\u9ad8\u5ea6\u4e8b\u52a1\u6027\u7684\u6570\u636e\u5e93\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u529f\u80fd\uff0c\u4f46\u5728\u6dfb\u52a0\u7d22\u5f15\u6216\u5927\u5bb9\u91cf\u6570\u636e\u4e4b\u540e\u7b49\u5f85\u81ea\u52a8\u6e05\u7406\u8fd0\u884c\u662f\u4e0d\u660e\u667a\u7684\uff0c\u5982\u679c\u6267\u884c\u5927\u6279\u91cf\u66f4\u65b0\uff0c\u5219\u5e94\u8be5\u624b\u52a8\u8fd0\u884cVACUUM\u547d\u4ee4\u3002<\/p>\n\n\n\n<p>\u6839\u636e\u9700\u8981\uff0c\u53ef\u4ee5\u5355\u72ec\u6267\u884c\u6e05\u7406\u548c\u5206\u6790\u3002\u53d1\u51faVACUUM\u547d\u4ee4\u4e0d\u4f1a\u66f4\u65b0\u6570\u636e\u5e93\u7edf\u8ba1\u4fe1\u606f\uff1b\u540c\u6837\uff0c\u6267\u884cANALYZE\u547d\u4ee4\u4e5f\u4e0d\u4f1a\u6e05\u7406\u672a\u4f7f\u7528\u7684\u8868\u7a7a\u95f4\u3002\u8fd9\u4e24\u4e2a\u547d\u4ee4\u90fd\u53ef\u4ee5\u9488\u5bf9\u6574\u4e2a\u6570\u636e\u5e93\u3001\u5355\u4e2a\u8868\u6216\u5355\u4e2a\u5217\u8fd0\u884c\u3002<\/p>\n\n\n\n<p>VACUUM ANALYZE nyc_census_blocks;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u516d\u3001\u51e0\u4f55\u56fe\u5f62\u521b\u5efa\u51fd\u6570\">\u516d\u3001\u51e0\u4f55\u56fe\u5f62\u521b\u5efa\u51fd\u6570<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"61-st_centroid--st_pointonsurface\">6.1 ST_Centroid \/ ST_PointOnSurface<\/h3>\n\n\n\n<ul><li><strong>ST_Centroid(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56de\u5927\u7ea6\u4f4d\u4e8e\u8f93\u5165\u51e0\u4f55\u56fe\u5f62\u7684<strong>\u8d28\u5fc3<\/strong>\u4e0a\u7684\u70b9\u3002\u8fd9\u79cd\u7b80\u5355\u7684\u8ba1\u7b97\u901f\u5ea6\u975e\u5e38\u5feb\uff0c\u4f46\u6709\u65f6\u5e76\u4e0d\u53ef\u53d6\uff0c\u56e0\u4e3a\u8fd4\u56de\u70b9\u4e0d\u4e00\u5b9a\u5728\u8981\u7d20\u672c\u8eab\u4e0a\u3002\u5982\u679c\u8f93\u5165\u7684\u51e0\u4f55\u56fe\u5f62\u5177\u6709\u51f8\u6027\uff08\u5047\u8bbe\u5b57\u6bcd\u2019C\u2019\uff09\uff0c\u5219\u8fd4\u56de\u7684\u8d28\u5fc3\u53ef\u80fd\u4e0d\u5728\u56fe\u5f62\u7684\u5185\u90e8\u3002<\/li><li><strong>ST_PointOnSurface(geometry)<\/strong>&nbsp;\u2014\u2014 \u8fd4\u56de\u4fdd\u8bc1\u5728\u8f93\u5165\u591a\u8fb9\u5f62\u5185\u7684\u70b9\u3002\u4ece\u8ba1\u7b97\u4e0a\u8bb2\uff0c\u5b83\u6bd4centroid\u64cd\u4f5c\u4ee3\u4ef7\u8981\u5927\u5f97\u591a\u3002<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"62-st_buffer\">6.2 ST_Buffer<\/h3>\n\n\n\n<p>**ST_Buffer(geometry, distance)**\u63a5\u53d7\u51e0\u4f55\u56fe\u5f62\u548c\u7f13\u51b2\u533a\u8ddd\u79bb\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u8f93\u51fa\u4e00\u4e2a\u591a\u8fb9\u5f62\uff0c\u8fd9\u4e2a\u591a\u8fb9\u5f62\u7684\u8fb9\u754c\u4e0e\u8f93\u5165\u7684\u51e0\u4f55\u56fe\u5f62\u4e4b\u95f4\u7684\u8ddd\u79bb\u4e0e\u8f93\u5165\u7684\u7f13\u51b2\u533a\u8ddd\u79bb\u76f8\u7b49\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"63-st_intersection\">6.3 ST_Intersection<\/h3>\n\n\n\n<p><strong>\u53e0\u7f6e<\/strong>\uff08overlay\uff09- \u901a\u8fc7\u8ba1\u7b97\u4e24\u4e2a\u91cd\u53e0\u591a\u8fb9\u5f62\u7684<strong>\u4ea4\u96c6<\/strong>\u6765\u521b\u5efa\u65b0\u7684\u51e0\u4f55\u56fe\u5f62\u3002<\/p>\n\n\n\n<p>**ST_Intersection(geometry A, geometry B)**\u51fd\u6570\u8fd4\u56de\u4e24\u4e2a\u53c2\u6570\u5171\u6709\u7684\u7a7a\u95f4\u533a\u57df\uff08\u6216\u76f4\u7ebf\uff0c\u6216\u70b9\uff09\u3002\u5982\u679c\u53c2\u6570\u4e0d\u76f8\u4ea4\uff0c\u8be5\u51fd\u6570\u5c06\u8fd4\u56de\u4e00\u4e2a\u7a7a\u51e0\u4f55\u56fe\u5f62<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"64-st_union\">6.4 ST_Union<\/h3>\n\n\n\n<p><strong>ST_Union<\/strong>\u5c06\u4e24\u4e2a\u51e0\u4f55\u56fe\u5f62\u5408\u5e76\u8d77\u6765\u3002ST_Union\u51fd\u6570\u6709\u4e24\u79cd\u5f62\u5f0f<\/p>\n\n\n\n<ul><li><strong>ST_Union(geometry, geometry)<\/strong>&nbsp;\u2014\u2014 \u63a5\u53d7\u4e24\u4e2a\u51e0\u4f55\u56fe\u5f62\u53c2\u6570\u5e76\u8fd4\u56de\u5408\u5e76\u7684\u5e76\u96c6\u3002<\/li><li><strong>ST_Union([geometry])<\/strong>&nbsp;\u2014\u2014 \u63a5\u53d7\u4e00\u7ec4\u51e0\u4f55\u56fe\u5f62\u5e76\u8fd4\u56de\u5168\u90e8\u51e0\u4f55\u56fe\u5f62\u7684\u5e76\u96c6\u3002ST_Union([geometry])\u53ef\u4e0eGROUP BY\u8bed\u53e5\u4e00\u8d77\u4f7f\u7528\uff0c\u4ee5\u521b\u5efa\u7ecf\u8fc7\u7ec6\u81f4\u5408\u5e76\u7684\u57fa\u672c\u51e0\u4f55\u56fe\u5f62\u96c6\u3002\u8fd9\u79cd\u64cd\u4f5c\u975e\u5e38\u5f3a\u5927\u3002<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4e03\u3001\u56fe\u5f62\u6709\u6548\u6027\u548c\u7b80\u5355\u6027\">\u4e03\u3001\u56fe\u5f62\u6709\u6548\u6027\u548c\u7b80\u5355\u6027<\/h2>\n\n\n\n<ul><li><strong>ST_IsValid(geometry)<\/strong>\uff0c\u68c0\u67e5\u56fe\u5f62\u6709\u6548\u6027<ul><li>\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0<strong>CHECK\u7ea6\u675f<\/strong>\uff08\u5373\u7528\u6237\u5b9a\u4e49\u7684\u5b8c\u6574\u6027\u7ea6\u675f\uff09\u6765\u624b\u52a8\u5bf9\u8868\u5f3a\u5236\u6267\u884c\u8fd9\u6837\u7684\u6709\u6548\u6027\u68c0\u67e5<\/li><\/ul>ALTER TABLE mytable ADD CONSTRAINT geometry_valid_check CHECK (ST_IsValid(the_geom));<\/li><li><strong>ST_IsValidReason(geometry)<\/strong>\uff0c\u67e5\u627e\u65e0\u6548\u7684\u539f\u56e0<\/li><li><strong>ST_MakeValid<\/strong>\uff0c\u51fd\u6570\u5c1d\u8bd5\u5728\u4e0d\u5bf9\u8f93\u5165\u51e0\u4f55\u56fe\u5f62\u8fdb\u884c\u66f4\u6539\u7684\u60c5\u51b5\u4e0b\u4fee\u590d\u7f3a\u9677\u3002\u4e0d\u4f1a\u5220\u9664\u6216\u79fb\u52a8\u4efb\u4f55\u9876\u70b9\uff0c\u53ea\u9700\u91cd\u65b0\u6392\u5217\u5bf9\u8c61\u7684\u7ed3\u6784\u5373\u53ef\u3002\u5bf9\u4e8e\u6e05\u6670\u4f46\u65e0\u6548\u7684\u6570\u636e\u6765\u8bf4\uff0c\u8fd9\u4e2a\u51fd\u6570\u975e\u5e38\u9002\u7528\uff0c\u5bf9\u4e8e\u6742\u4e71\u65e0\u7ae0\u4e14\u65e0\u6548\u7684\u6570\u636e\u6765\u8bf4\uff0c\u8fd9\u4e2a\u51fd\u6570\u53ef\u80fd\u5e76\u4e0d\u9002\u7528<\/li><li><strong>ST_IsSimple()<\/strong>\uff0c\u68c0\u67e5\u56fe\u5f62\u7684\u7b80\u5355\u6027<ul><li>\u51e0\u4f55\u56fe\u5f62\u7684<strong>\u7b80\u5355\u6027<\/strong>\u53ef\u4ee5\u7406\u89e3\u4e3a\u51e0\u4f55\u56fe\u5f62\u6bd4\u8f83\u7b80\u5355\u6574\u9f50\uff0c\u4e0d\u4f1a\u81ea\u5df1\u4e0e\u81ea\u5df1\u91cd\u53e0\uff0c\u4e0d\u7e41\u6742<\/li><\/ul><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"71-\u70b9\u7684\u7b80\u5355\u6027\u4e0e\u6709\u6548\u6027\">7.1 \u70b9\u7684\u7b80\u5355\u6027\u4e0e\u6709\u6548\u6027<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"711-\u5355\u70b9\">7.1.1 \u5355\u70b9<\/h4>\n\n\n\n<p>\u5355\u4e2a\u70b9\uff08<strong>Point<\/strong>\uff09\u80af\u5b9a\u662f\u7b80\u5355\u7684\u4e14\u6709\u6548\u7684\uff0c\u56e0\u4e3a\u4e00\u4e2a\u70b9\u5b64\u96f6\u96f6\u7684\u80af\u5b9a\u662f\u7b80\u5355\u3001\u6709\u6548\u7684<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"712-\u591a\u70b9\">7.1.2 \u591a\u70b9<\/h4>\n\n\n\n<p>\u591a\u4e2a\u70b9\uff08<strong>MultiPoint<\/strong>\uff09\u80af\u5b9a\u662f\u6709\u6548\u7684\uff0c\u4f46\u4e0d\u4e00\u5b9a\u662f\u7b80\u5355\u7684\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u591a\u70b9\u4e2d\u6709\u4e24\u4e2a\u6216\u4e24\u4e2a\u4ee5\u4e0a\u7684\u70b9<strong>\u91cd\u5408<\/strong>\uff08\u4e5f\u5c31\u662f\u5750\u6807\u4e00\u81f4\uff09\uff0c\u90a3\u4e48\u5b83\u5c31<strong>\u4e0d\u662f\u7b80\u5355<\/strong>\u7684\uff0c\u4f46\u662f\u786e\u662f<strong>\u6709\u6548<\/strong>\u7684<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"72-\u7ebf\u4e32\u7684\u7b80\u5355\u6027\u4e0e\u6709\u6548\u6027\">7.2 \u7ebf\u4e32\u7684\u7b80\u5355\u6027\u4e0e\u6709\u6548\u6027<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"721-\u5355\u7ebf\u4e32\">7.2.1 \u5355\u7ebf\u4e32<\/h4>\n\n\n\n<p>\u5355\u7ebf\u4e32\uff08LINESTRING\uff09\u5982\u679c<strong>\u6709\u91cd\u53e0\u3001\u76f8\u4ea4\u5c31\u4e0d\u662f\u7b80\u5355<\/strong>\u7684\uff08\u9664\u4e86\u7aef\u70b9\u76f8\u4ea4\uff0c\u7aef\u70b9\u76f8\u4ea4\u5c31\u8bf4\u660e\u8fd9\u6761\u7ebf\u4e32\u662f\u95ed\u5408\u7684\uff0c\u4f46\u5b83\u662f\u7b80\u5355\u7684\uff09<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"722-\u591a\u7ebf\u4e32\">7.2.2 \u591a\u7ebf\u4e32<\/h4>\n\n\n\n<p>\u591a\u7ebf\u4e32\uff08MULTILINESTRING\uff09\u53ea\u8981\u5b83\u7684<strong>\u5143\u7d20\uff08LINESTRING\uff09\u90fd\u662f\u7b80\u5355<\/strong>\u7684\uff0c\u4e14<strong>\u4e24\u4e2a\u5143\u7d20\u53ea\u5728\u67d0\u4e2a\u70b9\u76f8\u5207<\/strong>\uff0c\u90a3\u4e48\u5b83\u5c31\u662f\u7b80\u5355<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"73-\u591a\u8fb9\u5f62\u7684\u7b80\u5355\u6027\u4e0e\u6709\u6548\u6027\">7.3 \u591a\u8fb9\u5f62\u7684\u7b80\u5355\u6027\u4e0e\u6709\u6548\u6027<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"731-\u5355\u591a\u8fb9\u5f62\">7.3.1 \u5355\u591a\u8fb9\u5f62<\/h4>\n\n\n\n<p>\u6709\u6548\u6027\uff1a<\/p>\n\n\n\n<ul><li>\u591a\u8fb9\u5f62\u7684\u73af\u5fc5\u987b\u95ed\u5408<\/li><li>\u5185\u73af\u5e94\u8be5\u5904\u4e8e\u5916\u73af\u7684\u5185\u90e8<\/li><li>\u73af\u4e0d\u80fd\u81ea\u76f8\u4ea4\uff08\u5b83\u4eec\u4e0d\u80fd\u76f8\u4e92\u63a5\u89e6\uff0c\u4e5f\u4e0d\u80fd\u4ea4\u53c9\uff09<\/li><li>\u73af\u4e0d\u80fd\u4e0e\u5176\u4ed6\u73af\u63a5\u89e6\uff0c\u9664\u975e\u5728\u67d0\u4e2a\u70b9\u76f8\u5207\uff08\u53ea\u80fd\u6709\u4e00\u4e2a\u5728\u4e00\u4e2a\u70b9\u76f8\u5207\uff09<\/li><\/ul>\n\n\n\n<p>\u591a\u8fb9\u5f62\u7684\u73af\u53ea\u8981\u4e0d\u81ea\u76f8\u4ea4\uff0c\u5219\u8be5\u591a\u8fb9\u5f62\u5c31\u662f\u7b80\u5355\u7684<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"732-\u591a\u591a\u8fb9\u5f62\">7.3.2 \u591a\u591a\u8fb9\u5f62<\/h4>\n\n\n\n<p><strong>\u591a\u591a\u8fb9\u5f62\u91cc<\/strong>\u53ea\u8981\u5404\u4e2a<strong>\u5b50\u5143\u7d20\uff08\u5355\u591a\u8fb9\u5f62\uff09\u662f\u7b80\u5355\u7684\u3001\u6709\u6548<\/strong>\u7684\uff0c\u800c\u4e14<strong>\u5b50\u5143\u7d20\u4e4b\u95f4\u53ea\u5728\u6709\u9650\u7684\u70b9\u4e0a\u63a5\u89e6<\/strong>\uff0c\u90a3\u4e48\u5b83\u5c31\u662f\u7b80\u5355\u7684\u3001\u6709\u6548\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u516b\u3001\u51e0\u4f55\u56fe\u5f62\u7684\u76f8\u7b49\">\u516b\u3001\u51e0\u4f55\u56fe\u5f62\u7684\u76f8\u7b49<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"81-\u7cbe\u786e\u76f8\u7b49\uff08st_orderingequals\uff09\">8.1 \u7cbe\u786e\u76f8\u7b49\uff08ST_OrderingEquals\uff09<\/h3>\n\n\n\n<p>\u7cbe\u786e\u76f8\u7b49\u662f\u901a\u8fc7\u6309\u987a\u5e8f\u9010\u4e2a\u6bd4\u8f83\u4e24\u4e2a<strong>\u51e0\u4f55\u56fe\u5f62\u7684\u9876\u70b9<\/strong>\u6765\u786e\u5b9a\u7684\uff0c\u4ee5\u786e\u4fdd\u5b83\u4eec\u5728\u4f4d\u7f6e\u4e0a\u662f\u76f8\u540c\u7684\u3002\u786e\u5b9a\u56fe\u5f62\u7684\u70b9\u4f4d\u7f6e\u548c\u987a\u5e8f\u4e0d\u540c\uff0c\u5219\u56fe\u5f62\u4e0d\u7b49<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"82-\u7a7a\u95f4\u76f8\u7b49\uff08st_equals\uff09\">8.2 \u7a7a\u95f4\u76f8\u7b49\uff08ST_Equals\uff09<\/h3>\n\n\n\n<p>\u7cbe\u786e\u7684\u76f8\u7b49\u5e76\u6ca1\u6709\u8003\u8651\u5230\u51e0\u4f55\u56fe\u5f62\u7684\u7a7a\u95f4\u6027\u8d28\u3002\u6709\u4e00\u4e2a\u540d\u4e3a<strong>ST_Equals<\/strong>\u7684\u51fd\u6570\uff0c\u53ef\u7528\u4e8e\u6d4b\u8bd5\u51e0\u4f55\u56fe\u5f62\u7684\u7a7a\u95f4\u76f8\u7b49\u6027\u6216\u7b49\u4ef7\u6027\u3002\u65e0\u8bba\u662f\u7ed8\u5236\u591a\u8fb9\u5f62\u7684\u65b9\u5411\u3001\u5b9a\u4e49\u591a\u8fb9\u5f62\u7684\u8d77\u70b9\uff0c\u8fd8\u662f\u4f7f\u7528\u7684\u70b9\u7684\u4e2a\u6570\u7684\u5dee\u5f02\u5728\u8fd9\u91cc\u90fd\u4e0d\u91cd\u8981\u3002\u91cd\u8981\u7684\u662f\u591a\u8fb9\u5f62\u5305\u542b\u76f8\u540c\u7684<strong>\u7a7a\u95f4\u533a\u57df<\/strong>\u3002\u56fe\u5f62\u7684<strong>\u5b9e\u9645\u5f62\u72b6<\/strong>\u76f8\u540c\uff0c\u5219\u56fe\u5f62\u76f8\u7b49<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"83-\u7b49\u8fb9\u754c\u6846\uff08\uff09\">8.3 \u7b49\u8fb9\u754c\u6846\uff08=\uff09<\/h3>\n\n\n\n<p>\u5728\u6700\u574f\u7684\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u7cbe\u786e\u76f8\u7b49\u6765\u6bd4\u8f83\u51e0\u4f55\u56fe\u5f62\u4e2d\u7684\u6bcf\u4e2a\u9876\u70b9\u4ee5\u786e\u5b9a\u76f8\u7b49\u3002\u8fd9\u53ef\u80fd\u4f1a\u6bd4\u8f83\u6162\uff0c\u5e76\u4e14\u53ef\u80fd\u4e0d\u9002\u5408\u6570\u91cf\u5927\u7684\u51e0\u4f55\u56fe\u5f62\u3002\u4e3a\u4e86\u66f4\u5feb\u5730\u8fdb\u884c\u6bd4\u8f83\uff0c\u63d0\u4f9b\u4e86\u7b49\u8fb9\u754c\u8fd0\u7b97\u7b26 \u2019&nbsp;<strong>=<\/strong>&nbsp;\u2019 \u3002\u8fd9\u4ec5\u5728**\u8fb9\u754c\u6846\uff08\u77e9\u5f62\uff09**\u4e0a\u64cd\u4f5c\uff0c\u786e\u4fdd\u51e0\u4f55\u56fe\u5f62\u5360\u7528\u76f8\u540c\u7684\u4e8c\u7ef4\u8303\u56f4\uff0c\u4f46\u4e0d\u4e00\u5b9a\u5360\u7528\u76f8\u540c\u7684\u7a7a\u95f4\u3002**\u8fb9\u754c\u6846\uff08\u77e9\u5f62\uff09**\u76f8\u540c\uff0c\u5219\u56fe\u5f62\u76f8\u7b49<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u4e5d\u3001\u6700\u8fd1\u9886\u57df\u641c\u7d22\">\u4e5d\u3001\u6700\u8fd1\u9886\u57df\u641c\u7d22<\/h2>\n\n\n\n<p>\u6267\u884c<strong>\u6700\u8fd1\u90bb\u57df\u641c\u7d22<\/strong>\u7684\u7b80\u5355\u65b9\u6cd5\u662f\u6309\u4e0e\u8981\u67e5\u8be2\u7684\u51e0\u4f55\u56fe\u5f62\u7684\u8ddd\u79bb\u5bf9\u5019\u9009\u8868\u8fdb\u884c\u6392\u5e8f\uff0c\u7136\u540e\u83b7\u53d6\u6700\u5c0f\u8ddd\u79bb\u5bf9\u5e94\u7684\u8868\u8bb0\u5f55<\/p>\n\n\n\n<p>SELECT streets.gid, streets.nameFROM nyc_streets streets, nyc_subway_stations subwaysWHERE subways.name = 'Broad St'ORDER BY ST_Distance(streets.geom, subways.geom) ASCLIMIT 1;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5341\u3001\u5176\u4ed6\u51fd\u6570\">\u5341\u3001\u5176\u4ed6\u51fd\u6570<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"101-\u521b\u5efa\u7a7a\u6805\u683c\u51fd\u6570\">10.1 \u521b\u5efa\u7a7a\u6805\u683c\u51fd\u6570<\/h3>\n\n\n\n<p><strong>ST_MakeEmptyRaster<\/strong>\u7528\u4e8e\u521b\u5efa\u4e00\u4e2a\u7a7a\u7684\u6ca1\u6709\u50cf\u5143\u503c\u7684\u6805\u683c\uff08\u6ca1\u6709\u6ce2\u6bb5\uff09\uff0c\u5404\u4e2a\u53c2\u6570\u7528\u4e8e\u5b9a\u4e49\u8fd9\u4e2a\u7a7a\u6805\u683c\u7684\u5143\u6570\u636e\uff1a<\/p>\n\n\n\n<ul><li><strong>width<\/strong>\u3001<strong>height<\/strong>&nbsp;\u2014\u2014 \u6805\u683c\u7684\u5217\u6570\u548c\u884c\u6570<\/li><li><strong>upperleftx\u3001upperlefty<\/strong>&nbsp;\u2014\u2014 \u5bf9\u5e94\u7a7a\u95f4\u5750\u6807\u7cfb\u4e2d\u6805\u683c\u5de6\u4e0a\u89d2\u7684\u5750\u6807<\/li><li><strong>scalex\u3001scaley<\/strong>&nbsp;\u2014\u2014 \u5355\u4e2a\u50cf\u5143\u7684\u5bbd\u5ea6\u548c\u957f\u5ea6\uff08\u5355\u4f4d\u7b49\u540c\u4e8e\u7a7a\u95f4\u53c2\u8003\u5750\u6807\u7cfb\u7684\u5355\u4f4d\uff09\u3002<\/li><li><strong>skewx\u3001skewy<\/strong>&nbsp;\u2014\u2014 \u65cb\u8f6c\u89d2\u5ea6\uff0c\u5982\u679c\u6805\u683c\u6570\u636e\u5317\u65b9\u671d\u4e0a\uff0c\u8be5\u503c\u4e3a0\u3002\u9ed8\u8ba4\u503c\u4e3a0\u3002<\/li><li><strong>srid<\/strong>&nbsp;\u2014\u2014 \u7a7a\u95f4\u53c2\u8003\u5750\u6807\u7cfb\uff0c\u9ed8\u8ba4\u88ab\u8bbe\u7f6e\u4e3a0\u3002<\/li><li><strong>pixelsize<\/strong>&nbsp;\u2014\u2014 \u5355\u4e2a\u50cf\u5143\u7684\u5bbd\u5ea6\u548c\u957f\u5ea6\u3002\u5f53scalex\u548cscaley\u76f8\u7b49\u65f6\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u8fd9\u4e2a\u53c2\u6570\u8bbe\u7f6e\u50cf\u5143\u5927\u5c0f\u3002<\/li><\/ul>\n\n\n\n<p>\u4e0a\u9762\u7684\u7b2c\u4e00\u4e2a\u51fd\u6570\u7b7e\u540d\u4f20\u5165\u73b0\u6709\u7684\u6805\u683c\u6570\u636e\u4f5c\u4e3a\u65b0\u521b\u5efa\u6805\u683c\u7684\u6a21\u677f\uff0c\u4f1a\u8fd4\u56de\u5177\u6709\u76f8\u540c\u5143\u6570\u636e\uff08\u6ca1\u6709\u6ce2\u6bb5\u3001\u6ca1\u6709\u50cf\u5143\u503c\uff09\u7684\u6805\u683c\u6570\u636e\u3002<\/p>\n\n\n\n<p>\u5728\u521b\u5efa\u4e86\u4e00\u4e2a\u7a7a\u6805\u683c\u4e4b\u540e\uff0c\u8981\u5411\u5176\u6dfb\u52a0\u6ce2\u6bb5\uff0c\u5e76\u53ef\u80fd\u8981\u5bf9\u5176\u8fdb\u884c\u7f16\u8f91\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51fd\u6570\uff1a<\/p>\n\n\n\n<ul><li><a href=\"https:\/\/link.zhihu.com\/?target=http%3A\/\/postgis.net\/docs\/manual-3.0\/RT_ST_AddBand.html\">ST_AddBand<\/a>&nbsp;\u2014\u2014 \u7528\u4e8e\u5b9a\u4e49\u6ce2\u6bb5\u3002<\/li><li><a href=\"https:\/\/link.zhihu.com\/?target=http%3A\/\/postgis.net\/docs\/manual-3.0\/RT_ST_SetValue.html\">ST_SetValue<\/a>&nbsp;\u2014\u2014 \u7528\u4e8e\u8bbe\u7f6e\u50cf\u5143\u503c<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"102-\u77e2\u91cf\u5207\u7247\u5750\u6807\u8f6c\u6362\u51fd\u6570\">10.2 \u77e2\u91cf\u5207\u7247\u5750\u6807\u8f6c\u6362\u51fd\u6570<\/h3>\n\n\n\n<p><strong>ST_AsMVTGeom<\/strong><\/p>\n\n\n\n<p>\u5c06\u4e00\u4e2a\u56fe\u5c42\u4e2d\u4f4d\u4e8e\u53c2\u6570box2d\u8303\u56f4\u5185\u7684\u4e00\u4e2a\u51e0\u4f55\u56fe\u5f62\u7684\u6240\u6709\u5750\u6807\u8f6c\u6362\u4e3a<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/www.mapbox.com\/vector-tiles\/\">MapBox VectorTile<\/a>\u5750\u6807\u7a7a\u95f4\u91cc\u7684\u5750\u6807\u3002<\/p>\n\n\n\n<p>\u8be5\u51fd\u6570\u4f1a\u5c3d\u91cf\u4fdd\u6301\u3001\u751a\u81f3\u7ea0\u6b63\uff0c\u6765\u786e\u4fdd\u51e0\u4f55\u56fe\u5f62\u7684\u6709\u6548\u6027\uff08\u6709\u6548\u6027\u53ef\u4ee5\u67e5\u770b\u8fd9\u7bc7\u6587\u7ae0\uff1a<a href=\"https:\/\/zhuanlan.zhihu.com\/p\/117267292%EF%BC%89%EF%BC%8C%E5%B9%B6%E5%8F%AF%E8%83%BD%E5%9C%A8%E6%AD%A4%E8%BF%87%E7%A8%8B%E4%B8%AD%E5%B0%86%E5%87%A0%E4%BD%95%E5%9B%BE%E5%BD%A2%E9%99%8D%E7%BB%B4%EF%BC%88%E6%AF%94%E5%A6%82%E4%B8%89%E7%BB%B4%E5%87%A0%E4%BD%95%E5%9B%BE%E5%BD%A2%E8%A2%AB%E5%A4%84%E7%90%86%E6%88%90%E4%BA%8C%E7%BB%B4%E5%87%A0%E4%BD%95%E5%9B%BE%E5%BD%A2%EF%BC%89%E3%80%82\">https:\/\/zhuanlan.zhihu.com\/p\/117267292\uff09\uff0c\u5e76\u53ef\u80fd\u5728\u6b64\u8fc7\u7a0b\u4e2d\u5c06\u51e0\u4f55\u56fe\u5f62\u964d\u7ef4\uff08\u6bd4\u5982\u4e09\u7ef4\u51e0\u4f55\u56fe\u5f62\u88ab\u5904\u7406\u6210\u4e8c\u7ef4\u51e0\u4f55\u56fe\u5f62\uff09\u3002<\/a><\/p>\n\n\n\n<p>\u51fd\u6570\u5404\u4e2a\u53c2\u6570\u7684\u542b\u4e49\uff1a<\/p>\n\n\n\n<ul><li><strong>geom<\/strong>&nbsp;\u2014\u2014 \u88ab\u8f6c\u6362\u7684\u51e0\u4f55\u56fe\u5f62\u4fe1\u606f\u3002<\/li><li><strong>bounds<\/strong>&nbsp;\u2014\u2014 \u67d0\u4e2a\u77e2\u91cf\u5207\u7247\u7684\u8303\u56f4\u5bf9\u5e94\u7684\u7a7a\u95f4\u53c2\u8003\u5750\u6807\u7cfb\u4e2d\u7684\u51e0\u4f55\u77e9\u5f62\u6846\uff08\u6ca1\u6709\u7f13\u51b2\u533a\uff09\u3002<\/li><li><strong>extent<\/strong>&nbsp;\u2014\u2014 \u662f\u6309<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/www.mapbox.com\/vector-tiles\/specification\/\">\u89c4\u8303<\/a>\u5b9a\u4e49\u7684\u77e2\u91cf\u5207\u7247\u5750\u6807\u7a7a\u95f4\u4e2d\u7684\u67d0\u4e2a\u77e2\u91cf\u5207\u7247\u7684\u8303\u56f4\u3002\u5982\u679c\u4e3aNULL\uff0c\u5219\u9ed8\u8ba4\u4e3a4096\uff08\u8fb9\u957f\u4e3a4096\u4e2a\u5355\u4f4d\u7684\u6b63\u65b9\u5f62\uff09\u3002<\/li><li><strong>buffer<\/strong>&nbsp;\u2014\u2014 \u77e2\u91cf\u5750\u6807\u7a7a\u95f4\u4e2d\u7f13\u51b2\u533a\u7684\u8ddd\u79bb\uff0c\u4f4d\u4e8e\u8be5\u7f13\u51b2\u533a\u7684\u51e0\u4f55\u56fe\u5f62\u90e8\u4f4d\u6839\u636eclip_geom\u53c2\u6570\u88ab\u88c1\u526a\u6216\u4fdd\u7559\u3002\u5982\u679c\u4e3aNULL\uff0c\u5219\u9ed8\u8ba4\u4e3a256\u3002<\/li><li><strong>clip_geom<\/strong>&nbsp;\u2014\u2014 \u7528\u4e8e\u9009\u62e9\u4f4d\u4e8e\u7f13\u51b2\u533a\u7684\u51e0\u4f55\u56fe\u5f62\u90e8\u4f4d\u662f\u88ab\u88c1\u526a\u8fd8\u662f\u539f\u6837\u4fdd\u7559\u3002\u5982\u679c\u4e3aNULL\uff0c\u5219\u9ed8\u8ba4\u4e3atrue\u3002<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"103-\u751f\u6210\u77e2\u91cf\u5207\u7247\u7684\u51fd\u6570\">10.3 \u751f\u6210\u77e2\u91cf\u5207\u7247\u7684\u51fd\u6570<\/h3>\n\n\n\n<p>ST_AsMVT\u805a\u5408\u51fd\u6570\u7528\u4e8e\u5c06\u57fa\u4e8e<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/www.mapbox.com\/vector-tiles\/\">MapBox VectorTile<\/a>\u5750\u6807\u7a7a\u95f4\u7684\u51e0\u4f55\u56fe\u5f62\u8f6c\u6362\u4e3a<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/www.mapbox.com\/vector-tiles\/\">MapBox VectorTile<\/a>\u4e8c\u8fdb\u5236\u77e2\u91cf\u5207\u7247\u3002<\/p>\n\n\n\n<p>PostGIS\u751f\u6210MVT\u77e2\u91cf\u5207\u7247\u7684\u6b65\u9aa4\u662f\uff1a<\/p>\n\n\n\n<ul><li>\u4f7f\u7528ST_AsMVTGeom\u51fd\u6570\u5c06\u51e0\u4f55\u56fe\u5f62\u7684\u6240\u6709\u5750\u6807\u8f6c\u6362\u4e3a<a href=\"https:\/\/link.zhihu.com\/?target=https%3A\/\/www.mapbox.com\/vector-tiles\/\">MapBox VectorTile<\/a>\u5750\u6807\u7a7a\u95f4\u91cc\u7684\u5750\u6807\uff0c\u8fd9\u6837\u5c31\u5c06\u57fa\u4e8e\u7a7a\u95f4\u5750\u6807\u7cfb\u7684\u51e0\u4f55\u56fe\u5f62\u8f6c\u6362\u6210\u4e86\u57fa\u4e8eMVT\u5750\u6807\u7a7a\u95f4\u7684\u51e0\u4f55\u56fe\u5f62\u3002<\/li><li>\u4f7f\u7528ST_AsMVT\u51fd\u6570\u5c06\u57fa\u4e8eMVT\u5750\u6807\u7a7a\u95f4\u7684\u51e0\u4f55\u56fe\u5f62\u8f6c\u6362\u4e3aMVT\u4e8c\u8fdb\u5236\u77e2\u91cf\u5207\u7247\u3002<\/li><\/ul>\n\n\n\n<p>MVT\u683c\u5f0f\u53ef\u4ee5\u5b58\u50a8\u5177\u6709\u4e0d\u540c\u5c5e\u6027\u96c6\u7684\u8981\u7d20\u3002\u8981\u4f7f\u7528\u6b64\u529f\u80fd\uff0c\u8bf7\u5728\u884c\u6570\u636e\u4e2d\u5305\u542b\u4e00\u4e2aJSONB\u5217\uff0c\u8be5\u5217\u901a\u8fc7\u5728\u4e00\u7ea7\u6df1\u5ea6\u4e0b\u5305\u542b\u591a\u4e2aJson\u5bf9\u8c61\u6765\u5b58\u50a8\u591a\u4e2a\u4e0d\u540c\u5c5e\u6027\u96c6\u3002JSONB\u4e2d\u7684\u952e\u548c\u503c\u5c06\u88ab\u7f16\u7801\u4e3a\u8981\u7d20\u5c5e\u6027\u3002<\/p>\n\n\n\n<p>\u53ef\u4ee5\u901a\u8fc7\"<strong>||<\/strong>\"\u64cd\u4f5c\u7b26\u8c03\u7528\u591a\u6b21\u8fd9\u4e2a\u51fd\u6570\u6765\u540c\u65f6\u521b\u5efa\u591a\u4e2a\u56fe\u5c42\u7684\u540c\u4e00\u4f4d\u7f6e\u7684\u77e2\u91cf\u5207\u7247\u3002<\/p>\n\n\n\n<p>**\u6ce8\u610f\uff1a**\u4e0d\u8981\u5c06GEOMETRYCOLLECTION\u7c7b\u578b\u7684\u51e0\u4f55\u56fe\u5f62\u4f5c\u4e3a\u53c2\u6570\u8fdb\u884c\u5207\u7247\uff0c\u4f46\u662f\u53ef\u4ee5\u4f7f\u7528ST_AsMVTGeom\u51fd\u6570\u6765\u51c6\u5907GEOMETRYCOLLECTION\u7c7b\u578b\u7684\u51e0\u4f55\u56fe\u5f62\u3002<\/p>\n\n\n\n<p>\u51fd\u6570\u5404\u4e2a\u53c2\u6570\u7684\u542b\u4e49\uff1a<\/p>\n\n\n\n<ul><li><strong>row<\/strong>&nbsp;\u2014\u2014 \u81f3\u5c11\u5177\u6709\u4e00\u4e2ageometry\u5217\u7684\u884c\u6570\u636e\u3002<\/li><li><strong>name<\/strong>&nbsp;\u2014\u2014 \u56fe\u5c42\u540d\u5b57\uff0c\u9ed8\u8ba4\u4e3a\"default\"\u3002<\/li><li><strong>extent<\/strong>&nbsp;\u2014\u2014 \u7531MVT\u89c4\u8303\u5b9a\u4e49\u7684\u5c4f\u5e55\u7a7a\u95f4\uff08MVT\u5750\u6807\u7a7a\u95f4\uff09\u4e2d\u7684\u77e2\u91cf\u5207\u7247\u8303\u56f4\u3002<\/li><li><strong>geom_name<\/strong>&nbsp;\u2014\u2014 row\u53c2\u6570\u7684\u884c\u6570\u636e\u4e2dgeometry\u5217\u7684\u5217\u540d\uff0c\u9ed8\u8ba4\u662f\u7b2c\u4e00\u4e2ageometry\u7c7b\u578b\u7684\u5217\u3002<\/li><li><strong>feature_id_name<\/strong>&nbsp;\u2014\u2014 \u884c\u6570\u636e\u4e2d\u8981\u7d20ID\u5217\u7684\u5217\u540d\u3002\u5982\u679c\u672a\u6307\u5b9a\u6216\u4e3aNULL\uff0c\u5219\u7b2c\u4e00\u4e2a\u6709\u6548\u6570\u636e\u7c7b\u578b\uff08smallint, integer, bigint\uff09\u7684\u5217\u5c06\u4f5c\u4e3a\u8981\u7d20ID\u5217\uff0c\u5176\u4ed6\u7684\u5217\u4f5c\u4e3a\u8981\u7d20\u5c5e\u6027\u5217\u3002<\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>postgis \u51fd\u6570<\/p>\n","protected":false},"author":1,"featured_media":939,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[42,43],"_links":{"self":[{"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/posts\/938"}],"collection":[{"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/comments?post=938"}],"version-history":[{"count":3,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/posts\/938\/revisions"}],"predecessor-version":[{"id":963,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/posts\/938\/revisions\/963"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/media\/939"}],"wp:attachment":[{"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/media?parent=938"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/categories?post=938"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/tags?post=938"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}