VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 数据库 > MySQL >
  • Mysql空间数据&空间索引(spatial)(5)

         30000 15000))';
mysql> EXPLAIN SELECT fid,ST_AsText(g) FROM geom WHERE
    -> MBRContains(ST_GeomFromText(@poly),g)\G
*************************** 1. row ***************************
          id: 1
  select_type: SIMPLE
       table: geom
        type: range
possible_keys: g
         key: g
      key_len: 32
         ref: NULL
        rows: 50
       Extra: Using where
1 row in set (0.00 sec)
 
如果不使用空间索引的情况:
 
mysql> SET @poly =
    -> 'Polygon((30000 15000,
               31000 15000,
               31000 16000,
               30000 16000,
               30000 15000))';
mysql> EXPLAIN SELECT fid,ST_AsText(g) FROM g IGNORE INDEX (g) WHERE
    -> MBRContains(ST_GeomFromText(@poly),g)\G
*************************** 1. row ***************************
          id: 1
  select_type: SIMPLE
       table: geom
        type: ALL
possible_keys: NULL
         key: NULL
      key_len: NULL
         ref: NULL
        rows: 32376
       Extra: Using where
1 row in set (0.00 sec)
 
  执行不带空间索引的SELECT语句仍然获得了相同的数据但导致执行时间从0.00 增加到 0.46 秒:
 
mysql> SET @poly =
    -> 'Polygon((30000 15000,
               31000 15000,
               31000 16000,
               30000 16000,
               30000 15000))';
mysql> SELECT fid,ST_AsText(g) FROM geom IGNORE INDEX (g) WHERE
    -> MBRContains(ST_GeomFromText(@poly),g);
