Search in sources :

Example 6 with SpatialIndexException

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;
}
Also used : Node(org.apache.jena.graph.Node) SpatialIndexException(org.apache.jena.query.spatial.SpatialIndexException) LiteralLabel(org.apache.jena.graph.impl.LiteralLabel)

Aggregations

SpatialIndexException (org.apache.jena.query.spatial.SpatialIndexException)6 Node (org.apache.jena.graph.Node)3 LiteralLabel (org.apache.jena.graph.impl.LiteralLabel)3 EntityDefinition (org.apache.jena.query.spatial.EntityDefinition)2 Resource (org.apache.jena.rdf.model.Resource)2 Directory (org.apache.lucene.store.Directory)2 File (java.io.File)1 IOException (java.io.IOException)1 CmdException (jena.cmd.CmdException)1 SpatialVocab.pDirectory (org.apache.jena.query.spatial.assembler.SpatialVocab.pDirectory)1 Model (org.apache.jena.rdf.model.Model)1 RDFNode (org.apache.jena.rdf.model.RDFNode)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 Document (org.apache.lucene.document.Document)1 IndexReader (org.apache.lucene.index.IndexReader)1 IndexableField (org.apache.lucene.index.IndexableField)1 QueryParser (org.apache.lucene.queryparser.classic.QueryParser)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 Query (org.apache.lucene.search.Query)1 ScoreDoc (org.apache.lucene.search.ScoreDoc)1