Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140390

loading a shapefile with properties in non-UTF8 formats

$
0
0

I can successfully load and display a shapefile in Leaflet. However, when I try to access the features properties, the characters are all mangled. To investigate, I defined the following function:

function unpack(str) {
    var codePoints = [];
    for(var i = 0; i < str.length; i++)
        codePoints.push( str.charCodeAt(i) );
    return codePoints;
};

Then, I do the following:

const options = {
    onEachFeature: (feature, layer) => {
         console.log(unpack(feature.properties.NAME));
    }
};
L.shapefile(url, options);

When I load the application I see on the console arrays like the following:

[65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533]

... which corresponds to the Unicode replacement character.

For what it's worth, I've examined the *.dbf file using a binary editor and I've established that the feature.properties.NAME is given in ISO 8859-7 (ISO Latin/Greek alphabet).


Viewing all articles
Browse latest Browse all 140390

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>