orbisgis / h2gis

A spatial extension of the H2 database.
http://www.h2gis.org
GNU Lesser General Public License v3.0
207 stars 63 forks source link

Unknown data type: "POINT" #1314

Closed indrekluuk closed 2 years ago

indrekluuk commented 2 years ago

Hello!

We are using Postgres as our main database and H2 for tests. I want to start using PostGIS to store geographical information.

In Postgres I can create a new table like this:

create table test_table (
  test_table_id     SERIAL PRIMARY KEY,
  data_point        point,
  data_polygon      polygon
);

In H2 with the old version: H2: 1.4.197 h2gis: 1.5.0 This works without any errors:

CREATE ALIAS IF NOT EXISTS H2GIS_SPATIAL FOR "org.h2gis.functions.factory.H2GISFunctions.load";
CALL H2GIS_SPATIAL();

create table test_table (
  test_table_id     SERIAL PRIMARY KEY,
  data_point        point,
  data_polygon      polygon
);

But when I update to: H2: 2.1.210 (I also tried 2.1.212 and 2.1.214) h2gis: 2.0.0

Then the same query throws an error:

Caused by: java.sql.SQLException: Error executing stmt[create table test_table (
  test_table_id     SERIAL PRIMARY KEY,
  data_point        point,
  data_polygon      polygon
)] error[Unknown data type: "POINT"; SQL statement:
create table test_table (
  test_table_id     SERIAL PRIMARY KEY,
  data_point        point,
  data_polygon      polygon
)

Am I doing something wrong or am i misundestanging it?

The main Github page of H2GIS says that tables can be created like this: CREATE TABLE mygeometrytable (ID INTEGER, GEOM GEOMETRY(POINT));

Is "point" and "polygon" as direct types deprecated and I should create the table like this instead?:

create table test_table (
  test_table_id     SERIAL PRIMARY KEY,
  data_point         GEOMETRY(point),
  data_polygon       GEOMETRY(polygon)
);

Or is something broken with my configuration and the "point" and "polygon" as types should actually still work?

indrekluuk commented 2 years ago

Ok, I have done some additional reading and now it seems to me that Postgres' native types 'point' and 'polygon' are not part of Postgis. So, I should use 'GEOMETRY(point)' and 'GEOMETRY(polygon)'.

ebocher commented 2 years ago

You must used GEOMETRY(POINT) or GEOMETRY(POINT, sridValue)