I can run the query on my local machine no problem (Server version: 10.4.6-MariaDB), but when I run it on my remote one (Server version: 8.0.17 MySQL) it poops out this error message:

ERROR 3548 (SR001): There's no spatial reference system with SRID 1.

Here's my query:

SELECT c.cd116fp 
FROM spat.cb_2019_us_cd116_500k c 
WHERE ST_Contains(c.SHAPE, ST_GeomFromText('POINT(-78.8768302 42.8776271)', 4269))

Here's the contents of those special tables:

mysql> select * from geometry_columns ;
+-----------------+----------------+-----------------------+-------------------+-----------------+------+---------+
| F_TABLE_CATALOG | F_TABLE_SCHEMA | F_TABLE_NAME          | F_GEOMETRY_COLUMN | COORD_DIMENSION | SRID | TYPE    |
+-----------------+----------------+-----------------------+-------------------+-----------------+------+---------+
| NULL            | NULL           | cb_2019_36_sldl_500k  | SHAPE             |               2 | 4269 | POLYGON |
| NULL            | NULL           | cb_2019_36_sldu_500k  | SHAPE             |               2 | 4269 | POLYGON |
| NULL            | NULL           | cb_2019_us_cd116_500k | SHAPE             |               2 | 4269 | POLYGON |
+-----------------+----------------+-----------------------+-------------------+-----------------+------+---------+
3 rows in set (0.00 sec)

mysql> select * from spatial_ref_sys;
+------+-----------+-----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| SRID | AUTH_NAME | AUTH_SRID | SRTEXT                                                                                                                       |
+------+-----------+-----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 4269 | NULL      |      NULL | GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4269"]] |
+------+-----------+-----------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

These shapes were imported with ogr2ogr on my local machine and the SRIDs were set originally as 1, but I changed them to 4269 after searching through the information_schema st_spatial_reference_system for (what I believe to be) the proper SRID.

The similarity of srs_id 4269 to the one that was placed in my database by ogr2ogr can be seen here:

mysql> select * from st_spatial_reference_systems where `srs_id`=4269;
+----------+--------+--------------+--------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+
| SRS_NAME | SRS_ID | ORGANIZATION | ORGANIZATION_COORDSYS_ID | DEFINITION                                | DESCRIPTION |
+----------+--------+--------------+--------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+
| NAD83    |   4269 | EPSG         |                     4269 | GEOGCS["NAD83",DATUM["North American Datum 1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[1,1,-1,0,0,0,0],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.017453292519943278,AUTHORITY["EPSG","9122"]],AXIS["Lat",NORTH],AXIS["Lon",EAST],AUTHORITY["EPSG","4269"]] | NULL        |
+----------+--------+--------------+--------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+
1 row in set (0.00 sec)

I changed the SRIDs in my geometry_columns from 1 to 4269 after it gave me the error message, thinking it would correct the error, but to my amazement, it STILL says SRID 1 ain't there. On my local machine the query works using SRID 1 or 4269. After I uploaded it, I only get the above error, no matter what SRID I specify. I'm not sure if I was supposed to change it or not but that was my feeble attempt at troubleshooting.

The database is taken from the census.gov shape files.

I've normally been able to fudge my way through a basic spatial query but could someone point me in the right direction please?

Update: I just learned "With MySQL 8.0 or later, the ST_SPATIAL_REFERENCE_SYSTEMS table provided by the database is used instead of spatial_ref_sys."

有帮助吗?

解决方案

There were only two things I needed to do for the query to work:

1.) Set the SRID of each geometry object in the table. I did not understand that this information was stored here.

UPDATE spat.cb_2019_us_cd116_500k SET `SHAPE`=ST_SRID(`SHAPE`,4269);

2.) Reverse the order of the Latitude and Longitude in my queries. Latitude apparently must come first in MySQL 8 (or at least with the specific SRID of 4269).

SELECT c.cd116fp 
FROM spat.cb_2019_us_cd116_500k c 
WHERE ST_Contains(c.SHAPE, ST_GeomFromText('POINT(42.8776271 -78.8768302)', 4269))

As noted already, MySQL 8 does not use the spatial_ref_sys table that was generated by ogr2ogr. For the query to work, I didn't need to update the geometry_columns table either so perhaps that is equally vestigial.

许可以下: CC-BY-SA归因
不隶属于 dba.stackexchange
scroll top