/**
  * Creates a new Compare model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreatedraw()
 {
     $model = new Compare();
     if (Yii::$app->request->post()) {
         ini_set("memory_limit", "-1");
         /***
          * Langkah - langkah mengambil data kesesuaian lahan
          * 1. INTERSECTS (TRUE | FALSE)
          * 2. INTERSECTION (Kesesuain To Geom from draw)
          *
          * S = geom from draw
          * B = Hasil intersects
          **/
         $get_intersection = "SELECT b.*, ST_AsGeojson(ST_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))) as geom from (select kesesuaian.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),kesesuaian.geom)as touch from kesesuaian where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),kesesuaian.geom) = true) as b;";
         $value_intersections = Yii::$app->db->createCommand($get_intersection)->queryAll();
         $area_of_interest = "SELECT ST_AsGeoJson(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))";
         $aoi = Yii::$app->db->createCommand($area_of_interest)->queryAll();
         /***
          * Get Average Geometry Climate
          **/
         $climate_ag = ClimateAG::find()->OrderBy('id DESC')->one();
         $landnp_ag = LandnpeatAG::find()->OrderBy('id DESC')->one();
         $landp_ag = LandpeatAG::find()->OrderBy('id DESC')->one();
         $accessibility_ag = AccessibilityAG::find()->OrderBy('id DESC')->one();
         /***
          * Get Average Geometry Factor
          **/
         $factors_ag = FactorsAG::find()->OrderBy('id DESC')->one();
         /* Deklarasi variable result geojson */
         $result_geojson = '{"type": "FeatureCollection","features": [';
         if (isset($climate_ag)) {
             if (isset($landnp_ag)) {
                 if (isset($landp_ag)) {
                     if (isset($accessibility_ag)) {
                         if (isset($factors_ag)) {
                             for ($i = 0; $i < count($value_intersections); $i++) {
                                 $kesesuaian_climate = $value_intersections[$i]['scorech'] * ($climate_ag->bobot_ch * $factors_ag->bobot_climate) + $value_intersections[$i]['scoresuhu'] * ($climate_ag->boobt_temp * $factors_ag->bobot_climate) + $value_intersections[$i]['scoredry'] * ($climate_ag->bobot_dm * $factors_ag->bobot_climate);
                                 $status_climate = 'N';
                                 if ($kesesuaian_climate >= 0 and $kesesuaian_climate <= 1) {
                                     $status_climate = 'N';
                                 } elseif ($kesesuaian_climate > 1 and $kesesuaian_climate <= 2) {
                                     $status_climate = 'S3';
                                 } elseif ($kesesuaian_climate > 2 and $kesesuaian_climate <= 3) {
                                     $status_climate = 'S2';
                                 } elseif ($kesesuaian_climate > 3 and $kesesuaian_climate <= 4) {
                                     $status_climate = 'S1';
                                 } else {
                                     $status_climate = 'S(alah)';
                                 }
                                 $result_geojson .= "{\"type\": \"Feature\",\"properties\": {\"kesesuaian_climate\":\"" . $kesesuaian_climate . "\", \"status_climate\":\"" . $status_climate . "\"},\"geometry\": ";
                                 $result_geojson .= $value_intersections[$i]['geom'];
                                 $result_geojson .= "},";
                             }
                             $result_geojson .= ']}';
                             $result_data = substr($result_geojson, 0, -3) . ' ]}';
                             /* Convert WKT to Geom */
                             $query_geom_from_wkt = "SELECT ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326), ST_Area(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))";
                             $result_geom_from_wkt = Yii::$app->db->createCommand($query_geom_from_wkt)->queryAll();
                             /* Climate Rainfall */
                             $get_rainfall = "SELECT b.scorech as scorech,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from  kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.scorech;";
                             $value_rainfall = Yii::$app->db->createCommand($get_rainfall)->queryAll();
                             $result_geojson_rain = '{"type": "FeatureCollection","features": [';
                             for ($i = 0; $i < count($value_rainfall); $i++) {
                                 $scorech = $value_rainfall[$i]['scorech'];
                                 $status_rainfall = ' ';
                                 if ($scorech <= 1) {
                                     $status_rainfall = '< 1250, > 4000';
                                 } elseif ($scorech <= 2 and $scorech > 1) {
                                     $status_rainfall = '1250 - 1450, 3500 - 4000';
                                 } elseif ($scorech <= 3 and $scorech > 2) {
                                     $status_rainfall = '1450 - 1700, 2500 - 3500';
                                 } elseif ($scorech <= 4 and $scorech > 3) {
                                     $status_rainfall = '1700 - 2500';
                                 } else {
                                     $status_rainfall = 'S(alah)';
                                 }
                                 $result_geojson_rain .= "{\"type\": \"Feature\",\"properties\": {\"scorech\":\"" . $scorech . "\", \"status_rainfall\":\"" . $status_rainfall . "\"},\"geometry\": ";
                                 $result_geojson_rain .= $value_rainfall[$i]['geom'];
                                 $result_geojson_rain .= "},";
                             }
                             $result_geojson_rain .= ']}';
                             $result_data_rain = substr($result_geojson_rain, 0, -3) . ' ]}';
                             /* Climate Temperature */
                             $get_temperature = "SELECT b.scoresuhu as scoresuhu, ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from  kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.scoresuhu;";
                             $value_temperature = Yii::$app->db->createCommand($get_temperature)->queryAll();
                             $result_geojson_temp = '{"type": "FeatureCollection","features": [';
                             for ($i = 0; $i < count($value_temperature); $i++) {
                                 $scoresuhu = $value_temperature[$i]['scoresuhu'];
                                 $status_temperature = ' ';
                                 if ($scoresuhu <= 1) {
                                     $status_temperature = '< 20, > 35';
                                 } elseif ($scoresuhu <= 2 and $scoresuhu > 1) {
                                     $status_temperature = '20 - 22, 32 - 35 ';
                                 } elseif ($scoresuhu <= 3 and $scoresuhu > 2) {
                                     $status_temperature = '22 - 25, 28 - 32';
                                 } elseif ($scoresuhu <= 4 and $scoresuhu > 3) {
                                     $status_temperature = '25 - 28';
                                 } else {
                                     $status_temperature = 'S(alah)';
                                 }
                                 $result_geojson_temp .= "{\"type\": \"Feature\",\"properties\": {\"scoresuhu\":\"" . $scoresuhu . "\", \"status_temperature\":\"" . $status_temperature . "\"},\"geometry\": ";
                                 $result_geojson_temp .= $value_temperature[$i]['geom'];
                                 $result_geojson_temp .= "},";
                             }
                             $result_geojson_temp .= ']}';
                             $result_data_temp = substr($result_geojson_temp, 0, -3) . ' ]}';
                             /* Climate Dry Month */
                             $get_drymonth = "SELECT b.scoredry as scoredry ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from  kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.scoredry;";
                             $value_drymonth = Yii::$app->db->createCommand($get_drymonth)->queryAll();
                             $result_geojson_dm = '{"type": "FeatureCollection","features": [';
                             for ($i = 0; $i < count($value_drymonth); $i++) {
                                 $scoredry = $value_drymonth[$i]['scoredry'];
                                 $status_drymonth = '> 4';
                                 if ($scoredry <= 1) {
                                     $status_drymonth = '> 4';
                                 } elseif ($scoredry <= 2 and $scoredry > 1) {
                                     $status_drymonth = '3 – 4';
                                 } elseif ($scoredry <= 3 and $scoredry > 2) {
                                     $status_drymonth = '3 – 2';
                                 } elseif ($scoredry <= 4 and $scoredry > 3) {
                                     $status_drymonth = '< 2';
                                 } else {
                                     $status_drymonth = 'S(alah)';
                                 }
                                 $result_geojson_dm .= "{\"type\": \"Feature\",\"properties\": {\"scoredry\":\"" . $scoredry . "\", \"status_drymonth\":\"" . $status_drymonth . "\"},\"geometry\": ";
                                 $result_geojson_dm .= $value_drymonth[$i]['geom'];
                                 $result_geojson_dm .= "},";
                             }
                             $result_geojson_dm .= ']}';
                             $result_data_dm = substr($result_geojson_dm, 0, -3) . ' ]}';
                             /* Land slope */
                             $get_slope = "SELECT b.score_lrg as score_lrg ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from  kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.score_lrg order by b.score_lrg asc;";
                             $value_slope = Yii::$app->db->createCommand($get_slope)->queryAll();
                             $result_geojson_slp = '{"type": "FeatureCollection","features": [';
                             for ($i = 0; $i < count($value_slope); $i++) {
                                 $score_lrg = $value_slope[$i]['score_lrg'];
                                 $status_slope = '>30';
                                 if ($score_lrg <= 1) {
                                     $status_slope = '>30';
                                 } elseif ($score_lrg <= 2 and $score_lrg > 1) {
                                     $status_slope = '16 - 30';
                                 } elseif ($score_lrg <= 3 and $score_lrg > 2) {
                                     $status_slope = '8 - 16';
                                 } elseif ($score_lrg <= 4 and $score_lrg > 3) {
                                     $status_slope = '<8';
                                 } else {
                                     $status_slope = 'S(alah)';
                                 }
                                 $result_geojson_slp .= "{\"type\": \"Feature\",\"properties\": {\"score_lrg\":\"" . $score_lrg . "\", \"status_slope\":\"" . $status_slope . "\"},\"geometry\": ";
                                 $result_geojson_slp .= $value_slope[$i]['geom'];
                                 $result_geojson_slp .= "},";
                             }
                             $result_geojson_slp .= ']}';
                             $result_data_slp = substr($result_geojson_slp, 0, -3) . ' ]}';
                             /* Land  Non Peat Texture */
                             $get_texture = "SELECT b.score_text as score_text ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from  kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.score_text;";
                             $value_texture = Yii::$app->db->createCommand($get_texture)->queryAll();
                             $result_geojson_txt = '{"type": "FeatureCollection","features": [';
                             for ($i = 0; $i < count($value_texture); $i++) {
                                 $score_text = $value_texture[$i]['score_text'];
                                 $status_texture = 'Peat Area';
                                 if ($score_text <= 1) {
                                     $status_texture = 'Coarse';
                                 } elseif ($score_text <= 2 and $score_text > 1) {
                                     $status_texture = 'Slightly Coarse';
                                 } elseif ($score_text <= 3 and $score_text > 2) {
                                     $status_texture = '–';
                                 } elseif ($score_text <= 4 and $score_text > 3) {
                                     $status_texture = 'Fine, Slightly fine, Medium';
                                 } else {
                                     $status_texture = 'S(alah)';
                                 }
                                 $result_geojson_txt .= "{\"type\": \"Feature\",\"properties\": {\"score_text\":\"" . $score_text . "\", \"status_texture\":\"" . $status_texture . "\"},\"geometry\": ";
                                 $result_geojson_txt .= $value_texture[$i]['geom'];
                                 $result_geojson_txt .= "},";
                             }
                             $result_geojson_txt .= ']}';
                             $result_data_txt = substr($result_geojson_txt, 0, -3) . ' ]}';
                             /* Land Non Peat Elevation */
                             $get_elevation = "SELECT b.score_elev as score_elev ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from  kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.score_elev;";
                             $value_elevation = Yii::$app->db->createCommand($get_elevation)->queryAll();
                             $result_geojson_elev = '{"type": "FeatureCollection","features": [';
                             for ($i = 0; $i < count($value_elevation); $i++) {
                                 $score_elev = $value_elevation[$i]['score_elev'];
                                 $status_elevation = 'Peat Area';
                                 if ($score_elev <= 1) {
                                     $status_elevation = '> 400';
                                 } elseif ($score_elev <= 2 and $score_elev > 1) {
                                     $status_elevation = '300 - 400';
                                 } elseif ($score_elev <= 3 and $score_elev > 2) {
                                     $status_elevation = '200 - 300';
                                 } elseif ($score_elev <= 4 and $score_elev > 3) {
                                     $status_elevation = '0 - 200';
                                 } else {
                                     $status_elevation = 'S(alah)';
                                 }
                                 $result_geojson_elev .= "{\"type\": \"Feature\",\"properties\": {\"score_elev\":\"" . $score_elev . "\", \"status_elevation\":\"" . $status_elevation . "\"},\"geometry\": ";
                                 $result_geojson_elev .= $value_elevation[$i]['geom'];
                                 $result_geojson_elev .= "},";
                                 // print_r($status_elevation);
                             }
                             // die;
                             $result_geojson_elev .= ']}';
                             $result_data_elev = substr($result_geojson_elev, 0, -3) . ' ]}';
                             /* Land Peat Thickness */
                             $get_thickness = "SELECT b.scoredept as scoredept ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from  kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.scoredept;";
                             $value_thickness = Yii::$app->db->createCommand($get_thickness)->queryAll();
                             $result_geojson_thick = '{"type": "FeatureCollection","features": [';
                             for ($i = 0; $i < count($value_thickness); $i++) {
                                 $scoredept = $value_thickness[$i]['scoredept'];
                                 $status_thickness = 'Non Peat Area';
                                 if ($scoredept <= 1 and $scoredept > 0) {
                                     $status_thickness = '< 140';
                                 } elseif ($scoredept <= 2 and $scoredept > 1) {
                                     $status_thickness = '140 – 200';
                                 } elseif ($scoredept <= 3 and $scoredept > 2) {
                                     $status_thickness = '200 – 400';
                                 } elseif ($scoredept <= 4 and $scoredept > 3) {
                                     $status_thickness = '> 400';
                                 } else {
                                     $status_thickness = 'S(alah)';
                                 }
                                 $result_geojson_thick .= "{\"type\": \"Feature\",\"properties\": {\"scoredept\":\"" . $scoredept . "\", \"status_thickness\":\"" . $status_thickness . "\"},\"geometry\": ";
                                 $result_geojson_thick .= $value_thickness[$i]['geom'];
                                 $result_geojson_thick .= "},";
                             }
                             $result_geojson_thick .= ']}';
                             $result_data_thick = substr($result_geojson_thick, 0, -3) . ' ]}';
                             /* Land Peat Ripe */
                             $get_ripening = "SELECT b.scoreripe as scoreripe ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from  kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.scoreripe;";
                             $value_ripening = Yii::$app->db->createCommand($get_ripening)->queryAll();
                             $result_geojson_ripe = '{"type": "FeatureCollection","features": [';
                             for ($i = 0; $i < count($value_ripening); $i++) {
                                 $scoreripe = $value_ripening[$i]['scoreripe'];
                                 $status_ripening = 'Non Peat Area';
                                 if ($scoreripe <= 1 and $scoreripe > 0) {
                                     $status_ripening = 'Sapric*';
                                 } elseif ($scoreripe <= 2 and $scoreripe > 1) {
                                     $status_ripening = 'Sapric, Hemic*';
                                 } elseif ($scoreripe <= 3 and $scoreripe > 2) {
                                     $status_ripening = 'Hemic, Fibric*';
                                 } elseif ($scoreripe <= 4 and $scoreripe > 3) {
                                     $status_ripening = 'Fibric';
                                 } else {
                                     $status_ripening = 'S(alah)';
                                 }
                                 $result_geojson_ripe .= "{\"type\": \"Feature\",\"properties\": {\"scoreripe\":\"" . $scoreripe . "\", \"status_ripening\":\"" . $status_ripening . "\"},\"geometry\": ";
                                 $result_geojson_ripe .= $value_ripening[$i]['geom'];
                                 $result_geojson_ripe .= "},";
                             }
                             $result_geojson_ripe .= ']}';
                             $result_data_ripe = substr($result_geojson_ripe, 0, -3) . ' ]}';
                             /* Accessibility Distance From Road */
                             $get_road = "SELECT b.score_road as score_road ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from  kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.score_road;";
                             $value_road = Yii::$app->db->createCommand($get_road)->queryAll();
                             $result_geojson_rod = '{"type": "FeatureCollection","features": [';
                             for ($i = 0; $i < count($value_road); $i++) {
                                 $score_road = $value_road[$i]['score_road'];
                                 $status_road = '-';
                                 if ($score_road <= 1 and $score_road > 0) {
                                     $status_road = '-';
                                 } elseif ($score_road <= 2 and $score_road > 1) {
                                     $status_road = '> 10 Km';
                                 } elseif ($score_road <= 3 and $score_road > 2) {
                                     $status_road = '5 - 10 Km';
                                 } elseif ($score_road <= 4 and $score_road > 3) {
                                     $status_road = '0 - 5 Km';
                                 } else {
                                     $status_road = 'S(alah)';
                                 }
                                 $result_geojson_rod .= "{\"type\": \"Feature\",\"properties\": {\"score_road\":\"" . $score_road . "\", \"status_road\":\"" . $status_road . "\"},\"geometry\": ";
                                 $result_geojson_rod .= $value_road[$i]['geom'];
                                 $result_geojson_rod .= "},";
                             }
                             $result_geojson_rod .= ']}';
                             $result_data_rod = substr($result_geojson_rod, 0, -3) . ' ]}';
                             /* Accessibility Distance From Mills */
                             $get_mills = "SELECT b.score_mill as score_mill ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from  kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.score_mill;";
                             $value_mills = Yii::$app->db->createCommand($get_mills)->queryAll();
                             $result_geojson_mls = '{"type": "FeatureCollection","features": [';
                             for ($i = 0; $i < count($value_mills); $i++) {
                                 $score_mill = $value_mills[$i]['score_mill'];
                                 $status_mills = '-';
                                 if ($score_mill <= 1 and $score_mill > 0) {
                                     $status_mills = '-';
                                 } elseif ($score_mill <= 2 and $score_mill > 1) {
                                     $status_mills = '> 10 Km';
                                 } elseif ($score_mill <= 3 and $score_mill > 2) {
                                     $status_mills = '5 - 10 Km';
                                 } elseif ($score_mill <= 4 and $score_mill > 3) {
                                     $status_mills = '0 - 5 Km';
                                 } else {
                                     $status_mills = 'S(alah)';
                                 }
                                 $result_geojson_mls .= "{\"type\": \"Feature\",\"properties\": {\"score_mill\":\"" . $score_mill . "\", \"status_mills\":\"" . $status_mills . "\"},\"geometry\": ";
                                 $result_geojson_mls .= $value_mills[$i]['geom'];
                                 $result_geojson_mls .= "},";
                             }
                             $result_geojson_mls .= ']}';
                             $result_data_mls = substr($result_geojson_mls, 0, -3) . ' ]}';
                             /* Accessibility Distance From town */
                             $get_town = "SELECT b.score_town as score_town ,ST_AsGeojson(st_union(st_intersection(b.geom,ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326))))as geom from (select u.*, st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom)as touch from  kesesuaian as u where st_intersects(ST_GeomFromText('" . $_POST['Compare']['geom'] . "', 4326),u.geom) = true) as b group by b.score_town;";
                             $value_town = Yii::$app->db->createCommand($get_town)->queryAll();
                             $result_geojson_twn = '{"type": "FeatureCollection","features": [';
                             for ($i = 0; $i < count($value_town); $i++) {
                                 $score_town = $value_town[$i]['score_town'];
                                 $status_town = '-';
                                 if ($score_town <= 1 and $score_town > 0) {
                                     $status_town = '-';
                                 } elseif ($score_town <= 2 and $score_town > 1) {
                                     $status_town = '> 10 Km';
                                 } elseif ($score_town <= 3 and $score_town > 2) {
                                     $status_town = '5 - 10 Km';
                                 } elseif ($score_town <= 4 and $score_town > 3) {
                                     $status_town = '0 - 5 Km';
                                 } else {
                                     $status_town = 'S(alah)';
                                 }
                                 $result_geojson_twn .= "{\"type\": \"Feature\",\"properties\": {\"score_town\":\"" . $score_town . "\", \"status_town\":\"" . $status_town . "\"},\"geometry\": ";
                                 $result_geojson_twn .= $value_town[$i]['geom'];
                                 $result_geojson_twn .= "},";
                             }
                             $result_geojson_twn .= ']}';
                             $result_data_twn = substr($result_geojson_twn, 0, -3) . ' ]}';
                         } else {
                             return $this->redirect(['nodata', 'id' => $model->id]);
                         }
                     } else {
                         return $this->redirect(['nodata', 'id' => $model->id]);
                     }
                 } else {
                     return $this->redirect(['nodata', 'id' => $model->id]);
                 }
             } else {
                 return $this->redirect(['nodata', 'id' => $model->id]);
             }
         } else {
             return $this->redirect(['nodata', 'id' => $model->id]);
         }
         /* Convert m2 to Ha (Ha = m2 ÷ 10,000)*/
         $data_st_area = $result_geom_from_wkt[0]['st_area'];
         /* Intervensi POST with result */
         $_POST['Compare']['data'] = $result_data;
         $_POST['Compare']['geom'] = $result_geom_from_wkt[0]['st_geomfromtext'];
         $_POST['Compare']['st_area'] = $data_st_area;
         $_POST['Compare']['data_rain'] = $result_data_rain;
         $_POST['Compare']['data_temp'] = $result_data_temp;
         $_POST['Compare']['data_dm'] = $result_data_dm;
         $_POST['Compare']['data_slope'] = $result_data_slp;
         $_POST['Compare']['data_text'] = $result_data_txt;
         $_POST['Compare']['data_elev'] = $result_data_elev;
         $_POST['Compare']['data_thick'] = $result_data_thick;
         $_POST['Compare']['data_ripe'] = $result_data_ripe;
         $_POST['Compare']['data_road'] = $result_data_rod;
         $_POST['Compare']['data_mills'] = $result_data_mls;
         $_POST['Compare']['data_town'] = $result_data_twn;
         if (!Yii::$app->user->isGuest) {
             $_POST['Compare']['id_user'] = Yii::$app->user->identity->id;
         }
         if ($model->load($_POST) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             echo "error";
         }
     } else {
         $get_geojson_kecamatan = "SELECT *, ST_AsGeoJson(geom), ST_X(ST_Centroid(geom)), ST_Y(ST_Centroid(geom)) FROM admin";
         $data_admin = Yii::$app->db->createCommand($get_geojson_kecamatan)->queryAll();
         $get_bbox = "SELECT ST_AsGeoJson(Box2D(ST_Union(geom))) FROM admin";
         $bbox_geojsons = Yii::$app->db->createCommand($get_bbox)->queryColumn();
         $bbox_geojson = $bbox_geojsons[0];
         return $this->render('createdraw', ['model' => $model, 'data_admin' => $data_admin, 'bbox_geojson' => $bbox_geojson]);
     }
 }
 /**
  * Creates a new Landnpeat model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Landnpeat();
     if (Yii::$app->request->post()) {
         $slope_text = $_POST['Landnpeat']['slope_text'];
         $text_slope = 1 / $slope_text;
         $slope_slope = 1;
         $text_elev = $_POST['Landnpeat']['text_elev'];
         $elev_text = 1 / $text_elev;
         $text_text = 1;
         $slope_elev = $_POST['Landnpeat']['slope_elev'];
         $elev_slope = 1 / $slope_elev;
         $elev_elev = 1;
         $sum_column_slope = $slope_slope + $text_slope + $elev_slope;
         $sum_column_text = $slope_text + $text_text + $elev_text;
         $sum_column_elev = $slope_elev + $text_elev + $elev_elev;
         /* ---- */
         $divided_sum_sum = $sum_column_slope / $sum_column_slope;
         $divided_slope_slope_sum = $slope_slope / $sum_column_slope;
         $divided_slope_text_sum = $text_slope / $sum_column_slope;
         $divided_slope_elev_sum = $elev_slope / $sum_column_slope;
         $divided_text_slope_sum = $slope_text / $sum_column_text;
         $divided_text_text_sum = $text_text / $sum_column_text;
         $divided_text_elev_sum = $elev_text / $sum_column_text;
         $divided_elev_slope_sum = $slope_elev / $sum_column_elev;
         $divided_elev_text_sum = $text_elev / $sum_column_elev;
         $divided_elev_elev_sum = $elev_elev / $sum_column_elev;
         /* ---- */
         $sum_slope = $divided_slope_slope_sum + $divided_text_slope_sum + $divided_elev_slope_sum;
         $sum_text = $divided_slope_text_sum + $divided_text_text_sum + $divided_elev_text_sum;
         $sum_elev = $divided_slope_elev_sum + $divided_text_elev_sum + $divided_elev_elev_sum;
         $sum_divided = $divided_sum_sum + $divided_sum_sum + $divided_sum_sum;
         /* ---- */
         $bobot_slope = $sum_slope / $sum_divided;
         $bobot_text = $sum_text / $sum_divided;
         $bobot_elev = $sum_elev / $sum_divided;
         /* ---- */
         /* ---- */
         $multiple_slope_slope_bobot = $slope_slope * $bobot_slope;
         $multiple_slope_text_bobot = $text_slope * $bobot_slope;
         $multiple_slope_elev_bobot = $elev_slope * $bobot_slope;
         $multiple_text_slope_bobot = $slope_text * $bobot_text;
         $multiple_text_text_bobot = $text_text * $bobot_text;
         $multiple_text_elev_bobot = $elev_text * $bobot_text;
         $multiple_elev_slope_bobot = $slope_elev * $bobot_elev;
         $multiple_elev_text_bobot = $text_elev * $bobot_elev;
         $multiple_elev_elev_bobot = $elev_elev * $bobot_elev;
         /* ---- */
         /* ---- */
         $sum_bobot_slope = $multiple_slope_slope_bobot + $multiple_text_slope_bobot + $multiple_elev_slope_bobot;
         $sum_bobot_text = $multiple_slope_text_bobot + $multiple_text_text_bobot + $multiple_elev_text_bobot;
         $sum_bobot_elev = $multiple_slope_elev_bobot + $multiple_text_elev_bobot + $multiple_elev_elev_bobot;
         /* ---- */
         $divided_bobot_slope = $sum_bobot_slope / $bobot_slope;
         $divided_bobot_text = $sum_bobot_text / $bobot_text;
         $divided_bobot_elev = $sum_bobot_elev / $bobot_elev;
         /* ---- */
         $lamda_max = ($divided_bobot_slope + $divided_bobot_text + $divided_bobot_elev) / $sum_divided;
         $jumlah_factor = $sum_divided;
         $consistensi_index = ($lamda_max - $jumlah_factor) / ($jumlah_factor - 1);
         $rasio_index = 0.58;
         $consistensi_rasio = $consistensi_index / $rasio_index;
         /* ---- */
         if ($consistensi_rasio < 0.1) {
             $validation = TRUE;
         } else {
             $validation = FALSE;
         }
         if (Yii::$app->user->getId()) {
             $_POST['Landnpeat']['slope_text'] = $slope_text;
             $_POST['Landnpeat']['slope_elev'] = $slope_elev;
             $_POST['Landnpeat']['text_elev'] = $text_elev;
             $_POST['Landnpeat']['bobot_slope'] = $bobot_slope;
             $_POST['Landnpeat']['bobot_text'] = $bobot_text;
             $_POST['Landnpeat']['bobot_elev'] = $bobot_elev;
             $_POST['Landnpeat']['cr'] = $consistensi_rasio;
             $_POST['Landnpeat']['validation'] = $validation;
             $_POST['Landnpeat']['id_user'] = Yii::$app->user->getId();
             if ($model->load($_POST) && $model->save()) {
                 $data_text_texts = Landnpeat::find()->where(['validation' => TRUE])->AsArray()->All();
                 $slope_text_ag_base = [];
                 $slope_elev_ag_base = [];
                 $text_elev_ag_base = [];
                 $bobot_slope_ag_base = [];
                 $bobot_text_ag_base = [];
                 $bobot_elev_ag_base = [];
                 $consistensi_rasio_ag_base = [];
                 for ($i = 0; $i < count($data_text_texts); $i++) {
                     $slope_text_ag_base[$i] = $data_text_texts[$i]['slope_text'];
                     $slope_elev_ag_base[$i] = $data_text_texts[$i]['slope_elev'];
                     $text_elev_ag_base[$i] = $data_text_texts[$i]['text_elev'];
                     // $bobot_slope_ag_base[$i]        = $data_text_texts[$i]['bobot_slope'];
                     // $bobot_text_ag_base[$i]         = $data_text_texts[$i]['bobot_text'];
                     // $bobot_elev_ag_base[$i]         = $data_text_texts[$i]['bobot_elev'];
                     // $consistensi_rasio_ag_base[$i]  = $data_text_texts[$i]['cr'];
                 }
                 $slope_text_ag = pow(array_product($slope_text_ag_base), 1 / count($data_text_texts));
                 $text_slope_ag = 1 / $slope_text_ag;
                 $slope_slope_ag = 1;
                 $slope_elev_ag = pow(array_product($slope_elev_ag_base), 1 / count($data_text_texts));
                 $elev_slope_ag = 1 / $slope_elev_ag;
                 $elev_elev_ag = 1;
                 $text_elev_ag = pow(array_product($text_elev_ag_base), 1 / count($data_text_texts));
                 $elev_text_ag = 1 / $text_elev_ag;
                 $text_text_ag = 1;
                 // $bobot_slope_ag                     = sqrt (array_product($bobot_slope_ag_base));
                 // $bobot_text_ag                      = sqrt (array_product($bobot_text_ag_base));
                 // $bobot_elev_ag                      = sqrt (array_product($bobot_elev_ag_base));
                 // $consistensi_rasio_ag               = sqrt (array_product($consistensi_rasio_ag_base));
                 $sum_column_slope_ag = $slope_slope_ag + $text_slope_ag + $elev_slope_ag;
                 $sum_column_text_ag = $slope_text_ag + $text_text_ag + $elev_text_ag;
                 $sum_column_elev_ag = $slope_elev_ag + $text_elev_ag + $elev_elev_ag;
                 /* ---- */
                 $divided_sum_sum_ag = $sum_column_slope_ag / $sum_column_slope_ag;
                 $divided_slope_slope_ag_sum = $slope_slope_ag / $sum_column_slope_ag;
                 $divided_slope_text_ag_sum = $text_slope_ag / $sum_column_slope_ag;
                 $divided_slope_elev_ag_sum = $elev_slope_ag / $sum_column_slope_ag;
                 $divided_text_slope_ag_sum = $slope_text_ag / $sum_column_text_ag;
                 $divided_text_text_ag_sum = $text_text_ag / $sum_column_text_ag;
                 $divided_text_elev_ag_sum = $elev_text_ag / $sum_column_text_ag;
                 $divided_elev_slope_ag_sum = $slope_elev_ag / $sum_column_elev_ag;
                 $divided_elev_text_ag_sum = $text_elev_ag / $sum_column_elev_ag;
                 $divided_elev_elev_ag_sum = $elev_elev_ag / $sum_column_elev_ag;
                 /* ---- */
                 $sum_slope_ag = $divided_slope_slope_ag_sum + $divided_text_slope_ag_sum + $divided_elev_slope_ag_sum;
                 $sum_text_ag = $divided_slope_text_ag_sum + $divided_text_text_ag_sum + $divided_elev_text_ag_sum;
                 $sum_elev_ag = $divided_slope_elev_ag_sum + $divided_text_elev_ag_sum + $divided_elev_elev_ag_sum;
                 $sum_divided_ag = $divided_sum_sum_ag + $divided_sum_sum_ag + $divided_sum_sum_ag;
                 /* ---- */
                 $bobot_slope_ag = $sum_slope_ag / $sum_divided_ag;
                 $bobot_text_ag = $sum_text_ag / $sum_divided_ag;
                 $bobot_elev_ag = $sum_elev_ag / $sum_divided_ag;
                 /* ---- */
                 /* ---- */
                 $multiple_slope_slope_ag_bobot = $slope_slope_ag * $bobot_slope_ag;
                 $multiple_slope_text_ag_bobot = $text_slope_ag * $bobot_slope_ag;
                 $multiple_slope_elev_ag_bobot = $elev_slope_ag * $bobot_slope_ag;
                 $multiple_text_slope_ag_bobot = $slope_text_ag * $bobot_text_ag;
                 $multiple_text_text_ag_bobot = $text_text_ag * $bobot_text_ag;
                 $multiple_text_elev_ag_bobot = $elev_text_ag * $bobot_text_ag;
                 $multiple_elev_slope_ag_bobot = $slope_elev_ag * $bobot_elev_ag;
                 $multiple_elev_text_ag_bobot = $text_elev_ag * $bobot_elev_ag;
                 $multiple_elev_elev_ag_bobot = $elev_elev_ag * $bobot_elev_ag;
                 /* ---- */
                 /* ---- */
                 $sum_bobot_slope_ag = $multiple_slope_slope_ag_bobot + $multiple_text_slope_ag_bobot + $multiple_elev_slope_ag_bobot;
                 $sum_bobot_text_ag = $multiple_slope_text_ag_bobot + $multiple_text_text_ag_bobot + $multiple_elev_text_ag_bobot;
                 $sum_bobot_elev_ag = $multiple_slope_elev_ag_bobot + $multiple_text_elev_ag_bobot + $multiple_elev_elev_ag_bobot;
                 /* ---- */
                 $divided_bobot_slope_ag = $sum_bobot_slope_ag / $bobot_slope_ag;
                 $divided_bobot_text_ag = $sum_bobot_text_ag / $bobot_text_ag;
                 $divided_bobot_elev_ag = $sum_bobot_elev_ag / $bobot_elev_ag;
                 /* ---- */
                 $lamda_max_ag = ($divided_bobot_slope_ag + $divided_bobot_text_ag + $divided_bobot_elev_ag) / $sum_divided_ag;
                 $jumlah_factor_ag = $sum_divided_ag;
                 $consistensi_index_ag = ($lamda_max_ag - $jumlah_factor_ag) / ($jumlah_factor_ag - 1);
                 $rasio_index_ag = 0.58;
                 $consistensi_rasio_ag = $consistensi_index_ag / $rasio_index_ag;
                 /* ---- */
                 $model_ag = new LandnpeatAG();
                 $_POSTAG['LandnpeatAG']['slope_text'] = $slope_text_ag;
                 $_POSTAG['LandnpeatAG']['slope_elev'] = $slope_elev_ag;
                 $_POSTAG['LandnpeatAG']['text_elev'] = $text_elev_ag;
                 $_POSTAG['LandnpeatAG']['bobot_slope'] = $bobot_slope_ag;
                 $_POSTAG['LandnpeatAG']['bobot_text'] = $bobot_text_ag;
                 $_POSTAG['LandnpeatAG']['bobot_elev'] = $bobot_elev_ag;
                 $_POSTAG['LandnpeatAG']['cr'] = $consistensi_rasio_ag;
                 if ($model_ag->load($_POSTAG) && $model_ag->save()) {
                     return $this->redirect(['view', 'id' => $model->id]);
                 } else {
                     return $this->render('create', ['model' => $model]);
                 }
             } else {
                 return $this->render('create', ['model' => $model]);
             }
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }