{"id":2039,"date":"2020-07-29T23:22:05","date_gmt":"2020-07-29T15:22:05","guid":{"rendered":"http:\/\/39.97.231.10\/?p=2039"},"modified":"2020-07-29T23:22:05","modified_gmt":"2020-07-29T15:22:05","slug":"mysql%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b-%e5%9c%b0%e7%90%86%e7%a9%ba%e9%97%b4%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=2039","title":{"rendered":"MySQL\u6570\u636e\u7c7b\u578b-\u5730\u7406\u7a7a\u95f4\u6570\u636e\u7c7b\u578b"},"content":{"rendered":"<div class=\\\"blog_title\\\">\n<h2><span style=\\\"color: #000000; font-size: 1rem;\\\">MySQL\u652f\u6301\u5730\u7406\u7a7a\u95f4\u6570\u636e\u7684\u5b58\u50a8\uff0c\u57fa\u4e8eGIS\u7684\u76f8\u5173\u7406\u8bba\uff0cMySQL\u63d0\u4f9b\u4e86\u914d\u5957\u7684\u6570\u636e\u7c7b\u578b\u3001\u5185\u90e8\u5b58\u50a8\u683c\u5f0f\u3001\u5206\u6790\u51fd\u6570\u548c\u7a7a\u95f4\u7d22\u5f15\uff0c\u80fd\u591f\u9ad8\u6548\u5730\u5b58\u50a8\u3001\u67e5\u8be2\u5730\u7406\u7a7a\u95f4\u6570\u636e\u3002<\/span><\/h2>\n<\/div>\n<div class=\\\"blog_content\\\">\n<div class=\\\"blog_detail\\\">\n<div><\/div>\n<div><b>1\u3001MySQL\u5730\u7406\u7a7a\u95f4\u6570\u636e\u7c7b\u578b<\/b><\/div>\n<div><b>\u00a0<\/b><\/div>\n<ul>\n<li>\n<div>POINT\uff0c\u5b58\u50a8\u4e00\u4e2a\u4f4d\u7f6e\u70b9\u6570\u636e<\/div>\n<\/li>\n<li>\n<div>LINESTRING\uff0c\u5b58\u50a8\u4e00\u6761\u7ebf\u6570\u636e<\/div>\n<\/li>\n<li>\n<div>POLYGON\uff0c\u5b58\u50a8\u4e00\u4e2a\u591a\u8fb9\u5f62\u6570\u636e<\/div>\n<\/li>\n<li>\n<div>MULTIPOINT\uff0c\u5b58\u50a8\u591a\u4e2a\u4f4d\u7f6e\u70b9\u6570\u636e<\/div>\n<\/li>\n<li>\n<div>MULTILINESTRING\uff0c\u5b58\u50a8\u591a\u6761\u7ebf\u6570\u636e<\/div>\n<\/li>\n<li>\n<div>MULTIPOLYGON\uff0c\u5b58\u50a8\u591a\u4e2a\u591a\u8fb9\u5f62\u6570\u636e<\/div>\n<\/li>\n<li>\n<div>GEOMETRY\uff0c\u53ef\u4ee5\u5b58\u50a8\u4efb\u4f55POINT\uff0cLINESTRING\uff0cPOLYGON \u7684\u6570\u636e<\/div>\n<\/li>\n<li>\n<div>GEOMETRYCOLLECTION\uff0c\u53ef\u4ee5\u5b58\u50a8\u4efb\u4f55\u7a7a\u95f4\u6570\u636e\u7c7b\u578b\u7684\u96c6\u5408<\/div>\n<\/li>\n<\/ul>\n<div><\/div>\n<div>\u521b\u5efa\u4e00\u4e2a\u5e26\u6709\u7a7a\u95f4\u6570\u636e\u7c7b\u578b\u7684\u8868\uff1a<\/div>\n<div>CREATE TABLE geom (g GEOMETRY NOT NULL);<\/div>\n<div><\/div>\n<div>\u63d2\u5165\u7a7a\u95f4\u6570\u636e\uff1a<\/div>\n<div>INSERT INTO geom VALUES (ST_GeomFromText(\\&#8217;POINT(1 1)\\&#8217;));<\/div>\n<div><\/div>\n<div>\u67e5\u8be2\u7a7a\u95f4\u6570\u636e\uff1a<\/div>\n<div>SELECT ST_AsText(g) FROM geom;<\/div>\n<div>\u67e5\u8be2\u65f6\u8981\u52a0\u4e0aST_AsText()\u51fd\u6570\uff0c\u5c06\u7a7a\u95f4\u6570\u636e\u4ee5WKT\u6587\u672c\u683c\u5f0f\u663e\u793a\u51fa\u6765\uff0c\u5982\u679c\u4e0d\u7528ST_AsText()\u51fd\u6570\u8f6c\u6362\uff0c\u90a3\u4e48\u67e5\u8be2\u51fa\u6765\u7684\u7a7a\u95f4\u6570\u636e\u5c06\u662f\u4e00\u4e32\u4e8c\u8fdb\u5236\u7b26\u53f7\uff0c\u65e0\u6cd5\u9605\u8bfb\u3002<\/div>\n<div><\/div>\n<div><b>2\u3001MySQL\u652f\u6301\u7684\u5730\u7406\u7a7a\u95f4\u6570\u636e\u683c\u5f0f<\/b><\/div>\n<div><\/div>\n<div>\u5730\u7406\u7a7a\u95f4\u6570\u636e\u901a\u5e38\u4ee5\u6587\u672c\u65b9\u5f0f\u6765\u63cf\u8ff0\uff0c\u6bd4\u5982\u4e00\u4e2a\u70b9\u53ef\u4ee5\u63cf\u8ff0\u4e3a POINT(15 20)\uff0c\u518d\u4f7f\u7528 ST_GeomFromText()\u51fd\u6570\u5c06\u6587\u672c\u8f6c\u6210MySQL\u5185\u90e8\u7684\u5730\u7406\u7a7a\u95f4\u6570\u636e\uff0c\u4e0b\u9762\u5217\u51fa\u5e38\u7528\u7684\u5730\u7406\u7a7a\u95f4\u6570\u636e\u8868\u793a\u65b9\u6cd5\u3002<\/div>\n<div><\/div>\n<div><b>POINT\uff1a<\/b><\/div>\n<div>SELECT ST_GeomFromText(\\&#8217;POINT(15 20)\\&#8217;);<\/div>\n<div><\/div>\n<div><b>LINESTRING\uff1a<\/b><\/div>\n<div>SELECT ST_GeomFromText(\\&#8217;LINESTRING(0 0, 10 10, 20 25, 50 60)\\&#8217;);<\/div>\n<div>SELECT ST_LineStringFromText(\\&#8217;LINESTRING(0 0, 10 10, 20 25, 50 60)\\&#8217;);<\/div>\n<div><\/div>\n<div><b>POLYGON\uff1a<\/b><\/div>\n<div>SELECT ST_GeomFromText(\\&#8217;POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))\\&#8217;);<\/div>\n<div>SELECT ST_PolygonFromText(\\&#8217;POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))\\&#8217;);<\/div>\n<div><\/div>\n<div><b>MULTIPOINT\uff1a<\/b><\/div>\n<div>SELECT ST_MPointFromText(\\&#8217;MULTIPOINT (1 1, 2 2, 3 3)\\&#8217;);<\/div>\n<div>SELECT ST_MPointFromText(\\&#8217;MULTIPOINT ((1 1), (2 2), (3 3))\\&#8217;);<\/div>\n<div><\/div>\n<div><b>MULTILINESTRING\uff1a<\/b><\/div>\n<div>SELECT ST_GeomFromText(\\&#8217;MULTILINESTRING((10 10, 20 20), (15 15, 30 15))\\&#8217;);<\/div>\n<div><\/div>\n<div><b>MULTIPOLYGON\uff1a<\/b><\/div>\n<div>SELECT ST_GeomFromText(\\&#8217;MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)),((5 5,7 5,7 7,5 7, 5 5)))\\&#8217;);<\/div>\n<div><\/div>\n<div><b>GEOMETRYCOLLECTION\uff1a<\/b><\/div>\n<div>SELECT ST_GeomFromText(\\&#8217;GEOMETRYCOLLECTION(POINT(10 10), POINT(30 30), LINESTRING(15 15, 20 20))\\&#8217;);<\/div>\n<div>SELECT ST_GeomCollFromText(\\&#8217;GEOMETRYCOLLECTION(POINT(10 10), POINT(30 30), LINESTRING(15 15, 20 20))\\&#8217;);<\/div>\n<div><\/div>\n<div><b>3\u3001MySQL\u5730\u7406\u7a7a\u95f4\u7d22\u5f15<\/b><\/div>\n<div><\/div>\n<div>\u521b\u5efa\u7a7a\u95f4\u7d22\u5f15\u7684\u5b57\u6bb5\u5fc5\u987b\u4e3aNOT NULL\uff0c\u5426\u5219\u521b\u5efa\u7a7a\u95f4\u7d22\u5f15\u62a5\u9519\u3002<\/div>\n<div><\/div>\n<div>\u521b\u5efa\u8868\u7684\u540c\u65f6\u521b\u5efa\u7a7a\u95f4\u7d22\u5f15\uff1a<\/div>\n<div>CREATE TABLE geom (g GEOMETRY NOT NULL, SPATIAL INDEX(g));<\/div>\n<div><\/div>\n<div>ALTER TABLE\u65b9\u5f0f\u521b\u5efa\u7a7a\u95f4\u7d22\u5f15\uff1a<\/div>\n<div>CREATE TABLE geom (g GEOMETRY NOT NULL);<\/div>\n<div>ALTER TABLE geom ADD SPATIAL INDEX(g);<\/div>\n<div><\/div>\n<div>\u5220\u9664\u7a7a\u95f4\u7d22\u5f15\uff1a<\/div>\n<div>ALTER TABLE geom DROP INDEX g;<\/div>\n<div><\/div>\n<div><\/div>\n<div>\u521b\u5efa\u597d\u7d22\u5f15\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u5728\u4e00\u4e9b\u7a7a\u95f4\u67e5\u8be2\u51fd\u6570\u4e2d\u4f7f\u7528\u7d22\u5f15\uff0c\u6bd4\u5982 MBRContains()\uff0c MBRWithin()<\/div>\n<div><\/div>\n<div>\u4f8b\u5982\uff1a<\/div>\n<div>\n<div>mysql&gt; SET @poly = \\&#8217;Polygon((30000 15000, 31000 15000, 31000 16000, 30000 16000, 30000 15000))\\&#8217;;<\/div>\n<div>mysql&gt; SELECT fid,ST_AsText(g) FROM geom WHERE MBRContains(ST_GeomFromText(@poly),g);<\/div>\n<\/div>\n<div><\/div>\n<div>\u4e5f\u53ef\u4ee5\u4f7f\u7528explain \u6765\u67e5\u770bselect\u7a7a\u95f4\u67e5\u8be2\u6709\u6ca1\u6709\u8d70\u7a7a\u95f4\u7d22\u5f15\uff0c\u7528\u6cd5\u4e0e\u666e\u901a\u7d22\u5f15\u7c7b\u4f3c\uff0c\u4e0d\u518d\u8d58\u8ff0\u3002<\/div>\n<div><\/div>\n<div><\/div>\n<div><b>4\u3001MySQL\u4e2d\u5e38\u7528\u7684\u5730\u7406\u7a7a\u95f4\u51fd\u6570<\/b><\/div>\n<div><\/div>\n<div>MySQL\u63d0\u4f9b\u4e86\u5f88\u591a\u5730\u7406\u7a7a\u95f4\u6570\u636e\u76f8\u5173\u7684\u51fd\u6570\uff0c\u5305\u62ec\u5730\u7406\u7a7a\u95f4\u5bf9\u8c61\u6784\u9020\u51fd\u6570\uff0c\u5730\u7406\u7a7a\u95f4\u5206\u6790\u51fd\u6570\u7b49\u7b49\uff0c\u79cd\u7c7b\u975e\u5e38\u4e30\u5bcc\uff0c\u80fd\u591f\u5b9e\u73b0\u5404\u79cd\u590d\u6742\u7684\u5730\u7406\u7a7a\u95f4\u5e94\u7528\u3002\u6bd4\u5982<\/div>\n<div><\/div>\n<div>\u67e5\u8be2\u4e24\u4e2a\u5730\u7406\u5bf9\u8c61\u4e4b\u95f4\u7684\u8ddd\u79bb\uff0c\u53ef\u4f7f\u7528\u51fd\u6570 ST_Distance()\u3002<\/div>\n<div>\u5224\u65ad\u4e24\u4e2a\u5730\u7406\u5bf9\u8c61\u662f\u5426\u6709\u5305\u542b\u5173\u7cfb\uff0c\u53ef\u4f7f\u7528\u51fd\u6570 ST_Contains()\u3002<\/div>\n<div>\u5224\u65ad\u4e00\u4e2a\u5730\u7406\u5bf9\u8c61\u662f\u5426\u7a7f\u8fc7\u53e6\u5916\u4e00\u4e2a\u5730\u7406\u5bf9\u8c61\uff0c\u53ef\u4f7f\u7528\u51fd\u6570 ST_Crosses()\u3002<\/div>\n<div>\u5224\u65ad\u4e24\u4e2a\u5730\u7406\u5bf9\u8c61\u662f\u5426\u76f8\u4ea4\uff0c\u53ef\u4f7f\u7528\u51fd\u6570 ST_Intersects()\u3002<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>MySQL\u652f\u6301\u5730\u7406\u7a7a\u95f4\u6570\u636e\u7684\u5b58\u50a8\uff0c\u57fa\u4e8eGIS\u7684\u76f8\u5173\u7406\u8bba\uff0cMySQL\u63d0\u4f9b\u4e86\u914d\u5957\u7684\u6570\u636e\u7c7b\u578b\u3001\u5185\u90e8\u5b58\u50a8\u683c\u5f0f\u3001\u5206\u6790\u51fd\u6570 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=2039\"> <span class=\"screen-reader-text\">MySQL\u6570\u636e\u7c7b\u578b-\u5730\u7406\u7a7a\u95f4\u6570\u636e\u7c7b\u578b<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[90,88],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"MySQL\u652f\u6301\u5730\u7406\u7a7a\u95f4\u6570\u636e\u7684\u5b58\u50a8\uff0c\u57fa\u4e8eGIS\u7684\u76f8\u5173\u7406\u8bba\uff0cMySQL\u63d0\u4f9b\u4e86\u914d\u5957\u7684\u6570\u636e\u7c7b\u578b\u3001\u5185\u90e8\u5b58\u50a8\u683c\u5f0f\u3001\u5206\u6790\u51fd\u6570&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/2039"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2039"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/2039\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2039"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}