為什麼 MySQL 認為我使用的是 SRID 1?
我可以在我的本地機器上執行查詢沒有問題(伺服器版本:10.4.6-MariaDB),但是當我在我的遠端機器(伺服器版本:8.0.17 MySQL)上執行它時,它會彈出以下錯誤消息:
ERROR 3548 (SR001): There's no spatial reference system with SRID 1.
這是我的查詢:
SELECT c.cd116fp FROM spat.cb_2019_us_cd116_500k c WHERE ST_Contains(c.SHAPE, ST_GeomFromText('POINT(-78.8768302 42.8776271)', 4269))
以下是這些特殊表格的內容:
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)
這些形狀是在我的本地電腦上使用 ogr2ogr 導入的,SRID 最初設置為 1,但在搜尋
information_schema
st_spatial_reference_system
(我認為是)正確的 SRID 後,我將它們更改為 4269。srs_id 4269 與 ogr2ogr 放在我的數據庫中的相似度可以在這裡看到:
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)
geometry_columns
在它給我錯誤消息後,我將我的from1
中的 SRID 更改為4269
,認為它會糾正錯誤,但令我驚訝的是,它仍然顯示SRID 1 ain't there
。在我的本地電腦上,查詢使用 SRID 1 或 4269 進行。上傳後,無論我指定什麼 SRID,我都只會收到上述錯誤。我不確定我是否應該更改它,但這是我在故障排除方面的微弱嘗試。該數據庫取自census.gov形狀文件。
我通常能夠通過基本的空間查詢來捏造自己的方式,但是有人可以指出我正確的方向嗎?
更新:我剛剛了解到“使用 MySQL 8.0 或更高版本,使用數據庫提供的 ST_SPATIAL_REFERENCE_SYSTEMS 表而不是 spatial_ref_sys。”
為了使查詢正常工作,我只需要做兩件事:
1.) 設置表中每個幾何對象的 SRID。我不明白這些資訊儲存在這裡。
UPDATE spat.cb_2019_us_cd116_500k SET `SHAPE`=ST_SRID(`SHAPE`,4269);
2.) 在我的查詢中顛倒緯度和經度的順序。在 MySQL 8 中,緯度顯然必須排在第一位(或者至少在特定 SRID 為 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))
如前所述,MySQL 8 不使用
spatial_ref_sys
由 ogr2ogr 生成的表。為了使查詢正常工作,我也不需要更新geometry_columns
表,所以也許這同樣是退化的。