src/sidebar/Sidebar.js
// Gets geojson file and rule set on which to run extract on.
Gets geojson file and rule set on which to run extract on.
Gets geojson file and rule set on which to run extract on .
function callExtract(new_name, geojson_file_key, rule_set) {
  var layer_position = find_called_geojson(geojson_file_key)
  var selected_layer_geojson = collect_called_geojson(layer_position)
  var features = []
  var operators = {
    '==': function(a, b) { return a == b },
    '!=': function(a, b) { return a != b },
    '<': function(a, b) { return a > b },
    '>': function(a, b) { return a < b },
    '<=': function(a, b) { return a >= b },
    '>=': function(a, b) { return a <= b },
  };
  for (var j = 0; j < selected_layer_geojson.features.length; j++ ){
    for (var property in selected_layer_geojson.features[j].properties){
      if(property == rule_set[0][0]) {
        if(selected_layer_geojson.features[j].properties.hasOwnProperty(property)) {
          var value = selected_layer_geojson.features[j].properties[property]
          var properties = selected_layer_geojson.features[j].properties
          var coordinates = selected_layer_geojson.features[j].geometry.coordinates[0]
          if (operators[rule_set[0][1]](rule_set[0][2],value)) {
            var feature = {"type":"Feature","properties": properties,"geometry":{"type":"Polygon","coordinates": [coordinates] }}
            features.push(feature)
          }
        }
      }
    }
  }
  if (rule_set.length > 1) {
    for (var i = 1; i <rule_set.length; i++ ){
      var dummy_array = []
      for (var j = 0; j < features.length; j++ ){
        for (var property in features[j].properties){
          if(property == rule_set[i][0]) {
              var value = features[j].properties[property]
              var properties = features[j].properties
              var coordinates = features[j].geometry.coordinates[0]
              if (operators[rule_set[i][1]](rule_set[i][2],value)) {
                var feature = {"type": "Feature", "properties":properties,"geometry":{ "type": "Polygon", "coordinates": [coordinates] }}
                console.log(feature)
                dummy_array.push(feature)
              }
            }
          }
        }
        features = dummy_array;
      }
    }
    var new_geojson = {"type":"FeatureCollection","features": features };
    var dissolveLayer = new_geojson.features[0]
    for (var i = 1; i < new_geojson.features.length; i++) {
      dissolveLayer = turf.union(dissolveLayer, new_geojson.features[i])
    }
    if (dissolveLayer.geometry.type == 'MultiPolygon') {
      var multipolygon = {"type":"FeatureCollection","features": [dissolveLayer]};
      final_dissolve = geojsonMultiPolygonToPolygon(multipolygon)
    } else {
      var final_dissolve = {"type":"FeatureCollection","features": [dissolveLayer]};
    }
    console.log(final_dissolve)
    const extract_key = generateKey()
    createLayer(new_name, extract_key, final_dissolve)
}
function callExtract ( new_name , geojson_file_key , rule_set ) { var layer_position = find_called_geojson ( geojson_file_key ) var selected_layer_geojson = collect_called_geojson ( layer_position ) var features = [ ] var operators = { '==' : function ( a , b ) { return a == b } , '!=' : function ( a , b ) { return a != b } , '<' : function ( a , b ) { return a > b } , '>' : function ( a , b ) { return a < b } , '<=' : function ( a , b ) { return a >= b } , '>=' : function ( a , b ) { return a <= b } , } ; for ( var j = 0 ; j < selected_layer_geojson . features . length ; j ++ ) { for ( var property in selected_layer_geojson . features [ j ] . properties ) { if ( property == rule_set [ 0 ] [ 0 ] ) { if ( selected_layer_geojson . features [ j ] . properties . hasOwnProperty ( property ) ) { var value = selected_layer_geojson . features [ j ] . properties [ property ] var properties = selected_layer_geojson . features [ j ] . properties var coordinates = selected_layer_geojson . features [ j ] . geometry . coordinates [ 0 ] if ( operators [ rule_set [ 0 ] [ 1 ] ] ( rule_set [ 0 ] [ 2 ] , value ) ) { var feature = { "type" : "Feature" , "properties" : properties , "geometry" : { "type" : "Polygon" , "coordinates" : [ coordinates ] } } features . push ( feature ) } } } } } if ( rule_set . length > 1 ) { for ( var i = 1 ; i < rule_set . length ; i ++ ) { var dummy_array = [ ] for ( var j = 0 ; j < features . length ; j ++ ) { for ( var property in features [ j ] . properties ) { if ( property == rule_set [ i ] [ 0 ] ) { var value = features [ j ] . properties [ property ] var properties = features [ j ] . properties var coordinates = features [ j ] . geometry . coordinates [ 0 ] if ( operators [ rule_set [ i ] [ 1 ] ] ( rule_set [ i ] [ 2 ] , value ) ) { var feature = { "type" : "Feature" , "properties" : properties , "geometry" : { "type" : "Polygon" , "coordinates" : [ coordinates ] } } console . log ( feature ) dummy_array . push ( feature ) } } } } features = dummy_array ; } } var new_geojson = { "type" : "FeatureCollection" , "features" : features } ; var dissolveLayer = new_geojson . features [ 0 ] for ( var i = 1 ; i < new_geojson . features . length ; i ++ ) { dissolveLayer = turf . union ( dissolveLayer , new_geojson . features [ i ] ) } if ( dissolveLayer . geometry . type == 'MultiPolygon' ) { var multipolygon = { "type" : "FeatureCollection" , "features" : [ dissolveLayer ] } ; final_dissolve = geojsonMultiPolygonToPolygon ( multipolygon ) } else { var final_dissolve = { "type" : "FeatureCollection" , "features" : [ dissolveLayer ] } ; } console . log ( final_dissolve ) const extract_key = generateKey ( ) createLayer ( new_name , extract_key , final_dissolve ) }
Gets geojson file and rule set on which to run extract on.
Gets geojson file and rule set on which to run extract on .
// gets the data for the geojson file stored in memory. // building a custom logical operator checker, since our operator is a variable. // for each layer, checking the first rule initially. // for each feature in geojson layer // if the property is same as defined in rule: // if property has a value we collect it, otherwise the rule is invalid // Running a check to see if value is okay for rule. // If there are more than one rule, we update the feature list by removing those not // For each additional rule we need to check the accepted features from the first rule. // for each feature in geojson layer // if the property is same as defined in rule: // Running a check to see if value is okay for rule. // Cleans the returned dissolve data. //get_newgeojson(final_dissolve, extract_key)