-
Notifications
You must be signed in to change notification settings - Fork 866
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Roberto Franchin
authored and
Roberto Franchin
committed
Oct 23, 2015
1 parent
83eda3d
commit d224f34
Showing
6 changed files
with
178 additions
and
1 deletion.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
lucene/src/main/java/com/orientechnologies/orient/spatial/functions/OSTDWithinFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* | ||
* * Copyright 2014 Orient Technologies. | ||
* * | ||
* * Licensed under the Apache License, Version 2.0 (the "License"); | ||
* * you may not use this file except in compliance with the License. | ||
* * You may obtain a copy of the License at | ||
* * | ||
* * http://www.apache.org/licenses/LICENSE-2.0 | ||
* * | ||
* * Unless required by applicable law or agreed to in writing, software | ||
* * distributed under the License is distributed on an "AS IS" BASIS, | ||
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* * See the License for the specific language governing permissions and | ||
* * limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.orientechnologies.orient.spatial.functions; | ||
|
||
import com.orientechnologies.orient.core.command.OCommandContext; | ||
import com.orientechnologies.orient.core.db.record.OIdentifiable; | ||
import com.orientechnologies.orient.core.db.record.ridbag.DoubleReferenceItem; | ||
import com.orientechnologies.orient.core.sql.parser.OBinaryCompareOperator; | ||
import com.orientechnologies.orient.core.sql.parser.OExpression; | ||
import com.orientechnologies.orient.core.sql.parser.OFromClause; | ||
import com.orientechnologies.orient.spatial.strategy.SpatialQueryBuilderWithin; | ||
import com.spatial4j.core.shape.Shape; | ||
import com.spatial4j.core.shape.SpatialRelation; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Created by Enrico Risa on 12/08/15. | ||
*/ | ||
public class OSTDWithinFunction extends OSpatialFunctionAbstract { | ||
|
||
public static final String NAME = "st_dwithin"; | ||
|
||
public OSTDWithinFunction() { | ||
super(NAME, 3, 3); | ||
} | ||
|
||
@Override | ||
public Object execute(Object iThis, OIdentifiable iCurrentRecord, Object iCurrentResult, Object[] iParams, | ||
OCommandContext iContext) { | ||
|
||
Shape shape = factory.fromObject(iParams[0]); | ||
|
||
Shape shape1 = factory.fromObject(iParams[1]); | ||
|
||
Double distance = (Double) iParams[2]; | ||
|
||
return factory.operation().isWithInDistance(shape, shape1,distance); | ||
} | ||
|
||
@Override | ||
public String getSyntax() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Iterable<OIdentifiable> searchFromTarget(OFromClause target, OBinaryCompareOperator operator, Object rightValue, | ||
OCommandContext ctx, OExpression... args) { | ||
return results(target, args, ctx); | ||
} | ||
|
||
@Override | ||
public long estimate(OFromClause target, OBinaryCompareOperator operator, Object rightValue, OCommandContext ctx, | ||
OExpression... args) { | ||
|
||
Collection resultSet = results(target, args, ctx); | ||
return resultSet == null ? -1 : resultSet.size(); | ||
} | ||
|
||
@Override | ||
protected String operator() { | ||
return SpatialQueryBuilderWithin.NAME; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...c/test/java/com/orientechnologies/lucene/test/geo/functions/LuceneSpatialDWithinTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* | ||
* * Copyright 2014 Orient Technologies. | ||
* * | ||
* * Licensed under the Apache License, Version 2.0 (the "License"); | ||
* * you may not use this file except in compliance with the License. | ||
* * You may obtain a copy of the License at | ||
* * | ||
* * http://www.apache.org/licenses/LICENSE-2.0 | ||
* * | ||
* * Unless required by applicable law or agreed to in writing, software | ||
* * distributed under the License is distributed on an "AS IS" BASIS, | ||
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* * See the License for the specific language governing permissions and | ||
* * limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.orientechnologies.lucene.test.geo.functions; | ||
|
||
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx; | ||
import com.orientechnologies.orient.core.record.impl.ODocument; | ||
import com.orientechnologies.orient.core.sql.OCommandSQL; | ||
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by Enrico Risa on 28/09/15. | ||
*/ | ||
@Test(groups = "embedded") | ||
public class LuceneSpatialDWithinTest { | ||
|
||
@Test | ||
public void testDWithinNoIndex() { | ||
|
||
OrientGraphNoTx graph = new OrientGraphNoTx("memory:functionsTest"); | ||
try { | ||
ODatabaseDocumentTx db = graph.getRawGraph(); | ||
|
||
List<ODocument> execute = db | ||
.command( | ||
new OCommandSQL( | ||
"SELECT ST_DWithin(ST_GeomFromText('POLYGON((0 0, 10 0, 10 5, 0 5, 0 0))'), " + | ||
"ST_GeomFromText('POLYGON((12 0, 14 0, 14 6, 12 6, 12 0))'), 2.0d) as distance")) | ||
.execute(); | ||
ODocument next = execute.iterator().next(); | ||
|
||
Assert.assertEquals(next.field("distance"), true); | ||
|
||
} finally { | ||
graph.drop(); | ||
} | ||
} | ||
|
||
@Test(enabled = false) | ||
public void testWithinIndex() { | ||
|
||
OrientGraphNoTx graph = new OrientGraphNoTx("memory:functionsTest"); | ||
try { | ||
ODatabaseDocumentTx db = graph.getRawGraph(); | ||
|
||
db.command(new OCommandSQL("create class Polygon extends v")).execute(); | ||
db.command(new OCommandSQL("create property Polygon.geometry EMBEDDED OPolygon")).execute(); | ||
|
||
db.command(new OCommandSQL("insert into Polygon set geometry = ST_GeomFromText('POLYGON((0 0, 10 0, 10 5, 0 5, 0 0))')")).execute(); | ||
|
||
db.command(new OCommandSQL("create index Polygon.g on Polygon (geometry) SPATIAL engine lucene")).execute(); | ||
List<ODocument> execute = db.command(new OCommandSQL("SELECT from Polygon where ST_DWithin(geometry, ST_GeomFromText('POLYGON((12 0, 14 0, 14 6, 12 6, 12 0))'), 2.0d)) = true")) | ||
.execute(); | ||
|
||
Assert.assertEquals(execute.size(), 1); | ||
|
||
// execute = db.command( | ||
// new OCommandSQL("SELECT from Polygon where ST_Within(geometry, ST_Buffer(ST_GeomFromText('POINT(50 50)'), 30)) = true")) | ||
// .execute(); | ||
|
||
// Assert.assertEquals(execute.size(), 1); | ||
|
||
} finally { | ||
graph.drop(); | ||
} | ||
} | ||
|
||
} |