Skip to content

Commit 04a1127

Browse files
committed
Merge pull request #297 from ngageoint/GEOWAVE-285
added large polygon query, geometry interning in filters
2 parents e74e529 + 792c1c7 commit 04a1127

3 files changed

Lines changed: 224 additions & 110 deletions

File tree

geowave-accumulo/pom.xml

Lines changed: 106 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,112 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
4-
<parent>
5-
<artifactId>geowave-parent</artifactId>
6-
<groupId>mil.nga.giat</groupId>
7-
<relativePath>../</relativePath>
8-
<version>0.8.4-SNAPSHOT</version>
9-
</parent>
10-
<artifactId>geowave-accumulo</artifactId>
11-
<name>geowave-accumulo</name>
12-
<dependencies>
13-
<dependency>
14-
<groupId>mil.nga.giat</groupId>
15-
<artifactId>geowave-store</artifactId>
16-
<version>${project.version}</version>
17-
</dependency>
18-
<dependency>
19-
<groupId>org.apache.accumulo</groupId>
20-
<artifactId>accumulo-core</artifactId>
21-
</dependency>
22-
<dependency>
23-
<groupId>org.apache.hadoop</groupId>
24-
<artifactId>hadoop-client</artifactId>
25-
<exclusions>
26-
<exclusion>
27-
<artifactId>jdk.tools</artifactId>
28-
<groupId>jdk.tools</groupId>
29-
</exclusion>
30-
<exclusion>
31-
<artifactId>junit</artifactId>
32-
<groupId>junit</groupId>
33-
</exclusion>
34-
<exclusion>
35-
<artifactId>guava</artifactId>
36-
<groupId>com.google.guava</groupId>
37-
</exclusion>
38-
<exclusion>
39-
<groupId>javax.servlet</groupId>
40-
<artifactId>*</artifactId>
41-
</exclusion>
42-
</exclusions>
43-
</dependency>
44-
<dependency>
45-
<groupId>junit</groupId>
46-
<artifactId>junit</artifactId>
47-
<version>4.11</version>
48-
<scope>test</scope>
49-
</dependency>
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<artifactId>geowave-parent</artifactId>
6+
<groupId>mil.nga.giat</groupId>
7+
<relativePath>../</relativePath>
8+
<version>0.8.4-SNAPSHOT</version>
9+
</parent>
10+
<artifactId>geowave-accumulo</artifactId>
11+
<name>geowave-accumulo</name>
12+
<dependencies>
13+
<dependency>
14+
<groupId>mil.nga.giat</groupId>
15+
<artifactId>geowave-store</artifactId>
16+
<version>${project.version}</version>
17+
</dependency>
18+
<dependency>
19+
<groupId>org.apache.accumulo</groupId>
20+
<artifactId>accumulo-core</artifactId>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.apache.hadoop</groupId>
24+
<artifactId>hadoop-client</artifactId>
25+
<exclusions>
26+
<exclusion>
27+
<artifactId>jdk.tools</artifactId>
28+
<groupId>jdk.tools</groupId>
29+
</exclusion>
30+
<exclusion>
31+
<artifactId>junit</artifactId>
32+
<groupId>junit</groupId>
33+
</exclusion>
34+
<exclusion>
35+
<artifactId>guava</artifactId>
36+
<groupId>com.google.guava</groupId>
37+
</exclusion>
38+
<exclusion>
39+
<groupId>javax.servlet</groupId>
40+
<artifactId>*</artifactId>
41+
</exclusion>
42+
</exclusions>
43+
</dependency>
44+
<dependency>
45+
<groupId>junit</groupId>
46+
<artifactId>junit</artifactId>
47+
<version>4.11</version>
48+
<scope>test</scope>
49+
</dependency>
5050
<dependency>
5151
<groupId>com.google.code.findbugs</groupId>
5252
<artifactId>annotations</artifactId>
5353
</dependency>
5454
</dependencies>
55-
<build>
56-
<plugins>
57-
<plugin>
58-
<groupId>org.sonatype.plugins</groupId>
59-
<artifactId>munge-maven-plugin</artifactId>
60-
<version>1.0</version>
61-
<executions>
62-
<execution>
63-
<id>munge</id>
64-
<phase>generate-sources</phase>
65-
<goals>
66-
<goal>munge</goal>
67-
</goals>
68-
<configuration>
69-
<symbols>ACCUMULO_${accumulo.version}</symbols>
70-
</configuration>
71-
</execution>
72-
</executions>
73-
</plugin>
74-
</plugins>
75-
<pluginManagement>
76-
<plugins>
77-
<!--This plugin's configuration is used to store Eclipse m2e settings
78-
only. It has no influence on the Maven build itself. -->
79-
<plugin>
80-
<groupId>org.eclipse.m2e</groupId>
81-
<artifactId>lifecycle-mapping</artifactId>
82-
<version>1.0.0</version>
83-
<configuration>
84-
<lifecycleMappingMetadata>
85-
<pluginExecutions>
86-
<pluginExecution>
87-
<pluginExecutionFilter>
88-
<groupId>
89-
org.sonatype.plugins
90-
</groupId>
91-
<artifactId>
92-
munge-maven-plugin
93-
</artifactId>
94-
<versionRange>
95-
[1.0,)
96-
</versionRange>
97-
<goals>
98-
<goal>munge</goal>
99-
</goals>
100-
</pluginExecutionFilter>
101-
<action>
102-
<ignore />
103-
</action>
104-
</pluginExecution>
105-
</pluginExecutions>
106-
</lifecycleMappingMetadata>
107-
</configuration>
108-
</plugin>
109-
</plugins>
110-
</pluginManagement>
111-
</build>
112-
</project>
55+
<build>
56+
<plugins>
57+
<plugin>
58+
<groupId>org.sonatype.plugins</groupId>
59+
<artifactId>munge-maven-plugin</artifactId>
60+
<version>1.0</version>
61+
<executions>
62+
<execution>
63+
<id>munge</id>
64+
<phase>generate-sources</phase>
65+
<goals>
66+
<goal>munge</goal>
67+
</goals>
68+
<configuration>
69+
<symbols>ACCUMULO_${accumulo.version}</symbols>
70+
</configuration>
71+
</execution>
72+
</executions>
73+
</plugin>
74+
</plugins>
75+
<pluginManagement>
76+
<plugins>
77+
<!--This plugin's configuration is used to store Eclipse m2e settings
78+
only. It has no influence on the Maven build itself. -->
79+
<plugin>
80+
<groupId>org.eclipse.m2e</groupId>
81+
<artifactId>lifecycle-mapping</artifactId>
82+
<version>1.0.0</version>
83+
<configuration>
84+
<lifecycleMappingMetadata>
85+
<pluginExecutions>
86+
<pluginExecution>
87+
<pluginExecutionFilter>
88+
<groupId>
89+
org.sonatype.plugins
90+
</groupId>
91+
<artifactId>
92+
munge-maven-plugin
93+
</artifactId>
94+
<versionRange>
95+
[1.0,)
96+
</versionRange>
97+
<goals>
98+
<goal>munge</goal>
99+
</goals>
100+
</pluginExecutionFilter>
101+
<action>
102+
<ignore/>
103+
</action>
104+
</pluginExecution>
105+
</pluginExecutions>
106+
</lifecycleMappingMetadata>
107+
</configuration>
108+
</plugin>
109+
</plugins>
110+
</pluginManagement>
111+
</build>
112+
</project>

