站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > MySQL 5.1参考手册中文版

Chapter聽19.聽Spatial Extensions in MySQL - MySQL 5.1参考手册中文版

绗19绔狅細MySQL涓殑绌洪棿鎵╁睍

MySQL鏀寔绌洪棿鎵╁睍锛屽厑璁哥敓鎴愩佷繚瀛樺拰鍒嗘瀽鍦扮悊鐗瑰緛銆傝繖浜涚壒寰佸彲鐢ㄤ簬MyISAMInnoDBNDBBDBARCHIVE琛紙浣嗘槸锛ARCHIVE寮曟搸涓嶆敮鎸绱㈠紩鍔熻兘锛屽洜姝わ紝涓嶈兘涓ARCHIVE鍒椾腑鐨勭┖闂村垪缂栧埗绱㈠紩锛夈

鏈珷浠嬬粛浜嗕笅杩拌棰橈細

         OpenGIS鍑犱綍妯″瀷涓繖浜涚┖闂存墿灞曠殑鍩虹銆

         鐢ㄤ簬琛ㄧず绌洪棿鏁版嵁鐨勬暟鎹牸寮忋

         濡備綍鍦MySQL涓娇鐢ㄧ┖闂存暟鎹

         浣跨敤鍏充簬绌洪棿鏁版嵁鐨勭储寮曞姛鑳姐

         MySQLOpenGIS瑙勮寖鐨勫樊寮傘

濡傛灉鍦MySQL绌洪棿鎵╁睍鐨勪娇鐢ㄦ柟闈㈡湁浠讳綍闂锛屽彲鍦ㄦ垜浠綉绔欑殑GIS璁哄潧涓璁恒

19.1. 鍓嶈█

閬典粠OpenGIS鑱旂洘锛OGC锛夌殑瑙勮寖锛MySQL瀹炴柦浜嗙┖闂存墿灞曘OGC鏄竴涓敱250澶氬鍏徃銆佷唬鐞嗘満鏋勫拰澶у鍙備笌鐨勫浗闄呰仈鐩燂紝璐熻矗寮鍙戝叕寮鐨勬蹇佃В鍐虫柟妗堬紝杩欑被瑙e喅鏂规瀵规墍鏈夌敤鏉ョ鐞嗙┖闂存暟鎹殑搴旂敤閮芥槸鏈夌敤鐨勩OGC鐨勭綉绔欐槸http://www.opengis.org/

1997骞达紝OpenGIS鑱旂洘锛OGC锛夊彂甯冧簡閽堝SQLOpenGIS庐绠鍗曠壒寰佽鑼锛屽湪璇ユ枃妗d腑锛屾彁鍑轰簡鎵╁睍SQL RDBMS浠ユ敮鎸佺┖闂存暟鎹殑涓浜涙蹇垫ф柟娉曘傝瑙勮寖鍙粠OpenGIS缃戠珯涓婅幏寰http://www.opengis.org/docs/99-049.pdf銆傚叾涓寘鍚笌鏈珷鏈夊叧鐨勯澶栦俊鎭

MySQL瀹炴柦浜OGC寤鸿鐨鍏锋湁Geometry绫诲瀷鐨SQL鐜鐨勪竴涓瓙闆嗐傝鏈鎸囩殑鏄敤涓缁勯泦鍚堢被鍨嬫墿灞曠殑鐜銆傚叿鏈夊嚑浣曞肩殑SQL鍒楁槸浣滀负鎷ユ湁闆嗗悎绫诲瀷鐨勫垪瀹炴柦鐨勩傝瑙勮寖鎻忚堪浜SQL鍑犱綍绫诲瀷闆嗗悎锛屼互鍙婁綔鐢ㄥ湪杩欎簺绫诲瀷涓婄敤浜庡垱寤哄拰鍒嗘瀽鍑犱綍鍊肩殑鍑芥暟銆

鍦扮悊鐗瑰緛鎸囩殑鏄笘鐣屼笂鍏锋湁鍦扮悊浣嶇疆鐨勪换浣曚簨鐗┿傚畠鍙互鏄細

         瀹炰綋锛屽灞便佹睜婧忋佸煄甯傘

         绌洪棿锛屽閭斂鍖哄煙銆佺儹甯︺

         鍙畾涔夌殑浣嶇疆锛屽涓ゆ潯琛楅亾鐩镐氦鐨勫崄瀛楄矾鍙c

鏈変簺鏂囦欢閲囩敤鏈鍦扮悊绌洪棿鐗瑰緛鏉ユ寚浠e湴鐞嗙壒寰併

鍑犱綍鏄彟涓涓〃绀哄湴鐞嗙壒寰佺殑鏈銆傛渶鍒濓紝鍗曡瘝鍑犱綍琛ㄧず鐨勬槸瀵瑰ぇ鍦扮殑娴嬮噺銆傛潵鑷埗鍥惧鐨勫彟涓涓惈涔夋寚鐨勬槸鍒跺浘浜哄憳鐢ㄤ簬缁樺埗涓栫晫鍦板浘鐨勫湴鐞嗙壒寰併

鏈珷灏嗘墍鏈夎繖浜涙湳璇綋浣滃悓涔夎瘝瀵瑰緟锛鍦扮悊鐗瑰緛銆鍦扮悊绌洪棿鐗瑰緛鎴栧嚑浣銆傛渶甯镐娇鐢ㄧ殑鏈鏄鍑犱綍

鎴戜滑灏鍑犱綍瀹氫箟涓轰笘鐣屼笂鍏锋湁鍦扮悊浣嶇疆鐨勭偣鎴栫偣鐨勯泦鍚堛

19.2. OpenGIS鍑犱綍妯″瀷

OGC鍏锋湁鍑犱綍绫诲瀷鐨SQL鐜寤鸿鐨勫嚑浣曠被鍨嬮泦鍚堬紝鍩轰簬OpenGIS鍑犱綍妯″瀷銆傚湪鏈ā鍨嬩腑锛屾瘡涓嚑浣曞璞″潎鍏锋湁涓嬭堪涓鑸睘鎬э細

         涓庣┖闂村弬鑰冪郴缁熺浉鍏筹紝鍏朵腑浠嬬粛浜嗗畾涔夊璞$殑鍧愭爣绌洪棿銆

         灞炰簬鏌愮鍑犱綍绫汇

19.2.1. Geometry绫荤殑灞傛

鍑犱綍绫诲畾涔変簡涓嬭堪灞傛锛

         Geometry锛堥潪瀹炰緥鍖栵級

o        Point锛堝彲瀹炰緥鍖栫殑锛

o        Curve锛堥潪瀹炰緥鍖栵級

         LineString锛堝彲瀹炰緥鍖栫殑锛

         Line

         LinearRing

o        Surface锛堥潪瀹炰緥鍖栵級

         Polygon锛堝彲瀹炰緥鍖栫殑锛

o        GeometryCollection锛堝彲瀹炰緥鍖栫殑锛

         MultiPoint锛堝彲瀹炰緥鍖栫殑锛

         MultiCurve锛堥潪瀹炰緥鍖栵級

         MultiLineString锛堝彲瀹炰緥鍖栫殑锛

         MultiSurface锛堥潪瀹炰緥鍖栵級

         MultiPolygon锛堝彲瀹炰緥鍖栫殑锛

涓嶈兘鍦ㄩ潪瀹炰緥鍖栫被涓垱寤哄璞°傝兘澶熷湪鍙疄渚嬪寲绫讳腑鍒涘缓瀵硅薄銆傛墍鏈夌被鍧囨湁灞炴э紝鍙疄渚嬪寲绫昏繕鍙互鍖呭惈澹版槑锛堝畾涔夋湁鏁堢被瀹炰緥鐨勮鍒欙級銆

Geometry鏄竴绉嶅熀鏈被銆瀹冩槸涓绉嶆娊璞$被銆Geometry鐨勫彲瀹炰緥鍖栧瓙绫婚檺鍒朵负鍙湪2缁村潗鏍囩┖闂翠腑瀛樺湪鐨012缁村嚑浣曞璞°傛墍鏈夌殑鍙疄渚嬪寲鍑犱綍绫绘槸杩欐牱瀹氫箟鐨勶紝浠庤屼娇寰楀嚑浣曠被鐨勫疄渚嬩粠鎷撴墤鎰忎箟涓婅鏄棴鍚堢殑锛堜篃灏辨槸璇达紝鎵鏈夊畾涔夌殑鍑犱綍绫诲寘鍚叾杈圭晫锛夈

鍩烘湰Geometry绫诲叿鏈夊叧浜PointCurveSurfaceGeometryCollection鐨勫瓙绫伙細

         Point琛ㄧず0缁村璞°

         Curve琛ㄧず1缁村璞锛屽叿鏈夊瓙绫LineString锛屼互鍙婃绾у瓙绫LineLinearRing

         Surface鏄负2缁村璞¤璁$殑锛屽叿鏈夊瓙绫Polygon

         GeometryCollection鍏锋湁鐗规畩鐨0缁淬1缁村拰2缁寸被闆嗗悎锛屽悕涓MultiPointMultiLineStringMultiPolygon锛屽垎鍒敤浜庝负瀵瑰簲鐨PointsLineStringsPolygons闆嗗悎杩涜鍑犱綍寤烘ā銆MultiCurveMultiSurface鏄綔涓烘娊璞¤秴绫诲紩鍏ョ殑锛屽畠浠綊绾充簡鐢ㄤ簬澶勭悊CurvesSurfaces鐨勯泦鍚堟帴鍙c

GeometryCurveSurfaceMultiCurveMultiSurface瀹氫箟涓洪潪瀹炰緥鍖栫被銆傚畠浠负鍏跺瓙绫诲畾涔変簡鍏敤鏂规硶闆嗗悎锛岃屼笖鏄负鎵╁睍鑰屽寘鍚湪鍐呯殑銆

PointLineStringPolygonGeometryCollectionMultiPointMultiLineStringMultiPolygon瀹氫箟涓哄彲瀹炰緥鍖栫被銆

19.2.2. 绫籊eometry

Geometry鏄眰娆$粨鏋勭殑鏍圭被銆傚畠鏄竴绉嶉潪瀹炰緥鍖栫被锛屼絾鍏锋湁寰堝灞炴э紝杩欎簺灞炴у鐢变换浣Geometry瀛愮被鍒涘缓鐨勬墍鏈夊嚑浣曞兼潵璇存槸鍏卞悓鐨勩備笅闈粙缁嶄簡杩欎簺灞炴э紙灏ゅ叾鏄叿鏈夎嚜宸辩壒娈婂睘鎬х殑瀛愮被锛夈

Geometry灞炴

Geometry鍊煎叿鏈変笅杩板睘鎬э細

         type锛堢被鍨嬶級銆傛瘡涓geometry灞炰簬灞傛缁撴瀯涓彲瀹炰緥鍖栫被涔嬩竴銆

         SRID锛屾垨绌洪棿鍙傝ID銆傝鍊肩‘瀹氫簡鐢ㄤ簬鎻忚堪瀹氫箟鍑犱綍瀵硅薄鐨勫潗鏍囩┖闂寸殑绌洪棿鍧愭爣绯荤粺銆

MySQL涓紝SRID鍊间粎鏄笌geometry鍊肩浉鍏崇殑鏁存暟鍊笺傛墍鏈夎绠楀潎鏄湪娆у嚑閲屽緱鍑犱綍绯伙紙骞抽潰锛変腑杩涜鐨勩

         瀹冨湪鍏剁┖闂村潗鏍囩郴缁熶腑鐨coordinates锛堝潗鏍囷級锛岃〃绀轰负鍙岀簿搴︽暟鍊硷紙8瀛楄妭锛夈傛墍鏈夌殑闈炵┖鍑犱綍瀵硅薄鑷冲皯鍖呭惈涓瀵瑰潗鏍囷紙XY锛夈傜┖鍑犱綍瀵硅薄涓嶅惈鍧愭爣銆

鍧愭爣涓SRID鐩稿叧銆備緥濡傦紝鍦ㄤ笉鍚岀殑鍧愭爣绯诲唴锛屼袱涓璞′箣闂寸殑璺濈浼氭湁鎵涓嶅悓锛屽嵆浣胯繖涓や釜瀵硅薄鍏锋湁鐩稿悓鐨勫潗鏍囦篃鍚屾牱銆傝繖鏄洜涓猴紝骞抽潰鍧愭爣绯讳腑鐨勮窛绂诲拰鍦板績鍧愭爣绯伙紙鍦扮悆琛ㄩ潰涓婄殑鍧愭爣锛変腑鐨勮窛绂绘槸涓嶅悓鐨勪簨椤广

         interior锛堝唴閮級銆boundary锛堣竟鐣岋級鍜exterior锛堝閮級銆

姣忎釜鍑犱綍瀵硅薄鍧囧崰鎹┖闂翠腑鐨勬煇涓浣嶇疆銆傚嚑浣曞璞$殑exterior锛堝閮級鎸囩殑鏄湭琚瀵硅薄鍗犳嵁鐨勬墍鏈夌┖闂淬傚叾interior锛堝唴閮級鎸囩殑鏄璇ュ璞″崰鎹殑绌洪棿銆傚叾boundary锛堣竟鐣岋級鎸囩殑鏄嚑浣曞璞″唴閮ㄥ拰澶栭儴涔嬮棿鐨勭晫闈€

         MBR锛堟渶灏忚竟鐣岀煩褰級鎴栧寘缁滈潰銆傝繖鏄竴绉嶈竟鐣屽嚑浣曞硷紝鐢辨渶灏忓拰鏈澶у潗鏍囷紙X,Y锛夋瀯鎴愩

                ((MINX MINY, MAXX MINY, MAXX MAXY, MINX MAXY, MINX MINY))

         鏃犺鍊兼槸绠鍗曠殑闈炵畝鍗曠殑銆傜被鍨嬶紙LineStringMultiPointMultiLineString锛夌殑鍑犱綍鍊兼垨鏄畝鍗曠殑锛屾垨鏄潪绠鍗曠殑銆傛瘡涓被鍨嬪喅瀹氫簡鍏惰嚜宸辩殑绠鍗曟垨闈炵畝鍗曞0鏄庛

         鏃犺鍊兼槸灏侀棴鐨闈炲皝闂殑銆傜被鍨嬶紙LineStringMultiPoint锛夌殑鍑犱綍鍊兼垨鏄皝闂殑锛屾垨鏄潪灏侀棴鐨勩傛瘡涓被鍨嬪喅瀹氫簡鍏惰嚜宸辩殑灏侀棴鎴栭潪灏侀棴澹版槑銆

         鏃犺鍊兼槸绌虹殑闈炵┖鐨銆傚鏋滄病鏈変换浣曠偣锛屽嚑浣曞璞℃槸绌虹殑銆傜┖鍑犱綍瀵硅薄鐨勫唴閮ㄣ佸閮ㄥ拰杈圭晫鏈畾涔夛紙涔熷氨鏄锛屽畠浠敱Null鍊艰〃绀猴級銆傜┖鐨勫嚑浣曞璞″畾涔変负鎬绘槸绠鍗曠殑锛岄潰绉负0

         dimension锛堢淮鏁帮級銆傚嚑浣曞璞$殑缁存暟涓1012

o        1鐢ㄤ簬绌哄嚑浣曞璞°

o        0鐢ㄤ簬鏃犻暱搴︺佹棤闈㈢Н鐨勫嚑浣曞璞°

o        1鐢ㄤ簬鍏锋湁闈0闀垮害鍜0闈㈢Н鐨勫嚑浣曞璞°

o        2鐢ㄤ簬鍏锋湁闈0闈㈢Н鐨勫嚑浣曞璞°

Point瀵硅薄鐨勭淮鏁颁负0LineString瀵硅薄鐨勭淮鏁颁负1Polygon瀵硅薄鐨勭淮鏁颁负2MultiPointMultiLineStringMultiPolygon瀵硅薄鐨勭淮鏁颁笌鏋勬垚瀹冧滑鐨勫厓绱犵殑缁存暟鐩稿悓銆

19.2.3. 绫籔oint

Point锛堢偣锛夋寚鐨勬槸浠h〃鍧愭爣绌洪棿涓崟涓綅缃殑鍑犱綍绫汇

Point绀轰緥

         鎯冲儚涓寮犲叿鏈変紬澶氬煄甯傜殑澶т笘鐣屽湴鍥俱傛瘡涓Point瀵硅薄鍙唬琛1涓煄甯傘

         鍦ㄥ煄甯傚湴鍥句笂锛Point瀵硅薄鍙唬琛1涓叕鍏辨苯杞︾珯銆

Point灞炴

         X-鍧愭爣鍊笺

         Y-鍧愭爣鍊笺

         Point瀹氫箟涓0缁村嚑浣曞璞°

         Point鐨勮竟鐣屼负绌洪泦鍚堛

19.2.4. 绫籆urve

Curve锛堟洸绾匡級鏄竴绉1鍑犱綍瀵硅薄锛岄氬父鐢变竴绯诲垪鐐硅〃绀恒Curve鐨勭壒娈婂瓙绫诲畾涔変簡鐐逛箣闂寸殑鍐呮彃绫诲瀷銆Curve鏄竴绉嶉潪瀹炰緥鍖栫被銆

Curve灞炴

         Curve鍏锋湁鍏剁偣鐨勫潗鏍囥

         Curve瀹氫箟涓1缁村嚑浣曞璞°

         濡傛灉鏈氳繃鐩稿悓鐨勭偣涓ゆ锛Curve灏辨槸绠鍗曠殑銆

         濡傛灉鍏惰捣鐐圭瓑浜庡叾缁堢偣锛Curve灏辨槸灏侀棴鐨勩

         灏侀棴Curve鐨勮竟鐣屼负绌恒

         闈炲皝闂Curve鐨勮竟鐣岀敱鍏朵袱涓鐐规瀯鎴愩

         绠鍗曚笖灏侀棴鐨CurveLinearRing

19.2.5. 绫籐ineString

LineString鏄叿鏈夌偣涔嬮棿绾挎у唴鎻掔壒鎬х殑Curve

LineString绀轰緥

         鍦ㄤ笘鐣屽湴鍥句笂锛LineString瀵硅薄鍙〃绀烘渤娴併

         鍦ㄥ煄甯傚湴鍥句笂锛LineString瀵硅薄鍙〃绀鸿閬撱

LineString灞炴

         LineString鍏锋湁绾挎鐨勫潗鏍囷紝鐢辨瘡涓繛缁殑鐐瑰锛堜袱鐐癸級瀹氫箟銆

         濡傛灉浠呭寘鍚袱鐐癸紝LineStringLine

         濡傛灉瀹冩棦鏄畝鍗曠殑涔熸槸灏侀棴鐨勶紝LineStringLinearRing

19.2.6. 绫籗urface

Surface鏄竴绉2缁村嚑浣曞璞銆傚畠鏄竴绉嶉潪瀹炰緥鍖栫被銆傚叾鍞竴鐨勫彲瀹炰緥鍖栧瓙绫绘槸Polygon.

Surface灞炴

         Surface瀹氫箟涓2缁村嚑浣曞璞°

         OpenGIS瑙勮寖涓紝灏嗙畝鍗曠殑Surface瀹氫箟涓虹敱鍗曚竴patch鈥濇瀯鎴愮殑鍑犱綍瀵硅薄锛屽畠涓庡崟涓閮ㄨ竟鐣屼互鍙0鎴栧涓唴閮ㄨ竟鐣屾湁鍏炽

         绠鍗Surface鐨勮竟鐣屾槸涓缁勪笌鍏跺唴閮ㄥ拰澶栭儴杈圭晫瀵瑰簲鐨勫皝闂洸绾跨殑闆嗗悎銆

19.2.7. 绫籔olygon

Polygon鏄唬琛ㄥ杈瑰嚑浣曞璞$殑骞抽潰Surface銆傚畠鐢鍗曚釜澶栭儴杈圭晫浠ュ強0鎴栧涓唴閮ㄨ竟鐣屽畾涔夛紝鍏朵腑锛屾瘡涓唴閮ㄨ竟鐣屽畾涔変负Polygon涓殑1涓瓟銆

Polygon绀轰緥

         鍦ㄥ湴鍖哄湴鍥句笂锛Polygon瀵硅薄鍙〃绀烘.鏋椼佸尯绛夈

Polygon澹版槑

         Polygon鐨勮竟鐣鐢变竴缁勬瀯鎴愬叾澶栭儴杈圭晫鍜屾瘮鍐呴儴杈圭晫鐨LinearRing褰掑悜闆嗗悎鏋勬垚锛堝嵆锛岀畝鍗曚笖灏侀棴鐨LineString瀵硅薄锛夈

         Polygon娌℃湁浜ゅ弶鐨勭幆銆Polygon杈圭晫涓殑鐜彲鑳戒細鍦Point澶勭浉浜わ紝浣嗕粎浠ュ垏绾挎柟寮忕浉浜ゃ

         Polygon娌℃湁绾裤佸皷宄版垨绌垮瓟銆

         Polygon鏈夌敱杩炴帴鐐归泦鍚堟瀯鎴愮殑鍐呴儴銆

         Polygon鍙兘鍖呭惈瀛斻傚浜庡叿鏈夊瓟鐨Polygon锛屽叾澶栭儴涓嶈繛鎺ャ傛瘡涓瓟瀹氫箟浜嗚繛鎺ョ殑澶栭儴閮ㄤ欢銆

鍓嶈堪澹版槑浣垮緱Polygon鎴愪负绠鍗曠殑鍑犱綍瀵硅薄銆

19.2.8. 绫籊eometryCollection

GeometryCollection鏄敱1涓垨澶氫釜浠绘剰绫诲嚑浣曞璞℃瀯鎴愮殑鍑犱綍瀵硅薄銆

GeometryCollection涓殑鎵鏈夊厓绱犲繀椤诲叿鏈夌浉鍚岀殑绌洪棿鍙傝冪郴锛堝嵆鐩稿悓鐨勫潗鏍囩郴锛夈傚GeometryCollection鐨勫厓绱犳棤浠讳綍闄愬埗锛屼絾涓嬮潰浠嬬粛鐨GeometryCollection鐨勫瓙绫讳細闄愬埗鍏舵垚鍛樸傝繖绫婚檺鍒跺彲鑳藉熀浜庯細

         鍏冪礌绫诲瀷锛堜緥濡傦紝MultiPoint鍙兘浠呭寘鍚Point鍏冪礌锛夈

         缁存暟銆

         瀵瑰厓绱犻棿绌洪棿浜よ凯绋嬪害鐨勯檺鍒躲

19.2.9. 绫籑ultiPoint

MultiPoint鏄竴绉嶇敱Point鍏冪礌鏋勬垚鐨勫嚑浣曞璞¢泦鍚堛傝繖浜涚偣鏈互浠讳綍鏂瑰紡杩炴帴鎴栨帓搴忋

MultiPoint绀轰緥

         鍦ㄤ笘鐣屽湴鍥句笂锛MultiPoint鍙互浠h〃宀涢摼銆

         鍦ㄥ煄甯傚湴鍥句笂锛MultiPoint鍙互琛ㄧず鍞エ澶勭殑鍑哄彛銆

MultiPoint灞炴

         MultiPoint0缁村嚑浣曞璞°

         濡傛灉娌℃湁涓や釜Point鏄浉鍚岀殑锛堝叿鏈夌瓑鍚岀殑鍧愭爣鍊硷級锛MultiPoint鏄畝鍗曠殑銆

         MultiPoint鐨勮竟鐣屼负绌洪泦鍚堛

19.2.10. 绫籑ultiCurve

MultiCurve鏄竴绉嶇敱Curve鍏冪礌鏋勬垚鐨勫嚑浣曞璞¢泦鍚堛MultiCurve鏄竴绉嶉潪瀹炰緥鍖栫被銆

MultiCurve灞炴

         MultiCurve1缁村嚑浣曞璞°

         褰撲笖浠呭綋鍏舵墍鏈夊厓绱犲潎鏄畝鍗曠殑鏃讹紝MultiCurve鎵嶆槸绠鍗曠殑銆浠绘剰涓ゅ厓绱犵殑鍞竴浜ゅ弶浠呭嚭鐜板湪涓ゅ厓绱犺竟鐣岀殑鐐逛笂銆

         MultiCurve杈圭晫鏄氳繃閲囩敤鈥滄ā2鑱斿悎瑙勫垯鈥濓紙涔熺О涓哄鍋惰鍒欙級鑾峰緱鐨勶細濡傛灉鏌愪竴鐐逛綅浜庡鏁扮紪鍙MultiCurve鍏冪礌鐨勮竟鐣屽唴锛屽畠灏嗕綅浜MultiCurve鐨勮竟鐣屽唴銆

         濡傛灉鍏舵墍鏈夊厓绱犲潎鏄皝闂殑锛屽垯MultiCurve涓哄皝闂殑銆

         灏侀棴MultiCurve鐨勮竟鐣屾讳负绌恒

19.2.11. 绫籑ultiLineString

MultiLineString鏄竴绉嶇敱 LineString鍏冪礌鏋勬垚鐨MultiCurve鍑犱綍瀵硅薄闆嗗悎銆

MultiLineString绀轰緥

         鍦ㄥ湴鍖哄湴鍥句笂锛MultiLineString鍙〃绀烘渤娴佷綋绯绘垨楂橀熻矾绯荤粺銆

19.2.12. 绫籑ultiSurface

MultiSurface鏄竴绉嶇敱Surface鍏冪礌鏋勬垚鐨勫嚑浣曞璞¢泦鍚堛MultiSurface鏄竴绉嶉潪瀹炰緥鍖栫被銆傚叾鍞竴鐨勫彲瀹炰緥鍖栧瓙绫绘槸MultiPolygon

MultiSurface澹版槑

         2MultiSurface闈㈡病鏈夌浉浜ょ殑鍐呴儴銆

         2MultiSurface鍏冪礌鍏锋湁鏈澶氬湪鏈夐檺鐐逛笂鐩镐氦鐨勮竟鐣屻

19.2.13. 绫籑ultiPolygon

MultiPolygon鏄竴绉嶇敱Polygon鍏冪礌鏋勬垚鐨勫嚑浣曞璞¢泦鍚堛

MultiPolygon绀轰緥

         鍦ㄥ湴鍖哄湴鍥句笂锛MultiPolygon鍙〃绀烘箹娉婄郴缁熴

MultiPolygon澹版槑

         MultiPolygon娌℃湁鍐呴儴鐩镐氦鐨勭殑2Polygon鍏冪礌銆

         MultiPolygon娌℃湁2涓氦鍙夌殑Polygon鍏冪礌锛堝墠杩板0鏄庝篃绂佹浜ゅ弶锛夛紝涔熸病鏈夊湪鏃犳暟鐐瑰鐩告帴瑙︾殑2Polugon鍏冪礌銆

         MultiPolygon涓嶈兘鍚湁鏈夋柇寮鐨勭嚎銆佸皷宄版垨绌垮瓟銆MultiPolygon鏄竴绉嶆甯哥殑灏侀棴鐐归泦鍚堛

         瀵逛簬鏈1涓互涓Polygon鍏冪礌鐨MultiPolygon鍏锋湁涓嶈繛鎺ョ殑鍐呴儴銆MultiPolygon鍐呴儴宸茶繛鎺ラ儴浠剁殑鏁扮洰绛変簬MultiPolygonPolygon鍊肩殑鏁扮洰銆

MultiPolygon灞炴

         MultiPolygon2缁村嚑浣曞璞°

         MultiPolygon杈圭晫鏄笌鍏Polygon鍏冪礌鐨勮竟鐣屽搴旂殑灏侀棴鏇茬嚎闆嗗悎LineString鍊硷級銆

         MultiPolygon杈圭晫涓殑姣忎釜Curve鍑嗙‘浣嶄簬1Polygon鍏冪礌鐨勮竟鐣屽唴銆

         Polygon鍏冪礌杈圭晫涓殑姣忎釜Curve浣嶄簬MultiPolygon鐨勮竟鐣屼腑銆

19.3. 鏀寔鐨勭┖闂存暟鎹牸寮

鍦ㄦ湰鑺備腑锛屼粙缁嶄簡鐢ㄤ簬琛ㄧず鏌ヨ涓嚑浣曞璞$殑鏍囧噯绌洪棿鏁版嵁鏍煎紡銆傚畠浠槸锛

         钁楀悕鐨勬枃鏈(WKT)鏍煎紡

         钁楀悕鐨勪簩杩涘埗(WKB)鏍煎紡

浠庡叾鍐呴儴鐪嬶紝MySQL浠ヤ笉瀹屽叏绛夊悓浜WKTWKB鐨勬牸寮忎繚瀛樺嚑浣曞璞″笺

19.3.1. 钁楀悕鐨勬枃鏈(WKT)鏍煎紡

瀵逛簬Geometry鐨勮憲鍚嶆枃鏈紙WKT锛夎〃绀猴紝瀹冩槸涓轰笌閲囩敤ASCII鏍煎紡鐨勫嚑浣曟暟鎹繘琛屼氦鎹㈣岃璁$殑銆

鍑犱綍瀵硅薄WKT琛ㄧず鐨勭ず渚嬶細

         Point

                POINT(15 20)

娉ㄦ剰锛屾寚瀹氱偣鍧愭爣鏃朵笉浣跨敤鍒嗛殧鐢ㄩ楀彿銆

         鍏锋湁4涓偣鐨LineString

                LINESTRING(0 0, 10 10, 20 25, 50 60)

娉ㄦ剰锛岀偣鍧愭爣瀵归噰鐢ㄩ楀彿闅斿紑銆

         鍏锋湁1涓閮ㄧ幆鍜1涓唴閮ㄧ幆鐨Polygon

                POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))

         鍏锋湁涓変釜Point鍊肩殑MultiPoint

                MULTIPOINT(0 0, 20 20, 60 60)

         鍏锋湁2LineString鍊肩殑MultiLineString

                MULTILINESTRING((10 10, 20 20), (15 15, 30 15))

         鍏锋湁2Polygon鍊肩殑MultiPolygon

                MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)),((5 5,7 5,7 7,5 7, 5 5)))

         2Point鍊煎拰1LineString鏋勬垚鐨GeometryCollection

                GEOMETRYCOLLECTION(POINT(10 10), POINT(30 30), LINESTRING(15 15, 20 20))

鍦ㄦ湰绔犲紑濮嬪缁欏嚭鐨OGC瑙勮寖鏂囨。涓紝鍙壘鍒扮浉搴旂殑Backus-Naur璇硶锛屽畠鎸囧畾浜嗙敤浜庣紪鍐WKT鍊肩殑姝e紡鐢熶骇瑙勫垯銆

19.3.2. 钁楀悕鐨勪簩杩涘埗(WKB)鏍煎紡

鐢ㄤ簬鍑犱綍鍊肩殑钁楀悕浜岃繘鍒讹紙WKB锛夎〃绀烘槸鐢OpenGIS瑙勮寖瀹氫箟鐨勩傚畠杩樺畾涔夊湪ISO SQL/MM Part 3: Spatial鈥濇爣鍑嗕腑銆

WKB鐢ㄤ簬浠ヤ簩杩涘埗娴佺殑褰㈠紡浜ゆ崲鍑犱綍鏁版嵁锛屼簩杩涘埗娴佺敱鍚嚑浣WKB淇℃伅鐨BLOB鍊艰〃绀恒

WKB浣跨敤1瀛楄妭鏃犵鍙锋暣鏁般4瀛楄妭鏃犵鍙锋暣鏁般佷互鍙8瀛楄妭鍙岀簿搴︽暟锛IEEE 754鏍煎紡锛夈1瀛楄妭绛変簬8姣旂壒銆

渚嬪锛屼笌POINT(1 1)瀵瑰簲鐨WKB鍊肩敱涓嬭堪21瀛楄妭搴忓垪鏋勬垚锛堝湪姝わ紝姣忎釜瀛楄妭鐢2涓崄鍏繘鍒舵暟鍊艰〃绀猴級锛

0101000000000000000000F03F000000000000F03F

璇ュ簭鍒楀彲鍒嗕负涓嬭堪閮ㄥ垎锛

Byte order : 01
WKB type   : 01000000
X          : 000000000000F03F
Y          : 000000000000F03F

琛ㄧず濡備笅锛

         瀛楄妭椤哄簭锛Byte order锛夊彲浠ユ槸01锛屽垎鍒〃鏄little-endianbig-endian瀛樺偍銆little-endianbig-endian瀛楄妭椤哄簭涔熷垎鍒О涓虹綉缁滄暟鎹〃绀猴紙NDR锛夊拰澶栭儴鏁版嵁琛ㄧず锛XDR锛夈

         WKB type鈥濓紙WKB绫诲瀷锛夋槸鎸囨槑鍑犱綍绫诲瀷鐨勪唬鐮併傚彇鍊间粠17锛屽垎鍒〃绀PointLineStringPolygonMultiPointMultiLineStringMultiPolygon銆佸拰GeometryCollection

         Point鍊煎叿鏈XY鍧愭爣锛屾瘡涓煎潎鐢ㄥ弻绮惧害鍊艰〃绀恒

瀵逛簬鏇村鏉傚嚑浣曞肩殑WKB鍊硷紝瀹冧滑鏄敱鏇村鏉傜殑鏁版嵁缁撴瀯琛ㄧず鐨勶紝璇︽儏璇峰弬瑙OpenGIS瑙勮寖銆

19.4. 鍒涘缓鍏峰绌洪棿鍔熻兘鐨凪ySQL鏁版嵁搴

鏈妭浠嬬粛浜嗗彲鐢ㄤ簬琛ㄧずMySQL涓┖闂存暟鎹殑鏁版嵁绫诲瀷锛屼互鍙婄敤浜庡垱寤哄拰妫绱㈢┖闂村肩殑鍑芥暟銆

19.4.1. MySQL绌洪棿鏁版嵁绫诲瀷

MySQL鍏锋湁涓OpenGIS绫诲搴旂殑鏁版嵁绫诲瀷銆傛煇浜涚被鍨嬪彧鑳戒繚瀛樺崟涓嚑浣曞硷細

         GEOMETRY

         POINT

         LINESTRING

         POLYGON

GEOMETRY鑳藉淇濆瓨浠讳綍绫诲瀷鐨勫嚑浣曞笺傚叾浠栫殑鍗曞肩被鍨POINTLINESTRING浠ュ強POLYGON鍙兘淇濆瓨鐗瑰畾鍑犱綍绫诲瀷鐨鍊笺

鍏朵粬鏁版嵁绫诲瀷鑳戒繚瀛樺涓硷細

         MULTIPOINT

         MULTILINESTRING

         MULTIPOLYGON

         GEOMETRYCOLLECTION

GEOMETRYCOLLECTION鑳戒繚瀛樹换鎰忕被鍨嬬殑瀵硅薄闆嗗悎銆傚浜庡叾浠栭泦鍚堢被鍨嬶紝MULTIPOINTMULTILINESTRINGMULTIPOLYGONGEOMETRYCOLLECTION锛屼粎闄愪簬鍏锋湁鐗瑰畾鍑犱綍绫诲瀷鐨勯泦鍚堟垚鍛樸

19.4.2. 鍒涘缓绌洪棿鍊

鍦ㄦ湰鑺備腑锛屼粙缁嶄簡浣跨敤OpenGIS鏍囧噯涓畾涔夌殑WKTWKB鍑芥暟鍒涘缓绌洪棿鍊肩殑鏂规硶锛屼互鍙婁娇鐢ㄧ浉搴MySQL鍑芥暟鐨勬柟娉曘

19.4.2.1. 浣跨敤WKT鍑芥暟鍒涘缓Geometry锛堝嚑浣曪級鍊

MySQL鎻愪緵浜嗕紬澶氫互WKT琛ㄨ揪寮忋佷互鍙婂彲閫夌殑绌洪棿鍙傝冪郴IDSRID锛変负杈撳叆鍙傛暟鐨勫嚱鏁般傚畠浠皢杩斿洖瀵瑰簲鐨勫嚑浣曞璞°

