gdal3.js
gdal3.js copied to clipboard
gdal.ogrinfo: sql readonly database
possibly related: https://github.com/bugra9/gdal3.js/issues/83
I'm trying to use https://gdal.org/en/latest/programs/ogrinfo.html / https://gdal3.js.org/docs/module-a_ogrinfo.html
According to the ogrinfo we should be able to modify and edit the dataset:
-sql <statement>|@<filename>[](https://gdal.org/en/latest/programs/ogrinfo.html#cmdoption-ogrinfo-sql)
Execute the indicated SQL statement and return the result. Starting with GDAL 2.1, the @<filename> syntax can be used to indicate that the content is in the pointed filename (e.g @my_select.txt where my_select.txt is a file in the current directory). Data can also be edited with SQL INSERT, UPDATE, DELETE, DROP TABLE, ALTER TABLE etc. Editing capabilities depend on the selected dialect with [-dialect](https://gdal.org/en/latest/programs/ogrinfo.html#cmdoption-ogrinfo-dialect).
I'm trying to insert data into existing geopackage (by passing in the bytes) using the following options:
[
"-dialect",
"sqlite",
"-sql",
"INSERT INTO comments (inspector_id, center) VALUES ('ME', ST_Transform(GeomFromEWKT('SRID=4326;POINT(-93.2708352 -93.2708352)'), 103741))"
]
I get the following error:
gdal3.js:1 gdal stderr: ERROR 1: In ExecuteSQL(): sqlite3_step(INSERT INTO comments (inspector_id, center) VALUES ('EPX', ST_Transform(GeomFromEWKT('SRID=4326;POINT(-93.2708352 -93.2708352)'), 103741))):
r.printErr @ gdal3.js:1
put_char @ gdal3.js:1
write @ gdal3.js:1
write @ gdal3.js:1
(anonymous) @ gdal3.js:1
sb @ gdal3.js:1
$func13630 @ gdal3WebAssembly.wasm:0xc48d70
$func4261 @ gdal3WebAssembly.wasm:0x3ec411
$func1391 @ gdal3WebAssembly.wasm:0x9c849
$func7260 @ gdal3WebAssembly.wasm:0x670638
$func2461 @ gdal3WebAssembly.wasm:0x13f3da
$func5302 @ gdal3WebAssembly.wasm:0x4a832f
$func365 @ gdal3WebAssembly.wasm:0x1d095
$func25087 @ gdal3WebAssembly.wasm:0x14278ff
f @ gdal3.js:1
$func6705 @ gdal3WebAssembly.wasm:0x5fcbab
$func2048 @ gdal3WebAssembly.wasm:0xf8585
$lf @ gdal3WebAssembly.wasm:0x18325
j @ gdal3.js:1
$func20793 @ gdal3WebAssembly.wasm:0x110eb9c
k @ gdal3.js:1
$Og @ gdal3WebAssembly.wasm:0xd7ea6a
ue @ gdal3.js:1
(anonymous) @ gdal3.js:1
(anonymous) @ gdal3.js:1
Jt @ gdal3.js:1
(anonymous) @ gdal3.js:1
Promise.then (async)
onmessage @ gdal3.js:1
gdal3.js:1 gdal stderr: attempt to write a readonly database
r.printErr @ gdal3.js:1
put_char @ gdal3.js:1
write @ gdal3.js:1
write @ gdal3.js:1
(anonymous) @ gdal3.js:1
sb @ gdal3.js:1
$func13630 @ gdal3WebAssembly.wasm:0xc48d70
$func2461 @ gdal3WebAssembly.wasm:0x13f3ef
$func5302 @ gdal3WebAssembly.wasm:0x4a832f
$func365 @ gdal3WebAssembly.wasm:0x1d095
$func25087 @ gdal3WebAssembly.wasm:0x14278ff
f @ gdal3.js:1
$func6705 @ gdal3WebAssembly.wasm:0x5fcbab
$func2048 @ gdal3WebAssembly.wasm:0xf8585
$lf @ gdal3WebAssembly.wasm:0x18325
j @ gdal3.js:1
$func20793 @ gdal3WebAssembly.wasm:0x110eb9c
k @ gdal3.js:1
$Og @ gdal3WebAssembly.wasm:0xd7ea6a
ue @ gdal3.js:1
(anonymous) @ gdal3.js:1
(anonymous) @ gdal3.js:1
Jt @ gdal3.js:1
(anonymous) @ gdal3.js:1
Promise.then (async)
onmessage @ gdal3.js:1
switchboard.js?t=1725643558806:69 Uncaught (in promise) {message: 'Unexpected end of JSON input'}
I'm using legit dataset created by gdal3:
[
{
"path": "comments.gpkg",
"pointer": 9583968,
"type": "vector",
"info": {
"description": "/input/comments.gpkg",
"driverShortName": "GPKG",
"driverLongName": "GeoPackage",
"layers": [
{
"name": "comments",
"metadata": {},
"geometryFields": [
{
"name": "center",
"type": "Point",
"nullable": true,
"extent": [
0,
0,
0,
0
],
"coordinateSystem": {
"wkt": "GEOGCRS[\"WGS 84\",\n ENSEMBLE[\"World Geodetic System 1984 ensemble\",\n MEMBER[\"World Geodetic System 1984 (Transit)\"],\n MEMBER[\"World Geodetic System 1984 (G730)\"],\n MEMBER[\"World Geodetic System 1984 (G873)\"],\n MEMBER[\"World Geodetic System 1984 (G1150)\"],\n MEMBER[\"World Geodetic System 1984 (G1674)\"],\n MEMBER[\"World Geodetic System 1984 (G1762)\"],\n MEMBER[\"World Geodetic System 1984 (G2139)\"],\n ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n LENGTHUNIT[\"metre\",1]],\n ENSEMBLEACCURACY[2.0]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n CS[ellipsoidal,2],\n AXIS[\"geodetic latitude (Lat)\",north,\n ORDER[1],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n AXIS[\"geodetic longitude (Lon)\",east,\n ORDER[2],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n USAGE[\n SCOPE[\"Horizontal component of 3D system.\"],\n AREA[\"World.\"],\n BBOX[-90,-180,90,180]],\n ID[\"EPSG\",4326]]",
"projjson": {
"$schema": "https://proj.org/schemas/v0.7/projjson.schema.json",
"type": "GeographicCRS",
"name": "WGS 84",
"datum_ensemble": {
"name": "World Geodetic System 1984 ensemble",
"members": [
{
"name": "World Geodetic System 1984 (Transit)",
"id": {
"authority": "EPSG",
"code": 1166
}
},
{
"name": "World Geodetic System 1984 (G730)",
"id": {
"authority": "EPSG",
"code": 1152
}
},
{
"name": "World Geodetic System 1984 (G873)",
"id": {
"authority": "EPSG",
"code": 1153
}
},
{
"name": "World Geodetic System 1984 (G1150)",
"id": {
"authority": "EPSG",
"code": 1154
}
},
{
"name": "World Geodetic System 1984 (G1674)",
"id": {
"authority": "EPSG",
"code": 1155
}
},
{
"name": "World Geodetic System 1984 (G1762)",
"id": {
"authority": "EPSG",
"code": 1156
}
},
{
"name": "World Geodetic System 1984 (G2139)",
"id": {
"authority": "EPSG",
"code": 1309
}
}
],
"ellipsoid": {
"name": "WGS 84",
"semi_major_axis": 6378137,
"inverse_flattening": 298.257223563
},
"accuracy": "2.0",
"id": {
"authority": "EPSG",
"code": 6326
}
},
"coordinate_system": {
"subtype": "ellipsoidal",
"axis": [
{
"name": "Geodetic latitude",
"abbreviation": "Lat",
"direction": "north",
"unit": "degree"
},
{
"name": "Geodetic longitude",
"abbreviation": "Lon",
"direction": "east",
"unit": "degree"
}
]
},
"scope": "Horizontal component of 3D system.",
"area": "World.",
"bbox": {
"south_latitude": -90,
"west_longitude": -180,
"north_latitude": 90,
"east_longitude": 180
},
"id": {
"authority": "EPSG",
"code": 4326
}
},
"dataAxisToSRSAxisMapping": [
2,
1
]
}
}
],
"featureCount": 1,
"fidColumnName": "fid",
"fields": [
{
"name": "date-time",
"type": "Integer",
"nullable": true,
"uniqueConstraint": false
},
{
"name": "comments",
"type": "String",
"nullable": true,
"uniqueConstraint": false
},
{
"name": "onsite",
"type": "Integer",
"subType": "Boolean",
"nullable": true,
"uniqueConstraint": false
},
{
"name": "area_ac",
"type": "Real",
"nullable": true,
"uniqueConstraint": false
},
{
"name": "image",
"type": "String",
"nullable": true,
"uniqueConstraint": false
},
{
"name": "inspector_id",
"type": "String",
"nullable": true,
"uniqueConstraint": false
},
{
"name": "select_id_2",
"type": "String",
"nullable": true,
"uniqueConstraint": false
},
{
"name": "created",
"type": "String",
"nullable": true,
"uniqueConstraint": false
}
]
}
],
"metadata": {},
"domains": {},
"relationships": {}
}
}
]
reading through some of the ogr2ogr stuff, it suggests the /input
folder might need to be Writable and that's preventing it. Otherwise, maybe the file is readonly and needs to be opened as writeable. Not sure where wasm FS specifies this, but it might be as simple as having ogrinfo open the dataset in rw mode; though it could be more complex.
If I can't get RW, i'd need to pull in another large wasm binary like spl.js which would be excessive, being able to update and modify files would be a key feature of the web based library.
You may even want to add a rw/r flag to ogrinfo to make it clear that it's possible to update datasets. There's an explicit ro flag that could be triggered for syntatic sugar:
-ro
Open the data source in read-only mode.