4

I have some geometry in cgal that I would like to export to postgis. The kernel I'm using is the same as what sfcgal uses (exact predicate exact construction), but I'm encountering some errors in postgis when I use the standard float output for the cgal points with ST_GeomFromText. For instance when I try to use ST_3DIntersection with a polygon I get an error that the polygon points aren't coplanar, but I have confirmed that that the points are coplanar in my cgal program.

What I'm hoping for is a way to construct the postgis geometry using the exact fraction output from point().exact() in cgal, e.g. ST_ExactGeomFromText('PointZ(0, 0, 8676011023327629/4611686018427387904)'). I haven't been able to find a function like this in the docs though. If there isn't such a function does anyone have some suggestions on how I can get valid geometry from cgal to postgis?

EDIT:

I've now tried building postgis and sfcgal from source with SFCGAL_CHECK_VALIDITY=OFF as well as a couple other things, but nothing seems to be working. Here's a reproduction:

You'll notice IsPlanar is true, but ST_3DArea raises an error saying the points aren't coplanar.

CREATE TABLE polygon_test();
SELECT AddGeometryColumn('polygon_test', 'geom', 4326, 'POLYGONZ', 3);
INSERT INTO polygon_test (geom) VALUES(ST_GeomFromText('POLYGON Z ((-2456.65849662024 -494.251393883276 412,-2486.7786660429 -413.696999618586 412,-2486.77945264572 -413.696623334753 354,-2456.65889152129 -494.252065179804 354,-2456.65849662024 -494.251393883276 412))', 4326));
SELECT ST_IsPlanar(geom) FROM polygon_test;


SELECT ST_3DArea(geom) FROM polygon_test;
2

As of PostGIS 2.5, the geometry and geography types only support storage of double-precision floating point values. Any coordinates that you input to PostGIS are converted to the geometry type, and thus will be rounded to double-precision before finding their way to SFCGAL.

Maybe it is possible to reduce the precision of your geometry in CGAL before importing it into PostGIS, so that it can be imported exactly? I've used CGAL's 2D Snap Rounding package for this purpose, but I'm not sure if similar functionality exists in 3D.

(Bonus: a description of the PostGIS GSERIALIZED type, which stores both geometry and geography objects, is available here)

-1

As you said it is a 3d and geometry suggest that the coordinates are coplanar.

You should check if the three dimensions align properly in both files.

Also, transformation between two different coordinate system might be a possible cause of this issue.

  • I'm not sure I understand what you mean. CGAL isn't geospatial so it just uses plain Cartesian coordinates and I'm exporting with SRID 4326. – user3747260 Oct 30 '16 at 19:00
  • This happens when the actual values recorded were in certain geographic coordinate system like NAD 1983 and when you try to import it into the POSTGRESQL then just try to import it in NAD 1983 and then apply the transformation into WGS84 — SRID 4326 – Akshay Anand Oct 31 '16 at 1:43

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.