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

Vector layer points are not being imported/shown from MySQL datasource #55463

Closed
2 tasks done
Sakoes opened this issue Nov 29, 2023 · 6 comments · Fixed by OSGeo/gdal#9152
Closed
2 tasks done

Vector layer points are not being imported/shown from MySQL datasource #55463

Sakoes opened this issue Nov 29, 2023 · 6 comments · Fixed by OSGeo/gdal#9152
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Data Provider Related to specific vector, raster or mesh data providers Regression Something which used to work, but doesn't anymore

Comments

@Sakoes
Copy link

Sakoes commented Nov 29, 2023

What is the bug or the crash?

Issue

QGis 3.28.13 does not visualise/import points from a vector layer with a MySQL datasource anymore.

In QGis 3.28.13, I import a table from a MySQL datasource as a vector layer. However, the points are not being visualized. I suspect QGis is not importing the data correctly.

I classified this as a bug because this worked fine in QGis 3.4. I had to upgrade because my SQL provider does not accept the TLS version used by QGis 3.4 anymore.

Context

In the images below following can be observed: The coord (coordinate) column from the MySQL database, containing the points that need to be plotted, is missing from the QGis table structure.
I suspect that is the reason why QGis is not plotting/visualizing any points.
It looks like QGis is incorrectly converting the coord column into a geometry column.
Compare images below:

MySQL table structure

The coord column is a "point" datatype:
MySQL table structure

QGis 3.28.13 table structure

The coord column is missing, a geometry is added
QGis table structure

MySQL record example

The coord column contains coordinates:
MySQL record example

QGis 3.28.13 example record:

The geometry column only contains the word "POINT"
QGis record example

Questions

  • Is this a bug in QGis? This worked fine in QGis 3.4
  • Should I reconfigure my MySQL table to use another datatype than "point" in order for QGis to correctly import the coordinates.

Steps to reproduce the issue

Steps

  1. layer > add layer > vector layer
  2. In the vector layer panel:
source type: database
encoding automatic

Database Type: mysql
Connections: myconnection
Test Connection > Succesful
add 
  1. select items to add: tableWithCoordinates (shown in image above) > add layers
  2. Check attributes of imported layer -> coord column is missing, geometry column is added as described above
  3. I get following warning but I think it is unrelated:
this layer appears to have no projection specification. by default, this..
Choose: BD72 / Belgian Lambert 72

Versions

3.4 -> worked fine, but uses a deprecated TLS version
3.28.13 -> issue described above

QGIS version
3.28.13-Firenze
QGIS code revision
3b4db4f
Qt version
5.15.3
Python version
3.9.5
GDAL/OGR version
3.8.0
PROJ version
9.3.0
EPSG Registry database version
v10.094 (2023-08-08)
GEOS version
3.12.1-CAPI-1.18.1
SQLite version
3.41.1
PDAL version
2.6.0
PostgreSQL client version
unknown
SpatiaLite version
5.1.0
QWT version
6.1.6
QScintilla2 version
2.13.4
OS version
Windows 10 Version 2009

Active Python plugins
advison_module
0.1
geopunt4Qgis
2.3.0.5
db_manager
0.1.20
sagaprovider
2.12.99

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

Additional context

No response

@Sakoes Sakoes added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Nov 29, 2023
@agiudiceandrea
Copy link
Contributor

@Sakoes, thanks for reporting. In the issue report you mentioned QGIS 3.04 (maybe QGIS 3.4?), QGIS 3.24 which is no longer supported and QGIS 3.28. Could you please clarify with which version exactly the issue didn't occur and with which currently supported version the issue occurs? Please also provide the full version info of the currently supported versions with which the issue occurs ("In the QGIS Help menu -> About, click in the table, Ctrl+A and then Ctrl+C. Finally paste here. Do not make a screenshot.") as requested in the issue report form.

@agiudiceandrea agiudiceandrea added Feedback Waiting on the submitter for answers Data Provider Related to specific vector, raster or mesh data providers labels Dec 3, 2023
@Sakoes
Copy link
Author

Sakoes commented Dec 6, 2023

@agiudiceandrea yes my apologies. I switched up some versions in my head.
The correct versions are:

  • 3.4 & 3.10: Point are correctly visualized, but the TLS version is to low to connect to my MySQL db
  • 3.28.12 & 3.28.13: Correct TLS version, but points are not being plotted/visualized as described in the original post

I'll update it in the original post

@agiudiceandrea
Copy link
Contributor

Please also provide the full version info of the currently supported versions with which the issue occurs ("In the QGIS Help menu -> About, click in the table, Ctrl+A and then Ctrl+C. Finally paste here. Do not make a screenshot.")

@agiudiceandrea agiudiceandrea added the Regression Something which used to work, but doesn't anymore label Dec 6, 2023
@Sakoes
Copy link
Author

Sakoes commented Dec 6, 2023

QGIS version
3.28.13-Firenze
QGIS code revision
3b4db4f
Qt version
5.15.3
Python version
3.9.5
GDAL/OGR version
3.8.0
PROJ version
9.3.0
EPSG Registry database version
v10.094 (2023-08-08)
GEOS version
3.12.1-CAPI-1.18.1
SQLite version
3.41.1
PDAL version
2.6.0
PostgreSQL client version
unknown
SpatiaLite version
5.1.0
QWT version
6.1.6
QScintilla2 version
2.13.4
OS version
Windows 10 Version 2009

Active Python plugins
advison_module
0.1
geopunt4Qgis
2.3.0.5
db_manager
0.1.20
sagaprovider
2.12.99

@agiudiceandrea agiudiceandrea removed the Feedback Waiting on the submitter for answers label Dec 6, 2023
@rduivenvoorde
Copy link
Contributor

See also this thread: https://lists.osgeo.org/pipermail/qgis-developer/2024-January/066352.html

In short: if mysql does not have a crs defined on the geom column in the table, QGIS will never be able to show the geoms (though it IS retrieving the data and able to show attributes).
If you (even afterwards) fix the column/crs registration all is fine.

Longer anwer:

It looks like mysql has 2 places to store crs information: on the column (geom column registration during creation of the the table) and in the geometry.

With the help of Even R it is easy to reproduce in a docker container:

docker run --name gdal-mysql1 -e MYSQL_ROOT_PASSWORD=passwd -e "MYSQL_ROOT_HOST=%" -p 33060:3306 -d mysql:8.0.34 mysqld --default-authentication-plugin=mysql_native_password
docker exec gdal-mysql1 sh -c "echo 'CREATE DATABASE test; SELECT Version()' | mysql -uroot -ppasswd"
printf 'id,WKT\n1,"POINT(168937.186906043 175180.302889316)"\n' > test.csv

# use ONE of the following lines:

# after THIS one the columns has a crs (and QGIS will show the point):
ogr2ogr -update "mysql:test,user=root,password=passwd,port=33060,host=127.0.0.1" test.csv -select id -nlt point -a_srs EPSG:31370
# after THIS one the column has no crs (and QGIS will NOT show the point):
ogr2ogr -update "mysql:test,user=root,password=passwd,port=33060,host=127.0.0.1" test.csv -select id -nlt point

Some queries to show the differences (with help of https://ant.burnett.com.au/adding-spatial-column-to-existing-mysql-table/ )"

SELECT SRS_ID FROM INFORMATION_SCHEMA.ST_GEOMETRY_COLUMNS WHERE TABLE_NAME = 'test' ;

SRS_ID|
------+
      |      

select SHAPE, ST_AsWKT(SHAPE), ST_SRID(SHAPE) from test;

SHAPE                                    |ST_AsWKT(SHAPE)                         |ST_SRID(SHAPE)|
-----------------------------------------+----------------------------------------+--------------+
POINT (168937.186906043 175180.302889316)|POINT(168937.186906043 175180.302889316)|             0|

Fixing the srid of the geom:

UPDATE test SET SHAPE = ST_GeomFromText(ST_AsText(SHAPE), 31370);
-- UPdated Rows | 1

select SHAPE, ST_AsWKT(SHAPE), ST_SRID(SHAPE) from test;

SHAPE                                    |ST_AsWKT(SHAPE)                         |ST_SRID(SHAPE)|
-----------------------------------------+----------------------------------------+--------------+
POINT (168937.186906043 175180.302889316)|POINT(168937.186906043 175180.302889316)|         31370|

SELECT SRS_ID FROM INFORMATION_SCHEMA.ST_GEOMETRY_COLUMNS WHERE TABLE_NAME = 'test' 
SRS_ID|
------+
      |

Still makes QGIS not show the geom as the QgsCoordinateReferenceSystem is invalid:

iface.activeLayer().dataProvider().crs()
<QgsCoordinateReferenceSystem: invalid>

BUT fixing the columns crs (in the INFORMATION_SCHEMA, see the link above):

-- first drop spatial index (called 'SHAPE')
ALTER TABLE test DROP INDEX SHAPE;
-- change the column defintion of SHAPE (see the link for the funny syntax needed) via:
ALTER TABLE test CHANGE COLUMN SHAPE SHAPE GEOMETRY /*!80003 SRID 31370 */ NOT NULL DEFAULT (ST_SRID(POINT(0,0),31370));
--  create a new spatial index:
ALTER TABLE test ADD SPATIAL INDEX(SHAPE);

NOW also the INFORMATION_SCHEMA holds the crs:

SELECT SRS_ID FROM INFORMATION_SCHEMA.ST_GEOMETRY_COLUMNS WHERE TABLE_NAME = 'test' ;

SRS_ID|
------+
 31370|

And QGIS is showing the point and reporting a valid crs:

iface.activeLayer().dataProvider().crs()
<QgsCoordinateReferenceSystem: EPSG:31370>

Only question I have is why QGIS, even when telling that the layer the right crs, is still not able to show the features.

rouault added a commit to rouault/gdal that referenced this issue Jan 28, 2024
…L >= 8 (fixes qgis/QGIS#55463)

It seems spatial predicates are totally broken when using geographic SRS. For some reason

select MBRIntersects(ST_GeomFromText('POLYGON((-90 -90, 90 -90, 90 90, -90 90, -90 -90))', 4326), ST_GeomFromText('POINT(0 0)', 4326));

returns true as expected

But

select MBRIntersects(ST_GeomFromText('POLYGON((-179 -89, 179 -89, 179 89, -179 89, -179 -89))', 4326, 'axis-order=long-lat'), ST_GeomFromText('POINT(0 0)', 4326));

returns false !!!!

And

select MBRIntersects(ST_GeomFromText('POLYGON((-179 -89, 179 -89, 179 89, -179 89, -179 -89))', 32631), ST_GeomFromText('POINT(0 0)', 32631));

returns true as expected

Consequence, it seems safer to disable spatial filtering on layers with geographic coordinates with MySQL...
@rouault
Copy link
Contributor

rouault commented Jan 28, 2024

Likely resolution in the OGR MySQL driver queued in OSGeo/gdal#9152

rouault added a commit to rouault/gdal that referenced this issue Jan 28, 2024
…ith MySQL >= 8 (fixes qgis/QGIS#55463)

It seems spatial predicates are totally broken when using geographic SRS. For some reason

select MBRIntersects(ST_GeomFromText('POLYGON((-90 -90, 90 -90, 90 90, -90 90, -90 -90))', 4326), ST_GeomFromText('POINT(0 0)', 4326));

returns true as expected

But

select MBRIntersects(ST_GeomFromText('POLYGON((-179 -89, 179 -89, 179 89, -179 89, -179 -89))', 4326, 'axis-order=long-lat'), ST_GeomFromText('POINT(0 0)', 4326));

returns false !!!!

And

select MBRIntersects(ST_GeomFromText('POLYGON((-179 -89, 179 -89, 179 89, -179 89, -179 -89))', 32631), ST_GeomFromText('POINT(0 0)', 32631));

returns true as expected

Consequence, it seems safer to disable spatial filtering on layers with geographic coordinates with MySQL...
rouault added a commit to rouault/gdal that referenced this issue Jan 28, 2024
…aphic with MySQL >= 8 (fixes qgis/QGIS#55463)

It seems spatial predicates are not directly usable when using geographic SRS. For some reason

select MBRIntersects(ST_GeomFromText('POLYGON((-90 -90, 90 -90, 90 90, -90 90, -90 -90))', 4326), ST_GeomFromText('POINT(0 0)', 4326));

returns true as expected

But

select MBRIntersects(ST_GeomFromText('POLYGON((-179 -89, 179 -89, 179 89, -179 89, -179 -89))', 4326, 'axis-order=long-lat'), ST_GeomFromText('POINT(0 0)', 4326));

returns false !!!!

And

select MBRIntersects(ST_GeomFromText('POLYGON((-179 -89, 179 -89, 179 89, -179 89, -179 -89))', 32631), ST_GeomFromText('POINT(0 0)', 32631));

returns true as expected

Consequence, we need to force a projected SRS for the arguments of MBRIntersects()
rouault added a commit to rouault/gdal that referenced this issue Jan 28, 2024
…aphic with MySQL >= 8 (fixes qgis/QGIS#55463)

It seems spatial predicates are not directly usable when using geographic SRS. For some reason

select MBRIntersects(ST_GeomFromText('POLYGON((-90 -90, 90 -90, 90 90, -90 90, -90 -90))', 4326), ST_GeomFromText('POINT(0 0)', 4326));

returns true as expected

But

select MBRIntersects(ST_GeomFromText('POLYGON((-179 -89, 179 -89, 179 89, -179 89, -179 -89))', 4326, 'axis-order=long-lat'), ST_GeomFromText('POINT(0 0)', 4326));

returns false !!!!

And

select MBRIntersects(ST_GeomFromText('POLYGON((-179 -89, 179 -89, 179 89, -179 89, -179 -89))', 32631), ST_GeomFromText('POINT(0 0)', 32631));

returns true as expected

Consequence, we need to force a projected SRS for the arguments of MBRIntersects()
rouault added a commit to OSGeo/gdal that referenced this issue Feb 1, 2024
MySQL: fix/workaround server-side spatial filtering when SRS is geographic with MySQL >= 8 (fixes qgis/QGIS#55463)
rouault added a commit to OSGeo/gdal that referenced this issue Feb 1, 2024
…aphic with MySQL >= 8 (fixes qgis/QGIS#55463)

It seems spatial predicates are not directly usable when using geographic SRS. For some reason

select MBRIntersects(ST_GeomFromText('POLYGON((-90 -90, 90 -90, 90 90, -90 90, -90 -90))', 4326), ST_GeomFromText('POINT(0 0)', 4326));

returns true as expected

But

select MBRIntersects(ST_GeomFromText('POLYGON((-179 -89, 179 -89, 179 89, -179 89, -179 -89))', 4326, 'axis-order=long-lat'), ST_GeomFromText('POINT(0 0)', 4326));

returns false !!!!

And

select MBRIntersects(ST_GeomFromText('POLYGON((-179 -89, 179 -89, 179 89, -179 89, -179 -89))', 32631), ST_GeomFromText('POINT(0 0)', 32631));

returns true as expected

Consequence, we need to force a projected SRS for the arguments of MBRIntersects()
rouault added a commit to OSGeo/gdal that referenced this issue Feb 1, 2024
[Backport release/3.8] MySQL: fix/workaround server-side spatial filtering when SRS is geographic with MySQL >= 8 (fixes qgis/QGIS#55463)
clrpackages pushed a commit to clearlinux-pkgs/gdal that referenced this issue Feb 20, 2024
Daniel Baston (1):
      CI: Remove redundant clang-format check

Even Rouault (47):
      EEDA/EEDAI: use 'crsWkt' element
      gdalinfo: do not emit errors if corner coordinate reprojection fails
      HOWTO-RELEASE: update [ci skip]
      CSV: do not quote numeric fields even if STRING_QUOTING=ALWAYS (3.8.1 regression) (fixes qgis/QGIS#55808)
      OGR2SQLITE_Setup(): robustify against potential crashing scenario
      WMS: fix nullptr dereference on invalid document (fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65772)
      gdalwarp: do not enable blank line detection when -tap and -te are specified (fixes #9059)
      CI fedora_rawhide: explicitly install python3-setuptools
      FindECW.cmake: make it work for Windows 32-bit builds (fixes #9106)
      Arrow/Parquet: add (minimum) support for libarrow 15.0
      OGRArrowLayer::MapArrowTypeToOGR(): make the code robust to potentially new entries in the arrow::Type enumeration
      GMLAS: recognize GeometricPrimitivePropertyType
      wms.py: set timeout on one test resource
      Restore use of gmtime_r and localtime_r; extend to ctime_r; use Windows variants too
      netCDF: use VSILocalTime()
      Internal libopencad: use localtime_r() or localtime_s() when possible
      PCIDSK SDK: use ctime_r() or ctime_s() when possible
      degrib: use gmtime_r() or gmtime_s() when possible
      ExecuteSQL(dialect=SQLite): support 'SELECT\n' for example (fixes #9093)
      ogr2ogr: Arrow code path: take into account -limit parameter for MAX_FEATURES_IN_BATCH
      FindSQLite3.cmake: improve detection of static libsqlite3.a (fixes #9096)
      PDS: fix compilation with Emscripten version 3.1.7
      Python bindings: remove run of 'python -m lib2to3' that is a no-op, given that lib2to3 is removed in python 3.13 (fixes #9173)
      BMP: fix reading images larger than 4GB
      MySQL: fix/workaround server-side spatial filtering when SRS is geographic with MySQL >= 8 (fixes qgis/QGIS#55463)
      OGRGeometryFactory::createGeometry(): do not assert on wkbUnkown input
      docker/ubuntu-full/Dockerfile: update to Arrow 15.0.0 (fixes #9183) [ci skip]
      OGRGeometryFactory::forceTo(): fix assertion with empty geometry and target type = unknown
      bmp_read.py: fix wrong driver name
      /vsisparse/: fix Stat() on files larger than 4 GB on 32-bit builds
      docker/ubuntu-full/Dockerfile: disable AVX2 when building TileDB [ci skip]
      PDF: correctly initialize PAM when opening a subdataset (specific page for example)
      GDALOverviewDataset: avoid setting SetEnableOverviews(false) during lifetime of object. Just do it transiently
      VRTPansharpenedRasterBand::GetOverviewCount(): robustify against potential failure of GDALCreateOverviewDataset()
      LIBKML: fix crash on a gx:Track without when subelements (fixes qgis/QGIS#55963)
      CPLAtof()/CPLStrtod(): recognize again INF and -INF
      /vsicurl/: fix potential multithreaded crash when downloading the same region in parallel and that the download fails
      ODS: fix parsing of large cells on Windows (at least with mingw64) with new expat 2.6.0 release
      GeoRSS: harmonize on a 8192 byte large parsing buffer on all platforms
      GPX: harmonize on a 8192 byte large parsing buffer on all platforms
      JML: harmonize on a 8192 byte large parsing buffer on all platforms
      KML: harmonize on a 8192 byte large parsing buffer on all platforms
      LVBAG: harmonize on a 8192 byte large parsing buffer on all platforms
      SVG: harmonize on a 8192 byte large parsing buffer on all platforms
      XLSX: harmonize on a 8192 byte large parsing buffer on all platforms
      PDF vector stream parser: correcly parse structures like '[3 3.5] 0 d '
      Prepare for GDAL 3.8.4

Georg Semmler (1):
      Allow the project_binary_dir to contain a whitespace

Patrik Sylve (1):
      PAM only unset GPF_DIRTY flag

Per Mildner (1):
      docker/ubuntu-full/Dockerfile: pin libarrow-acero-dev version (fixes #9183)

Tamas Szekeres (1):
      MSSQLSpatial Fix BCP performance problem (#9112)

Key imported:
--list-packet:
# off=0 ctb=99 tag=6 hlen=3 plen=269
:public key packet:
	version 4, algo 1, created 1434650461, expires 0
	pkey[0]: [2048 bits]
	pkey[1]: [17 bits]
	keyid: 33EBBFC47B3DD87D
# off=272 ctb=b4 tag=13 hlen=2 plen=41
:user ID packet: "Even Rouault <even.rouault@spatialys.com>"
# off=315 ctb=89 tag=2 hlen=3 plen=312
:signature packet: algo 1, keyid 33EBBFC47B3DD87D

--fingerprint:
pub   rsa2048 2015-06-18 [SC]
      B1FA 7D81 EEB8 E663 9917  8B97 33EB BFC4 7B3D D87D
uid           [ unknown] Even Rouault <even.rouault@spatialys.com>
sub   rsa2048 2015-06-18 [E]
ralphraul pushed a commit to 1SpatialGroupLtd/gdal that referenced this issue Mar 11, 2024
…aphic with MySQL >= 8 (fixes qgis/QGIS#55463)

It seems spatial predicates are not directly usable when using geographic SRS. For some reason

select MBRIntersects(ST_GeomFromText('POLYGON((-90 -90, 90 -90, 90 90, -90 90, -90 -90))', 4326), ST_GeomFromText('POINT(0 0)', 4326));

returns true as expected

But

select MBRIntersects(ST_GeomFromText('POLYGON((-179 -89, 179 -89, 179 89, -179 89, -179 -89))', 4326, 'axis-order=long-lat'), ST_GeomFromText('POINT(0 0)', 4326));

returns false !!!!

And

select MBRIntersects(ST_GeomFromText('POLYGON((-179 -89, 179 -89, 179 89, -179 89, -179 -89))', 32631), ST_GeomFromText('POINT(0 0)', 32631));

returns true as expected

Consequence, we need to force a projected SRS for the arguments of MBRIntersects()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Data Provider Related to specific vector, raster or mesh data providers Regression Something which used to work, but doesn't anymore
Projects
None yet
4 participants