Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correcting format MultiPolygons #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cbanbury
Copy link

According the the GeoJSON spec features with more than one polygon should have the type MultiPolygon rather than Polygon and be an array of polygon coordinate arrays.

Here's a code snippet for the changes made

var fs = require('fs');

var data = fs.readFileSync('cities.geojson');
data = JSON.parse(data);

data.features.forEach(item=>{
    var polygon = item.geometry.coordinates;
    
    if (polygon.length > 1) {
        item.geometry.type = 'MultiPolygon';
        
        var fixed = [];
        polygon.forEach(ring=>{
            fixed.push([ring]); // nest in additional array
        })
        
        item.geometry.coordinates = fixed;
    }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant