Hi there,
I´ve got another question corresponding to query-writing. I have
found no java documentation for Geomesa so far, thats why I have
some problems writing queries. Please have a look at the following
peace of code.
The code seems to work, but it doesn´t return anything. My aim is to
return the closest event to beijing considering the attribute
"geom". I found a KNNQuery class, but it´s not working for me,
because there are some "magic" parameters I don´t understand (see
comments in my code).
Thanks again.
Marcel.
public static
void queryGdelt(String[]
args) throws Exception {
SimpleFeatureSource fs =
GDELTGeomesaQueryClusterPreparation.getSimpleFeatureSource(args);
GeometryFactory geomFactory = new GeometryFactory();
double[]
coordinates = { 116.3974589, 39.9388838
};
Coordinate coord = new Coordinate(coordinates[0],
coordinates[1]);
Point point = geomFactory.createPoint(coord);
int unknownParameter1
= 1;
NearestNeighbors neighborsPrepare =
NearestNeighbors.apply(point, unknownParameter1);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date start = df.parse("1979-01-01");
FilterFactory2 ff =
CommonFactoryFinder.getFilterFactory2();
Filter timeFilter = ff.after(ff.property("SQLDATE"),
ff.literal(start));
double unknownParameter2
= 1;
double unknownParameter3
= 1;
GeoHashSpiral spiral =
GeoHashSpiral.apply(point, unknownParameter2,
unknownParameter3);
NearestNeighbors neighbors =
KNNQuery.runKNNQuery(fs,
new Query("gdelt",
timeFilter, new String[] { "SQLDATE", "geom"
}), spiral, neighborsPrepare);
Log.info(neighbors.size());
Iterator<SimpleFeatureWithDistance>
sfListWithDist = neighbors.getK().iterator();
while (sfListWithDist.hasNext())
{
SimpleFeatureWithDistance sfWithdist =
sfListWithDist.next();
double minimumDistance
= sfWithdist.dist();
int numberOfAttributes
= sfWithdist.sf().getAttributeCount();
String eventOutput = "";
for (int currentAttributeNumber
= 0; currentAttributeNumber < numberOfAttributes;
currentAttributeNumber++) {
Object o =
sfWithdist.sf().getAttributes().get(currentAttributeNumber);
if (o != null) {
eventOutput += o.toString() + " ";
} else
{
eventOutput += "NULL ";
}
}
Log.info(minimumDistance + " " +
eventOutput.trim());
}
}