public static bool SelectTracksInAOI(AOI aoi)
        {
            if (ExtractedTracksShapefile == null)
            {
                return(false);
            }
            else
            {
                SelectedTracks.Clear();
                Callback cb             = new Callback();
                var      selectedTracks = new object();
                var      ext            = ((Shapefile)MapLayersHandler[aoi.AOIHandle].LayerObject).Extents;
                ExtractedTracksShapefile.SelectShapes(ext, 0, SelectMode.INTERSECTION, ref selectedTracks);
                SelectedTrackIndexes = (int[])selectedTracks;
                for (int x = 0; x < SelectedTrackIndexes.Count(); x++)
                {
                    if (ExtractedTracksShapefile.ShapeVisible[SelectedTrackIndexes[x]])
                    {
                        SelectedTracks.Add(ExtractedTracksShapefile.Shape[SelectedTrackIndexes[x]]);
                    }
                }
            }

            return(SelectedTrackIndexes.Count() > 0);
        }
Esempio n. 2
0
 public static AOI  SaveAOI(string name, bool isEdited = false)
 {
     if (_hAOI >= 0)
     {
         var aoi = new AOI
         {
             Name           = name,
             UpperLeftX     = _sfAOI.Extents.xMin,
             UpperLeftY     = _sfAOI.Extents.yMax,
             LowerRightX    = _sfAOI.Extents.xMax,
             LowerRightY    = _sfAOI.Extents.yMin,
             Visibility     = true,
             MapLayerHandle = _hAOI
         };
         if (!isEdited)
         {
             aoi.ID = Entities.AOIViewModel.NextRecordNumber;
             Entities.AOIViewModel.AddRecordToRepo(aoi);
         }
         else
         {
             aoi.ID = _editedAOI_ID;
             Entities.AOIViewModel.UpdateRecordInRepo(aoi);
         }
         UpdateAOIName(name);
         MapWindowManager.ResetCursor();
         return(aoi);
     }
     return(null);
 }
Esempio n. 3
0
        public EntityValidationResult ValidateAOI(AOI aoi, bool isNew, string oldName)
        {
            EntityValidationResult evr = new EntityValidationResult();

            if (isNew && (aoi.Name == null || aoi.Name.Length < 2))
            {
                evr.AddMessage("Device name must be at least 2 letters long");
            }

            if (isNew && (aoi.ID == 0))
            {
                evr.AddMessage("AOI ID cannot be zero");
            }

            if (!isNew && aoi.Name.Length > 0 &&
                oldName != aoi.Name &&
                AOINameExist(aoi.Name))
            {
                evr.AddMessage("AOI name already used");
            }


            if (isNew && aoi.Name.Length > 0 && AOINameExist(aoi.Name))
            {
                evr.AddMessage("AOI name already used");
            }

            return(evr);
        }
Esempio n. 4
0
        private void AOICollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                int newIndex = e.NewStartingIndex;
                AOI newAOI   = AOICollection[newIndex];
                if (AOIs.Add(newAOI))
                {
                    CurrentEntity = newAOI;
                }
            }
            break;

            case NotifyCollectionChangedAction.Remove:
            {
                List <AOI> tempListOfRemovedItems = e.OldItems.OfType <AOI>().ToList();
                AOIs.Delete(tempListOfRemovedItems[0].ID);
            }
            break;

            case NotifyCollectionChangedAction.Replace:
            {
                List <AOI> tempList = e.NewItems.OfType <AOI>().ToList();
                AOIs.Update(tempList[0]);              // As the IDs are unique, only one row will be effected hence first index only
            }
            break;
            }
        }
Esempio n. 5
0
 public void AddRecordToRepo(AOI aoi)
 {
     if (aoi == null)
     {
         throw new ArgumentNullException("Error: The argument is Null");
     }
     AOICollection.Add(aoi);
 }
Esempio n. 6
0
 public static void Edit(AOI aoi)
 {
     _hAOI         = aoi.MapLayerHandle;
     AOIName       = aoi.Name;
     _editedAOI_ID = aoi.ID;;
     MapWindowManager.MapControl.MapCursor  = tkCursor.crsrCross;
     MapWindowManager.MapControl.CursorMode = tkCursorMode.cmSelection;
     EnableMapInteraction = true;
 }
Esempio n. 7
0
        private List <AOI> getAOIs()
        {
            var thisList = new List <AOI>();
            var dt       = new DataTable();

            using (var conection = new OleDbConnection(Global.ConnectionString))
            {
                try
                {
                    conection.Open();
                    string query = $"Select * from aoi";


                    var adapter = new OleDbDataAdapter(query, conection);
                    adapter.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        thisList.Clear();
                        foreach (DataRow dr in dt.Rows)
                        {
                            AOI aoi = new AOI();
                            aoi.UpperLeftX   = double.Parse(dr["UpperLeftX"].ToString());
                            aoi.UpperLeftY   = double.Parse(dr["UpperLeftY"].ToString());
                            aoi.LowerRightX  = double.Parse(dr["LowerRightX"].ToString());
                            aoi.LowerRightY  = double.Parse(dr["LowerRightY"].ToString());
                            aoi.Name         = dr["AOIName"].ToString();
                            aoi.GridFileName = dr["GridFileName"].ToString();
                            aoi.ID           = int.Parse(dr["RowID"].ToString());
                            aoi.Visibility   = true;
                            thisList.Add(aoi);
                        }
                    }
                }
                catch (OleDbException dbex)
                {
                }
                catch (Exception ex)
                {
                    switch (ex.HResult)
                    {
                    case -2147024809:
                        if (AddField(ex.Message.Split(' ', '\'')[2]))
                        {
                            return(getAOIs());
                        }
                        break;

                    default:
                        Logger.Log(ex);
                        break;
                    }
                }
            }
            return(thisList);
        }
