06年10月16日
需求:公司现在gis系统有大量的经纬度坐标,都是车辆行驶几个月采集过来的坐标。现在在做区域搜索功能(就是在上个月某个时间内车辆在哪里行驶)。因为现在数据库单个车辆的经纬度坐标太多,所以搜索起来非常慢(让人忍受不了的速度),随着时间的推移,可能搜索起来会越来越慢,所以公司决定考虑使用mysql的空间数据库特性。把经纬度坐标都转移到成空间数据库坐标.
公司使用mysql4.1.2,
参考资料:
官方中文资料: http://dev.mysql.com/doc/refman/5.1/zh/spatial-extensions-in-mysql.html#gis-class-polygon
说明:这是本人学习mysql的空间数据库特性时候解决的一些问题和和对一些问题的看法,肯定有错误的地方,希望看到这篇文章的朋友能够多多指教,给我留言。
06年10月18日 4 如何判断已有的经纬度点在某一区域内?
在mysal4.1官方的文档找到下列函数,应该就是解决问题4的
Relations on Geometry Minimal Bounding Rectangles (MBRs) MySQL provides several functions that test relations between minimal bounding rectangles of two geometries g1 and g2. The return values 1 and 0 indicate true and false, respectively. Returns 1 or 0 to indicate whether the Minimum Bounding Rectangle of g1 contains the Minimum Bounding Rectangle of 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 | +----------------------+----------------------+ Returns 1 or 0 to indicate whether the Minimum Bounding Rectangles of the two geometries g1 and g2 are disjoint (do not intersect). Returns 1 or 0 to indicate whether the Minimum Bounding Rectangles of the two geometries g1 and g2 are the same. Returns 1 or 0 to indicate whether the Minimum Bounding Rectangles of the two geometries g1 and g2 intersect. Returns 1 or 0 to indicate whether the Minimum Bounding Rectangles of the two geometries g1 and g2 overlap. Returns 1 or 0 to indicate whether the Minimum Bounding Rectangles of the two geometries g1 and g2 touch. Returns 1 or 0 to indicate whether the Minimum Bounding Rectangle of g1 is within the Minimum Bounding Rectangle of 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 | +--------------------+--------------------+
现在我需要的功能是查找一辆车在某一段时间内是否在一段区域内经过,用点来说明的话,就是一个空间坐标点在一个特定时间段内是否包含在一个特定的矩形区域内。下面这个函数应该能达到这个功能:
Returns 1 or 0 to indicate whether the Minimum Bounding Rectangle of g1 is within the Minimum Bounding Rectangle of g2.
晕,突然发现官方有中文的文档,不用看洋文了!!! http://dev.mysql.com/doc/refman/5.1/zh/spatial-extensions-in-mysql.html#gis-class-polygon
下面是文档中解决问题4的方法。
在geom有6个点,现在构造一个Polygon((2.1 2.1,2.1 3.1,2.1 3.1,3.1 3.1))
|