Geography¶
Geography is a data type composed of latitude and longitude that represents geospatial information. Nebula Graph currently supports Point, LineString, and Polygon in Simple Features and some functions in SQL-MM 3, such as part of the core geo parsing, construction, formatting, conversion, predicates, and dimensions.
Type description¶
A point is the basic data type of geography, which is determined by a latitude and a longitude. For example, "POINT(3 8)"
means that the longitude is 3°
and the latitude is 8°
. Multiple points can form a linestring or a polygon.
Shape | Example | Description |
---|---|---|
Point | "POINT(3 8)" |
Specifies the data type as a point. |
LineString | "LINESTRING(3 8, 4.7 73.23)" |
Specifies the data type as a linestring. |
Polygon | "POLYGON((0 1, 1 2, 2 3, 0 1))" |
Specifies the data type as a polygon. |
Examples¶
For functions about the geography data type, see Geography functions.
//Create a Tag to allow storing any geography data type.
nebula> CREATE TAG IF NOT EXISTS any_shape(geo geography);
//Create a Tag to allow storing a point only.
nebula> CREATE TAG IF NOT EXISTS only_point(geo geography(point));
//Create a Tag to allow storing a linestring only.
nebula> CREATE TAG IF NOT EXISTS only_linestring(geo geography(linestring));
//Create a Tag to allow storing a polygon only.
nebula> CREATE TAG IF NOT EXISTS only_polygon(geo geography(polygon));
//Create an Edge type to allow storing any geography data type.
nebula> CREATE EDGE IF NOT EXISTS any_shape_edge(geo geography);
//Create a vertex to store the geography of a polygon.
nebula> INSERT VERTEX any_shape(geo) VALUES "103":(ST_GeogFromText("POLYGON((0 1, 1 2, 2 3, 0 1))"));
//Create an edge to store the geography of a polygon.
nebula> INSERT EDGE any_shape_edge(geo) VALUES "201"->"302":(ST_GeogFromText("POLYGON((0 1, 1 2, 2 3, 0 1))"));
//Query the geography of Vertex 103.
nebula> FETCH PROP ON any_shape "103" YIELD ST_ASText(any_shape.geo);
+----------+---------------------------------+
| VertexID | ST_ASText(any_shape.geo) |
+----------+---------------------------------+
| "103" | "POLYGON((0 1, 1 2, 2 3, 0 1))" |
+----------+---------------------------------+
//Query the geography of the edge which traverses from Vertex 201 to Vertex 302.
nebula> FETCH PROP ON any_shape_edge "201"->"302" YIELD ST_ASText(any_shape_edge.geo);
+---------------------+---------------------+----------------------+---------------------------------+
| any_shape_edge._src | any_shape_edge._dst | any_shape_edge._rank | ST_ASText(any_shape_edge.geo) |
+---------------------+---------------------+----------------------+---------------------------------+
| "201" | "302" | 0 | "POLYGON((0 1, 1 2, 2 3, 0 1))" |
+---------------------+---------------------+----------------------+---------------------------------+
//Create an index for the geography of the Tag any_shape and run LOOKUP.
nebula> CREATE TAG INDEX IF NOT EXISTS any_shape_geo_index ON any_shape(geo);
nebula> REBUILD TAG INDEX any_shape_geo_index;
nebula> LOOKUP ON any_shape YIELD ST_ASText(any_shape.geo);
+----------+-------------------------------------------------+
| VertexID | ST_ASText(any_shape.geo) |
+----------+-------------------------------------------------+
| "103" | "POLYGON((0 1, 1 2, 2 3, 0 1))" |
+----------+-------------------------------------------------+
Last update: November 10, 2021