Skip to content

API Reference

/

Data types

Geometry

The Geometry class represents SurrealDB geometric data types. It currently supports point geometry, mapping to Java's Point2D.Double from java.awt.geom.

Source: surrealdb.java

Checks if the geometry value is a point.

Method Syntax
geometry.isPoint()

Returns: boolean

Returns the point coordinates as a Point2D.Double. The x coordinate represents longitude and y represents latitude.

Method Syntax
geometry.getPoint()

Returns: Point2D.Double (java.awt.geom)

Working with geometry values
import com.surrealdb.Surreal;
import com.surrealdb.Response;
import com.surrealdb.Value;
import com.surrealdb.Geometry;
import com.surrealdb.signin.RootCredential;
import java.awt.geom.Point2D;

try (Surreal db = new Surreal()) {
    db.connect("ws://localhost:8000");
    db.useNs("surrealdb").useDb("docs");
    db.signin(new RootCredential("root", "root"));

    Response response = db.query(
        "RETURN <geometry> { type: 'Point', coordinates: [10.0, 20.0] }"
    );
    Value result = response.take(0);
    Geometry geo = result.getGeometry();

    if (geo.isPoint()) {
        Point2D.Double point = geo.getPoint();
    }
}

Was this page helpful?