Esempio n. 8
0
        public static Shapefile AOIShapefileFromAOI(AOI aoi)
        {
            var sf = new Shapefile();

            if (sf.CreateNewWithShapeID("", ShpfileType.SHP_POLYGON))
            {
                var extent = new Extents();
                extent.SetBounds(aoi.UpperLeftX, aoi.LowerRightY, 0, aoi.LowerRightX, aoi.UpperLeftY, 0);
                if (sf.EditAddShape(extent.ToShape()) >= 0)
                {
                    sf.DefaultDrawingOptions.FillTransparency = 0.25F;
                    return(sf);
                }
            }
            return(null);
        }
Esempio n. 9
0
        public List <string> GetAOISubGridFileNames(AOI aoi)
        {
            List <string> gridShapeFiles = new List <string>();
            DirectoryInfo folder         = new DirectoryInfo($"{Global.Settings.SaveFolderForGrids}");

            if (folder.Exists) // else: Invalid folder!
            {
                string     search = $"grid_{aoi.Name.Replace(' ', '_')}_*.shp";
                FileInfo[] files  = folder.GetFiles(search);

                foreach (FileInfo file in files)
                {
                    gridShapeFiles.Add(file.FullName);
                }
            }
            return(gridShapeFiles);
        }
Esempio n. 10
0
        public void UpdateRecordInRepo(AOI aoi)
        {
            if (aoi.ID == 0)
            {
                throw new Exception("Error: ID cannot be null");
            }

            int index = 0;

            while (index < AOICollection.Count)
            {
                if (AOICollection[index].ID == aoi.ID)
                {
                    AOICollection[index] = aoi;
                    break;
                }
                index++;
            }
        }
Esempio n. 11
0
        public bool Update(AOI aoi)
        {
            bool success = false;

            using (OleDbConnection conn = new OleDbConnection(Global.ConnectionString))
            {
                conn.Open();
                var sql = $@"Update aoi set
                                UpperLeftX= {aoi.UpperLeftX},
                                UpperLeftY = {aoi.UpperLeftY},
                                LowerRightX = {aoi.LowerRightX},
                                LowerRightY = {aoi.LowerRightY},
                                AOIName = '{aoi.Name}'
                            WHERE RowID = {aoi.ID}";
                using (OleDbCommand update = new OleDbCommand(sql, conn))
                {
                    success = update.ExecuteNonQuery() > 0;
                }
            }
            return(success);
        }
Esempio n. 12
0
        private List <AOI> getAOIs()
        {
            var thisList = new List <AOI>();
            var dt       = new DataTable();

            using (var conection = new OleDbConnection(Global.ConnectionString))
            {
                try
                {
                    conection.Open();
                    string query = $"Select * from aoi";


                    var adapter = new OleDbDataAdapter(query, conection);
                    adapter.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        thisList.Clear();
                        foreach (DataRow dr in dt.Rows)
                        {
                            AOI aoi = new AOI();
                            aoi.UpperLeftX  = double.Parse(dr["UpperLeftX"].ToString());
                            aoi.UpperLeftY  = double.Parse(dr["UpperLeftY"].ToString());
                            aoi.LowerRightX = double.Parse(dr["LowerRightX"].ToString());
                            aoi.LowerRightY = double.Parse(dr["LowerRightY"].ToString());
                            aoi.Name        = dr["AOIName"].ToString();
                            aoi.ID          = int.Parse(dr["RowID"].ToString());
                            aoi.Visibility  = true;
                            thisList.Add(aoi);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                }
            }
            return(thisList);
        }
Esempio n. 13
0
        public bool Add(AOI aoi)
        {
            bool success = false;

            using (OleDbConnection conn = new OleDbConnection(Global.ConnectionString))
            {
                conn.Open();
                var sql = $@"Insert into aoi(UpperLeftX, UpperLeftY, LowerRightX, LowerRightY, AOIName, RowID)
                           Values (
                               {aoi.UpperLeftX},
                               {aoi.UpperLeftY},
                               {aoi.LowerRightX},
                               {aoi.LowerRightY},
                               '{aoi.Name}',
                               {aoi.ID}
                           )";
                using (OleDbCommand update = new OleDbCommand(sql, conn))
                {
                    success = update.ExecuteNonQuery() > 0;
                }
            }
            return(success);
        }
Esempio n. 14
0
 public AOI GetAOI(string name)
 {
     CurrentEntity = AOICollection.FirstOrDefault(n => n.Name == name);
     return(CurrentEntity);
 }
Esempio n. 15
0
 public AOI GetAOI(int id)
 {
     CurrentEntity = AOICollection.FirstOrDefault(n => n.ID == id);
     return(CurrentEntity);
 }