Incorrect parsing of FGF geometry

98 views
Skip to first unread message

Vedran Stojnović

unread,
Aug 25, 2023, 10:38:46 AM8/25/23
to spatiali...@googlegroups.com
Hi,

I have problems with GeomFromFGF() function.
I have exported geometries from AutoCAD Map to SQLite Spatial (FDO SQLite), and they load and display correctly in QGIS. I also did a Check Validity with GEOS and QGIS all it reports that all features in layer are valid.

But when I try to use it with spatial functions via SpatiaLite I get errors and crashes:
for example with: ST_PointOnSurface(GeomFromFGF(Geom)),
or with ST_Within().

Simple query SELECT AsWKT(GeomFromFGF(Geom)) AS WKT FROM table WHERE FeatID = 2 returns:
MULTIPOLYGON(
    (
        (
            653074.9 5003366.259999999,
            0 653069.4499999999,
            5003366.7 0,
            653058.26 5003367.82,
            0 653056.79,
            5003367.929999999 0,
            653068.6899999999 5003410.07,
            0 653079.31,
            5003447.66 0,
            653080.5699999999 5003452.339999999,
            0 653096.8299999999
        )
    ),
    (
        (
            0 0,
            0 0,
            0 0,
            0 106455133957404600000000000000000000000000000000000000000000000000000000000,
            0 0,
            220013634712918100000000000000000000000000000000000000000000000000000 769843823860227700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,
            220119001716826400000000000000000000000000000000000000000000000000000 220013652603593900000000000000000000000000000000000000000000000000000,
            260852630201480700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0,
            220013652603593900000000000000000000000000000000000000000000000000000 769843823860227700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,
            106457026406292900000000000000000000000000000000000000000000000000000000000 0,
            772533753723214800000000000000000000000000000 156436313205679400000000000000000000000000000000000000000000000000000000000000000000000000000000000
        )
    )
)

While for the same feature (FeatId = 2) QGIS shows this:
Polygon Z (
    (
        653074.90000000002328306 5003366.25999999977648258 0,
        653069.44999999995343387 5003366.70000000018626451 0,
        653058.26000000000931323 5003367.82000000029802322 0,
        653056.7900000000372529 5003367.92999999970197678 0,
        653068.68999999994412065 5003410.07000000029802322 0,
        653079.31000000005587935 5003447.66000000014901161 0,
        653080.56999999994877726 5003452.33999999985098839 0,
        653096.82999999995809048 5003447.87999999988824129 0,
        653078.81000000005587935 5003378.63999999966472387 0,
        653075.55000000004656613 5003366.12000000011175871 0,
        653074.90000000002328306 5003366.25999999977648258 0
    )
)


Even when I try to execute same query twice in a row I sometimes get different results:

spatialite>SELECT FeatId, AsWKT(GeomFromFGF(Geom)) AS WKT FROM table WHERE FeatId = 2;
2|MULTIPOLYGON(((653074.9 5003366.259999999,0 653069.4499999999,5003366.7 0,653058.26 5003367.82,0 653056.79,5003367.929999999 0,653068.6899999999 5003410.07,0 653079.31,5003447.66 0,653080.5699999999 5003452.339999999,0 653096.8299999999)),((0 0,0 0,0 0,0 0,0 0,0 0,nan 0,0 0,0 0,0 0,nan 0)))

spatialite>SELECT FeatId, AsWKT(GeomFromFGF(Geom)) AS WKT FROM table WHERE FeatId = 2;
2|MULTIPOLYGON(((653074.9 5003366.259999999,0 653069.4499999999,5003366.7 0,653058.26 5003367.82,0 653056.79,5003367.929999999 0,653068.6899999999 5003410.07,0 653079.31,5003447.66 0,653080.5699999999 5003452.339999999,0 653096.8299999999)),((0 0,0 -4260607557632,0 598008221088484700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,0 0,-190359804756584700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0,0 0,nan 0,0 0,0 0,0 0,nan 0)))

