-
Notifications
You must be signed in to change notification settings - Fork 862
/
spatial.xml
186 lines (136 loc) · 4.91 KB
/
spatial.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<sect1 id="spatial" revision="1">
<title>Querydsl Spatial</title>
<para>Support for Spatial queries is available via the Querydsl Spatial module, which is an extension
module to the SQL module. The Spatial module supports the object model of Simple Feature Access in queries
and object binding.</para>
<para>The <ulink url="http://www.geolatte.org/">geolatte</ulink> project is used for the object model.</para>
<imagedata fileref="media/spatial.svg" scalefit="1" width="90%"/>
<sect2>
<title>Maven integration</title>
<para>
Add the following dependency to your Maven project:
</para>
<programlisting language="xml"><![CDATA[
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-sql-spatial</artifactId>
<version>${querydsl.version}</version>
</dependency>
]]></programlisting>
<para>Additionally the following database specific extra dependencies:</para>
<programlisting language="xml"><![CDATA[
<!-- for PostgreSQL usage -->
<dependency>
<groupId>org.postgis</groupId>
<artifactId>postgis-jdbc</artifactId>
<version>1.3.3</version>
<scope>provided</scope>
</dependency>
<!-- for Oracle usage -->
<dependency>
<groupId>oracle</groupId>
<artifactId>sdoapi</artifactId>
<version>11.2.0</version>
<scope>provided</scope>
</dependency>
]]></programlisting>
</sect2>
<sect2>
<title>Code generation via Maven</title>
<para>The code generation for Querydsl SQL can be set to detect the usage of spatial types in
database schemas and use geolatte types in these case via the spatial property:</para>
<programlisting language="xml"><![CDATA[
<project>
<build>
<plugins>
...
<plugin>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-maven-plugin</artifactId>
<version>${querydsl.version}</version>
...
<configuration>
...
<spatial>true</spatial>
</configuration>
</plugin>
...
</plugins>
</build>
</project>
]]></programlisting>
</sect2>
<sect2>
<title>Runtime configuration</title>
<para>The runtime configuration aspect of the spatial module is that instead of the normal
SQLTemplates instances, spatial enabled instances are used. Below is a list of spatial enabled
SQLTemplates classes.</para>
<itemizedlist>
<listitem>
<para>GeoDBTemplates (for H2)</para>
</listitem>
<listitem>
<para>MySQLSpatialTemplates</para>
</listitem>
<listitem>
<para>OracleSpatialTemplates (alpha stage)</para>
</listitem>
<listitem>
<para>PostGISTemplates</para>
</listitem>
<listitem>
<para>SQLServer2008SpatialTemplates</para>
</listitem>
<listitem>
<para>TeradataSpatialTemplates</para>
</listitem>
</itemizedlist>
</sect2>
<sect2>
<title>Querying</title>
<para>With code generation and runtime configuration set for spatial types we can now try
queries with it.</para>
<sect3>
<title>Filter by Distance</title>
<programlisting language="java"><![CDATA[
Geometry point = Wkt.fromWkt("Point(2 2)");
query.where(table.geo.distance(point).lt(5.0));
]]></programlisting>
<para>In addition to straight distance between geometries spherical and spheroidal distance are provided via
distanceSphere and distanceSpheroid.</para>
</sect3>
<sect3>
<title>Contains</title>
<programlisting language="java"><![CDATA[
Geometry point = Wkt.fromWkt("Point(2 2)");
query.where(table.geo.contains(point));
]]></programlisting>
</sect3>
<sect3>
<title>Intersection</title>
<programlisting language="java"><![CDATA[
Geometry geo = query.select(table.geo1.intersection(table.geo2)).fetchOne();
]]></programlisting>
</sect3>
<sect3>
<title>Access to the SPATIAL_REF_SYS table</title>
<para>Unified access to the SPATIAL_REF_SYS standard table is provided via the QSpatialRefSys
and SpatialRefSys classes. SPATIAL_REF_SYS contains data about the supported spatial reference systems.</para>
<programlisting language="java"><![CDATA[
QSpatialRefSys spatialRefSys = QSpatialRefSys.spatialRefSys;
List<SpatialRefSys> referenceSystems = query.select(spatialRefSys).from(spatialRefSys).fetch();
]]></programlisting>
</sect3>
</sect2>
<sect2>
<title>Inheritance</title>
<para>In case you use only generic geometry types in your database schema you can use conversion methods
in the object model to convert to more specific types.</para>
<programlisting language="java"><![CDATA[
GeometryPath<Geometry> geometry = shapes.geometry;
PointPath<Point> point = geometry.asPoint();
NumberExpression<Double> pointX = point.x(); // x() is not available on GeometryExpression/GeometryPath
]]></programlisting>
</sect2>
</sect1>