GeomFromText()鎺ュ彈浠讳綍鍑犱綍绫诲瀷鐨WKT浣滀负鍏剁1涓弬閲忋傚湪瀹炴柦鏂规涓篃鎻愪緵浜嗕笌绫诲瀷鐩稿叧鐨勬瀯閫犲嚱鏁帮紝鐢ㄤ簬鏋勯犳瘡涓绉嶅嚑浣曠被鍨嬬殑鍑犱綍鍊笺

  • GeomCollFromText(wkt[,srid]) , GeometryCollectionFromText(wkt[,srid])

    浣跨敤鍏WKT琛ㄧず鍜SRID鏋勯GEOMETRYCOLLECTION鍊笺

  • GeomFromText(wkt[,srid]) , GeometryFromText(wkt[,srid])

    浣跨敤鍏WKT琛ㄧず鍜SRID鏋勯浠讳綍绫诲瀷鐨勫嚑浣曞笺

  • LineFromText(wkt[,srid]) , LineStringFromText(wkt[,srid])

    浣跨敤鍏WKT琛ㄧず鍜SRID鏋勯LINESTRING鍊笺

  • MLineFromText(wkt[,srid]) , MultiLineStringFromText(wkt[,srid])

    浣跨敤鍏WKT琛ㄧず鍜SRID鏋勯MULTILINESTRING鍊笺

  • MPointFromText(wkt[,srid]) , MultiPointFromText(wkt[,srid])

    浣跨敤鍏WKT琛ㄧず鍜SRID鏋勯MULTIPOINT鍊笺

  • MPolyFromText(wkt[,srid]) , MultiPolygonFromText(wkt[,srid])

    浣跨敤鍏WKT琛ㄧず鍜SRID鏋勯MULTIPOLYGON鍊笺

  • PointFromText(wkt[,srid])

    浣跨敤鍏WKT琛ㄧず鍜SRID鏋勯POINT鍊笺

  • PolyFromText(wkt[,srid]) , PolygonFromText(wkt[,srid])

    浣跨敤鍏WKT琛ㄧず鍜SRID鏋勯POLYGON鍊笺

OpenGIS瑙勮寖杩樹粙缁嶄簡鐢ㄤ簬鏋勯PolygonMultiPolygon鍊肩殑鍙夊嚱鏁帮紝杩欎簺鍊煎熀浜庣幆鍜屽皝闂LineString鍊奸泦鍚堢殑WKT琛ㄨ揪寮忋傝繖浜涘煎彲浠ョ浉浜ゃMySQL鏈疄鏂戒笅杩板嚱鏁帮細

  • BdMPolyFromText(wkt,srid)

    浠ュ寘鍚凡鍏抽棴LineString鍊间换鎰忛泦鍚堢殑WKT鏍煎紡锛屼粠MultiLineString鍊兼瀯閫MultiPolygon鍊笺

  • BdPolyFromText(wkt,srid)

    浠ュ寘鍚凡鍏抽棴LineString鍊间换鎰忛泦鍚堢殑WKT鏍煎紡锛屼粠MultiLineString鍊兼瀯閫Polygon鍊笺

19.4.2.2. 浣跨敤WKB鍑芥暟鍒涘缓Geometry锛堝嚑浣曪級鍊

MySQL鎻愪緵浜嗕紬澶氬嚱鏁帮紝瀹冧滑灏嗗寘鍚WKT琛ㄨ揪寮忋佹垨鍙夌殑绌洪棿鍙傝冪郴缁IDSRID锛夌殑BLOB浣滀负杈撳叆鍙傛暟銆傚畠浠繑鍥炲搴旂殑鍑犱綍瀵硅薄銆

GeomFromWKB()鎺ュ彈浠讳綍鍑犱綍绫诲瀷鐨WKB浣滀负鍏剁1涓弬閲忋傚湪瀹炴柦鏂规涓篃鎻愪緵浜嗕笌绫诲瀷鐩稿叧鐨勬瀯閫犲嚱鏁帮紝鐢ㄤ簬鏋勯犳瘡涓绉嶅嚑浣曠被鍨嬬殑鍑犱綍鍊笺
  • GeomCollFromWKB(wkb[,srid]) , GeometryCollectionFromWKB(wkb[,srid])

    浣跨敤鍏WKB琛ㄧず鍜SRID鏋勯GEOMETRYCOLLECTION鍊笺

  • GeomFromWKB(wkb[,srid]) , GeometryFromWKB(wkb[,srid])

    浣跨敤鍏WKB琛ㄧず鍜SRID鏋勯浠绘剰绫诲瀷鐨勫嚑浣曞笺

  • LineFromWKB(wkb[,srid]) , LineStringFromWKB(wkb[,srid])

    浣跨敤鍏WKB琛ㄧず鍜SRID鏋勯LINESTRING鍊笺

  • MLineFromWKB(wkb[,srid]) , MultiLineStringFromWKB(wkb[,srid])

    浣跨敤鍏WKB琛ㄧず鍜SRID鏋勯MULTILINESTRING鍊笺

  • MPointFromWKB(wkb[,srid]) , MultiPointFromWKB(wkb[,srid])

    浣跨敤鍏WKB琛ㄧず鍜SRID鏋勯MULTIPOINT鍊笺

  • MPolyFromWKB(wkb[,srid]) , MultiPolygonFromWKB(wkb[,srid])

    浣跨敤鍏WKB琛ㄧず鍜SRID鏋勯MULTIPOLYGON鍊笺

  • PointFromWKB(wkb[,srid])

    浣跨敤鍏WKB琛ㄧず鍜SRID鏋勯POINT鍊笺

  • PolyFromWKB(wkb[,srid]) , PolygonFromWKB(wkb[,srid])

    浣跨敤鍏WKB琛ㄧず鍜SRID鏋勯POLYGON鍊笺

OpenGIS瑙勮寖杩樹粙缁嶄簡鐢ㄤ簬鏋勯PolygonMultiPolygon鍊肩殑鍙夊嚱鏁帮紝杩欎簺鍊煎熀浜庣幆鍜屽皝闂LineString鍊奸泦鍚堢殑WKB琛ㄨ揪寮忋傝繖浜涘煎彲浠ョ浉浜ゃMySQL鏈疄鏂戒笅杩板嚱鏁帮細

  • BdMPolyFromWKB(wkb,srid)

    浠ュ寘鍚凡鍏抽棴LineString鍊间换鎰忛泦鍚堢殑WKB鏍煎紡锛屼粠MultiLineString鍊兼瀯閫MultiPolygon鍊笺

  • BdPolyFromWKB(wkb,srid)

    浠ュ寘鍚凡鍏抽棴LineString鍊间换鎰忛泦鍚堢殑WKB鏍煎紡锛屼粠MultiLineString鍊兼瀯閫Polygon鍊笺

19.4.2.3. 浣跨敤MySQL鍑芥暟鍒涘缓鍑犱綍鍊

娉ㄩ噴锛MySQL鏈疄鏂芥湰鑺傛墍鍒楃殑鍑芥暟銆

MySQL涓哄垱寤哄嚑浣WKB琛ㄨ揪寮忔彁渚涗簡鏈夌敤鐨勫嚱鏁伴泦鍚堛傛湰鑺備粙缁嶇殑鍑芥暟鏄OpenGIS瑙勮寖鐨MySQL鎵╁睍銆傝繖浜涘嚱鏁扮殑缁撴灉鏄寘鍚嚑浣曞硷紙鏃SRID锛夌殑BLOB鍊笺傝繖浜涘嚱鏁扮殑缁撴灉鍙GeomFromWKB()鍑芥暟绯诲垪涓换鎰忓嚱鏁扮殑绗1涓弬閲忓彇浠c
  • GeometryCollection(g1,g2,...)

    鏋勯WKB GeometryCollection銆傚鏋滀换浣曞弬閲忎笉鏄瀯閫犺壇濂界殑鍑犱綍瀵硅薄WKB琛ㄨ揪寮忥紝杩斿洖鍊间负NULL

  • LineString(pt1,pt2,...)

    浠庡涓WKB Point鍙傞噺鏋勯WKB LineString銆傚鏋滀换浣曞弬閲忎笉鏄WKB Point锛岃繑鍥炲间负NULL銆傚鏋Point鍙傞噺鐨勬暟鐩皬浜2锛岃繑鍥炲间负NULL

  • MultiLineString(ls1,ls2,...)

    浣跨敤WKB LineString鍙傞噺鏋勯WKB MultiLineString銆傚鏋滀换浣曞弬閲忎笉鏄WKB LineString锛岃繑鍥炲间负NULL

  • MultiPoint(pt1,pt2,...)

    浣跨敤WKB Point鍙傞噺鏋勯WKB MultiPoint鍊笺傚鏋滀换浣曞弬閲忎笉鏄WKB Point锛岃繑鍥炲间负NULL

  • MultiPolygon(poly1,poly2,...)

    浠庝竴缁WKB Polygon鍙傞噺鏋勯WKB MultiPolygon鍊笺傚鏋滀换浣曞弬閲忎笉鏄WKB Polygon锛岃繑鍥炲间负NULL

  • Point(x,y)

    浣跨敤鍏跺潗鏍囨瀯閫WKB Point

  • Polygon(ls1,ls2,...)

    浠庡涓WKB LineString鍙傞噺鏋勯WKB Polygon鍊笺傚鏋滀换浣曞弬閲忔湭琛ㄧず涓LinearRingWKB褰㈠紡锛堝嵆锛岄潪灏侀棴鍜岀畝鍗LineString锛岃繑鍥炲间负NULL

19.4.3. 鍒涘缓绌洪棿鍒

MySQL鎻愪緵浜嗕负鍑犱綍绫诲瀷鍒涘缓绌洪棿鍒楃殑鏍囧噯鏂规硶锛屼緥濡傦紝浣跨敤CREATE TABLEALTER TABLE銆傜洰鍓嶏紝浠呭MyISAM鏍囨敮鎸佺┖闂村垪銆

         浣跨敤CREATE TABLE璇彞鍒涘缓鍏锋湁绌洪棿鍒楃殑琛細

                mysql> CREATE TABLE geom (g GEOMETRY);
                Query OK, 0 rows affected (0.02 sec)

         浣跨敤ALTER TABLE璇彞鍦ㄥ凡鏈夎〃涓鍔犵┖闂村垪锛屾垨灏嗙┖闂村垪浠庡凡鏈夎〃涓垹闄わ細

                mysql> ALTER TABLE geom ADD pt POINT;
                Query OK, 0 rows affected (0.00 sec)
                Records: 0  Duplicates: 0  Warnings: 0
                mysql> ALTER TABLE geom DROP pt;
                Query OK, 0 rows affected (0.00 sec)
                Records: 0  Duplicates: 0  Warnings: 0

19.4.4. 濉厖绌洪棿鍒

鍒涘缓浜嗙┖闂村垪鍚庯紝鍙敤绌洪棿鏁版嵁濉厖瀹冧滑銆

鍊煎簲浠ュ唴閮ㄥ嚑浣曟牸寮忎繚瀛橈紝浣嗕綘涔熻兘灏嗗叾浠WKTWKB鏍煎紡杞崲涓哄唴閮ㄥ嚑浣曟牸寮忋傚湪涓嬮潰鐨勭ず渚嬩腑锛屼粙缁嶄簡閫氳繃灏WKT鍊艰浆鎹负鍐呴儴鍑犱綍鏍煎紡浠ヤ究灏嗗嚑浣曞兼彃鍏ヨ〃涓殑鏂规硶銆

浣犲彲浠ュ湪INSERT璇彞涓墽琛岀洿鎺ヨ浆鎹㈡搷浣滐細

INSERT INTO geom VALUES (GeomFromText('POINT(1 1)'));
 
SET @g = 'POINT(1 1)';
INSERT INTO geom VALUES (GeomFromText(@g));

涔熷彲浠ュ湪INSERT涔嬪墠鎵ц杞崲鎿嶄綔锛

SET @g = GeomFromText('POINT(1 1)');
INSERT INTO geom VALUES (@g);

鍦ㄤ笅闈㈢殑绀轰緥涓紝灏嗗涓鏉傜殑鍑犱綍鍊兼彃鍏ュ埌浜嗚〃涓細

SET @g = 'LINESTRING(0 0,1 1,2 2)';
INSERT INTO geom VALUES (GeomFromText(@g));
 
SET @g = 'POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))';
INSERT INTO geom VALUES (GeomFromText(@g));
 
SET @g =
'GEOMETRYCOLLECTION(POINT(1 1),LINESTRING(0 0,1 1,2 2,3 3,4 4))';
INSERT INTO geom VALUES (GeomFromText(@g));

鍦ㄥ墠闈㈢殑鎵鏈夌ず渚嬩腑锛屽潎閲囩敤浜GeomFromText()鏉ュ垱寤哄嚑浣曞笺備綘涔熷彲浠ヤ娇鐢ㄤ笌绫诲瀷鐩稿叧鐨勫嚱鏁帮細

SET @g = 'POINT(1 1)';
INSERT INTO geom VALUES (PointFromText(@g));
 
SET @g = 'LINESTRING(0 0,1 1,2 2)';
INSERT INTO geom VALUES (LineStringFromText(@g));
 
SET @g = 'POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))';
INSERT INTO geom VALUES (PolygonFromText(@g));
 
