GeoMesa实用程序¶
中提供了有用的实用程序 geomesa-utils
模块。
简单的功能包装器生成¶
GeoMesa可用于生成Scala value classes 用于在TypeSafe配置文件中定义的简单功能类型。将为类路径上找到的任何要素类型生成类。要与Maven一起使用,请将以下代码片段添加到您的POM中,指定您希望生成的类所在的包:
<dependencies>
<dependency>
<groupId>org.locationtech.geomesa</groupId>
<artifactId>geomesa-utils_${scala.binary.version}</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>generate-sft-wrappers</id>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.locationtech.geomesa.utils.geotools.GenerateRichFeatureModels</mainClass>
<addResourcesToClasspath>true</addResourcesToClasspath>
<cleanupDaemonThreads>false</cleanupDaemonThreads>
<killAfter>-1</killAfter>
<arguments>
<argument>${project.basedir}</argument>
<argument>com.example.geomesa</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Geohash¶
Geohashes 是一种使用 Z-order curve 将纬度/经度栅格分层细分为逐渐变小的存储箱。Geohash的长度(以位为单位)表示其精度。
例如,下表显示了点(-78.48,38.03)周围的Geohash边界框,以位为单位增加了精度级别(为清楚起见,坐标四舍五入为三位小数):
比特数 |
包围盒 |
质心 |
Geohash |
---|---|---|---|
1 |
-180.000-90.000,0.000 90.000 |
-90.000 0.000 |
0 |
2 |
-180.000 0.000,0.000 90.000 |
-90.000 45.000 |
01 |
3 |
-90.000 0.000,0.000 90.000 |
-45.000 45.000 |
011 |
4 |
-90.000 0.000,0.000 45.000 |
-45.000 22.500 |
0110 |
5 |
-90.000 0.000,-45.000 45.000 |
-67.500 22.500 |
01100 |
6 |
-90.000 22.500,-45.000 45.000 |
-67.500 33.750 |
011001 |
7 |
-90.000 22.500,-67.500 45.000 |
-78.750 33.750 |
0110010 |
8 |
-90.000 33.750,-67.500 45.000 |
-78.750 39.375 |
01100101 |
9 |
-78.750 33.750,-67.500 45.000 |
-73.125 39.375 |
011001011 |
10 |
-78.750 33.750,-67.500 39.375 |
-73.125 36.563 |
0110010110 |
11 |
-78.750 33.750,-73.125 39.375 |
-75.938 36.563 |
01100101100 |
12 |
-78.750 36.563,-73.125 39.375 |
-75.938 37.969 |
011001011001 |
13 |
-78.750 36.563,-75.938 39.375 |
-77.344 37.969 |
0110010110010 |
14 |
-78.750 37.969,-75.938 39.375 |
-77.344 38.672 |
01100101100101 |
15 |
-78.750 37.969,-77.344 39.375 |
-78.047 38.672 |
011001011001010 |
16 |
-78.750 37.969,-77.344 38.672 |
-78.047 38.320 |
0110010110010100 |
17 |
-78.750 37.969,-78.047 38.672 |
-78.398 38.320 |
01100101100101000 |
18 |
-78.750 37.969,-78.047 38.320 |
-78.398 38.145 |
011001011001010000 |
19 |
-78.750 37.969,-78.398 38.320 |
-78.574 38.145 |
0110010110010100000 |
20 |
-78.750 37.969,-78.398 38.145 |
-78.574 38.057 |
01100101100101000000 |
21 |
-78.574 37.969,-78.398 38.145 |
-78.486 38.057 |
011001011001010000001 |
22 |
-78.574 37.969,-78.398 38.057 |
-78.486 38.013 |
0110010110010100000010 |
23 |
-78.486 37.969,-78.398 38.057 |
-78.442 38.013 |
01100101100101000000101 |
24 |
-78.486 38.013,-78.398 38.057 |
-78.442 38.035 |
011001011001010000001011 |
25 |
-78.486 38.013,-78.442 38.057 |
-78.464 38.035 |
0110010110010100000010110 |
与上表中的Geohash对应的边界框在此地图上显示为红色多边形:

这个 org.locationtech.geomesa.utils.geohash.GeoHash
类提供了使用Geohash的工具。上表的数据可以使用以下Scala代码生成:
import org.locationtech.geomesa.utils.geohash.GeoHash
for (p <- 1 to 25) {
val gh = GeoHash(-78.48, 38.03, p)
println(s"""$p ${gh.bbox.toText} ${gh.getPoint.toText} ${gh.toBinaryString}""")
}
基数-32编码¶
Geohash被编码为具有以下32进制表示形式的字符串:
12月 |
二进制 |
基数-32 |
12月 |
二进制 |
基数-32 |
---|---|---|---|---|---|
0 |
00000 |
0 |
16 |
10000 |
H |
1 |
00001 |
1 |
17 |
10001 |
J |
2 |
00010 |
2 |
18 |
10010 |
K |
3 |
00011 |
3 |
19 |
10011 |
M |
4 |
00100 |
4 |
20 |
10100 |
N |
5 |
00101 |
5 |
21 |
10101 |
P |
6 |
00110 |
6 |
22 |
10110 |
问: |
7 |
00111 |
7 |
23 |
10111 |
R |
8 |
01000 |
8 |
24 |
11000 |
S |
9 |
01001 |
9 |
25 |
11001 |
T |
10 |
01010 |
B类 |
26 |
11010 |
使用 |
11 |
01011 |
C |
27 |
11011 |
V |
12 |
01100 |
D |
28 |
11100 |
W |
13 |
01101 |
E |
29 |
11101 |
X |
14 |
01110 |
F |
30 |
11110 |
是 |
15 |
01111 |
G |
31 |
11111 |
Z |
按照此约定,包含上述(-78.48,38.03)的25位Geohash将被编码为“dqb0q”::
01100 10110 01010 00000 10110
----- ----- ----- ----- -----
d q b 0 q