use of org.apache.jena.query.spatial.SpatialIndexException in project jena by apache.
the class SpatialOperationWithCircleBase method objectToStruct.
/** Deconstruct the node or list object argument and make a NearbyMatch */
@Override
protected SpatialMatch objectToStruct(PropFuncArg argObject) {
// EntityDefinition docDef = server.getDocDef();
if (argObject.isNode()) {
log.warn("Object not a List: " + argObject);
return null;
}
List<Node> list = argObject.getArgList();
if (list.size() < 3 || list.size() > 5)
throw new SpatialIndexException("Change in object list size");
int idx = 0;
Node x = list.get(idx);
if (!x.isLiteral()) {
log.warn("Latitude is not a literal " + list);
return null;
}
if (!SpatialValueUtil.isDecimal(x)) {
log.warn("Latitude is not a decimal " + list);
return null;
}
Double latitude = Double.parseDouble(x.getLiteralLexicalForm());
idx++;
x = list.get(idx);
if (!x.isLiteral()) {
log.warn("Longitude is not a literal " + list);
return null;
}
if (!SpatialValueUtil.isDecimal(x)) {
log.warn("Longitude is not a decimal " + list);
return null;
}
Double longtitude = Double.parseDouble(x.getLiteralLexicalForm());
idx++;
x = list.get(idx);
if (!x.isLiteral()) {
log.warn("Radius is not a literal " + list);
return null;
}
if (!SpatialValueUtil.isDecimal(x)) {
log.warn("Radius is not a decimal " + list);
return null;
}
Double radius = Double.parseDouble(x.getLiteralLexicalForm());
if (radius <= 0) {
log.warn("Radius is not a correct decimal " + list);
return null;
}
// Kilometres
String units = DistanceUnitsUtils.defaultDistanceUnit;
int limit = -1;
idx++;
if (idx < list.size()) {
x = list.get(idx);
if (!x.isLiteral()) {
log.warn("Units or limit is not a literal " + list);
return null;
}
if (x.getLiteralDatatype() == null || x.getLiteralDatatype().equals(XSDDatatype.XSDstring)) {
String u = x.getLiteralLexicalForm();
if (DistanceUnitsUtils.isSupportedUnits(u)) {
idx++;
units = u;
} else {
log.warn("Units are not a supported " + list);
return null;
}
}
}
if (idx < list.size()) {
x = list.get(idx);
if (!x.isLiteral()) {
log.warn("Limit is not a literal " + list);
return null;
}
LiteralLabel lit = x.getLiteral();
if (!XSDDatatype.XSDinteger.isValidLiteral(lit)) {
log.warn("Limit is not an integer " + list);
return null;
}
int v = NodeFactoryExtra.nodeToInt(x);
limit = (v < 0) ? -1 : v;
idx++;
if (idx < list.size()) {
log.warn("Limit is not the last parameter " + list);
return null;
}
}
SpatialMatch match = new SpatialMatch(latitude, longtitude, radius, units, limit, this.getSpatialOperation());
if (log.isDebugEnabled())
log.debug("Trying SpatialMatch: " + match.toString());
return match;
}
Aggregations