spatialite>SELECT FeatId, AsWKT(GeomFromFGF(Geom)) AS WKT FROM table WHERE FeatId = 2;
2|MULTIPOLYGON(((653074.9 5003366.259999999,0 653069.4499999999,5003366.7 0,653058.26 5003367.82,0 653056.79,5003367.929999999 0,653068.6899999999 5003410.07,0 653079.31,5003447.66 0,653080.5699999999 5003452.339999999,0 653096.8299999999)),((0 0,0 -4365060407296,0 598008221088484700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,0 0,-190359804756584700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0,0 0,nan 0,0 0,0 0,0 0,nan 0)))

--
Srdačan pozdrav / Kind regards,
Vedran Stojnović.

a.fu...@lqt.it

unread,
Aug 25, 2023, 12:00:45 PM8/25/23
to spatiali...@googlegroups.com
On Fri, 25 Aug 2023 16:38:06 +0200, Vedran Stojnović wrote:
> Hi,
>
> I have problems with GeomFromFGF() function.
>

Hi Vedran,

it seems very likely that you are the first ever to try using
the exotic FGF geometries on SpatiaLite.

I myself as the main developer and maintainer of the project
didn't even remembered that they existed and had to read
the documentation to figure out what we were talking about.

so standing things, it's no surprise to me that the FGF parser
could be seriously buggy.

I'm interested in fixing this bug even if it doesn't seem
strategic at all, but to do such a thing I absolutely need
some examples of FGF geometries to test and debug.

I see you wasted a lot of time patiently copying some
coordinate sequences produced by QGIS, but it's completely
useless stuff.

what would be needed is a very small SQLite DB containing
some FGF samples possibly accompanied by their corresponding
WKTs

you can also possibly send it directly to my private mailbox
<a.fu...@lqt.it>

best regards,
Sandro

Vedran Stojnović

unread,
Aug 25, 2023, 12:32:49 PM8/25/23
to spatiali...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "SpatiaLite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spatialite-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/spatialite-users/69766a794bcec2bc49f6dbe824ae275e%40lqt.it.

Alessandro Furieri

unread,
Sep 2, 2023, 5:25:55 AM9/2/23
to SpatiaLite Users
Hi Vedran,

after a thorough debug session it emerged that the current implementation of FGF was kind of a worm factory

the interpretation of the geometries with XY dimensions was correct, but that for XYZ, XYM and XYZM was completely wrong.
unfortunately your problematic sample actually contains XYZ polygons.

thank you very much for passing me the links to the official AutoDesk documentation which finally allowed me to develop an implementation compliant with the FGF specifications also for 3D dimensions.

the code with all the latest patches for FGF is available on the project's Fossil repository  and will be released publicly with the next version of SpatiaLite:

https://www.gaia-gis.it/fossil/libspatialite/index

bye Sandro

Vedran Stojnović

unread,
Sep 2, 2023, 10:00:43 AM9/2/23
to spatiali...@googlegroups.com
Hi Sandro,

amazing news from You!
Thank You very much for fixing this, it'll help me a lot in my current workflows and automations, without the need to convert data to different format.

James McGuiness

unread,
Oct 16, 2024, 3:55:11 AM10/16/24
to SpatiaLite Users
Hi all,

I'm trying to get FGF functionality working for a similar reason - extracting data from autocad in my case to manipulate in python.

Looking at the dates on the source and binary files, it all looks like they were modified before this conversation. Does 5.1.0 incorporate these changes?

I've tried the binary mod_spatialite.dll to no avail, and wanted to check the updates were in the source I'd downloaded before I embarked on that adventure.

I'm a newb, so I may well have this totally wrong.

a.fu...@lqt.it

unread,
Oct 16, 2024, 4:27:10 AM10/16/24
to spatiali...@googlegroups.com
On Wed, 16 Oct 2024 00:31:50 -0700 (PDT), James McGuiness wrote:
> Hi all,
>
> I'm trying to get FGF functionality working for a similar reason -
> extracting data from autocad in my case to manipulate in python.
>
> Looking at the dates on the source and binary files, it all looks
> like
> they were modified before this conversation. Does 5.1.0 incorporate
> these changes?
>

a necessary premise:

support for FGF geometries is certainly one of the least used
SpatiaLite features.
As far as I remember, in the last ten years there have only
been a couple of interested users.
I personally have never used it at all.
In short: support for FGF is not exactly one of our most
urgent priorities.


Having said that: it seems that the bug on FGF was reported
(and resolved) only after the release of 5.1.0

bye Sandro
Reply all
Reply to author
Forward
0 new messages