Error
Error Code:
3672
MySQL Error 3672: GeoJSON CRS Not Top-Level
Description
This error indicates that GeoJSON data provided to a MySQL spatial function is malformed because the 'crs' (Coordinate Reference System) member is not found at the top level of the GeoJSON object. MySQL expects the CRS definition to be a direct property of the root GeoJSON object, preventing the function from processing the data correctly.
Error Message
Invalid GeoJSON data provided to function %s: Member 'crs' must be specified in the top level object.
Known Causes
3 known causesIncorrect GeoJSON Structure
The 'crs' member, if present, is nested within a Feature, Geometry, or FeatureCollection instead of being a direct property of the root GeoJSON object as expected by MySQL.
Missing Top-Level 'crs' Member
While newer GeoJSON specifications often omit 'crs', the specific MySQL function or context implicitly requires its presence at the top level for valid processing.
GeoJSON Specification Mismatch
The GeoJSON data adheres to a different specification or version than what MySQL's function expects regarding the 'crs' member's inclusion or placement.
Solutions
3 solutions available1. Correct GeoJSON Structure easy
Ensure the 'crs' member is at the top level of the GeoJSON object.
1
Review the GeoJSON data you are attempting to insert or use with MySQL's spatial functions. The 'crs' member, if present, must be a direct child of the root GeoJSON object.
{
"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "EPSG:4326"
}
},
"features": [
...
]
}
2
If 'crs' is nested within a 'properties' object of a Feature or Geometry, move it to the top level.
Incorrect example (crs nested):
{
"type": "Feature",
"properties": {
"name": "Example",
"crs": {
"type": "name",
"properties": {
"name": "EPSG:4326"
}
}
},
"geometry": {
"type": "Point",
"coordinates": [100.0, 0.0]
}
}
Correct example (crs at top level):
{
"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "EPSG:4326"
}
},
"features": [
{
"type": "Feature",
"properties": {
"name": "Example"
},
"geometry": {
"type": "Point",
"coordinates": [100.0, 0.0]
}
}
]
}
3
Re-execute the MySQL operation that failed with the corrected GeoJSON data.
INSERT INTO your_table (geom_column) VALUES (ST_GeomFromGeoJSON('{"type": "Point", "coordinates": [100.0, 0.0]}'));
-- Or if CRS is intended to be part of the GeoJSON for ST_GeomFromGeoJSON:
INSERT INTO your_table (geom_column) VALUES (ST_GeomFromGeoJSON('{"type": "FeatureCollection", "crs": {"type": "name", "properties": {"name": "EPSG:4326"}}, "features": [{"type": "Feature", "properties": {}, "geometry": {"type": "Point", "coordinates": [100.0, 0.0]}}]}'));
2. Omit CRS if Not Required easy
Remove the 'crs' member from the GeoJSON if it's not essential for your use case.
1
If your GeoJSON data includes a 'crs' member but you don't explicitly need it for your spatial operations in MySQL, simply remove the entire 'crs' object.
Original GeoJSON:
{
"type": "Feature",
"crs": {
"type": "name",
"properties": {
"name": "EPSG:4326"
}
},
"properties": {
"name": "My Point"
},
"geometry": {
"type": "Point",
"coordinates": [10, 20]
}
}
Modified GeoJSON (crs removed):
{
"type": "Feature",
"properties": {
"name": "My Point"
},
"geometry": {
"type": "Point",
"coordinates": [10, 20]
}
}
2
Use the GeoJSON without the 'crs' member in your MySQL query.
INSERT INTO your_table (geom_column) VALUES (ST_GeomFromGeoJSON('{"type": "Point", "coordinates": [10, 20]}'));
3. Specify SRID Explicitly (When Omitting CRS) medium
If you omit CRS, ensure your spatial data is correctly interpreted by setting the SRID.
1
When you omit the 'crs' member from your GeoJSON, MySQL's spatial functions might default to an SRID of 0, which can lead to incorrect spatial calculations. You should explicitly specify the Spatial Reference Identifier (SRID) when inserting or creating spatial data.
If your GeoJSON is WGS 84 (EPSG:4326) and you've removed the CRS member:
INSERT INTO your_table (geom_column) VALUES (ST_SetSRID(ST_GeomFromGeoJSON('{"type": "Point", "coordinates": [10, 20]}'), 4326));
2
When creating your spatial column, define it with the correct SRID if you intend to consistently use a specific one.
CREATE TABLE your_table (
id INT AUTO_INCREMENT PRIMARY KEY,
geom_column GEOMETRY SRID 4326
);
3
If you are using a stored procedure or application logic to process GeoJSON, ensure that the SRID is passed to the `ST_GeomFromGeoJSON` function or applied using `ST_SetSRID`.
Example in application code (conceptual):
const geojsonWithoutCRS = { ... }; // Your GeoJSON without 'crs'
const srid = 4326;
const sql = `INSERT INTO your_table (geom_column) VALUES (ST_SetSRID(ST_GeomFromGeoJSON(?), ?))`;
connection.query(sql, [JSON.stringify(geojsonWithoutCRS), srid], (err, results) => { ... });