Search code examples
javascripttypescriptsqliteionic3cordova-plugins

Store polygon type of data on the `SQLite` database


Can you tell me how can I store polygon type of data on the SQLite database?

Note: I'm using this Cordova plugin.

polygon: Point[];

interface Point {
    x: number;
    y: number;
}

enter image description here


Solution

  • As Shawn pointed out, SQLite has recently implemented its own GeoPoly type - https://www.sqlite.org/geopoly.html

    But the "correct" way to do this is probably using one of the various GIS standards. Both GeoJSON and WKT can be used to store a polygon easily in a text field. Or if for whatever reason you want binary, there's WKB which you can then store in a blob field (see the WKT link).

    There are numerous tools in various languages which allow you to easily convert and handle these data types.

    Note: storing as GeoPoly in SQLite will get you basic spatial capabilities. The other two won't. But if you do want spatial capabilities, but may want to consider spatialite instead.