How to define polygons in Grakn?

123 Views Asked by At

I want to model physical objects in Grakn. It's quite straightforward to model physical objects as a point or a rectangle:

define

length sub attribute,
    value double;

position sub attribute,
    value double;

lon sub position;
lat sub position;
elevation sub position;
width sub length;
depth sub length;
height sub length;


physical_object sub entity,
    has lon,
    has lat,
    has elevation,
    has width,
    has depth,
    has height;

For a point, simple leave width, depth and height empty.

However, I'm struggling with how to model a physical object that is a polygon, i.e. a list of connected lines. How can I model this elegantly in Grakn?

2

There are 2 best solutions below

0
Vlad On

Given that not every physical_object in your world has width, depth and height, maybe we can remove these attributes from the high-level definition?

physical_object sub entity,
    has lon,
    has lat,
    has elevation;

And rectangle can be

rect sub physical_object,
    has width,
    has depth,
    has height;

Then you can define point like that

point sub physical_object,
    plays edge-point_point;

and an edge would be 2 points

edge-point sub relation,
    relates edge-point_point,
    relates edge-point_edge;

edge sub entity,
    has length,
    plays edge-point_edge;

after that polygon can be represented as

polygon sub physical_object,
    has edge; // here it can be multiple edges, we don't have cardinality constraints yet

But in that way polygon can be a set of not connected edges, you can define polygon differently depending on how you want to use it

0
Michael J Sullivan On

Most spatial graph databases (and CAD programs) store their data as arrays of primitives to facilitate describing any possible shape. These databases also allow one to natively perform intersection/unions on such arrays. You might want to follow that pattern if only to be able to import/export from/into these systems. Here is one example: https://docs.oracle.com/database/121/SPATL/simple-example-inserting-indexing-and-querying-spatial-data.htm#SPATL486

So perhaps the question to the GRAKN community should be: how to best model arrays of primitives?

P.S. adding temporality into the mix would make it even more interesting/challenging!