geowave-accumulo/src/test/java/mil/nga/giat/geowave/accumulo/query/AccumuloRangeQueryTest.java

Lines changed: 112 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package mil.nga.giat.geowave.accumulo.query;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
3+
import java.util.*;
54

6-
import junit.framework.Assert;
5+
6+
import com.vividsolutions.jts.geom.Polygon;
7+
import com.vividsolutions.jts.io.ParseException;
8+
import com.vividsolutions.jts.io.WKBReader;
9+
import com.vividsolutions.jts.io.WKBWriter;
710
import mil.nga.giat.geowave.accumulo.AccumuloDataStore;
811
import mil.nga.giat.geowave.accumulo.BasicAccumuloOperations;
912
import mil.nga.giat.geowave.index.ByteArrayId;
1013
import mil.nga.giat.geowave.store.CloseableIterator;
1114
import mil.nga.giat.geowave.store.DataStore;
15+
import mil.nga.giat.geowave.store.GeometryUtils;
1216
import mil.nga.giat.geowave.store.adapter.AbstractDataAdapter;
1317
import mil.nga.giat.geowave.store.adapter.NativeFieldHandler;
1418
import mil.nga.giat.geowave.store.adapter.NativeFieldHandler.RowBuilder;
@@ -33,6 +37,7 @@
3337
import org.apache.accumulo.core.client.Connector;
3438
import org.apache.accumulo.core.client.mock.MockInstance;
3539
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
40+
import org.junit.Assert;
3641
import org.junit.Before;
3742
import org.junit.Test;
3843

@@ -111,6 +116,85 @@ public void testIntersection() {
111116
Assert.assertTrue(resultOfIntersect.hasNext());
112117
}
113118

