震驚,PostGIS還可以這樣用!!!

{"type":"doc","content":[{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​​​​摘要: PostGIS爲PostgreSQL提供了空間數據庫分析能力,是目前業界主流的地理數據庫之一,提供如下空間信息服務功能:空間對象、空間索引、空間操作函數和空間操作符等。在GaussDB 中,目前已支持PostGIS地理數據庫擴展,並已廣泛應用於國內外公安、農業、安平等政企客戶。","attrs":{}}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"本文分享自華爲雲社區","attrs":{}},{"type":"link","attrs":{"href":"https://bbs.huaweicloud.com/blogs/190410?utm_source=infoq&utm_medium=bbs-ex&utm_campaign=ei&utm_content=content","title":"","type":null},"content":[{"type":"text","text":"《震驚,PostGIS還可以這樣用!!!》","attrs":{}}]},{"type":"text","text":",原文作者:秋之語  。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"一、地理數據庫能做什麼 ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"地理數據庫屬於空間數據庫,爲地理數據提供了標準的格式和存貯方法,能夠方便迅速地進行檢索、更新和數據分析,最終達到爲多種應用服務的目的。地理數據則包括觀測數據、分析測定數據、遙感數據和統計調查數據。地理數據庫已廣泛的應用於單車、導航,旅遊、水利,農業、安平城市等應用場景,滲透到人民生活點點滴滴中。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/b9/b9fcb76a94039596cc8d57812e45bb92.jpeg","alt":"圖1. 地理數據庫典型應用場景","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"圖1. 地理數據庫典型應用場景","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"二、PostGIS功能介紹","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"對於如上介紹的使用場景中,地理數據通常存儲爲點、線或者多邊形的集合。在PostgreSQL中,已經提供了點、線、多邊形等空間數據類型,但其提供的數據處理方法和性能很難達到GIS的要求,主要表現在:缺乏複雜的空間類型;沒有提供空間分析;沒有提供投影變換功能。爲了使得PostgreSQL更好的提供空間信息服務,PostGIS也就應運而生。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"2.1 PostGIS支持數據類型","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"PostGIS完全遵循OpenGIS規範,支持OpenGIS中所有空間數據類型:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"a.POINT, LINESTRING,POLYGON, MULTI-POINT,","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"b.MULTI-LINESTRING,MULTI-POLYGON,","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"c.GEOMETRY COLLECTION","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"除了OpenGIS定義的地理數據類型之外,PostGIS還對數據類型進行了擴展,在WKT和WKB數據類型基礎上擴展出EWKT和EWKB數據類型:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"a.EWKT, EWKB(包含了SRID信息的WKT/WKB)","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"b.SRID(SpatialReferencing System Identifier):每個空間實例都有一個空間引用標識符 (SRID)。SRID 對應於基於特定橢圓體的空間引用系統,可用於平面球體映射或圓球映射。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"此外,PostGIS還支持柵格數據raster分析,可以基於已有的影像或者衛星數據,實現影像或者衛星數據不同類別的統計分析。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"2.2 PostGIS支持函數類型","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"PostGIS常見函數大致可以分爲以下六類,對於各函數具體用法參考","attrs":{}},{"type":"link","attrs":{"href":"https://download.osgeo.org/postgis/docs/postgis-2.4.2.pdf","title":"","type":null},"content":[{"type":"text","text":"《PostGIS使用手冊》","attrs":{}}]},{"type":"text","text":":","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"1.    字段處理函數","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"a.AddGeometryColumn爲已有的數據表增加一個地理幾何數據字段;","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"b.DropGeometryColumn刪除一個地理數據字段的;","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"c.ST_SetSRID設置SRID值","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"2.    幾何關係函數","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這類函數描述幾何對象的距離、包含、範圍、相等等幾何關係,常見函數如下:ST_Distance、ST_Equals、ST_Disjoint、ST_Intersects、ST_Touches、ST_Within、 ST_Overlaps、ST_Contains。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"3.    讀寫函數","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這類函數主要用於各種數據類型之間的轉換,尤其是Geometry數據類型與其他字符型等數據類型之間的轉換,如ST_AsText、ST_GeomFromText、ST_AsGeoJSONST_AsHEXEWKB、ST_AsKML、 ST_AsLatLonText。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"4.    幾何對象創建函數","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這類函數用於點、線、多變形等幾何對象創建,如ST_GeomFromEWKT、ST_GeomFromEWKB、ST_MakePoint、ST_MakeBox2D、ST_LineFromText、ST_Polygon。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"5.    幾何對象編輯函數","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這類函數提供對幾何圖像的平移、翻轉、旋轉、放大等功能,如ST_AddPoint、ST_Reverse、ST_Rotate、ST_Scale、ST_Snap、ST_Transform、ST_Translate、ST_TransScale。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"6.    空間關係及測量函數","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這類函數實現幾何對象最遠、最近、長度、面積等計算,如ST_3DClosestPoint、ST_3DDistance、 ST_3DDWithin、ST_3DDFullyWithin、ST_3DIntersects、ST_3DLongestLine、ST_3DMaxDistance、ST_3DShortestLine、ST_Area。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"三、PostGIS的安裝:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"         ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"3.1 基礎編譯環境準備:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"         ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"GaussDB(DWS)中的PostGISExtension需使用GCC和G++工具進行編譯安裝。安裝前需確認GCC和G++版本號大於等於4.8.5,且兩個工具可正常使用。具體可通過gcc-v和g++-v查看相關版本。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/3b/3b6f4a423380aa917cbbb748cc0c4ba3.jpeg","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​如上圖所示環境gcc和g++版本爲4.3.4,不滿足版本要求,需使用源碼安裝方式進行升級。若集羣中沒有低版本gcc和g++編譯器,可以通過掛載操作系統鏡像進行安裝,這裏不做贅述。如需要升級則可從如下網站獲取GCC相關安裝包:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"https://ftp.gnu.org/gnu/gcc/gcc-5.4.0/gcc-5.4.0.tar.gz","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"https://ftp.gnu.org/gnu/gmp/gmp-4.3.2.tar.gz","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"https://ftp.gnu.org/gnu/mpfr/mpfr-2.4.2.tar.gz","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"https://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"此外PostGIS安裝還需要確保zlib、autoconf和automake等工具已正確安裝。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"       ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"3.2 PostGIS依賴庫安裝:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"       ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"PostGIS依賴Geos、 Proj、 JSON-C、 Libxml2、 Gdal第三方開源工具。安全前首先需要下載Geos、 Proj、 JSON-C、 Libxml2、 Gdal、 PostGIS源碼至$GAUSSHOME目錄。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"       ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"安裝時需切換至omm用戶,並檢查GaussDB環境變量已正確加載,且可正常登錄和使用GaussDB環境。具體安裝命令可參考產品文檔,且確保安裝路徑與文檔中給定路徑完全一致,自定義路徑會導致最終庫文件分發失敗。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"       ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在整個安裝過程中,可使用make -sj和make install -sj命令並行加速編譯,-sj命令極低概率性出現安裝錯誤,如果安裝失敗則請使用make和make install進行串行安裝。此外對於ARM物理機,在每個安裝包configure時需要增加如下編譯參數: --build=aarch64-unknown-linuxgnu,否則會出現安裝失敗。同時,在三方開源庫proj的安裝過程中,可能會報錯$GAUSSHOME/install/proj/bin目錄不存在,可手動創建該目錄再執行proj的安裝。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"       ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"安裝成功後截圖大致如下,其中關於get_PlatForm_str.sh不存在的提示信息可直接忽略。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/c1/c15d4882d09e4ba0f196e38b9f22bd86.jpeg","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​安裝完成後則需要使用PostGIS_install.sh工具完成PostGIS相關動態鏈接庫在集羣節點中的分發。執行方式爲:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"sh$GAUSSHOME/share/postgis/PostGIS_install.sh","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"       ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如若失敗,可打開PostGIS_install.sh文件分別執行分發命令,確定是哪個文件不存在而導致分發失敗,並進一步分析該庫文件編譯失敗原因。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"四、PostGIS使用:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"       ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"目前GaussDB對PostGIS中絕大多數函數均已支持下推至DN處理。因此對於絕大多數地理數據運算,都可以充分利用GaussDB的分佈式計算優勢,帶來相比於PostgreSQL近似線性擴展比的性能加速。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"       ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"4.1 地理數據的導入:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"       ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"PostGIS支持shape格式地理數據導入。因此對於其它地理數據庫平臺數據,如Oracle或者ArcGIS中的地理數據,可先將其導出爲shape格式文件,然後使用$GAUSSHOME/bin目錄下的shp2pgsql工具將shape文件轉換爲sql文件並進一步導入GaussDB。如果生成sql文件中的地理表定義缺少分佈鍵的話,可以手動增加一個id自增的分佈鍵,使地理數據均勻分佈到各個DN,進而充分利用GaussDB的分佈式計算優勢。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"     ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"4.2 GIS函數使用demo:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"       ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"對於GaussDB支持各GIS函數的具體使用方法,請參考","attrs":{}},{"type":"link","attrs":{"href":"https://download.osgeo.org/postgis/docs/postgis-2.4.2.pdf","title":"","type":null},"content":[{"type":"text","text":"《 PostGIS-2.4.2用戶手冊》","attrs":{}}]},{"type":"text","text":"。這裏給一個簡單的使用demo。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"       ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"示例1 :幾何表的創建。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"      ","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"CREATETABLE cities ( id integer, city_name varchar(50) );\n\nSELECTAddGeometryColumn('cities', 'position', 4326, 'POINT', 2); ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"示例2:幾何數據的插入。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"    ","attrs":{}}]},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"INSERTINTO cities (id, position, city_name) VALUES (1,ST_GeomFromText('POINT(-9.523)',4326),'CityA');\n\nINSERTINTO cities (id, position, city_name) VALUES (2,ST_GeomFromText('POINT(-10.640.3)',4326),'CityB');\n\nINSERTINTO cities (id, position, city_name) VALUES (3,ST_GeomFromText('POINT(20.830.3)',4326), 'CityC');   ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"示例3:計算三個城市間任意兩個城市距離。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"SELECTp1.city_name,p2.city_name,ST_Distance(p1.position,p2.position) FROM cities ASp1, cities AS p2 WHERE p1.id > p2.id;","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"       ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"執行結果爲:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/7c/7c07c8ec9491e59c32602809cb8b440b.jpeg","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​示例4:查詢query執行計劃,發現執行過程中p1表是廣播到全部DN節點的,因此對於每個DN,其只需要處理自己節點上的p2數據,通過對比本地p2數據與全局p1數據即可完成整個分析,這也是分佈式數據庫的優勢所在。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/34/34a0149ca7f00f9af1b6a56661a811e6.jpeg","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"五、PostGIS性能介紹","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"目前市場上的空間數據庫包括MySQL的Spatial Extension、PostgreSQL的PostGIS、Oracle Spatial、ArcGIS的ArcSDE及MongoDB等。對於這幾款數據庫的性能對比,之前有一篇文檔","attrs":{}},{"type":"link","attrs":{"href":"http://www.docin.com/p-985295494.html","title":"","type":null},"content":[{"type":"text","text":"《常用地理數據庫對比測試》","attrs":{}}]},{"type":"text","text":"有一個比較詳細的對比和介紹。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"從圖2至圖5中的測試數據可以看出,對於點數據,在相同查詢條件下,PostGIS數據庫的空間查詢速度最快。對於線數據,PostGIS則相比於其它數據庫要慢一些,這可能與不同地理數據庫使用不同索引技術有關。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/1e/1e0c828e1e6ad3d2596d93beb17d7c08.jpeg","alt":"圖2. 第一次點查數據結果","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"圖2. 第一次點查數據結果","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/e1/e1198cefdf51f47c4e4fe87785cd3e14.jpeg","alt":"圖3. 第二次點查數據結果","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"圖3. 第二次點查數據結果","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/7a/7a51b8a28676f34386b8bab501df15fa.jpeg","alt":"圖4. 第一次線查數據結果","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"圖4. 第一次線查數據結果","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/67/679be75ab99eda60b992182dace7f894.jpeg","alt":"圖5. 第二次線查數據結果","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"圖5. 第二次線查數據結果","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"​","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"GaussDB作爲分佈式數據庫,對PostGIS做了深度適配。目前GaussDB對PostGIS中絕大多數函數均已支持下推至DN處理。因此對於絕大多數地理數據運算,都可以充分利用GaussDB的分佈式計算優勢,帶來相比於PostgreSQL近似線性擴展比的性能加速,滿足客戶在大數據場景的地理數據處理和分析需求。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"六、總結","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"     ","attrs":{}},{"type":"text","text":"  ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"本篇博文簡單介紹了GaussDB中Postgis的安裝和使用,歡迎廣大讀者收藏和討論。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"想了解GuassDB(DWS)更多信息,歡迎微信搜索“GaussDB DWS”關注微信公衆號,和您分享最新最全的PB級數倉黑科技,後臺還可獲取衆多學習資料~","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://bbs.huaweicloud.com/blogs?utm_source=infoq&utm_medium=bbs-ex&utm_campaign=ei&utm_content=content","title":"","type":null},"content":[{"type":"text","text":"點擊關注,第一時間瞭解華爲雲新鮮技術~","attrs":{}}]}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章