spatial: How to get indexed nodes from LayerNodeIndex?

54 views
Skip to first unread message

Axel Morgner

unread,
May 3, 2012, 12:16:10 PM5/3/12
to ne...@googlegroups.com
Hi,

I'm struggling with getting the indexed node from a LayerNodeIndex.

Let's say adding a node (id 1) to the layer index:

ᅵᅵᅵ layerIndex.add(node, "", "");

In LayerNodeIndex, the id is saved as id property on the SpatialDatabaseRecord object.

ᅵᅵᅵ layer.add(
ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ decodeGeometry, new String[] { "id" },
ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ new Object[] { geometry.getId() } );

Internally, (in EditableLayerImpl), an additional geomNode (let's say id 2) is created:

ᅵᅵᅵ private Node addGeomNode(Geometry geom, String[] fieldsName, Object[] fields) {
ᅵᅵᅵ ᅵᅵᅵ Node geomNode = getDatabase().createNode();
ᅵᅵᅵ [...]

When querying the index, the iterator returns node 2, not node 1.

SpatialRecordHits:

ᅵᅵᅵ protected Node fetchNextOrNull()
ᅵᅵᅵ {
ᅵᅵᅵᅵᅵᅵᅵ int i = index++;
ᅵᅵᅵᅵᅵᅵᅵ return i < size() ? hits.get( i ).getGeomNode() : null;
ᅵᅵᅵ }


I would expect to get the original node (id 1 here) from the index. Am I missing something?

Greetings
Axel




Peter Neubauer

unread,
May 3, 2012, 12:25:37 PM5/3/12
to ne...@googlegroups.com

Well,
Thing is that there might not be a one to one mapping between geometry and your domain node. It might just be the entry point to a whole polygon or a traversal. That is why you get back the geometry node, and the decoder can then resolve it to original underlying domain subgraphs (in the easiest case only one node)

Makes sense?

On May 3, 2012 6:16 PM, "Axel Morgner" <ax...@morgner.de> wrote:
Hi,

I'm struggling with getting the indexed node from a LayerNodeIndex.

Let's say adding a node (id 1) to the layer index:

    layerIndex.add(node, "", "");

In LayerNodeIndex, the id is saved as id property on the SpatialDatabaseRecord object.

    layer.add(

                decodeGeometry, new String[] { "id" },
                new Object[] { geometry.getId() } );

Internally, (in EditableLayerImpl), an additional geomNode (let's say id 2) is created:

    private Node addGeomNode(Geometry geom, String[] fieldsName, Object[] fields) {
        Node geomNode = getDatabase().createNode();
    [...]

When querying the index, the iterator returns node 2, not node 1.

SpatialRecordHits:

    protected Node fetchNextOrNull()
    {
        int i = index++;

        return i < size() ? hits.get( i ).getGeomNode() : null;
    }

Axel Morgner

unread,
May 3, 2012, 1:00:49 PM5/3/12
to ne...@googlegroups.com
Thanks Peter for the quick reply!

Ok, with a decoder (f.e. the SimplePointEncoder#decodeGeometry), I get the geometry, but still no reference to my domain node which I added to the index.

Solved it for me by using graphDb.getNodeById((Long) geomNode.getProperty("id")).

Peter Neubauer

unread,
May 3, 2012, 3:00:43 PM5/3/12
to ne...@googlegroups.com
That is true. Do you think that would be better? Craig, WDYT of
changing this to be a relationship?

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

If you can write, you can code - @coderdojomalmo
If you can sketch, you can use a graph database - @neo4j

Craig Taverner

unread,
May 4, 2012, 5:19:08 PM5/4/12
to ne...@googlegroups.com
This differs somewhat from my memory of how things work. In the SimplePointLayer the node added to the index is in fact the geometry node. Are you using some other GeometryEncoder that expects the node to be something else?

On the other hand, reading the code above I see you are actually not working with the original index, but the LayerNodeIndex which Peter added as a wrapper. In that case I think only Peter knows the reason for not storing and retrieving the node originally passed. I know very little about the indexProvider wrappings.

My own vote is to keep to the original model conceptually, which is that whatever you add to the index is whatever you get back, and in principle this should be the node that represents the geometry. How that geometry is actually stored is up to the geometry encoder, and can be separate from the node passed, but is usually either the node passed (as in SimplePointGeometryEncoder and DefaultGeometryEncoder) or closely linked by relationships to it (as in the OSMGeometryEncoder).

Peter, do you remember why you used a different node in the IndexProvider?

Peter Neubauer

unread,
May 5, 2012, 1:33:16 AM5/5/12
to ne...@googlegroups.com

No, I don't. Thisight actually be a bug. Axel, if you change it and send a PR ad I am not on my machine, I'd that OK?

Axel Morgner

unread,
May 5, 2012, 3:10:15 PM5/5/12
to ne...@googlegroups.com
Ok! If I find a little time tomorrow, I will have a look on it and make a suggestion and PR.

Peter Neubauer

unread,
May 5, 2012, 3:13:21 PM5/5/12
to ne...@googlegroups.com

You rock.

Axel Morgner

unread,
May 6, 2012, 5:54:54 PM5/6/12
to ne...@googlegroups.com
Unfortunately, I did not succeed in making changes that won't break the tests. We'll see what insights tomorrow will bring perhaps ..
-- 
Axel Morgner
Morgner UG
Hanauer Landstr. 291a
60314 Frankfurt
Germany

Phone +49 151 40522060
Skype axel.morgner
E-mail ax...@morgner.de
Web http://www.morgner.de
Twitter @amorgner
Reply all
Reply to author
Forward
0 new messages