Support for the POINT datatype such as Postgres and Mysql have

199 views
Skip to first unread message

Paul Taylor

unread,
Sep 27, 2013, 4:48:01 AM9/27/13
to h2-da...@googlegroups.com
Do you  plan to support this datatype, that seems to be getting used alot more.

In my own case I use h2 for my unit tests in postgres mode, postgres is the database used in production. I now have a problem they have started to use the POINT datatype and because iM using h2 I cannot create any unit test for this.

Noel Grandin

unread,
Sep 27, 2013, 4:59:55 AM9/27/13
to h2-da...@googlegroups.com, Paul Taylor, Nicolas Fortin (OrbisGIS)
It's not well documented, but we already support geometry datatypes.

http://h2database.com/html/datatypes.html#geometry_type

Nicolas Fortin has been working on this, perhaps he can expand.

Paul Taylor

unread,
Sep 27, 2013, 6:47:04 AM9/27/13
to h2-da...@googlegroups.com, Paul Taylor, Nicolas Fortin (OrbisGIS)
Thats promising, but im trying to create a table with a POINT datatype, is that possible in my sql this line is failng:

    coordinates         POINT,

so is there a way to do that

vrota...@gmail.com

unread,
Sep 27, 2013, 7:38:38 AM9/27/13
to h2-database
create domain point as array check (array_length(value) = 2)

this?


--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database...@googlegroups.com.
To post to this group, send email to h2-da...@googlegroups.com.
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/groups/opt_out.



--
   Vasile Rotaru

Paul Taylor

unread,
Sep 27, 2013, 8:49:59 AM9/27/13
to h2-da...@googlegroups.com


On Friday, 27 September 2013 12:38:38 UTC+1, Vasile Rotaru wrote:
create domain point as array check (array_length(value) = 2)

this?


Hi, thanks that does work :)
But Im now struggling with the syntax of an INSERT statement , could you provide an example please

vrota...@gmail.com

unread,
Sep 27, 2013, 9:19:04 AM9/27/13
to h2-database
This seem to wok...

create table points (id identity, point point not null)

insert into points(point) values((2, 3))


--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database...@googlegroups.com.
To post to this group, send email to h2-da...@googlegroups.com.
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/groups/opt_out.



--
   Vasile Rotaru

Paul Taylor

unread,
Sep 27, 2013, 11:48:47 AM9/27/13
to h2-da...@googlegroups.com
Thanks again, that works, but how do I extract the values

I can do rs.getString(coords) to output something like

(160,120)

but then I have to parse the value, is there some object I can cast it to so I can refer to the two values directly ?

Nicolas Fortin (OrbisGIS)

unread,
Sep 27, 2013, 2:24:16 PM9/27/13
to h2-da...@googlegroups.com
Hi,

Yes you are right , point is only a constraint. In H2GIS here https://github.com/irstv/H2GIS there is a complete set of Constraint (Point Polygon and LineString) and standard spatial functions.

You can use the quick start here, https://github.com/irstv/H2GIS/wiki there is a build (h2gis dist) that embed h2 h2gis and jts.

H2GIS use a slightly modified h2 version because Geometry.equals is improperly used in ValueGeometry. ValueGeometry should use WKB (binary) equality check.


Nicolas Fortin (OrbisGIS)

unread,
Sep 27, 2013, 2:50:44 PM9/27/13
to h2-da...@googlegroups.com
You can use regular h2 by using geometry type and WKT

create table pttable (the_geom geometry);
insert into pttable values( 'POINT ( 10 10 10 )');


In JDBC you get the values using this function:

import com.vividsolutions.jts.geom.Point;

ResultSet rs = statement.executeQuery( "select * from pttable" );
while( rs.next() ) {
    Point myPoint = (Point)rs.getObject(1);
}

Documentation of jts is here:
http://tsusiatsoftware.net/jts/main.html
Point class:
http://tsusiatsoftware.net/jts/javadoc/com/vividsolutions/jts/geom/Point.html
 
-Nicolas Fortin
Atelier SIG
IRSTV FR CNRS 2488
Reply all
Reply to author
Forward
0 new messages