src/sidebar/Sidebar.js
/* Converts a geojson consisting of MultiPolygon to  a geojson file separate Polygons.
Note: This function exists to revert geojson files back to single polygons, in order to:
a) Keep the data consistent. b) Single polygons are required for some functions (e.g Dissolve) */
Converts a geojson consisting of MultiPolygon to  a geojson file separate Polygons.
Note: This function exists to revert geojson files back to single polygons, in order to:
a) Keep the data consistent. b) Single polygons are required for some functions
Converts a geojson consisting of MultiPolygon to a geojson file separate Polygons . Note : This function exists to revert geojson files back to single polygons in order to : a ) Keep the data consistent . b ) Single polygons are required for some functions
function geojsonMultiPolygonToPolygon(geojson) {
  var geojson_features = geojson.features
  var new_features = []
  for (var i = 0; i < geojson_features.length; i++) {
    if(geojson_features[i].geometry.type == 'Polygon') {
      new_features.push(geojson_features[i])
    } else if(geojson_features[i].geometry.type == 'MultiPolygon') {
      for (var j = 0; j < geojson_features[i].geometry.coordinates.length; j++) {
        var feature = {"type": "Feature", "properties": {},  "geometry": { "type": "Polygon", "coordinates": geojson_features[i].geometry.coordinates[j] }}
        new_features.push(feature)
      }
    }
  }
  var new_geojson = {"type":"FeatureCollection","features": new_features };
  console.log(new_geojson)
  return new_geojson
}
function geojsonMultiPolygonToPolygon ( geojson ) { var geojson_features = geojson . features var new_features = [ ] for ( var i = 0 ; i < geojson_features . length ; i ++ ) { if ( geojson_features [ i ] . geometry . type == 'Polygon' ) { new_features . push ( geojson_features [ i ] ) } else if ( geojson_features [ i ] . geometry . type == 'MultiPolygon' ) { for ( var j = 0 ; j < geojson_features [ i ] . geometry . coordinates . length ; j ++ ) { var feature = { "type" : "Feature" , "properties" : { } , "geometry" : { "type" : "Polygon" , "coordinates" : geojson_features [ i ] . geometry . coordinates [ j ] } } new_features . push ( feature ) } } } var new_geojson = { "type" : "FeatureCollection" , "features" : new_features } ; console . log ( new_geojson ) return new_geojson }
Converts a geojson consisting of MultiPolygon to  a geojson file separate Polygons.
Converts a geojson consisting of MultiPolygon to a geojson file separate Polygons .