SET @g =
'GEOMETRYCOLLECTION(POINT(1 1),LINESTRING(0 0,1 1,2 2,3 3,4 4))';
INSERT INTO geom VALUES (GeomCollFromText(@g));

娉ㄦ剰锛屽鏋滃鎴风搴旂敤绋嬪簭鎵撶畻浣跨敤鍑犱綍鍊肩殑WKB琛ㄧず锛屽畠闇瑕佸湪闃熷垪涓皢姝g‘鏋勯犵殑WKB鍙戦佽嚦鏈嶅姟鍣ㄣ備絾鏄紝瀛樺湪鏁扮婊¤冻璇ヨ姹傜殑鏂规硶銆備緥濡傦細

         鐢ㄥ崄鍏繘鍒舵枃瀛楄娉曟彃鍏POINT(1 1)鍊硷細

                mysql> INSERT INTO geom VALUES
                    -> (GeomFromWKB(0x0101000000000000000000F03F000000000000F03F));

         ODBC搴旂敤绋嬪簭鑳藉鍙戦WKB琛ㄨ揪寮忥紝骞朵娇鐢ㄥ叿鏈BLOB绫诲瀷鐨勫弬閲忓皢鍏剁粦瀹氬埌鍗犱綅绗︼細

                INSERT INTO geom VALUES (GeomFromWKB(?))

鍏朵粬缂栫▼鎺ュ彛鎴栬涔熸敮鎸佺被浼肩殑鍗犱綅绗︽満鍒躲

C绋嬪簭涓紝鍙互浣跨敤mysql_real_escape_string()杞箟浜岃繘鍒跺硷紝骞跺皢缁撴灉鍖呭惈鍦ㄥ皢鍙戦佽嚦鏈嶅姟鍣ㄧ殑鏌ヨ瀛楃涓层傝鍙傝25.2.3.52鑺傦紝鈥渕ysql_real_escape_string()鈥

19.4.5. 鑾峰彇绌洪棿鏁版嵁

瀵逛簬琛ㄤ腑淇濆瓨鐨勫嚑浣曞硷紝鑳藉浠ュ唴閮ㄦ牸寮忚幏鍙栥備綘涔熻兘灏嗗叾杞崲涓WKTWKB鏍煎紡銆

19.4.5.1. 浠ュ唴閮ㄦ牸寮忚幏鍙栫┖闂存暟鎹

鍦ㄨ〃瀵硅〃浼犺緭涓紝浣跨敤鍐呴儴鏍煎紡鏉ヨ幏鍙栧嚑浣曞煎彲鑳芥槸鏈夌敤鐨勩
CREATE TABLE geom2 (g GEOMETRY) SELECT g FROM geom;

19.4.5.2. 浠KT鏍煎紡鑾峰彇绌洪棿鏁版嵁

AsText()鍑芥暟鑳藉灏嗗嚑浣曞间粠鍐呴儴鏍煎紡杞崲涓WKT瀛楃涓层
SELECT AsText(g) FROM geom;

19.4.5.3. 浠ユ牸寮忚幏鍙栫┖闂存暟鎹

AsBinary()鍑芥暟鑳藉灏嗗嚑浣曞间粠鍐呴儴鏍煎紡杞崲涓鍖呭惈WKB鍊肩殑BLOB
SELECT AsBinary(g) FROM geom;

19.5. 鍒嗘瀽绌洪棿淇℃伅

鐢ㄥ煎~鍏呬簡绌洪棿鍒楀悗锛屽嵆鍙煡璇㈠拰鍒嗘瀽瀹冧滑銆MySQL鎻愪緵浜嗕竴缁勫湪绌洪棿鏁版嵁涓婃墽琛屽悇绉嶆搷浣滅殑鍑芥暟銆傛牴鎹畠浠墍鎵ц鐨勬搷浣滅被鍨嬶紝鍙互灏嗚繖浜涘嚱鏁板垎涓哄洓绉嶄富瑕佺被鍒細

         鐢ㄤ簬鍦ㄥ悇绉嶆牸寮忛棿杞崲鍑犱綍鍊肩殑鍑芥暟銆

         鐢ㄤ簬璁块棶鍑犱綍鍊煎畾鎬ф垨瀹氶噺灞炴х殑鍑芥暟銆

         鎻忚堪涓ょ鍑犱綍鍊间箣闂村叧绯荤殑鍑芥暟銆

         浠庡凡鏈Geometry鍒涘缓鏂Geometry鐨勫嚱鏁

绌洪棿鍒嗘瀽鍑芥暟鍙敤浜庡緢澶氬満鍚堜笅锛屽锛

         浠讳綍浜や簰寮SQL绋嬪簭锛屽mysqlMySQLCC

         浠ヤ换浣曡瑷缂栧啓鐨勩佹敮鎸MySQL瀹㈡埛绔API鐨勫簲鐢ㄧ▼搴忋

19.5.1. Geometry鏍煎紡杞崲鍑芥暟

MySQL鏀寔涓嬭堪鐢ㄤ簬鍦ㄥ唴閮ㄦ牸寮忓拰WKTWKB鏍煎紡闂磋浆鎹㈠嚑浣曞肩殑鍑芥暟锛

  • AsBinary(g)

    灏嗛噰鐢ㄥ唴閮ㄥ嚑浣曟牸寮忕殑鍊艰浆鎹负鍏WKB琛ㄧず锛屽苟杩斿洖浜岃繘鍒剁粨鏋溿

    SELECT AsBinary(g) FROM geom;
    
  • AsText(g)

    灏嗛噰鐢ㄥ唴閮ㄥ嚑浣曟牸寮忕殑鍊艰浆鎹负鍏WKT琛ㄧず锛屽苟杩斿洖瀛楃涓茬粨鏋溿

    mysql> SET @g = 'LineString(1 1,2 2,3 3)';
    mysql> SELECT AsText(GeomFromText(@g));
    +--------------------------+
    | AsText(GeomFromText(@g)) |
    +--------------------------+
    | LINESTRING(1 1,2 2,3 3)  |
    +--------------------------+
    
  • GeomFromText(wkt[,srid])

    灏嗗瓧绗︿覆鍊间粠鍏WKT琛ㄧず杞崲涓哄唴閮ㄥ嚑浣曟牸寮忥紝骞惰繑鍥炵粨鏋溿備篃鏀寔澶氱涓庣被鍨嬬浉鍏崇殑鍑芥暟锛屽PointFromText()LineFromText()璇峰弬瑙19.4.2.1鑺傦紝鈥滀娇鐢╓KT鍑芥暟鍒涘缓Geometry锛堝嚑浣曪級鍊尖

  • GeomFromWKB(wkb[,srid])

    灏嗕簩杩涘埗鍊间粠鍏WKB琛ㄧず杞崲涓哄唴閮ㄥ嚑浣曟牸寮忥紝骞惰繑鍥炵粨鏋溿備篃鏀寔澶氱涓庣被鍨嬬浉鍏崇殑鍑芥暟锛屽PointFromWKB()LineFromWKB()锛岃鍙傝19.4.2.2鑺傦紝鈥滀娇鐢╓KB鍑芥暟鍒涘缓Geometry锛堝嚑浣曪級鍊尖

19.5.2.聽Geometry鍑芥暟

灞炰簬璇ョ粍鐨勬瘡涓嚱鏁板潎灏嗗嚑浣曞间綔涓哄叾鍙傞噺锛屽苟杩斿洖鍑犱綍鍊肩殑瀹氭ф垨瀹氶噺灞炴с傛煇浜涘嚱鏁伴檺鍒朵簡鍏跺弬閲忕被鍨嬨傚鏋滃弬閲忔槸涓嶆纭殑鍑犱綍绫诲瀷锛岃繖绫诲嚱鏁板皢杩斿洖NULL銆備緥濡傦紝濡傛灉瀵硅薄绫诲瀷鏃笉鏄Polygon涔熶笉鏄MultiPolygonArea()灏嗚繑鍥NULL

19.5.2.1. 閫氱敤鍑犱綍鍑芥暟

鏈妭鍒楀嚭鐨勫嚱鏁颁笉闄愬埗鍏跺弬閲忥紝鍙帴鍙椾换浣曠被鍨嬬殑鍑犱綍鍊笺

  • Dimension(g)

    杩斿洖鍑犱綍鍊g鐨勫浐鏈夌淮鏁般傜粨鏋滃彲浠ユ槸-1012銆傦紙鍏充簬杩欎簺鍊肩殑鍚箟锛岃鍙傝19.2.2鑺傦紝鈥滅被Geometry鈥锛夈

    mysql> SELECT Dimension(GeomFromText('LineString(1 1,2 2)'));
    +------------------------------------------------+
    | Dimension(GeomFromText('LineString(1 1,2 2)')) |
    +------------------------------------------------+
    |                                              1 |
    +------------------------------------------------+
    
  • Envelope(g)

    杩斿洖鍑犱綍鍊g鐨勬渶灏忚竟鐣岀煩褰紙MBR锛夈傜粨鏋滀互Polygon鍊肩殑褰㈠紡杩斿洖銆

    澶氳竟褰紙polygon锛夋槸鐢辫竟鐣屾鐨勯《鐐瑰畾涔夌殑锛
    POLYGON((MINX MINY, MAXX MINY, MAXX MAXY, MINX MAXY, MINX MINY))
    
    mysql> SELECT AsText(Envelope(GeomFromText('LineString(1 1,2 2)')));
    +-------------------------------------------------------+
    | AsText(Envelope(GeomFromText('LineString(1 1,2 2)'))) |
    +-------------------------------------------------------+
    | POLYGON((1 1,2 1,2 2,1 2,1 1))                        |
    +-------------------------------------------------------+
    
  • GeometryType(g)

    浠ュ瓧绗︿覆褰㈠紡杩斿洖鍑犱綍绫诲瀷鐨勫悕绉帮紝鍑犱綍瀹炰緥g鏄嚑浣曠被鍨嬬殑鎴愬憳銆傝鍚嶇О涓庡彲瀹炰緥鍖栧嚑浣曞瓙绫讳箣涓瀵瑰簲銆

    mysql> SELECT GeometryType(GeomFromText('POINT(1 1)'));
    +------------------------------------------+
    | GeometryType(GeomFromText('POINT(1 1)')) |
    +------------------------------------------+
    | POINT                                    |
    +------------------------------------------+
    
  • SRID(g)

    杩斿洖鎸囨槑浜嗗嚑浣曞g鐨勭┖闂村弬鑰冪郴缁ID鐨勬暣鏁般

    MySQL涓紝SRID鍊间粎鏄笌鍑犱綍鍊肩浉鍏崇殑鏁存暟銆傛墍鏈夎绠楀潎鏄湪娆у嚑閲屽緱锛堝钩闈級鍑犱綍涓繘琛岀殑銆

    mysql> SELECT SRID(GeomFromText('LineString(1 1,2 2)',101));
    +-----------------------------------------------+
    | SRID(GeomFromText('LineString(1 1,2 2)',101)) |
    +-----------------------------------------------+
    |                                           101 |
    +-----------------------------------------------+
    

OpenGIS瑙勮寖杩樺畾涔変簡涓嬭堪鍑芥暟锛MySQL鏈疄鏂借繖绫诲嚱鏁帮細

  • Boundary(g)

    杩斿洖鍑犱綍鍊g鐨勭粍鍚堣竟鐣岀殑闂寘鐨勫嚑浣曞璞°

  • IsEmpty(g)

    濡傛灉鍑犱綍鍊g涓虹┖鐨勫嚑浣曞璞★紝杩斿洖1锛屽鏋滈潪绌猴紝杩斿洖0锛屽鏋滃弬閲忎负NULL锛岃繑鍥-1銆傚鏋滃嚑浣曞璞℃槸绌虹殑锛屽畠琛ㄧず绌虹殑鐐归泦鍚堛

  • IsSimple(g)

    鐩墠璇ュ嚱鏁版槸鍗犱綅绗︼紝涓嶅簲浣跨敤瀹冦傚鏋滃疄鏂戒簡瀹冿紝鍏惰涓轰笌涓嬫鎵缁欏嚭鐨勬弿杩扮被浼笺

    濡傛灉鍑犱綍鍊糶娌℃湁寮傚父鐨勫嚑浣曠偣锛堝鑷浉浜ゆ垨鑷浉鍒囷級锛岃繑鍥1銆傚鏋滃弬閲忎笉鏄畝鍗曞弬閲忥紝IsSimple()杩斿洖0锛濡傛灉鍙傞噺鏄疦ULL锛岃繑鍥-1銆

    瀵逛簬鏈珷鍓嶉潰浠嬬粛鐨勬瘡涓彲瀹炰緥鍖栧嚑浣曠被锛屽潎鍖呭惈鐗瑰畾鐨勬潯浠讹紝杩欑被鏉′欢浼氫娇绫诲疄渚嬭鍒嗙被涓洪潪绠鍗曠殑銆

