src/sidebar/Sidebar.js
// Converts a geojson consisting with mulitple polygons into a geojson file with MultiPolygon geometry for difference function.
Converts a geojson consisting with mulitple polygons into a geojson file with MultiPolygon geometry for difference function.
Converts a geojson consisting with mulitple polygons into a geojson file with MultiPolygon geometry for difference function .
function geojsonPolygonToMultiPolygon(geojson) {
  var geojson_features = geojson.features
  var coordinates = []
  for (var i = 0; i < geojson_features.length; i++) {
      if(geojson_features[i].geometry.type == 'Polygon') {
        coordinates.push(geojson_features[i].geometry.coordinates)
      } else if(geojson_features[i].geometry.type == 'LineString') {
        var feature = turf.buffer(geojson_features[i].geometry, 0.5)
        coordinates.push(feature.geometry.coordinates)
      } else if (geojson_features[i].geometry.type == 'MultiPolygon'){
        coordinates.push(geojson_features[i].geometry.coordinates)
      } else if(geojson_features[i].geometry.type == 'Point') {
        var feature = turf.buffer(geojson_features[i].geometry, 0.5)
        coordinates.push(feature.geometry.coordinates)
      }
  }
  var new_geojson = {"type":"FeatureCollection","features":[{"type": "Feature", "properties": {},  "geometry": { "type": "MultiPolygon", "coordinates": coordinates }}]};
  return new_geojson
}
function geojsonPolygonToMultiPolygon ( geojson ) { var geojson_features = geojson . features var coordinates = [ ] for ( var i = 0 ; i < geojson_features . length ; i ++ ) { if ( geojson_features [ i ] . geometry . type == 'Polygon' ) { coordinates . push ( geojson_features [ i ] . geometry . coordinates ) } else if ( geojson_features [ i ] . geometry . type == 'LineString' ) { var feature = turf . buffer ( geojson_features [ i ] . geometry , 0.5 ) coordinates . push ( feature . geometry . coordinates ) } else if ( geojson_features [ i ] . geometry . type == 'MultiPolygon' ) { coordinates . push ( geojson_features [ i ] . geometry . coordinates ) } else if ( geojson_features [ i ] . geometry . type == 'Point' ) { var feature = turf . buffer ( geojson_features [ i ] . geometry , 0.5 ) coordinates . push ( feature . geometry . coordinates ) } } var new_geojson = { "type" : "FeatureCollection" , "features" : [ { "type" : "Feature" , "properties" : { } , "geometry" : { "type" : "MultiPolygon" , "coordinates" : coordinates } } ] } ; return new_geojson }
Converts a geojson consisting with mulitple polygons into a geojson file with MultiPolygon geometry for difference function.
Converts a geojson consisting with mulitple polygons into a geojson file with MultiPolygon geometry for difference function .