119+
@Test
120+
public void largeQuery() {
121+
final Geometry largeGeo = createPolygon(50000);
122+
final Query largeQuery = new SpatialQuery(
123+
largeGeo);
124+
final CloseableIterator itr = mockDataStore.query(
125+
index,
126+
largeQuery);
127+
int numfeats = 0;
128+
while (itr.hasNext()) {
129+
itr.next();
130+
numfeats++;
131+
}
132+
Assert.assertEquals(
133+
numfeats,
134+
1);
135+
}
136+
137+
/**
138+
* Verifies equality for interning is still working as expected (topologically),
139+
* as the the largeQuery() test has a dependency on this;
140+
* @throws ParseException
141+
*/
142+
@Test
143+
public void testInterning()
144+
throws ParseException {
145+
final Geometry g = GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] {
146+
new Coordinate(
147+
0,
148+
0),
149+
new Coordinate(
150+
1,
151+
0),
152+
new Coordinate(
153+
1,
154+
1),
155+
new Coordinate(
156+
0,
157+
1),
158+
new Coordinate(
159+
0,
160+
0)
161+
});
162+
final Geometry gNewInstance = GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] {
163+
new Coordinate(
164+
0,
165+
0),
166+
new Coordinate(
167+
1,
168+
0),
169+
new Coordinate(
170+
1,
171+
1),
172+
new Coordinate(
173+
0,
174+
1),
175+
new Coordinate(
176+
0,
177+
0)
178+
});
179+
final WKBWriter wkbWriter = new WKBWriter();
180+
final byte[] b = wkbWriter.write(g);
181+
final byte[] b2 = new byte[b.length];
182+
System.arraycopy(
183+
b,
184+
0,
185+
b2,
186+
0,
187+
b.length);
188+
final WKBReader wkbReader = new WKBReader();
189+
final Geometry gSerialized = wkbReader.read(b);
190+
final Geometry gSerializedArrayCopy = wkbReader.read(b2);
191+
192+
Assert.assertEquals(g, gNewInstance);
193+
Assert.assertEquals(g, gSerializedArrayCopy);
194+
Assert.assertEquals(gSerialized, gSerializedArrayCopy);
195+
Assert.assertEquals(gSerialized, gSerializedArrayCopy);
196+
}
197+
114198
@Test
115199
public void testMiss() {
116200
final Query intersectQuery = new SpatialQuery(
@@ -161,6 +245,31 @@ public void testEncompass() {
161245
geom1.id);
162246
}
163247

248+
private static Polygon createPolygon(
249+
int numPoints ) {
250+
double centerX = 4;
251+
double centerY = 12;
252+
int maxRadius = 80;
253+
254+
List<Coordinate> coords = new ArrayList<Coordinate>();
255+
Random rand = new Random(
256+
8675309l);
257+
258+
double increment = (double) 360 / numPoints;
259+
260+
for (double theta = 0; theta <= 360; theta += increment) {
261+
double radius = rand.nextDouble() * maxRadius + 0.1;
262+
double rad = theta * Math.PI / 180.0;
263+
double x = centerX + radius * Math.sin(rad);
264+
double y = centerY + radius * Math.cos(rad);
265+
coords.add(new Coordinate(
266+
x,
267+
y));
268+
}
269+
coords.add(coords.get(0));
270+
return GeometryUtils.GEOMETRY_FACTORY.createPolygon(coords.toArray(new Coordinate[coords.size()]));
271+
}
272+
164273
protected static class TestGeometry
165274
{
166275
protected final Geometry geom;

geowave-store/src/main/java/mil/nga/giat/geowave/store/filter/SpatialQueryFilter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.util.List;
77
import java.util.Set;
88

9+
import com.google.common.collect.Interner;
10+
import com.google.common.collect.Interners;
911
import mil.nga.giat.geowave.index.ByteArrayId;
1012
import mil.nga.giat.geowave.index.sfc.data.BasicNumericDataset;
1113
import mil.nga.giat.geowave.index.sfc.data.MultiDimensionalNumericData;
@@ -25,6 +27,9 @@
2527
public class SpatialQueryFilter extends
2628
BasicQueryFilter
2729
{
30+
31+
private static final Interner<Geometry> geometryInterner = Interners.newWeakInterner();
32+
2833
private Geometry queryGeometry;
2934

3035
private Set<ByteArrayId> geometryFieldIds;
@@ -188,7 +193,7 @@ public void fromBinary(
188193
fieldId));
189194
}
190195
buf.get(theRest);
191-
queryGeometry = GeometryUtils.geometryFromBinary(geometryBinary);
196+
queryGeometry = geometryInterner.intern(GeometryUtils.geometryFromBinary(geometryBinary));
192197

193198
super.fromBinary(theRest);
194199
}

0 commit comments

Comments
 (0)