19.5.2.2.聽Point鍑芥暟
 

PointXY鍧愭爣鏋勬垚锛屽彲浣跨敤涓嬭堪鍑芥暟鑾峰緱瀹冧滑锛

  • X(p)

    浠ュ弻绮惧害鏁板艰繑鍥炵偣pX鍧愭爣鍊笺

    mysql> SELECT X(GeomFromText('Point(56.7 53.34)'));
    +--------------------------------------+
    | X(GeomFromText('Point(56.7 53.34)')) |
    +--------------------------------------+
    |                                 56.7 |
    +--------------------------------------+
    
  • Y(p)

    浠ュ弻绮惧害鏁板艰繑鍥炵偣pY鍧愭爣鍊笺

    mysql> SELECT Y(GeomFromText('Point(56.7 53.34)'));
    +--------------------------------------+
    | Y(GeomFromText('Point(56.7 53.34)')) |
    +--------------------------------------+
    |                                53.34 |
    +--------------------------------------+
    

19.5.2.3.聽LineString鍑芥暟

LineStringPoint鍊肩粍鎴愩備綘鍙互鎻愬彇LineString鐨勭壒瀹氱偣锛岃鏁板畠鎵鍖呭惈鐨勭偣鏁帮紝鎴栬幏鍙栧叾闀垮害銆

  • EndPoint(ls)

    杩斿洖LineString1s鐨勬渶鍚庝竴涓偣鐨Point

    mysql> SET @ls = 'LineString(1 1,2 2,3 3)';
    mysql> SELECT AsText(EndPoint(GeomFromText(@ls)));
    +-------------------------------------+
    | AsText(EndPoint(GeomFromText(@ls))) |
    +-------------------------------------+
    | POINT(3 3)                          |
    +-------------------------------------+
    
  • GLength(ls)

    浠ュ弻绮惧害鏁板艰繑鍥LineString1s鍦ㄧ浉鍏崇殑绌洪棿鍙傝冪郴涓殑闀垮害銆

    mysql> SET @ls = 'LineString(1 1,2 2,3 3)';
    mysql> SELECT GLength(GeomFromText(@ls));
    +----------------------------+
    | GLength(GeomFromText(@ls)) |
    +----------------------------+
    |            2.8284271247462 |
    +----------------------------+
    
  • NumPoints(ls)

    杩斿洖LineString1s涓殑鐐规暟銆

    mysql> SET @ls = 'LineString(1 1,2 2,3 3)';
    mysql> SELECT NumPoints(GeomFromText(@ls));
    +------------------------------+
    | NumPoints(GeomFromText(@ls)) |
    +------------------------------+
    |                            3 |
    +------------------------------+
    
  • PointN(ls,n)

    杩斿洖LineString1s涓殑绗n涓偣銆傜偣缂栧彿浠1寮濮嬨

    mysql> SET @ls = 'LineString(1 1,2 2,3 3)';
    mysql> SELECT AsText(PointN(GeomFromText(@ls),2));
    +-------------------------------------+
    | AsText(PointN(GeomFromText(@ls),2)) |
    +-------------------------------------+
    | POINT(2 2)                          |
    +-------------------------------------+
    
  • StartPoint(ls)

    杩斿洖LineString1s鐨勭涓涓偣鐨Point

    mysql> SET @ls = 'LineString(1 1,2 2,3 3)';
    mysql> SELECT AsText(StartPoint(GeomFromText(@ls)));
    +---------------------------------------+
    | AsText(StartPoint(GeomFromText(@ls))) |
    +---------------------------------------+
    | POINT(1 1)                            |
    +---------------------------------------+
    

OpenGIS瑙勮寖杩樺畾涔変簡涓嬭堪鍑芥暟锛MySQL灏氭湭瀹炴柦杩欎簺鍑芥暟锛

  • IsRing(ls)

    濡傛灉LineStringls鏄皝闂殑锛堝嵆鍏StartPoint()EndPoint()鍊肩浉鍚锛夊拰绠鍗曠殑锛堟湭閫氳繃鐩稿悓鐨勭偣1娆′互涓婏級杩斿洖1銆傚鏋ls涓嶆槸鐜紝杩斿洖0锛屽鏋滃畠鏄NULL锛岃繑鍥-1

19.5.2.4.聽MultiLineString鍑芥暟

  • GLength(mls)

    浠ュ弻绮惧害鏁板煎舰寮忚繑鍥MultiLineStringm1s鐨勯暱搴︺mls鐨勯暱搴︾瓑浜庡叾鍏冪礌鐨勯暱搴︿箣鍜屻

    mysql> SET @mls = 'MultiLineString((1 1,2 2,3 3),(4 4,5 5))';
    mysql> SELECT GLength(GeomFromText(@mls));
    +-----------------------------+
    | GLength(GeomFromText(@mls)) |
    +-----------------------------+
    |             4.2426406871193 |
    +-----------------------------+
    
  • IsClosed(mls)

    濡傛灉MultiLineStringm1s鏄皝闂殑锛堝嵆StartPoint()EndPoint()鍊煎m1s涓殑姣忎釜LineString鏄浉鍚岀殑锛夎繑鍥1銆傚鏋mls鏄潪灏侀棴鐨勶紝杩斿洖0锛屽鏋滃畠鏄NULL锛岃繑鍥-1

    mysql> SET @mls = 'MultiLineString((1 1,2 2,3 3),(4 4,5 5))';
    mysql> SELECT IsClosed(GeomFromText(@mls));
    +------------------------------+
    | IsClosed(GeomFromText(@mls)) |
    +------------------------------+
    |                            0 |
    +------------------------------+
    

19.5.2.5.聽Polygon鍑芥暟

  • Area(poly)

    浠ュ弻绮惧害鏁板煎舰寮忚繑鍥Polygonpoly鐨勯潰绉紝鏍规嵁鍦ㄥ叾绌洪棿鍙傝冪郴涓殑娴嬮噺鍊笺

    mysql> SET @poly = 'Polygon((0 0,0 3,3 0,0 0),(1 1,1 2,2 1,1 1))';
    mysql> SELECT Area(GeomFromText(@poly));
    +---------------------------+
    | Area(GeomFromText(@poly)) |
    +---------------------------+
    |                         4 |
    +---------------------------+
    
  • ExteriorRing(poly)

    LineString褰㈠紡杩斿洖Polygonpoly鐨勫鐜

    mysql> SET @poly =
        -> 'Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))';
    mysql> SELECT AsText(ExteriorRing(GeomFromText(@poly)));
    +-------------------------------------------+
    | AsText(ExteriorRing(GeomFromText(@poly))) |
    +-------------------------------------------+
    | LINESTRING(0 0,0 3,3 3,3 0,0 0)           |
    +-------------------------------------------+
    
  • InteriorRingN(poly,n)

    LineString褰㈠紡杩斿洖Polygonpoly鐨勭n涓唴鐜傜幆缂栧彿浠1寮濮嬨

    mysql> SET @poly =
        -> 'Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))';
    mysql> SELECT AsText(InteriorRingN(GeomFromText(@poly),1));
    +----------------------------------------------+
    | AsText(InteriorRingN(GeomFromText(@poly),1)) |
    +----------------------------------------------+
    | LINESTRING(1 1,1 2,2 2,2 1,1 1)              |
    +----------------------------------------------+
    
  • NumInteriorRings(poly)

    杩斿洖Polygonpoly鐨勫唴鐜殑鏁扮洰銆

    mysql> SET @poly =
        -> 'Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))';
    mysql> SELECT NumInteriorRings(GeomFromText(@poly));
    +---------------------------------------+
    | NumInteriorRings(GeomFromText(@poly)) |
    +---------------------------------------+
    |                                     1 |
    +---------------------------------------+
    

19.5.2.6.聽MultiPolygon鍑芥暟

  • Area(mpoly)

    浠ュ弻绮惧害鏁板煎舰寮忚繑鍥MultiPolygonmpoly鐨勯潰绉紝鏍规嵁鍦ㄥ叾绌洪棿鍙傝冪郴涓殑娴嬮噺缁撴灉銆

    mysql> SET @mpoly =
        -> 'MultiPolygon(((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1)))';
    mysql> SELECT Area(GeomFromText(@mpoly));
    +----------------------------+
    | Area(GeomFromText(@mpoly)) |
    +----------------------------+
    |                          8 |
    +----------------------------+
    

OpenGIS瑙勮寖杩樺畾涔変簡涓嬭堪鍑芥暟锛MySQL鏈疄鏂借繖绫诲嚱鏁帮細

  • Centroid(mpoly)

    Point褰㈠紡杩斿洖鐢ㄤ簬MultiPolygonmpoly鐨勬暟瀛﹁川蹇冦備笉淇濊瘉缁撴灉浣嶄簬MultiPolygon涓娿

  • PointOnSurface(mpoly)

    杩斿洖Point鍊硷紝淇濊瘉璇ュ间綅浜MultiPolygonmpoly涓娿

19.5.2.7.聽GeometryCollection鍑芥暟

  • GeometryN(gc,n)

    杩斿洖GeometryCollectiongc涓n涓嚑浣曞璞°傚嚑浣曞璞$殑缂栧彿浠1寮濮嬨

    mysql> SET @gc = 'GeometryCollection(Point(1 1),LineString(2 2, 3 3))';
    mysql> SELECT AsText(GeometryN(GeomFromText(@gc),1));
    +----------------------------------------+
    | AsText(GeometryN(GeomFromText(@gc),1)) |
    +----------------------------------------+
    | POINT(1 1)                             |
    +----------------------------------------+
    
  • NumGeometries(gc)

    杩斿洖GeometryCollectiongc涓嚑浣曞璞$殑鏁扮洰銆

    mysql> SET @gc = 'GeometryCollection(Point(1 1),LineString(2 2, 3 3))';
    mysql> SELECT NumGeometries(GeomFromText(@gc));
    +----------------------------------+
    | NumGeometries(GeomFromText(@gc)) |
    +----------------------------------+
    |                                2 |
    +----------------------------------+
    

19.5.3. 浠庡凡鏈塆eometry鍒涘缓鏂癎eometry鐨勫嚱鏁

19.5.3.1. 鐢熸垚鏂癎eometry鐨凣eometry鍑芥暟

19.5.2鑺傦紝鈥淕eometry鍑芥暟鈥涓紝鎴戜滑璁ㄨ浜嗕竴浜涘彲浠庡凡鏈夊嚑浣曞璞℃瀯閫犳柊鍑犱綍瀵硅薄鐨勫嚱鏁帮細

  • Envelope(g)

  • StartPoint(ls)

  • EndPoint(ls)

  • PointN(ls,n)

  • ExteriorRing(poly)

  • InteriorRingN(poly,n)

  • GeometryN(gc,n)

19.5.3.2. 绌洪棿鎿嶄綔绗

OpenGIS寤鸿浜嗗緢澶氬彲鐢熸垚鍑犱綍瀵硅薄鐨勫叾浠栧嚱鏁般傚畠浠槸涓哄疄鏂界┖闂存搷浣滅鑰岃璁$殑銆

MySQL涓湭瀹炴柦杩欎簺鍑芥暟銆傚畠浠垨璁镐細鍦ㄦ湭鏉ョ殑鐗堟湰涓嚭鐜般

  • Buffer(g,d)

    杩斿洖鍑犱綍瀵硅薄锛岃瀵硅薄浠h〃鎵鏈夎窛鍑犱綍鍊g鐨勮窛绂诲皬浜庢垨绛変簬d鐨勬墍鏈夌偣銆

  • ConvexHull(g)

    杩斿洖鍑犱綍瀵硅薄锛岃瀵硅薄浠h〃鍑犱綍鍊g鐨勫嚫鍖呫

  • Difference(g1,g2)

    杩斿洖鍑犱綍瀵硅薄锛岃瀵硅薄琛ㄧず浜嗗嚑浣曞g1g2鐨勭偣闆嗗悎宸紓銆

  • Intersection(g1,g2)

    杩斿洖鍑犱綍瀵硅薄锛岃瀵硅薄琛ㄧず浜嗗嚑浣曞g1g2鐨勭偣闆嗗悎浜ら泦銆

  • SymDifference(g1,g2)

    杩斿洖鍑犱綍瀵硅薄锛岃瀵硅薄琛ㄧず浜嗗嚑浣曞g1g2鐨勭偣闆嗗悎瀵圭О宸

  • Union(g1,g2)

    杩斿洖鍑犱綍瀵硅薄锛岃瀵硅薄琛ㄧず浜嗗嚑浣曞g1g2鐨勭偣闆嗗悎鑱斿悎銆

