Exemplo n.º 1
0
Handle<Value> StrTree::Remove(const Arguments& args) {
    HandleScope scope;

    if(args.Length() == 0) {
        return ThrowException(String::New("no geometry to remove."));
    }

    StrTree *strTree = ObjectWrap::Unwrap<StrTree>(args.This());
    Geometry *geom = ObjectWrap::Unwrap<Geometry>(args[0]->ToObject());
    GEOSGeometry *g = geom->GetGEOSGeometry();
    char r = GEOSSTRtree_remove(strTree->geos_strTree_,g, NULL);
    if(r) {
        return True();
    } else {
        return False();
    }
}
Exemplo n.º 2
0
Handle<Value> StrTree::Insert(const Arguments& args) {
    HandleScope scope;
    if(args.Length() == 0) {
        return ThrowException(String::New("nothing to insert."));
    }

    Local<Object> o = args[1]->ToObject();
    StrTree* strTree = ObjectWrap::Unwrap<StrTree>(args.This());
    //TODO check if input is geometry object
    Geometry *geom = ObjectWrap::Unwrap<Geometry>(args[0]->ToObject());
    GEOSGeometry *g = geom->GetGEOSGeometry();
    //TODO handle userdata
    bucket *b = new bucket();
    b->o = o;
    GEOSSTRtree_insert(strTree->geos_strTree_, g, b);

    return Undefined(); //return nothing and close scope?

}
Exemplo n.º 3
0
Handle<Value> StrTree::Query(const Arguments& args) {
    HandleScope scope;

    if(args.Length() != 2)
        return ThrowException(String::New("no geometry to query."));

    StrTree *strTree = ObjectWrap::Unwrap<StrTree>(args.This());
    Geometry *geom = ObjectWrap::Unwrap<Geometry>(args[0]->ToObject());
    GEOSGeometry *g = geom->GetGEOSGeometry();

    Local<Function> callback = Local<Function>::Cast(args[1]);
    Persistent<Function> cb = Persistent<Function>::New(callback);

    //this seems to be async
    //strTree->Ref();
    payload *p = new payload();
    p->cb = cb;
    p->strTree = strTree;
    GEOSSTRtree_query(strTree->geos_strTree_,g, QueryCallback, p);

    return Undefined();
}