Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgisGeometryCodec is hardcoded for only two dimensions #630

Open
frjonsen opened this issue Jan 24, 2024 · 2 comments
Open

PostgisGeometryCodec is hardcoded for only two dimensions #630

frjonsen opened this issue Jan 24, 2024 · 2 comments
Labels
status: blocked An issue that is blocked on an external project change

Comments

@frjonsen
Copy link

frjonsen commented Jan 24, 2024

Bug Report

Versions

  • Driver: Postgres
  • Database: Postgres with PostGIS extension
  • Java: 17
  • OS: ArchLinux

Current Behavior

I am using PostGIS, and have a table defined as geometry(Pointz, 4326). I have manually inserted a record in the database, where the value for this column is serialized as 01010000A0E6100000C5FEB27BF2B02840BC0512143FBA53400000000000407F40. I can query this table just fine. For reference, converted to GeoJson the result I get is { "type": "Point", "coordinates": [ 12.3456, 78.9101, 500 ] }, which is what I would expected.

However, passing this same GeoJson back in, converting to a JTS Point, and trying to insert it, I can an error, io.r2dbc.postgresql.ExceptionFactory$PostgresqlBadGrammarException: Column has Z dimension but geometry does not

As far as I can tell, this is because the codec appears to be hardcoded for two dimensions
rather than actually checking the number of dimensions the Geometry object is holding.

org.springframework.r2dbc.BadSqlGrammarException: executeMany; bad SQL grammar [INSERT INTO device.chargers (device_id, serial_number, max_charge_power, location) VALUES ($1, $2, $3, $4)]
	at org.springframework.r2dbc.connection.ConnectionFactoryUtils.convertR2dbcException(ConnectionFactoryUtils.java:253) ~[spring-r2dbc-6.1.3.jar:6.1.3]

Table schema

create table device.chargers (
  device_id uuid primary key not null,
  serial_number character varying(30),
  max_charge_power double precision,
  location public.geometry(PointZ,4326) not null
);
Input Code
-- your SQL here;

Steps to reproduce

Input Code
// your code here;

Expected behavior/code

Insert should not error, and all dimensions should be set

Possible Solution

A naïve solution that works in my case is

int dims = Double.isNaN(geometry.getCoordinate().z) ? 2 : 3;
WKBWriter writer = new WKBWriter(dims, true);

but I'm not familiar enough with either PostGIS or JTS to tell if this solution is general for all geometric types, or if it only solves the case of Point and PointZ.

Additional context

@frjonsen frjonsen added the status: waiting-for-triage An issue we've not yet triaged label Jan 24, 2024
@mp911de
Copy link
Collaborator

mp911de commented Jan 25, 2024

I'm totally not an expert on Postgis and WKBWriter either. I'm happy to improve the codec if someone knowledgeable provides us with some guidance.

@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 25, 2024
@mp911de
Copy link
Collaborator

mp911de commented Apr 9, 2024

Seems the required information cannot be retrieved reliably as per locationtech/jts#654

@mp911de mp911de added status: blocked An issue that is blocked on an external project change and removed type: bug A general bug labels Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: blocked An issue that is blocked on an external project change
Projects
None yet
Development

No branches or pull requests

2 participants