19.5.4. 娴嬭瘯鍑犱綍瀵硅薄闂寸┖闂村叧绯荤殑鍑芥暟

杩欎簺鑺備腑鎵浠嬬粛鐨勫嚱鏁颁互2涓嚑浣曞璞′綔涓鸿緭鍏ュ弬鏁帮紝骞惰繑鍥炲畠浠箣闂寸殑瀹氶噺鎴栧畾鎬у叧绯汇

19.5.5. 鍏充簬鍑犱綍鏈灏忚竟鐣岀煩褰紙MBR锛夌殑鍏崇郴

MySQL鎻愪緵浜嗕竴浜涘彲娴嬭瘯涓や釜鍑犱綍瀵硅薄g1g2鏈灏忚竟鐣岀煩褰箣闂村叧绯荤殑鍑芥暟銆傚畠浠寘鎷細

  • MBRContains(g1,g2)

    杩斿洖10浠ユ寚鏄g1鐨勬渶灏忚竟鐣岀煩褰㈡槸鍚﹀寘鍚g2鐨勬渶灏忚竟鐣岀煩褰€

    mysql> SET @g1 = GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))');
    mysql> SET @g2 = GeomFromText('Point(1 1)');
    mysql> SELECT MBRContains(@g1,@g2), MBRContains(@g2,@g1);
    ----------------------+----------------------+
    | MBRContains(@g1,@g2) | MBRContains(@g2,@g1) |
    +----------------------+----------------------+
    |                    1 |                    0 |
    +----------------------+----------------------+
    
  • MBRDisjoint(g1,g2)

    杩斿洖10浠ユ寚鏄庝袱涓嚑浣曞彉閲g1g2鐨勬渶灏忚竟鐣岀煩褰㈡槸鍚︿笉鐩镐氦銆

  • MBREqual(g1,g2)

    杩斿洖10浠ユ寚鏄庝袱涓嚑浣曞彉閲g1g2鐨勬渶灏忚竟鐣岀煩褰㈡槸鍚︾浉鍚屻

  • MBRIntersects(g1,g2)

    杩斿洖10浠ユ寚鏄庝袱涓嚑浣曞彉閲g1g2鐨勬渶灏忚竟鐣岀煩褰㈡槸鍚︾浉浜ゃ

  • MBROverlaps(g1,g2)

    杩斿洖10浠ユ寚鏄庝袱涓嚑浣曞彉閲g1g2鐨勬渶灏忚竟鐣岀煩褰㈡槸鍚︿氦杩

  • MBRTouches(g1,g2)

    杩斿洖10浠ユ寚鏄庝袱涓嚑浣曞彉閲g1g2鐨勬渶灏忚竟鐣岀煩褰㈡槸鍚︽帴瑙︺

  • MBRWithin(g1,g2)

    杩斿洖10浠ユ寚鏄g1鐨勬渶灏忚竟鐣岀煩褰㈡槸鍚︿綅浜g2鐨勬渶灏忚竟鐣岀煩褰㈠唴銆

    mysql> SET @g1 = GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0))');
    mysql> SET @g2 = GeomFromText('Polygon((0 0,0 5,5 5,5 0,0 0))');
    mysql> SELECT MBRWithin(@g1,@g2), MBRWithin(@g2,@g1);
    +--------------------+--------------------+
    | MBRWithin(@g1,@g2) | MBRWithin(@g2,@g1) |
    +--------------------+--------------------+
    |                  1 |                  0 |
    +--------------------+--------------------+
    

19.5.6. 娴嬭瘯鍑犱綍绫讳箣闂寸┖闂村叧绯荤殑鍑芥暟

OpenGIS瑙勮寖瀹氫箟浜嗕笅杩板嚱鏁般傜洰鍓嶅湪MySQL灏氭湭鎸夌収瑙勮寖瀹炴柦瀹冧滑銆傚浜庨偅浜涘凡瀹炴柦鐨勫嚱鏁帮紝瀹冧滑杩斿洖鐨勭粨鏋滀笌瀵瑰簲鐨勫熀浜MBR鐨勫嚱鏁拌繑鍥炵殑鐩稿悓銆傚寘鎷笅闈㈠垪鍑虹殑鍑芥暟锛屼絾Distance()Related()闄ゅ銆

鍦ㄦ湭鏉ョ殑鐗堟湰涓紝鍙兘浼氬疄鏂借繖浜涘嚱鏁帮紝涓虹┖闂村垎鏋愭彁渚涘叏閮ㄦ敮鎸侊紝鑰屼笉浠呬粎鏄熀浜MBR鐨勬敮鎸併

杩欎簺鍑芥暟浣滅敤鍦2涓嚑浣曞g1g2涓娿

  • Contains(g1,g2)

    杩斿洖10浠ユ寚鏄g1鏄惁瀹屽叏鍖呭惈g2

  • Crosses(g1,g2)

    濡傛灉g1鍦ㄧ┖闂翠笂涓巊2鐩镐氦锛岃繑鍥1銆傚鏋g1涓篜olygonMultiPolygon锛岃繑鍥濶ULL锛屾垨濡傛灉g2PointMultiPoint杩斿洖NULL銆傚惁鍒欙紝杩斿洖0銆

    鏈鈥滅┖闂翠笂浜ゅ弶鈥濇寚鐨勬槸2涓粰瀹氬嚑浣曞璞′箣闂寸殑绌洪棿鍏崇郴锛屽畠鍏锋湁涓嬭堪灞炴э細

    o        2涓粨鍚堝璞′氦鍙夈

    o        鍏朵氦鍙夌粨鏋滃皢瀵艰嚧鍏剁淮鏁板皬浜庝袱涓粰瀹氬嚑浣曞璞℃渶澶х淮鏁扮殑鍑犱綍瀵硅薄銆

    o        鍏朵氦鍙変笉绛変簬涓や釜鍑犱綍瀵硅薄涓殑浠讳綍1涓

  • Disjoint(g1,g2)

    杩斿洖10浠ユ寚鏄g1鏄惁涓g2浠庣┖闂翠笂涓嶇浉浜ゃ

  • Distance(g1,g2)

    浠ュ弻绮惧害鏁板煎舰寮忚繑鍥2涓嚑浣曞璞′腑2鐐归棿鐨勬渶鐭窛绂汇

  • Equals(g1,g2)

    杩斿洖10浠ユ寚鏄g1鏄惁浠庣┖闂翠笂绛夊悓浜g2

  • Intersects(g1,g2)

    杩斿洖10浠ユ寚鏄g1鏄惁浠庣┖闂翠笂涓g2鐩镐氦銆

  • Overlaps(g1,g2)

    杩斿洖10浠ユ寚鏄g1鏄惁浠庣┖闂翠笂涓g2浜よ凯銆傚鏋2涓嚑浣曞璞′氦鍙夎屼笖鍏朵氦鍙夊皢瀵艰嚧鍏锋湁鐩稿悓缁存暟浣嗗苟涓嶇瓑鍚屼簬浠讳竴鍑犱綍瀵硅薄鐨勫嚑浣曞璞★紝灏嗕娇鐢ㄦ湳璇滅┖闂翠氦杩濄

  • Related(g1,g2,pattern_matrix)

    杩斿洖10浠ユ寚鏄庣敱pattern_matrix鎸囧畾鐨勭┖闂村叧绯绘槸鍚﹀湪g1g2闂村瓨鍦ㄣ傚鏋滃弬閲忎负NULL杩斿洖-1銆傛ā寮忕煩褰负瀛楃涓层傚鏋滃疄鏂戒簡璇ュ嚱鏁帮紝鍏惰鑼冨皢鍦ㄦ缁欏嚭銆

  • Touches(g1,g2)

    杩斿洖10浠ユ寚鏄g1鏄惁浠庣┖闂翠笂涓g2鎺ヨЕ銆傚鏋滃嚑浣曞璞$殑鍐呴儴涓嶄氦鍙夛紝浣1涓嚑浣曞璞$殑杈圭晫涓庡彟涓涓殑杈圭晫鎴栧唴閮ㄤ氦鍙夛紝杩欎袱涓嚑浣曞璞℃槸浠庣┖闂翠笂鎺ヨЕ鐨勩

  • Within(g1,g2)

    杩斿洖10浠ユ寚鏄g1鏄惁浠庣┖闂翠笂浣嶄簬g2鍐呫

19.6. 浼樺寲绌洪棿鍒嗘瀽

鍙互浣跨敤绱㈠紩瀵2涓潪绌洪棿鏁版嵁搴撲腑鐨勬悳绱㈡搷浣滆繘琛屼紭鍖栥傚浜庣┖闂存暟鎹簱锛岃繖鍚屾牱鎴愮珛銆傛湁浜嗕互鍓嶈璁$殑澶ч噺澶氱淮绱㈠紩鍔熻兘鐨勫府鍔╋紝鑳藉瀵圭┖闂存悳绱㈣繘琛屼紭鍖栥傛渶鍏稿瀷鐨勬儏鍐靛涓嬶細

         鎼滅储鍖呭惈缁欏畾鐐圭殑鎵鏈夊璞$殑Point鏌ヨ銆

         鎼滅储涓庣粰瀹氬湴鍖轰氦杩殑鎵鏈夊璞$殑鍦板尯鏌ヨ銆

MySQL閲囩敤浜鍏锋湁2娆″垎瑁傜壒鎬х殑R-Trees鏉ヤ负绌洪棿鍒楃紪鍒剁储寮曘備娇鐢ㄥ嚑浣曞璞$殑MBR鏉ュ垱寤虹┖闂寸储寮曘傚浜庡ぇ澶氭暟鍑犱綍瀵硅薄锛MBR鏄寘鍥村嚑浣曞璞$殑鏈灏忕煩褰€傚浜庢按骞虫垨鍨傜洿linestringMBR閫鍖栦负linestring鐨勭煩褰€傚浜庣偣锛MBR鏄鍖栦负鐐圭殑鐭╁舰銆

姝ゅ锛岃繕鑳藉湪绌洪棿鍒椾笂鍒涘缓姝e父绱㈠紩銆傞渶瑕佷负闄POINT鍒椾箣澶栫殑绌洪棿鍒椾笂鐨勪换浣曠储寮曪紙闈炵┖闂达級澹版槑鍓嶇紑銆

19.6.1. 鍒涘缓绌洪棿绱㈠紩

MySQL鑳藉浣跨敤涓庡垱寤烘瑙勭储寮曠被浼肩殑璇硶鍒涘缓绌洪棿绱㈠紩锛屼絾浣跨敤浜SPATIAL鍏抽敭瀛楄繘琛屼簡鎵╁睍銆傚浜庣洰鍓嶇紪鍒朵簡绱㈠紩鐨勭┖闂村垪锛屽繀椤诲皢鍏跺0鏄庝负NOT NULL銆傚湪涓嬮潰鐨勭ず渚嬩腑锛屼粙缁嶄簡鍒涘缓绌洪棿绱㈠紩鐨勬柟娉曘

         瀵逛簬CREATE TABLE

                mysql> CREATE TABLE geom (g GEOMETRY NOT NULL, SPATIAL INDEX(g));

         瀵逛簬ALTER TABLE

                mysql> ALTER TABLE geom ADD SPATIAL INDEX(g);

         瀵逛簬CREATE INDEX

                mysql> CREATE SPATIAL INDEX sp_index ON geom (g);

瀵逛簬MyISAM琛紝SPATIAL INDEX璐熻矗鍒涘缓R-tree绱㈠紩銆傚浜庢敮鎸佺┖闂寸储寮曠殑鍏朵粬瀛樺偍寮曟搸锛SPATIAL INDEX鑳藉鍒涘缓B-tree绱㈠紩銆傚浜庡噯纭殑鍊兼煡鎵捐屼笉鏄寖鍥存壂鎻忥紝浣滅敤鍦ㄧ┖闂村间笂鐨B-tree绱㈠紩寰堟湁鐢ㄣ

