MySQL空间数据库学习
来源:互联网 发布:js字符串中间加逗号 编辑:程序博客网 时间:2024/06/06 12:57
MySQL支持的空间数据格式有WKT,WKB,数据类型有:POINT、LINESTRING、POLYGON、MULTIPOINT、MULTILINESTRING、MULTIPOLYGON、GEOMETRYCOLLECTION。
例如WKT格式如下:
POINT(15, 20)
LINESTRING(0 0, 10 10, 20 25, 50 60)
POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))
MULTIPOINT(0 0, 20 20, 60 60)
MULTILINESTRING((10 10, 20 20), (15 15, 30 15))
MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)),((5 5,7 5,7 7,5 7, 5 5)))
GEOMETRYCOLLECTION(POINT(10 10), POINT(30 30), LINESTRING(15 15, 20 20))
WKB格式则使用BLOB类型。
创建空间数据库:
create database spatialtest;
创建可以存储点、线、面的空间数据表:
create table t_geo(geo geometry);
创建存储点的空间数据表:
create table t_pt(pt point);
create table t_line(line linestring);
创建存储面的空间数据表:
create table t_polygon(poly polygon);
插入WKT数据测试:
insert into t_geo(geo) values(GeometryFromText('POINT(0 0)'));
insert into t_geo(geo) values(GeometryFromText('POLYGON((5 0.0,0.0 -5,-5 0,0.0 5,5 0.0))'));
insert into t_geo(geo) values(GeometryFromText('LINESTRING(10 0, 5 5, 9 8, -10 -10)'));
insert into t_pt(pt) values(GeometryFromText('POINT(0 2)'));
insert into t_line(line) values(GeometryFromText('LINESTRING(10 0, 5 5, 9 8, -10 -10)'));
insert into t_polygon(poly) values(GeometryFromText('POLYGON((5 0.0,0.0 -5,-5 0,0.0 5,5 0.0))'));
查询数据测试:
select Asbinary(pt) from t_pt;
select Astext(pt) from t_pt;
alter table t_pt add spatial index(pt);
返回错误:
The used table type doesn't support SPATIAL indexes
查询文档发现:Before MySQL 5.0.16, these features are available for
MyISAM
tables only. As of MySQL 5.0.16, InnoDB
, NDB
,BDB
, and ARCHIVE
also support spatial features.所以需要执行如下语句:
ALTER TABLE `spatialtest`.`t_geo` ENGINE = MyISAM ;
然后在执行创建空间索引则返回成功。
参考:http://dev.mysql.com/doc/refman/5.0/en/spatial-extensions.html
0 0
- MySQL空间数据库学习
- Mysql gis 空间数据库功能详解学习
- Mysql gis 空间数据库功能详解学习
- MySQL作为空间数据库
- mysql 空间数据库使用
- mysql空间数据库
- 查看mysql数据库空间大小
- 【Mysql】Mysql数据库查询“表空间”
- MYSQL:查看的数据库表空间
- 使用MySql数据库创建表空间,日志
- 查看MYSQL数据库占用空间大小
- 查看MYSQL的数据库表空间
- mysql 空间数据库中的各个方法函数
- 查看MYSQL数据库的占用空间
- 查看mysql数据库空间使用情况
- MySql GIS 空间数据库使用体验
- 学习数据库之MySql数据库
- MYSQL数据库学习----MYSQL数据类型
- 使用BeginInvoke和EndInvoke进行异步调用的四种常用方法
- Activiti5 两种乱码问题解决方案
- SQL中的关于字符类型的自我总结
- Windows 7、Windows Server 2008等系统音频系统底层API
- 你的博客,写给谁人看
- MySQL空间数据库学习
- 产品经理装逼指南
- 缓存淘汰算法之LRU
- 一千行MySQL学习笔记
- 【Android动画】之Tween动画 (渐变、缩放、位移、旋转)
- AFNetwork 作用和用法详解
- poj1797--Dijkstra变化
- oracle sql 批量更新 [转]
- 控制uibutton图标与标题的上下位置