Geohash is a system for encoding latitude and longitude coordinates of arbitrary precision into a text string. Geohash是一种将任意精度的经纬度坐标编码为文本字符串的系统。Geohash values are strings that contain only characters chosen from Geohash值是仅包含从“0123456789bcdefghjkmnpqrstuvwxyz”中选择的字符的字符串。"0123456789bcdefghjkmnpqrstuvwxyz"
.
The functions in this section enable manipulation of geohash values, which provides applications the capabilities of importing and exporting geohash data, and of indexing and searching geohash values.本节中的函数支持geohash值的操作,这为应用程序提供了导入和导出geohash数据以及索引和搜索geohash值的功能。
Unless otherwise specified, functions in this section handle their geometry arguments as follows:除非另有规定,否则本节中的函数按如下方式处理其几何参数:
If any argument is 如果任何参数为NULL
, the return value is NULL
.NULL
,则返回值为NULL
。
If any argument is invalid, an error occurs.如果任何参数无效,则会发生错误。
If any argument has a longitude or latitude that is out of range, an error occurs:如果任何参数的经度或纬度超出范围,则会发生错误:
If a longitude value is not in the range (−180, 180], an 如果经度值不在范围(-180,180]内,则会发生ER_GEOMETRY_PARAM_LONGITUDE_OUT_OF_RANGE
error occurs (ER_LONGITUDE_OUT_OF_RANGE
prior to MySQL 8.0.12).ER_GEOMETRY_PARAM_LONGITUDE_OUT_OF_RANGE
错误(在MySQL 8.0.12之前发生ER_LONGITUDE_OUT_OF_RANGE
错误)。
If a latitude value is not in the range [−90, 90], an 如果纬度值不在范围[-90,90]内,则会发生ER_GEOMETRY_PARAM_LATITUDE_OUT_OF_RANGE
error occurs (ER_LATITUDE_OUT_OF_RANGE
prior to MySQL 8.0.12).ER_GEOMETRY_PARAM_LATITUDE_OUT_OF_RANGE
错误(在MySQL 8.0.12之前发生ER_LATITUDE_OUT_OF_RANGE
错误)。
Ranges shown are in degrees. 显示的范围以度为单位。The exact range limits deviate slightly due to floating-point arithmetic.由于采用浮点运算,精确的范围限制略有偏差。
If any point argument does not have SRID 0 or 4326, an 如果任何点参数没有SRID 0或4326,则会发生ER_SRS_NOT_FOUND
error occurs. ER_SRS_NOT_FOUND
错误。不检查point
argument SRID validity is not checked.point
参数SRID有效性。
If any SRID argument refers to an undefined spatial reference system (SRS), an 如果任何SRID参数引用未定义的空间参考系(SRS),则会发生ER_SRS_NOT_FOUND
error occurs.ER_SRS_NOT_FOUND
错误。
If any SRID argument is not within the range of a 32-bit unsigned integer, an 如果任何SRID参数不在32位无符号整数的范围内,则会发生ER_DATA_OUT_OF_RANGE
error occurs.ER_DATA_OUT_OF_RANGE
错误。
Otherwise, the return value is non-否则,返回值为非NULL
.NULL
。
These geohash functions are available:这些geohash函数可用:
ST_GeoHash(
, longitude
, latitude
, max_length
)ST_GeoHash(
point
, max_length
)
Returns a geohash string in the connection character set and collation.返回连接字符集和排序规则中的geohash字符串。
For the first syntax, the 对于第一种语法,longitude
must be a number in the range [−180, 180], and the latitude
must be a number in the range [−90, 90]. longitude
必须是[180,180]范围内的数字,latitude
必须是[90,90]范围内的数字。For the second syntax, a 对于第二种语法,需要一个POINT
value is required, where the X and Y coordinates are in the valid ranges for longitude and latitude, respectively.Point
值,其中X和Y坐标分别位于经度和纬度的有效范围内。
The resulting string is no longer than 结果字符串的长度不超过max_length
characters, which has an upper limit of 100. max_length
字符,上限为100。The string might be shorter than 字符串可能短于max_length
characters because the algorithm that creates the geohash value continues until it has created a string that is either an exact representation of the location or max_length
characters, whichever comes first.max_length
字符,因为创建geohash值的算法将继续,直到它创建了一个精确表示位置或max_length
字符的字符串(以先到者为准)。
ST_GeoHash()
handles its arguments as described in the introduction to this section.ST_GeoHash()
处理其参数,如本节简介中所述。
mysql> SELECT ST_GeoHash(180,0,10), ST_GeoHash(-180,-90,15);
+----------------------+-------------------------+
| ST_GeoHash(180,0,10) | ST_GeoHash(-180,-90,15) |
+----------------------+-------------------------+
| xbpbpbpbpb | 000000000000000 |
+----------------------+-------------------------+
ST_LatFromGeoHash(
geohash_str
)
Returns the latitude from a geohash string value, as a double-precision number in the range [−90, 90].从geohash字符串值返回纬度,作为范围[90,90]内的双精度数字。
The ST_LatFromGeoHash()
decoding function reads no more than 433 characters from the geohash_str
argument. ST_LatFromGeoHash()
解码函数从geohash_str参数读取的字符不超过433个。That represents the upper limit on information in the internal representation of coordinate values. 表示坐标值内部表示形式中信息的上限。Characters past the 433rd are ignored, even if they are otherwise illegal and produce an error.超过433的字符将被忽略,即使它们是非法的并产生错误。
ST_LatFromGeoHash()
handles its arguments as described in the introduction to this sectionST_LatFromGeoHash()
处理其参数,如本节简介中所述.
mysql> SELECT ST_LatFromGeoHash(ST_GeoHash(45,-20,10));
+------------------------------------------+
| ST_LatFromGeoHash(ST_GeoHash(45,-20,10)) |
+------------------------------------------+
| -20 |
+------------------------------------------+
ST_LongFromGeoHash(
geohash_str
)
Returns the longitude from a geohash string value, as a double-precision number in the range [−180, 180].从geohash字符串值返回经度,作为范围为[180,180]的双精度数字。
The remarks in the description of ST_LatFromGeoHash()
regarding the maximum number of characters processed from the geohash_str
argument also apply to ST_LongFromGeoHash()
.ST_LatFromGeoHash()
说明中有关geohash_str
参数处理的最大字符数的注释也适用于ST_LongFromGeoHash()
。
ST_LongFromGeoHash()
handles its arguments as described in the introduction to this section.ST_LongFromGeoHash()
处理其参数,如本节简介中所述。
mysql> SELECT ST_LongFromGeoHash(ST_GeoHash(45,-20,10));
+-------------------------------------------+
| ST_LongFromGeoHash(ST_GeoHash(45,-20,10)) |
+-------------------------------------------+
| 45 |
+-------------------------------------------+
ST_PointFromGeoHash(
geohash_str
, srid
)
Returns a 给定geohash字符串值,返回包含已解码geohash值的POINT
value containing the decoded geohash value, given a geohash string value.POINT
值。
The X and Y coordinates of the point are the longitude in the range [−180, 180] and the latitude in the range [−90, 90], respectively.点的X和Y坐标分别是范围[-180,180]中的经度和范围[-90,90]中的纬度。
The srid
argument is an 32-bit unsigned integer.srid
参数是32位无符号整数。
The remarks in the description of ST_LatFromGeoHash()
regarding the maximum number of characters processed from the geohash_str
argument also apply to ST_PointFromGeoHash()
.ST_LatFromGeoHash()
说明中有关geohash_str
参数处理的最大字符数的注释也适用于ST_PointFromGeoHash()
。
ST_PointFromGeoHash()
handles its arguments as described in the introduction to this section.ST_PointFromGeoHash()
处理其参数,如本节简介中所述。
mysql>SET @gh = ST_GeoHash(45,-20,10);
mysql>SELECT ST_AsText(ST_PointFromGeoHash(@gh,0));
+---------------------------------------+ | ST_AsText(ST_PointFromGeoHash(@gh,0)) | +---------------------------------------+ | POINT(45 -20) | +---------------------------------------+