mmomtchev / node-gdal-async

Node.js bindings for GDAL (Geospatial Data Abstraction Library) with full async support
https://mmomtchev.github.io/node-gdal-async/
Apache License 2.0
131 stars 26 forks source link

Unable to get subtype Boolean for vector layers?! #37

Open ThomasG77 opened 2 years ago

ThomasG77 commented 2 years ago

When I run

ogrinfo -so -al /vsigzip//vsicurl/https://cadastre.data.gouv.fr/data/etalab-cadastre/2022-04-01/geojson/communes/44/44109/cadastre-44109-parcelles.json.gz

It returns

INFO: Open of `/vsigzip//vsicurl/https://cadastre.data.gouv.fr/data/etalab-cadastre/2022-04-01/geojson/communes/44/44109/cadastre-44109-parcelles.json.gz'
      using driver `GeoJSON' successful.

Layer name: cadastre-44109-parcelles.json
Geometry: Polygon
Feature Count: 56956
Extent: (-1.641297, 47.180874) - (-1.480756, 47.295832)
Layer SRS WKT:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,
        AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4326"]]
id: String (0.0)
commune: String (0.0)
prefixe: String (0.0)
section: String (0.0)
numero: String (0.0)
contenance: Integer (0.0)
arpente: Integer(Boolean) (1.0)
created: Date (0.0)
updated: Date (0.0)

When I look at code, I see there is an implementation to get subtype Boolean https://github.com/OSGeo/gdal/blob/master/apps/ogrinfo.cpp#L410. That's how I get Boolean for arpente column in the ogrinfo output

Now in the library, I do the following

const gdal = require("gdal-async")

const dataset = gdal.open('/vsigzip//vsicurl/https://cadastre.data.gouv.fr/data/etalab-cadastre/2022-04-01/geojson/communes/44/44109/cadastre-44109-parcelles.json.gz')
const layer = dataset.layers.get(0)

console.log(layer.fields.map(function(field) {return field}).filter(f => f.name == 'arpente'))

// Alternate option not changing the result
var first = layer.features.first()
console.log(first.defn.fields.map(f => f).filter(f => f.name == 'arpente'))

It returns

[
  FieldDefn {
    ignored: false,
    precision: 0,
    width: 1,
    justification: undefined,
    type: 'integer',
    name: 'arpente'
  }
]
[
  FieldDefn {
    ignored: false,
    precision: 0,
    width: 1,
    justification: undefined,
    type: 'integer',
    name: 'arpente'
  }
]

Is there an issue to get subtype boolean, do I miss something?

mmomtchev commented 2 years ago

Currently there is no way to get the subtype with gdal-async - it is a purely cosmetic feature in GDAL anyway - it does not have any real effect on the processing - you still get an integer

ThomasG77 commented 2 years ago

Not exactly cosmetic only. My explanation was about the behavior but when converting to PostgreSQL from the source using pure GDAL approach, you get a boolean for type not an integer