瑕佹兂鎾ら攢绌洪棿绱㈠紩锛屽彲浣跨敤ALTER TABLEDROP INDEX

         瀵逛簬ALTER TABLE

                mysql> ALTER TABLE geom DROP INDEX g;

         瀵逛簬DROP INDEX

                mysql> DROP INDEX sp_index ON geom;

绀轰緥锛氬亣瀹氳〃geom鍖呭惈32000浠ヤ笂鐨勫嚑浣曞璞★紝瀹冧滑淇濆瓨鍦ㄧ被鍨嬩负GEOMETRY鐨勫垪g涓璇ヨ〃杩樻湁鐢ㄤ簬淇濆瓨瀵硅薄ID鍊肩殑AUTO_INCREMENT鍒椼

mysql> DESCRIBE geom;
+-------+----------+------+-----+---------+----------------+
| Field | Type     | Null | Key | Default | Extra          |
+-------+----------+------+-----+---------+----------------+
| fid   | int(11)  |      | PRI | NULL    | auto_increment |
| g     | geometry |      |     |         |                |
+-------+----------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

mysql> SELECT COUNT(*) FROM geom;
+----------+
| count(*) |
+----------+
|    32376 |
+----------+
1 row in set (0.00 sec)

瑕佹兂鍦ㄥ垪g涓婃坊鍔犵┖闂寸储寮曪紝鍙娇鐢ㄤ笅杩拌鍙ワ細

mysql> ALTER TABLE geom ADD SPATIAL INDEX(g);
Query OK, 32376 rows affected (4.05 sec)
Records: 32376  Duplicates: 0  Warnings: 0

19.6.2. 浣跨敤绌洪棿绱㈠紩

浼樺寲绋嬪簭灏嗚皟鏌ュ彲鐢ㄧ殑绌洪棿绱㈠紩鏄惁鑳藉寘鍚湪浣跨敤鏌愪簺鍑芥暟鐨勬煡璇㈡悳绱腑锛屽WHERE瀛愬彞涓殑MBRContains()MBRWithin()鍑芥暟銆渚嬪锛屽亣瀹氭垜浠墦绠楁壘鍑轰綅浜庣粰瀹氱煩褰腑鐨勬墍鏈夊璞★細

mysql> SELECT fid,AsText(g) FROM geom WHERE
mysql> MBRContains(GeomFromText('Polygon((30000 15000,31000 15000,31000 16000,30000 16000,30000 15000))'),g);
+-----+-----------------------------------------------------------------------------+
| fid | AsText(g)                                                                   |
+-----+-----------------------------------------------------------------------------+
|  21 | LINESTRING(30350.4 15828.8,30350.6 15845,30333.8 15845,30333.8 15828.8)     |
|  22 | LINESTRING(30350.6 15871.4,30350.6 15887.8,30334 15887.8,30334 15871.4)     |
|  23 | LINESTRING(30350.6 15914.2,30350.6 15930.4,30334 15930.4,30334 15914.2)     |
|  24 | LINESTRING(30290.2 15823,30290.2 15839.4,30273.4 15839.4,30273.4 15823)     |
|  25 | LINESTRING(30291.4 15866.2,30291.6 15882.4,30274.8 15882.4,30274.8 15866.2) |
|  26 | LINESTRING(30291.6 15918.2,30291.6 15934.4,30275 15934.4,30275 15918.2)     |
| 249 | LINESTRING(30337.8 15938.6,30337.8 15946.8,30320.4 15946.8,30320.4 15938.4) |
|   1 | LINESTRING(30250.4 15129.2,30248.8 15138.4,30238.2 15136.4,30240 15127.2)   |
|   2 | LINESTRING(30220.2 15122.8,30217.2 15137.8,30207.6 15136,30210.4 15121)     |
|   3 | LINESTRING(30179 15114.4,30176.6 15129.4,30167 15128,30169 15113)           |
|   4 | LINESTRING(30155.2 15121.4,30140.4 15118.6,30142 15109,30157 15111.6)       |
|   5 | LINESTRING(30192.4 15085,30177.6 15082.2,30179.2 15072.4,30194.2 15075.2)   |
|   6 | LINESTRING(30244 15087,30229 15086.2,30229.4 15076.4,30244.6 15077)         |
|   7 | LINESTRING(30200.6 15059.4,30185.6 15058.6,30186 15048.8,30201.2 15049.4)   |
|  10 | LINESTRING(30179.6 15017.8,30181 15002.8,30190.8 15003.6,30189.6 15019)     |
|  11 | LINESTRING(30154.2 15000.4,30168.6 15004.8,30166 15014.2,30151.2 15009.8)   |
|  13 | LINESTRING(30105 15065.8,30108.4 15050.8,30118 15053,30114.6 15067.8)       |
| 154 | LINESTRING(30276.2 15143.8,30261.4 15141,30263 15131.4,30278 15134)         |
| 155 | LINESTRING(30269.8 15084,30269.4 15093.4,30258.6 15093,30259 15083.4)       |
| 157 | LINESTRING(30128.2 15011,30113.2 15010.2,30113.6 15000.4,30128.8 15001)     |
+-----+-----------------------------------------------------------------------------+
20 rows in set (0.00 sec)

鎴戜滑浣跨敤EXPLAIN鏉ユ鏌ヨ鏌ヨ鐨勬墽琛屾柟寮忥紙ID鍒楀凡琚垹闄わ紝浠ヤ究杈撳嚭鑳芥洿濂藉湴涓庨〉鍖归厤锛

mysql> EXPLAIN SELECT fid,AsText(g) FROM geom WHERE
mysql> MBRContains(GeomFromText('Polygon((30000 15000,31000 15000,31000 16000,30000 16000,30000 15000))'),g);
+-------------+-------+-------+---------------+------+---------+------+------+-------------+
| select_type | table | type  | possible_keys | key  | key_len | ref  | rows | Extra       |
+-------------+-------+-------+---------------+------+---------+------+------+-------------+
| SIMPLE      | geom  | range | g             | g    |      32 | NULL |   50 | Using where |
+-------------+-------+-------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)

璁╂垜浠鏌ヤ竴涓嬪湪娌℃湁绌洪棿绱㈠紩鐨勬儏鍐典笅浼氬嚭鐜颁粈涔堬細

mysql> EXPLAIN SELECT fid,AsText(g) FROM g IGNORE INDEX (g) WHERE
mysql> MBRContains(GeomFromText('Polygon((30000 15000,31000 15000,31000 16000,30000 16000,30000 15000))'),g);
+-------------+-------+------+---------------+------+---------+------+-------+-------------+
| select_type | table | type | possible_keys | key  | key_len | ref  | rows  | Extra       |
+-------------+-------+------+---------------+------+---------+------+-------+-------------+
| SIMPLE      | geom  | ALL  | NULL          | NULL |    NULL | NULL | 32376 | Using where |
+-------------+-------+------+---------------+------+---------+------+-------+-------------+
1 row in set (0.00 sec)

鎵цSELECT璇彞锛屽拷鐣绌洪棿閿細

mysql> SELECT fid,AsText(g) FROM geom IGNORE INDEX (g) WHERE
mysql> MBRContains(GeomFromText('Polygon((30000 15000,31000 15000,31000 16000,30000 16000,30000 15000))'),g);
+-----+-----------------------------------------------------------------------------+
| fid | AsText(g)                                                                   |
+-----+-----------------------------------------------------------------------------+
|   1 | LINESTRING(30250.4 15129.2,30248.8 15138.4,30238.2 15136.4,30240 15127.2)   |
|   2 | LINESTRING(30220.2 15122.8,30217.2 15137.8,30207.6 15136,30210.4 15121)     |
|   3 | LINESTRING(30179 15114.4,30176.6 15129.4,30167 15128,30169 15113)           |
|   4 | LINESTRING(30155.2 15121.4,30140.4 15118.6,30142 15109,30157 15111.6)       |
|   5 | LINESTRING(30192.4 15085,30177.6 15082.2,30179.2 15072.4,30194.2 15075.2)   |
|   6 | LINESTRING(30244 15087,30229 15086.2,30229.4 15076.4,30244.6 15077)         |
|   7 | LINESTRING(30200.6 15059.4,30185.6 15058.6,30186 15048.8,30201.2 15049.4)   |
|  10 | LINESTRING(30179.6 15017.8,30181 15002.8,30190.8 15003.6,30189.6 15019)     |
|  11 | LINESTRING(30154.2 15000.4,30168.6 15004.8,30166 15014.2,30151.2 15009.8)   |
|  13 | LINESTRING(30105 15065.8,30108.4 15050.8,30118 15053,30114.6 15067.8)       |
|  21 | LINESTRING(30350.4 15828.8,30350.6 15845,30333.8 15845,30333.8 15828.8)     |
|  22 | LINESTRING(30350.6 15871.4,30350.6 15887.8,30334 15887.8,30334 15871.4)     |
|  23 | LINESTRING(30350.6 15914.2,30350.6 15930.4,30334 15930.4,30334 15914.2)     |
|  24 | LINESTRING(30290.2 15823,30290.2 15839.4,30273.4 15839.4,30273.4 15823)     |
|  25 | LINESTRING(30291.4 15866.2,30291.6 15882.4,30274.8 15882.4,30274.8 15866.2) |
|  26 | LINESTRING(30291.6 15918.2,30291.6 15934.4,30275 15934.4,30275 15918.2)     |
| 154 | LINESTRING(30276.2 15143.8,30261.4 15141,30263 15131.4,30278 15134)         |
| 155 | LINESTRING(30269.8 15084,30269.4 15093.4,30258.6 15093,30259 15083.4)       |
| 157 | LINESTRING(30128.2 15011,30113.2 15010.2,30113.6 15000.4,30128.8 15001)     |
| 249 | LINESTRING(30337.8 15938.6,30337.8 15946.8,30320.4 15946.8,30320.4 15938.4) |
+-----+-----------------------------------------------------------------------------+
20 rows in set (0.46 sec)

鏈娇鐢ㄧ储寮曟椂锛岃鏌ヨ鐨勬墽琛屾椂闂村皢浠0.00绉掍笂鍗囧埌0.46绉掋

鍦ㄦ湭鏉ョ殑鐗堟湰涓紝绌洪棿绱㈠紩涔熷彲鑳戒細鐢ㄤ簬浼樺寲鍏朵粬鍑芥暟銆傝鍙傝19.5.4鑺傦紝鈥滄祴璇曞嚑浣曞璞¢棿绌洪棿鍏崇郴鐨勫嚱鏁扳

19.7. MySQL鐨勪竴鑷存у拰鍏煎鎬

19.7.1. 灏氭湭瀹炴柦鐨凣IS鐗规

  • 棰濆鐨勫厓鏁版嵁瑙嗗浘

    OpenGIS瑙勮寖寤鸿浜嗘暟绉嶉澶栫殑鍏冩暟鎹鍥俱備緥濡傦紝鍖呭惈鍑犱綍鍒楃殑鎻忚堪鐨勫悕涓GEOMETRY_COLUMNS鐨勭郴缁熻鍥撅紝瀵逛簬鏁版嵁搴撲腑鐨勬瘡鍒楁湁1琛岀浉鍏冲唴瀹广

  • 浣滅敤鍦LineStringMultiLineString涓婄殑OpenGIS鍑芥暟Length()鐩墠搴斿湪MySQL涓互GLength()鐨勬柟寮忚皟鐢ㄣ

    闂鍦ㄤ簬瀛樺湪1涓敤浜庤绠楀瓧绗︿覆鍊奸暱搴︾殑宸叉湁SQL鍑芥暟Length()锛岃屼笖鍦ㄦ煇浜涙儏鍐典笅鏃犳硶鍒ゆ柇鍑芥暟鏄湪鏂囨湰鍦烘櫙涓嬭繕鏄┖闂村満鏅笅璋冪敤鐨勩傛垜浠渶瑕佷互鏌愮鏂瑰紡瑙e喅璇ラ棶棰橈紝鎴栫‘瀹氬彟涓涓嚱鏁板悕銆


杩欐槸MySQL鍙傝冩墜鍐岀殑缈昏瘧鐗堟湰锛屽叧浜嶮ySQL鍙傝冩墜鍐岋紝璇疯闂dev.mysql.com銆傚師濮嬪弬鑰冩墜鍐屼负鑻辨枃鐗堬紝涓庤嫳鏂囩増鍙傝冩墜鍐岀浉姣旓紝鏈炕璇戠増鍙兘涓嶆槸鏈鏂扮殑銆