use of org.geotoolkit.index.tree.manager.NamedEnvelope in project geotoolkit by Geomatys.
the class LuceneSGBDTreeEltMapper method getObjectFromTreeIdentifier.
@Override
public NamedEnvelope getObjectFromTreeIdentifier(final int treeIdentifier) throws IOException {
NamedEnvelope result = null;
try (Connection conn = source.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELECT * FROM \"" + schemaName + "\".\"records\" WHERE \"id\"=?")) {
stmt.setInt(1, treeIdentifier);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
final String identifier = rs.getString("identifier");
final int nbEnv = rs.getInt("nbenv");
final double minx = rs.getDouble("minx");
final double maxx = rs.getDouble("maxx");
final double miny = rs.getDouble("miny");
final double maxy = rs.getDouble("maxy");
result = new NamedEnvelope(crs, identifier, nbEnv);
result.setRange(0, minx, maxx);
result.setRange(1, miny, maxy);
}
}
} catch (SQLException ex) {
throw new IOException("Error while getting envelope", ex);
}
return result;
}
use of org.geotoolkit.index.tree.manager.NamedEnvelope in project geotoolkit by Geomatys.
the class LuceneSGBDTreeEltMapper method getFullMap.
@Override
public Map<Integer, NamedEnvelope> getFullMap() throws IOException {
Map<Integer, NamedEnvelope> result = new HashMap<>();
try (Connection conn = source.getConnection();
PreparedStatement stmt = conn.prepareStatement("SELECT * FROM \"" + schemaName + "\".\"records\"");
ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
final String identifier = rs.getString("identifier");
final int treeId = rs.getInt("id");
final int nbEnv = rs.getInt("nbenv");
final double minx = rs.getDouble("minx");
final double maxx = rs.getDouble("maxx");
final double miny = rs.getDouble("miny");
final double maxy = rs.getDouble("maxy");
final NamedEnvelope env = new NamedEnvelope(crs, identifier, nbEnv);
env.setRange(0, minx, maxx);
env.setRange(1, miny, maxy);
result.put(treeId, env);
}
} catch (SQLException ex) {
throw new IOException("Error while getting envelope", ex);
}
return result;
}
use of org.geotoolkit.index.tree.manager.NamedEnvelope in project geotoolkit by Geomatys.
the class LuceneSearcherTest method QueryAndSpatialFilterAfterRemoveTest.
/**
* Test the combination of a String query and/or spatial filter.
* @throws java.lang.Exception
*/
@Test
public void QueryAndSpatialFilterAfterRemoveTest() throws Exception {
// we remove a document
final Analyzer analyzer = new StandardAnalyzer();
DocumentIndexer indexer = new DocumentIndexer(directory, null, analyzer);
indexer.removeDocument("box 2 projected");
indexer.destroy();
searcher.destroy();
searcher = new LuceneIndexSearcher(directory, null, new ClassicAnalyzer(), false);
/*
* case 1: a normal spatial request BBOX
*/
double[] min1 = { -20, -20 };
double[] max1 = { 20, 20 };
GeneralEnvelope bbox = new GeneralEnvelope(min1, max1);
bbox.setCoordinateReferenceSystem(CommonCRS.defaultGeographic());
org.opengis.filter.Filter bboxFilter = FF.bbox(GEOMETRY_PROPERTY, -20, -20, 20, 20, "CRS:84");
SpatialQuery bboxQuery = new SpatialQuery(wrap(bboxFilter));
// we perform a lucene query
Set<String> results = searcher.doSearch(bboxQuery);
int nbResults = results.size();
LOGGER.log(Level.FINER, "QnS:BBOX 1 CRS=4326: nb Results: {0}", nbResults);
// we verify that we obtain the correct results
assertEquals(nbResults, 9);
assertTrue(results.contains("point 1"));
assertTrue(results.contains("point 1 projected"));
assertTrue(results.contains("point 2"));
assertTrue(results.contains("point 3"));
assertTrue(results.contains("box 4"));
assertTrue(results.contains("box 2"));
assertTrue(results.contains("line 2"));
assertTrue(results.contains("line 1"));
assertTrue(results.contains("line 1 projected"));
// re-add the document
final CoordinateReferenceSystem CRS3395 = CRS.forCode("EPSG:3395");
Document docu = new Document();
docu.add(new StringField("id", "box 2 projected", Field.Store.YES));
docu.add(new StringField("docid", 66 + "", Field.Store.YES));
docu.add(new StringField("metafile", "doc", Field.Store.YES));
// attention !! reprojeté
NamedEnvelope env = addBoundingBox(docu, 556597.4539663679, 1113194.9079327357, 1111475.1028522244, 1678147.5163917788, CRS3395);
indexer = new DocumentIndexer(directory, null, analyzer);
indexer.indexDocument(new DocumentIndexer.DocumentEnvelope(docu, env));
indexer.destroy();
searcher.destroy();
searcher = new LuceneIndexSearcher(directory, null, new ClassicAnalyzer(), false);
// we perform a lucene query
results = searcher.doSearch(bboxQuery);
nbResults = results.size();
LOGGER.log(Level.FINER, "QnS:BBOX 1 CRS=4326: nb Results: {0}", nbResults);
// we verify that we obtain the correct results
assertEquals(nbResults, 10);
assertTrue(results.contains("point 1"));
assertTrue(results.contains("point 1 projected"));
assertTrue(results.contains("point 2"));
assertTrue(results.contains("point 3"));
assertTrue(results.contains("box 4"));
assertTrue(results.contains("box 2"));
assertTrue(results.contains("box 2 projected"));
assertTrue(results.contains("line 2"));
assertTrue(results.contains("line 1"));
assertTrue(results.contains("line 1 projected"));
}
use of org.geotoolkit.index.tree.manager.NamedEnvelope in project geotoolkit by Geomatys.
the class LuceneSearcherTest method addPoint.
/**
* Add a point geometry to the specified Document.
*
* @param doc The document to add the geometry
* @param x The x coordinate of the point.
* @param y The y coordinate of the point.
* @param crsName The coordinate reference system in witch the coordinates are expressed.
*/
private static NamedEnvelope addPoint(final Document doc, final double x, final double y, final CoordinateReferenceSystem crs) throws Exception {
Point pt = GF.createPoint(new Coordinate(x, y));
JTS.setCRS(pt, crs);
final String id = doc.get("id");
NamedEnvelope namedBound = LuceneUtils.getNamedEnvelope(id, pt, treeCrs);
doc.add(new StoredField(LuceneOGCSpatialQuery.GEOMETRY_FIELD_NAME, WKBUtils.toWKBwithSRID(pt)));
return namedBound;
}
use of org.geotoolkit.index.tree.manager.NamedEnvelope in project geotoolkit by Geomatys.
the class LuceneSearcherTest method addLine.
/**
* Add a Line geometry to the specified Document.
*
* @param doc The document to add the geometry
* @param x1 the X coordinate of the first point of the line.
* @param y1 the Y coordinate of the first point of the line.
* @param x2 the X coordinate of the second point of the line.
* @param y2 the Y coordinate of the first point of the line.
* @param crsName The coordinate reference system in witch the coordinates are expressed.
*/
private static NamedEnvelope addLine(final Document doc, final double x1, final double y1, final double x2, final double y2, final CoordinateReferenceSystem crs) throws Exception {
LineString line = GF.createLineString(new Coordinate[] { new Coordinate(x1, y1), new Coordinate(x2, y2) });
JTS.setCRS(line, crs);
final String id = doc.get("id");
NamedEnvelope namedBound = LuceneUtils.getNamedEnvelope(id, line, treeCrs);
doc.add(new StoredField(LuceneOGCSpatialQuery.GEOMETRY_FIELD_NAME, WKBUtils.toWKBwithSRID(line)));
return namedBound;
}
Aggregations