shapefile icon indicating copy to clipboard operation
shapefile copied to clipboard

Numeric column coming in as NULL property

Open nwesterman opened this issue 3 years ago • 0 comments

Hi! We think we have found an edge case. We have a file that has a numeric column "Blend - *", that when we run it through shapefile, returns all NULL values in the property field instead of the true values. Values can be properly read by other software such as mapshaper or our C++ program, but not this library.

The shape points get converted correctly, and the property "Blend - *" appears on the result object, just not the associated property values.

Code for testing:

async function parseShapefile(absPath) {
    const geoJson = await shapefile.read(absPath)
    if (!geoJson) { return {} }
    // Find numeric columns to use for rate selection
    for (const property of Object.keys(shape.properties)) {
        let numeric = true
        for (const feature of geoJson.features) {
            // Use both global isNaN() and parseFloat() to determine if we have a numeric column.
            // isNaN() catches most non-numeric columns, but not null
            // parseFloat(null) == NaN, but a column value such as "32 UAN" will return a number (32)
            if (isNaN(feature.properties[property]) || Number.isNaN(parseFloat(feature.properties[property]))) {
                numeric = false
            }
            else {
                console.log('Found Number')
            }
        }
        if (numeric) {
             console.log(`Numeric Column: ${property}`)
        }
    }
}

File in question: TID_822919_OID_2363808_Raven_Viper_2021-04-26-03-53-54.zip

nwesterman avatar Jul 20 '21 19:07 nwesterman