+-----+---------------------------------------------------------------+
| fid | ST_AsText(g)                                          |
+-----+---------------------------------------------------------------+
|   1 | LINESTRING(30250.4 15129.2,30248.8 15138.4,30238.2 15136. ... |
|   2 | LINESTRING(30220.2 15122.8,30217.2 15137.8,30207.6 15136, ... |
|   3 | LINESTRING(30179 15114.4,30176.6 15129.4,30167 15128,3016 ... |
|   4 | LINESTRING(30155.2 15121.4,30140.4 15118.6,30142 15109,30 ... |
|   5 | LINESTRING(30192.4 15085,30177.6 15082.2,30179.2 15072.4, ... |
|   6 | LINESTRING(30244 15087,30229 15086.2,30229.4 15076.4,3024 ... |
|   7 | LINESTRING(30200.6 15059.4,30185.6 15058.6,30186 15048.8, ... |
|  10 | LINESTRING(30179.6 15017.8,30181 15002.8,30190.8 15003.6, ... |
|  11 | LINESTRING(30154.2 15000.4,30168.6 15004.8,30166 15014.2, ... |
|  13 | LINESTRING(30105 15065.8,30108.4 15050.8,30118 15053,3011 ... |
|  21 | LINESTRING(30350.4 15828.8,30350.6 15845,30333.8 15845,30 ... |
|  22 | LINESTRING(30350.6 15871.4,30350.6 15887.8,30334 15887.8, ... |
|  23 | LINESTRING(30350.6 15914.2,30350.6 15930.4,30334 15930.4, ... |
|  24 | LINESTRING(30290.2 15823,30290.2 15839.4,30273.4 15839.4, ... |
|  25 | LINESTRING(30291.4 15866.2,30291.6 15882.4,30274.8 15882. ... |
|  26 | LINESTRING(30291.6 15918.2,30291.6 15934.4,30275 15934.4, ... |
| 154 | LINESTRING(30276.2 15143.8,30261.4 15141,30263 15131.4,30 ... |
| 155 | LINESTRING(30269.8 15084,30269.4 15093.4,30258.6 15093,30 ... |
| 157 | LINESTRING(30128.2 15011,30113.2 15010.2,30113.6 15000.4, ... |
| 249 | LINESTRING(30337.8 15938.6,30337.8 15946.8,30320.4 15946. ... |
+-----+---------------------------------------------------------------+
20 rows in set (0.46 sec)
 
 

13.15 Spatial Analysis Functions

     

MySQL提供了在空间数据上执行各种操作的函数。根据操作的类型这些函数可以被分成几个大类
  • 创建各种格式几何图形函数 (WKT, WKB, internal)
  • 几何图形格式之间的转换函数
  • 几何的定性或定量属性的访问函数
  • 描述两个图形之间的关系函数
  •  从现有的创建新的几何图形函数

 

13.15.1 Spatial Function Reference

The following table lists each spatial function and provides a short description of each one.

Table 13.19 Spatial Functions

Name Description
Area() (弃用 5.7.6) Return Polygon or MultiPolygon area
AsBinary(), AsWKB() (弃用5.7.6) Convert from internal geometry format to WKB
AsText(), AsWKT() (弃用 5.7.6) Convert from internal geometry format to WKT
Buffer() (弃用5.7.6) Return geometry of points within given distance from geometry
Centroid() (弃用5.7.6) Return centroid as a point
Contains() (弃用5.7.6) Whether MBR of one geometry contains MBR of another
ConvexHull() (弃用5.7.6) Return convex hull of geometry
Crosses() (弃用5.7.6) Whether one geometry crosses another
Dimension() (弃用5.7.6) Dimension of geometry
Disjoint() (弃用5.7.6) Whether MBRs of two geometries are disjoint
Distance() (弃用5.7.6) The distance of one geometry from another
EndPoint() (弃用5.7.6) End Point of LineString
Envelope() (弃用 5.7.6) Return MBR of geometry
Equals() (弃用 5.7.6) Whether MBRs of two geometries are equal
ExteriorRing() (弃用5.7.6) Return exterior ring of Polygon
GeomCollFromText(), GeometryCollectionFromText() (弃用5.7.6) Return geometry collection from WKT
GeomCollFromWKB(), GeometryCollectionFromWKB() (弃用5.7.6) Return geometry collection from WKB
GeometryCollection()
从几何图形构造几何图形集合
GeometryN() (弃用5.7.6) Return N-th geometry from geometry collection
GeometryType() (弃用5.7.6) Return name of geometry type
GeomFromText(), GeometryFromText() (弃用5.7.6) Return geometry from WKT
GeomFromWKB(), GeometryFromWKB() (弃用5.7.6) Return geometry from WKB
GLength() (弃用5.7.6) Return length of LineString
InteriorRingN() (弃用5.7.6) Return N-th interior ring of Polygon
Intersects() (弃用5.7.6) Whether MBRs of two geometries intersect
IsClosed() (弃用5.7.6) Whether a geometry is closed and simple
IsEmpty() (弃用5.7.6) Placeholder function
IsSimple() (弃用5.7.6) Whether a geometry is simple
LineFromText(), LineStringFromText() (弃用5.7.6) Construct LineString from WKT
LineFromWKB(), LineStringFromWKB() (弃用5.7.6) Construct LineString from WKB
LineString()

构造 LineString from Point values

MBRContains() 一个几何的MBR包含了另一个的MBR
MBRCoveredBy() 一个MBR是否被另一个覆盖
MBRCovers() 一个MBR是否覆盖了另一个
MBRDisjoint() 两个几何体的MBR是否分离
MBREqual() (弃用 5.7.6) Whether MBRs of two geometries are equal
MBREquals() 两个几何体的MBR是否相同
MBRIntersects() 两个几何体的MBR是否相交
MBROverlaps() 两个几何体的MBR是否重叠
MBRTouches() 两个几何体的MBR是否触碰
MBRWithin() 一个几何体的MBR是否在另一个的MBR里面
MLineFromText(), MultiLineStringFromText() (deprecated 5.7.6) Construct MultiLineString from WKT
MLineFromWKB(), MultiLineStringFromWKB() (deprecated 5.7.6) Construct MultiLineString from WKB
MPointFromText(), MultiPointFromText() (deprecated 5.7.6) Construct MultiPoint from WKT
MPointFromWKB(), MultiPointFromWKB() (deprecated 5.7.6) Construct MultiPoint from WKB
MPolyFromText(), MultiPolygonFromText() (deprecated 5.7.6) Construct MultiPolygon from WKT
MPolyFromWKB(), MultiPolygonFromWKB() (deprecated 5.7.6) Construct MultiPolygon from WKB
MultiLineString() Contruct MultiLineString from LineString values
MultiPoint() Construct MultiPoint from Point values
MultiPolygon() Construct MultiPolygon from Polygon values
NumGeometries() (deprecated 5.7.6) Return number of geometries in geometry collection
NumInteriorRings() (deprecated 5.7.6) Return number of interior rings in Polygon
NumPoints() (deprecated 5.7.6) Return number of points in LineString
Overlaps() (deprecated 5.7.6) Whether MBRs of two geometries overlap
Point() Construct Point from coordinates
PointFromText() (deprecated 5.7.6) Construct Point from WKT
PointFromWKB() (deprecated 5.7.6) Construct Point from WKB
PointN() (deprecated 5.7.6) Return N-th point from LineString
PolyFromText(), PolygonFromText() (deprecated 5.7.6) Construct Polygon from WKT
PolyFromWKB(), PolygonFromWKB() (deprecated 5.7.6) Construct Polygon from WKB
Polygon() Construct Polygon from LineString arguments
SRID() (deprecated 5.7.6) Return spatial reference system ID for geometry
ST_Area() 返回 Polygon or MultiPolygon 范围
ST_AsBinary(), ST_AsWKB() 将内部格式转换成WKB
ST_AsGeoJSON() 从几何体中生成GeoJSON
ST_AsText(), ST_AsWKT() 将内部格式转换成WKT
ST_Buffer() 返回给定几何体给定距离内的几何体的点
ST_Buffer_Strategy() ST_Buffer()生成策略选项
ST_Centroid() 返回几何中心点
ST_Contains() 是否一个几何体包含另外一个
ST_ConvexHull() Return convex hull of geometry
ST_Crosses() 是否一个几何体和其他的交叉
ST_Difference() 返回两个几何体不同的点集合
ST_Dimension() 几何体维度
ST_Disjoint() 一个几何体是否和另一个分离
ST_Distance() 两个几何体的距离
ST_Distance_Sphere() 两个几何体在地球上的最小距离
ST_EndPoint() 返回LineString的结束点
ST_Envelope() 返回几何体MBR
ST_Equals() 两个几何体是否相等
ST_ExteriorRing() 返回Polygon的外部圈
ST_GeoHash() 生成geohash值
ST_GeomCollFromText(), ST_GeometryCollectionFromText(), ST_GeomCollFromTxt() 返回从 WKT生成的几何体集合
ST_GeomCollFromWKB(), ST_GeometryCollectionFromWKB() 返回从 WKB生成的几何体集合
ST_GeometryN() 返回集合中第N个几何体
ST_GeometryType() 返回几何体类型
ST_GeomFromGeoJSON() 从GeoJSON对象生成几何体
ST_GeomFromText(), ST_GeometryFromText() 从 WKT返回几何体
ST_GeomFromWKB(), ST_GeometryFromWKB() 从WKB返回几何体
ST_InteriorRingN() 返回Polygon的第N个内部环
ST_Intersection() 返回两个几何体的交叉点集合
ST_Intersects() 一个几何体是否和另一个交叉
ST_IsClosed() 一个几何体是否是simple且closed
ST_IsEmpty() Placeholder function
ST_IsSimple() Whether a geometry is simple
ST_IsValid() Whether a geometry is valid
ST_LatFromGeoHash() 从geohash返回纬度
ST_Length() Return length of LineString
ST_LineFromText(), ST_LineStringFromText() Construct LineString from WKT
ST_LineFromWKB(), ST_LineStringFromWKB() Construct LineString from WKB
ST_LongFromGeoHash() 从geohash返回经度
ST_MakeEnvelope() 两点之间的矩形
ST_MLineFromText(), ST_MultiLineStringFromText() Construct MultiLineString from WKT
ST_MLineFromWKB(), ST_MultiLineStringFromWKB() Construct MultiLineString from WKB
ST_MPointFromText(), ST_MultiPointFromText() Construct MultiPoint from WKT
ST_MPointFromWKB(), ST_MultiPointFromWKB() Construct MultiPoint from WKB
ST_MPolyFromText(), ST_MultiPolygonFromText() Construct MultiPolygon from WKT
ST_MPolyFromWKB(), ST_MultiPolygonFromWKB() Construct MultiPolygon from WKB
ST_NumGeometries() 返回集合中的几何体个数
ST_NumInteriorRing(), ST_NumInteriorRings()  返回Polygon内部环的个数
ST_NumPoints() 返回LineString中点的个数
ST_Overlaps() 是否一个几何体和另一个重叠
ST_PointFromGeoHash() 从geohash转换成POINT值
ST_PointFromText() 从WKT生成POINT
ST_PointFromWKB() 从WKB生成POINT
ST_PointN() 返回LineString的第N点
ST_PolyFromText(), ST_PolygonFromText() Construct Polygon from WKT
ST_PolyFromWKB(), ST_PolygonFromWKB() Construct Polygon from WKB
ST_Simplify() 返回简化的几何体
ST_SRID() 返回几何体的空间关系系统ID
ST_StartPoint() LineString的开始点
ST_SymDifference() Return point set symmetric difference of two geometries
ST_Touches() 一个几何体是否触碰到另一个
ST_Union() 返回两个几何体所有点的联合集合
ST_Validate() Return validated geometry
ST_Within() 一个几何体是否在另一个中
ST_X() 返回点的X坐标
ST_Y() 返回点的Y坐标
StartPoint() (deprecated 5.7.6) Start Point of LineString
Touches() (deprecated 5.7.6) Whether one geometry touches another
Within() (deprecated 5.7.6) Whether MBR of one geometry is within MBR of another
X() (deprecated 5.7.6) Return X coordinate of Point
Y() (deprecated 5.7.6) Return Y coordinate of Point