Re: [Geotools-gt2-users] Writing to a postgis database with 4 dimensional coordinates From: Mark Payne - 2011-10-19 09:46 ```Hi Diego, I had to do a bit of work with 4D coordinates and what I found out was that all the JTS classes used for building geometries (Coordinate, and those supplied to implement the interfaces CoordinateSequence and CoordinateSequenceFactory) are inherently 3D only. If you want to use 4D you have to provide some kind of 4D coordinate class, and implementations of CoordinateSequence and CoordinateSequenceFactory that know how to populate it. Fortunately in the full source download of JTS there is a package called com.vividsolutions.jtsexample.geom that has examples of how to do this. Note that in the version of JTS I downloaded (1.11) there was a bug in ExtendedCoordinateSequence.java; the switch statements in setOrdinate(int, int, double) is missing break statements after each case. Mark > ---------------------------------------------------------------------- > > Message: 1 > Date: Tue, 18 Oct 2011 12:30:17 +0100 > From: Diego Jesus > Subject: [Geotools-gt2-users] Writing to a postgis database with 4 > dimensional coordinates > To: geotools users > Message-ID:<4E9D6349.4050505@...> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > Hi! > > I'm trying to write a geometry to a postgis database which has a > constraint that only allows 4D coordinates: > > CONSTRAINT enforce_dims_the_geom CHECK (st_ndims(the_geom) = 4 > > I'm using a a GeometryFactory to create my geometries and I have tried > to set a hint: > > GeometryFactory factory = JTSFactoryFinder.getGeometryFactory(new > Hints(Hints.COORDINATE_DIMENSION, new Integer(4))); > Geometry geom = factory.createPoint(new Coordinate(100, 101, 102)); > > However, this does not work and postgres complains with a: > > new row for relation "Geometry" violates check constraint > "enforce_dims_the_geom". > > I need to write the data with a Postgresql Connection and so I did: > > WKBWriter writer = new WKBWriter(); > PreparedStatement st = con.prepareStatement("INSERT INTO > \""+TABLE_NAME+"\" " + > "("+THE_GEOM+") " + > "VALUES (?)", > PreparedStatement.RETURN_GENERATED_KEYS); > st.setBytes(1, writer.write(g.mGeometry)); > > How can I write the geometry with 4D coordinates? > > Thanks ```
 Re: [Geotools-gt2-users] Writing to a postgis database with 4 dimensional coordinates From: Diego Jesus - 2011-10-19 10:04 Attachments: Message as HTML ```Hello and thanks for the replies, I have found an alternative solution: Instead of using geotools to create 4D coordinates, I used postgis to force whatever geometry I want to write to be in 4D. Here's some code: Geometry mGeometry = factory.createPoint(new Coordinate(100, 101, 102)); st = con.prepareStatement("INSERT INTO \""+TABLE_NAME+"\" " + "("+THE_GEOM+") " + "VALUES (ST_Force_4D(ST_GeomFromText(?, 20791)))", PreparedStatement.RETURN_GENERATED_KEYS); st.setString(1, g.mGeometry.toText()); I convert the geometry to Well Known Text and in the SQL statement I convert it back to a geometry and force it to use 4D. It may be a work around but I believe it is working. Diego > ------------------------------------------------------------------------ > > Mark Payne > October 19, 2011 10:27 AM > > > Hi Diego, > > I had to do a bit of work with 4D coordinates and what I found out was > that all the JTS classes used for building geometries (Coordinate, and > those supplied to implement the interfaces CoordinateSequence and > CoordinateSequenceFactory) are inherently 3D only. > > If you want to use 4D you have to provide some kind of 4D coordinate > class, and implementations of CoordinateSequence and > CoordinateSequenceFactory that know how to populate it. Fortunately in > the full source download of JTS there is a package called > com.vividsolutions.jtsexample.geom that has examples of how to do this. > > Note that in the version of JTS I downloaded (1.11) there was a bug in > ExtendedCoordinateSequence.java; the switch statements in > setOrdinate(int, int, double) is missing break statements after each case. > > Mark > > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure contains a > definitive record of customers, application performance, security > threats, fraudulent activity and more. Splunk takes this data and makes > sense of it. Business sense. IT sense. Common sense. > http://p.sf.net/sfu/splunk-d2d-oct > _______________________________________________ > Geotools-gt2-users mailing list > Geotools-gt2-users@... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users ```