private void OnMainButtonClick(object sender, EventArgs e) { switch (((Button)sender).Name) { case "btnShow": global.MappingForm.MapLayersHandler.AddMBRLayer(_targetArea, true); break; case "buttonOK": if (ValidateForm()) { if (SaveTargetArea()) { if (_isNew) { _parent_form.NewTargetArea(txtName.Text, _targetArea.TargetAreaGuid); } else { FishingGrid.Refresh(); _parent_form.RefreshLV("target_area"); } Close(); } } break; case "buttonCancel": this.Close(); break; } }
private void OnMapMouseMove(object sender, _DMapEvents_MouseMoveEvent e) { double utmX = 0, utmY = 0; _mapControl.PixelToProj(e.x, e.y, ref utmX, ref utmY); var g25Coord = FishingGrid.utmCoordinatesToGrid25(utmX, utmY, _majorGrid.UTMZone); txtCoord.Text = $"UTM: {_utmZone} {utmX.ToString("N0")}, {utmY.ToString("N0")}\r\nGrid25: {g25Coord.grid25Name}"; }
private bool SaveTargetArea() { var Success = false; var tabPage = tabAOI.SelectedTab.Name; if (_isNew) { _targetArea.TargetAreaGuid = Guid.NewGuid().ToString(); } Dictionary <string, string> TargetAreaData = new Dictionary <string, string>(); TargetAreaData.Add("AOIName", txtName.Text); TargetAreaData.Add("Letter", txtCode.Text); TargetAreaData.Add("AOIGUID", _targetArea.TargetAreaGuid); TargetAreaData.Add("DataStatus", _isNew ? fad3DataStatus.statusNew.ToString() : fad3DataStatus.statusEdited.ToString()); TargetAreaData.Add("SubGridStyle", comboSubGrid.SelectedIndex.ToString()); if (TargetArea.UpdateData(TargetAreaData)) { var Maps = new Dictionary <string, (string MapName, string ULGrid, string LRGrid)>(); var FirstMap = ""; var Zone = ""; var SubGridStyle = 0; if (tabPage == "tabGrid25") { //save grid25 data foreach (ListViewItem lvi in lvMaps.Items) { var Map = (lvi.Text, lvi.SubItems[1].Text, lvi.SubItems[2].Text); Maps.Add(lvi.Text, Map); } FirstMap = lvMaps.Items[0].Text; Zone = comboUTMZone.Text; SubGridStyle = comboSubGrid.SelectedIndex; } else { //save other grid data Maps = null; } Success = FishingGrid.SaveTargetAreaGrid25(_targetArea.TargetAreaGuid, UseGrid25: tabPage == "tabGrid25", Zone, SubGridStyle, Maps, FirstMap); } return(Success); }
private void ShowGridMapForm(ListViewItem lvi = null) { FishingGroundDefinitionForm fge; if (lvi == null) { fge = new FishingGroundDefinitionForm(this); fge.UTMZone = FishingGrid.ZoneFromZoneName(comboUTMZone.Text); } else { var UTMZone = FishingGrid.ZoneFromZoneName(comboUTMZone.Text); fge = new FishingGroundDefinitionForm(this, UTMZone, lvi.Text, lvi.SubItems[1].Text, lvi.SubItems[2].Text); } fge.ShowDialog(Parent_form); }
/// <summary> /// Map a single fishing ground when coming from a selected sampling /// </summary> /// <param name="fishingGround"></param> /// <param name="utmZone"></param> /// <returns></returns> public bool MapFishingGround(string fishingGround, fadUTMZone utmZone, string layerName = "", bool testIfInland = false) { var sf = new Shapefile(); bool success = false; var fgLayerName = "Fishing ground"; if (layerName.Length > 0) { fgLayerName = layerName; } if (sf.CreateNew("", ShpfileType.SHP_POINT)) { var shp = new Shape(); if (shp.Create(ShpfileType.SHP_POINT)) { var iShp = 0; if (_geoProjection.IsGeographic) { var result = FishingGrid.Grid25ToLatLong(fishingGround, utmZone); iShp = shp.AddPoint(result.longitude, result.latitude); } else { FishingGrid.Grid25_to_UTM(fishingGround, out int x, out int y); iShp = shp.AddPoint(x, y); } if (iShp >= 0 && sf.EditInsertShape(shp, 0)) { MapLayersHandler.RemoveLayer(fgLayerName); sf.GeoProjection = _geoProjection; var ifldLabel = sf.EditAddField("Label", FieldType.STRING_FIELD, 1, 15); sf.EditCellValue(ifldLabel, iShp, fgLayerName); sf.CollisionMode = tkCollisionMode.AllowCollisions; SymbolizeFishingGround(sf, fgLayerName, testIfInland); success = MapLayersHandler.AddLayer(sf, fgLayerName, true, true) >= 0; } } } return(success); }
private void OnbuttonGrid25_Click(object sender, EventArgs e) { switch (((Button)sender).Name) { case "buttonAddMap": if (comboUTMZone.Text.Length > 0) { if (lvMaps.SelectedItems.Count == 0) { ShowGridMapForm(); } else { ShowGridMapForm(lvMaps.SelectedItems[0]); } } else { MessageBox.Show("Please select a UTM zone", "UTM zone is missing", MessageBoxButtons.OK, MessageBoxIcon.Information); comboUTMZone.Select(); } break; case "buttonRemoveMap": if (lvMaps.SelectedItems.Count == 0) { MessageBox.Show("Select a fishing ground map in the list", "No map was selected", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { var itemText = lvMaps.SelectedItems[0].Text; if (FishingGrid.DeleteFishingGroundMap(itemText, _targetArea.TargetAreaGuid)) { lvMaps.Items.RemoveByKey(itemText); } } break; } }
private void Onbutton_Click(object sender, EventArgs e) { switch (((Button)sender).Name) { case "buttonOK": if (FishingGrid.ValidGridCorners(textBoxULGrid.Text, textBoxLRGrid.Text)) { _Parent_form.SetFishingGround(textBoxDescription.Text, textBoxULGrid.Text, textBoxLRGrid.Text); Close(); } else { MessageBox.Show("Upper left grid must be at the left and top of lower right grid", "Validation error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } break; case "buttonCancel": Close(); break; } }
private void OntextBoxGrid_Validating(object sender, CancelEventArgs e) { ((TextBox)sender).With(o => { var s = o.Text; var msg = ""; if (s.Length > 0) { switch (o.Name) { case "textBoxULGrid": case "textBoxLRGrid": e.Cancel = FishingGrid.ValidFGName(_UTMZone, o.Text, out msg) == false; if (!e.Cancel) { o.Text = o.Text.ToUpper(); } break; case "textBoxDescription": if (o.Text.Length < 3) { e.Cancel = true; msg = "Description is too short"; } break; } } if (e.Cancel) { MessageBox.Show(msg, "Validation error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }); }
/// <summary> /// Creates a new shapefile from a point shapefile where each point is located in the center of a grid25 cell. All fields in the source point shapefile are copied to the new shapefile /// </summary> /// <param name="pointShapefile"></param> /// <param name="utmZone"></param> /// <returns></returns> public static Shapefile ConvertToGrid25(Shapefile pointShapefile, fadUTMZone utmZone, fad3ActionType inlandAction = fad3ActionType.atIgnore, fad3ActionType outsideMapAction = fad3ActionType.atIgnore, bool includeCoordinates = false) { var sf = new Shapefile(); var listFields = new List <string>(); var zoneName = string.Empty; if (sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT)) { var gp = new GeoProjection(); switch (utmZone) { case fadUTMZone.utmZone50N: gp.SetWgs84Projection(tkWgs84Projection.Wgs84_UTM_zone_50N); zoneName = "50N"; break; case fadUTMZone.utmZone51N: gp.SetWgs84Projection(tkWgs84Projection.Wgs84_UTM_zone_51N); zoneName = "51N"; break; } sf.GeoProjection = gp; //recreate all fields from source to destination for (int f = 0; f < pointShapefile.NumFields; f++) { listFields.Add(pointShapefile.Field[f].Name); sf.EditAddField(listFields[f], pointShapefile.Field[f].Type, pointShapefile.Field[f].Precision, pointShapefile.Field[f].Width); } var ifldGrid = sf.EditAddField("grid25", FieldType.STRING_FIELD, 1, 8); var ifldInlandAction = -1; if (inlandAction == fad3ActionType.atTakeNote) { ifldInlandAction = sf.EditAddField("isInland", FieldType.BOOLEAN_FIELD, 1, 1); } var ifldOutsideAction = -1; if (outsideMapAction == fad3ActionType.atTakeNote) { ifldOutsideAction = sf.EditAddField("isOutsid", FieldType.BOOLEAN_FIELD, 1, 1); } //create fields for coordinate data var ifldCoordinatesX = -1; var ifldCoordinatesY = -1; if (includeCoordinates) { ifldCoordinatesX = sf.EditAddField("Grid25X", FieldType.INTEGER_FIELD, 0, 8); ifldCoordinatesY = sf.EditAddField("Grid25Y", FieldType.INTEGER_FIELD, 0, 8); } for (int n = 0; n < pointShapefile.NumShapes; n++) { var shp = new Shape(); if (shp.Create(ShpfileType.SHP_POINT)) { //get the x,y coordinates of the source point shape var x = pointShapefile.Shape[n].Point[0].x; var y = pointShapefile.Shape[n].Point[0].y; //call the function that returns the coordinates of the grid center where the point is located var result = FishingGrid.utmCoordinatesToGrid25(x, y, utmZone); var removeInland = false; var isInland = false; if (inlandAction != fad3ActionType.atIgnore) { isInland = FishingGrid.MinorGridIsInland(result.grid25Name, zoneName); removeInland = isInland && inlandAction == fad3ActionType.atRemove; } if (!removeInland) { //create a new point shape and add it to the destination shapefile shp.AddPoint(result.Easting, result.Northing); var iShp = sf.EditAddShape(shp); //update the destination shapefile fields foreach (var item in listFields) { var ifldDestination = sf.FieldIndexByName[item]; var ifldSource = pointShapefile.FieldIndexByName[item]; sf.EditCellValue(ifldDestination, iShp, pointShapefile.CellValue[ifldSource, n]); } sf.EditCellValue(ifldGrid, iShp, result.grid25Name); //update coordinate fields if required if (includeCoordinates) { sf.EditCellValue(ifldCoordinatesX, iShp, result.Easting); sf.EditCellValue(ifldCoordinatesY, iShp, result.Northing); } //update isInland field if required if (ifldInlandAction >= 0) { sf.EditCellValue(ifldInlandAction, iShp, isInland); } } } } return(sf); } return(null); }
/// <summary> /// maps fishing grounds belonging to a target area, landing site, or type of gear gear /// </summary> /// <param name="aoiGUID"></param> /// <param name="samplingYears"></param> /// <param name="utmZone"></param> /// <param name="Aggregated"></param> /// <param name="notInclude1"></param> /// <param name="landingSiteGuid"></param> /// <param name="gearVariationGuid"></param> public void MapFishingGrounds(string aoiGUID, string samplingYears, fadUTMZone utmZone, bool Aggregated = true, bool notInclude1 = false, string landingSiteGuid = "", string gearVariationGuid = "") { var query = ""; var sf = new Shapefile(); var ifldAOI = 0; var ifldLS = 0; var ifldGear = 0; var ifldYear = 0; var ifldFG = 0; var ifldCount = 0; var ifldMaxWt = 0; var ifldMinWt = 0; var ifldAfgWt = 0; var ifldEnumerator = 0; var ifldGearClass = 0; var ifldNumberHauls = 0; var ifldNumberFisher = 0; var ifldDateSet = 0; var ifldTimeSet = 0; var ifldDateHauled = 0; var ifldTimeHauled = 0; var ifldVessel = 0; var ifldHP = 0; var ifldCatchWt = 0; if (aoiGUID.Length > 0 && samplingYears.Length > 0 && sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT)) { ifldAOI = sf.EditAddField("AOIName", FieldType.STRING_FIELD, 1, 255); sf.Field[ifldAOI].Alias = "Target area name"; if (Aggregated) { if (landingSiteGuid.Length > 0) { ifldLS = sf.EditAddField("LSName", FieldType.STRING_FIELD, 1, 255); sf.Field[ifldLS].Alias = "Landing site name"; } if (gearVariationGuid.Length > 0) { ifldGear = sf.EditAddField("GearName", FieldType.STRING_FIELD, 1, 255); sf.Field[ifldGear].Alias = "Gear variation used"; } ifldYear = sf.EditAddField("Year", FieldType.INTEGER_FIELD, 1, 4); sf.Field[ifldYear].Alias = "Year sampled"; ifldFG = sf.EditAddField("fg", FieldType.STRING_FIELD, 1, 25); sf.Field[ifldFG].Alias = "Fishing ground"; ifldCount = sf.EditAddField("n", FieldType.INTEGER_FIELD, 1, 4); ifldMaxWt = sf.EditAddField("MaxWt", FieldType.DOUBLE_FIELD, 2, 8); sf.Field[ifldMaxWt].Alias = "Maximum catch weight"; ifldMinWt = sf.EditAddField("MinWt", FieldType.DOUBLE_FIELD, 2, 8); sf.Field[ifldMinWt].Alias = "Minimum catch weight"; ifldAfgWt = sf.EditAddField("AvgWt", FieldType.DOUBLE_FIELD, 2, 8); sf.Field[ifldAfgWt].Alias = "Average catch weight"; if (gearVariationGuid.Length > 0) { query = $@"SELECT tblAOI.AOIName, tblLandingSites.LSName, tblGearVariations.Variation, tblSampling.FishingGround, Year([SamplingDate]) AS samplingYear, Count(tblSampling.SamplingGUID) AS n, Max(tblSampling.WtCatch) AS MaxCatch, Min(tblSampling.WtCatch) AS MinCatch, Avg(tblSampling.WtCatch) AS AvgCatch FROM tblGearVariations INNER JOIN ((tblAOI INNER JOIN tblLandingSites ON tblAOI.AOIGuid = tblLandingSites.AOIGuid) INNER JOIN tblSampling ON tblLandingSites.LSGUID = tblSampling.LSGUID) ON tblGearVariations.GearVarGUID = tblSampling.GearVarGUID WHERE tblLandingSites.LSGUID={{{landingSiteGuid}}} AND tblSampling.GearVarGUID={{{gearVariationGuid}}} GROUP BY tblAOI.AOIName, tblLandingSites.LSName, tblGearVariations.Variation, tblSampling.FishingGround, Year([SamplingDate]) "; if (notInclude1) { query += $"HAVING Count(tblSampling.SamplingGUID)>1 AND Year([SamplingDate]) In ({samplingYears})"; } else { query += $"HAVING Year([SamplingDate]) In ({samplingYears})"; } } else if (landingSiteGuid.Length > 0) { query = $@"SELECT tblAOI.AOIName, tblLandingSites.LSName, tblSampling.FishingGround, Year([SamplingDate]) AS samplingYear, Count(tblSampling.SamplingGUID) AS n, Max(tblSampling.WtCatch) AS MaxCatch, Min(tblSampling.WtCatch) AS MinCatch, Avg(tblSampling.WtCatch) AS AvgCatch FROM (tblAOI INNER JOIN tblLandingSites ON tblAOI.AOIGuid = tblLandingSites.AOIGuid) INNER JOIN tblSampling ON tblLandingSites.LSGUID = tblSampling.LSGUID WHERE tblLandingSites.LSGUID={{{landingSiteGuid}}} GROUP BY tblAOI.AOIName, tblLandingSites.LSName, tblSampling.FishingGround, Year([SamplingDate]) "; if (notInclude1) { query += $"HAVING Count(tblSampling.SamplingGUID)>1 AND Year([SamplingDate]) In ({samplingYears})"; } else { query += $"HAVING Year([SamplingDate]) In ({samplingYears})"; } } else { query = $@"SELECT tblAOI.AOIName, tblSampling.FishingGround, Year([SamplingDate]) AS samplingYear, Count(tblSampling.SamplingGUID) AS n, Max(tblSampling.WtCatch) AS MaxCatch, Min(tblSampling.WtCatch) AS MinCatch, Avg(tblSampling.WtCatch) AS AvgCatch FROM tblAOI INNER JOIN tblSampling ON tblAOI.AOIGuid = tblSampling.AOI GROUP BY tblAOI.AOIName, tblSampling.FishingGround, tblSampling.AOI, Year([SamplingDate]) "; if (notInclude1) { query += $"HAVING tblSampling.AOI= {{{aoiGUID}}} AND Count(tblSampling.SamplingGUID)>1 AND Year([SamplingDate]) In ({samplingYears})"; } else { query += $"HAVING tblSampling.AOI= {{{aoiGUID}}} AND Year([SamplingDate]) In ({samplingYears})"; } } } else //not aggregated { ifldEnumerator = sf.EditAddField("Enumerat", FieldType.STRING_FIELD, 1, 100); sf.Field[ifldEnumerator].Alias = "Name of enumerator"; ifldLS = sf.EditAddField("LSName", FieldType.STRING_FIELD, 1, 255); sf.Field[ifldLS].Alias = "Landing site name"; ifldGearClass = sf.EditAddField("GearClass", FieldType.STRING_FIELD, 1, 100); sf.Field[ifldGearClass].Alias = "Gear class used"; ifldGear = sf.EditAddField("GearName", FieldType.STRING_FIELD, 1, 255); sf.Field[ifldGear].Alias = "Gear variation used"; ifldYear = sf.EditAddField("Year", FieldType.INTEGER_FIELD, 1, 4); sf.Field[ifldYear].Alias = "Year sampled"; ifldFG = sf.EditAddField("fg", FieldType.STRING_FIELD, 1, 25); sf.Field[ifldFG].Alias = "Fishing ground"; ifldNumberHauls = sf.EditAddField("NoHauls", FieldType.INTEGER_FIELD, 1, 2); sf.Field[ifldNumberHauls].Alias = "Number of hauls"; ifldNumberFisher = sf.EditAddField("NoFishers", FieldType.INTEGER_FIELD, 1, 2); sf.Field[ifldNumberFisher].Alias = "Number of fishers"; ifldDateSet = sf.EditAddField("DateSet", FieldType.DATE_FIELD, 1, 2); sf.Field[ifldDateSet].Alias = "Date gear set"; ifldTimeSet = sf.EditAddField("TimeSet", FieldType.DATE_FIELD, 1, 2); sf.Field[ifldTimeSet].Alias = "Time gear set"; ifldDateHauled = sf.EditAddField("DateHaul", FieldType.DATE_FIELD, 1, 2); sf.Field[ifldDateHauled].Alias = "Date gear hauled"; ifldTimeHauled = sf.EditAddField("TimeHaul", FieldType.DATE_FIELD, 1, 2); sf.Field[ifldTimeHauled].Alias = "Time gear hauled"; ifldVessel = sf.EditAddField("VesType", FieldType.STRING_FIELD, 1, 30); sf.Field[ifldVessel].Alias = "Type of vessel used"; ifldHP = sf.EditAddField("hp", FieldType.STRING_FIELD, 1, 2); sf.Field[ifldHP].Alias = "Engine hp"; ifldCatchWt = sf.EditAddField("CatchWt", FieldType.DOUBLE_FIELD, 2, 8); sf.Field[ifldCatchWt].Alias = "Catch weight"; query = @"SELECT tblAOI.AOIName, tblEnumerators.EnumeratorName, tblLandingSites.LSName, tblGearClass.GearClassName, tblGearVariations.Variation, Year([SamplingDate]) AS samplingYear, tblSampling.FishingGround, tblSampling.NoHauls, tblSampling.NoFishers, tblSampling.DateSet, tblSampling.TimeSet, tblSampling.DateHauled, tblSampling.TimeHauled, tblSampling.VesType, tblSampling.hp, tblSampling.WtCatch FROM (tblAOI INNER JOIN tblLandingSites ON tblAOI.AOIGuid = tblLandingSites.AOIGuid) INNER JOIN ((tblGearClass INNER JOIN tblGearVariations ON tblGearClass.GearClass = tblGearVariations.GearClass) INNER JOIN (tblEnumerators RIGHT JOIN tblSampling ON tblEnumerators.EnumeratorID = tblSampling.Enumerator) ON tblGearVariations.GearVarGUID = tblSampling.GearVarGUID) ON tblLandingSites.LSGUID = tblSampling.LSGUID "; if (gearVariationGuid.Length > 0) { query += $@"WHERE Year([SamplingDate]) In({samplingYears}) AND tblSampling.LSGUID ={{{landingSiteGuid}}} AND tblSampling.GearVarGUID ={{{gearVariationGuid}}}"; } else if (landingSiteGuid.Length > 0) { query += $"WHERE Year([SamplingDate]) In({samplingYears}) AND tblSampling.LSGUID ={{{landingSiteGuid}}}"; } else { query += $"WHERE Year([SamplingDate]) In({samplingYears}) AND tblSampling.AOI ={{{aoiGUID}}}"; } } using (var conection = new OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;data source=" + global.MDBPath)) { conection.Open(); using (var adapter = new OleDbDataAdapter(query, conection)) using (var myDT = new DataTable()) { adapter.Fill(myDT); //var n = 0; foreach (DataRow dr in myDT.Rows) { var fg = dr["FishingGround"].ToString(); if (fg.Length > 0) { var shp = new MapWinGIS.Shape(); if (shp.Create(ShpfileType.SHP_POINT)) { var proceed = false; if (RemoveInland && !FishingGrid.MinorGridIsInland(fg)) { proceed = true; } else if (!RemoveInland) { proceed = true; } if (proceed) { var iShp = 0; if (_geoProjection.IsGeographic) { var result = FishingGrid.Grid25ToLatLong(fg, utmZone); iShp = shp.AddPoint(result.longitude, result.latitude); } else { FishingGrid.Grid25_to_UTM(fg, out int x, out int y); iShp = shp.AddPoint(x, y); } if (iShp >= 0 && sf.EditInsertShape(shp, 0)) { sf.EditCellValue(ifldAOI, iShp, dr["AOIName"].ToString()); sf.EditCellValue(ifldYear, iShp, int.Parse(dr["samplingYear"].ToString())); sf.EditCellValue(ifldFG, iShp, dr["FishingGround"].ToString()); //aggregated if (Aggregated) { if (landingSiteGuid.Length > 0) { sf.EditCellValue(ifldLS, iShp, dr["LSName"].ToString()); } if (gearVariationGuid.Length > 0) { sf.EditCellValue(ifldGear, iShp, dr["Variation"].ToString()); } sf.EditCellValue(ifldCount, iShp, int.Parse(dr["n"].ToString())); sf.EditCellValue(ifldMaxWt, iShp, double.Parse(dr["MaxCatch"].ToString())); sf.EditCellValue(ifldMinWt, iShp, double.Parse(dr["MinCatch"].ToString())); sf.EditCellValue(ifldAfgWt, iShp, double.Parse(dr["AvgCatch"].ToString())); Console.WriteLine($"n-{sf.CellValue[ifldCount, iShp]}, AvgCatch -{sf.CellValue[ifldAfgWt, iShp]}"); } //not aggregated else { sf.EditCellValue(ifldEnumerator, iShp, dr["EnumeratorName"].ToString()); sf.EditCellValue(ifldLS, iShp, dr["LSName"].ToString()); sf.EditCellValue(ifldGearClass, iShp, dr["GearClassName"].ToString()); sf.EditCellValue(ifldGear, iShp, dr["Variation"].ToString()); if (dr["NoHauls"].ToString().Length > 0) { sf.EditCellValue(ifldNumberHauls, iShp, int.Parse(dr["NoHauls"].ToString())); } if (dr["NoFishers"].ToString().Length > 0) { sf.EditCellValue(ifldNumberFisher, iShp, int.Parse(dr["NoFishers"].ToString())); } if (dr["DateSet"].ToString().Length > 0) { sf.EditCellValue(ifldDateSet, iShp, DateTime.Parse(dr["DateSet"].ToString())); } if (dr["TimeSet"].ToString().Length > 0) { sf.EditCellValue(ifldTimeSet, iShp, DateTime.Parse(dr["TimeSet"].ToString())); } if (dr["DateHauled"].ToString().Length > 0) { sf.EditCellValue(ifldDateHauled, iShp, DateTime.Parse(dr["DateHauled"].ToString())); } if (dr["TimeHauled"].ToString().Length > 0) { sf.EditCellValue(ifldTimeHauled, iShp, DateTime.Parse(dr["TimeHauled"].ToString())); } if (dr["VesType"].ToString().Length > 0) { var vesselType = "Motorized"; switch (int.Parse(dr["VesType"].ToString())) { case 1: vesselType = "Motorized"; break; case 2: vesselType = "Non-motorized"; break; case 3: vesselType = "No vessel used"; break; case 4: vesselType = "Not provided"; break; } sf.EditCellValue(ifldVessel, iShp, vesselType); } if (dr["hp"].ToString().Length > 0) { sf.EditCellValue(ifldHP, iShp, dr["hp"].ToString()); } sf.EditCellValue(ifldCatchWt, iShp, double.Parse(dr["WtCatch"].ToString())); } } } } } //n++; } } } MapLayersHandler.RemoveLayer("Fishing grounds"); if (sf.NumShapes > 0) { sf.GeoProjection = _geoProjection; sf.CollisionMode = tkCollisionMode.AllowCollisions; sf.DefaultDrawingOptions.PointShape = tkPointShapeType.ptShapeCircle; sf.DefaultDrawingOptions.FillColor = new Utils().ColorByName(tkMapColor.Red); sf.DefaultDrawingOptions.LineColor = new Utils().ColorByName(tkMapColor.White); ClassificationType classificationType = ClassificationType.None; if (Aggregated) { classificationType = ClassificationType.NaturalBreaks; ShapefileLayerHelper.CategorizeNumericPointLayer(sf, ifldCount); } else { sf.DefaultDrawingOptions.PointSize = 7; } sf.SelectionAppearance = tkSelectionAppearance.saDrawingOptions; sf.SelectionDrawingOptions.PointShape = tkPointShapeType.ptShapeCircle; if (ShapefileLayerHelper.ExtentsPosition(MapControl.Extents, sf.Extents) == ExtentCompare.excoOutside) { var newExtent = MapControl.Extents; newExtent.MoveTo(sf.Extents.Center.x, sf.Extents.Center.y); MapControl.Extents = newExtent; } var h = MapLayersHandler.AddLayer(sf, "Fishing grounds", true, true); MapLayersHandler[h].ClassificationType = classificationType; } } }
private void OntextBoxValidating(object sender, CancelEventArgs e) { var s = ((TextBox)sender).Text; var msg = ""; if (s.Length > 0) { switch (((TextBox)sender).Name) { case "textBoxGridNo": if (FishingGrid.MajorGridFound(s) == false) { msg = "Grid number not found in the maps"; } break; case "textBoxColumn": if (s.Length == 1) { var c = s.ToUpper().ToArray(); if (c[0] < 'A' || c[0] > 'Y') { msg = "Grid column not found"; } ((TextBox)sender).Text = s.ToUpper(); } else { msg = "Grid column not found"; } break; case "textBoxRow": try { var n = int.Parse(s); if (n < 1 || n > 25) { msg = "Expected value is a number from 1 to 25"; } } catch { msg = "Expected value is a number from 1 to 25"; } break; case "textBoxSubGrid": if (int.TryParse(textBoxSubGrid.Text, out int sg) && sg >= 1 && sg < 10) { switch (FishingGrid.SubGridStyle) { case fadSubgridStyle.SubgridStyle4: if (sg > 4) { msg = "Expected value is a number from 1 to 4"; } break; case fadSubgridStyle.SubgridStyle9: if (sg > 9) { msg = "Expected value is a number from 1 to 9"; } break; } } else { e.Cancel = true; switch (FishingGrid.SubGridStyle) { case fadSubgridStyle.SubgridStyle4: msg = "Expected value is a number from 1 to 4"; break; case fadSubgridStyle.SubgridStyle9: msg = "Expected value is a number from 1 to 9"; break; } } break; } } if (msg.Length > 0) { e.Cancel = true; MessageBox.Show(msg, "Validation error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public bool Import() { int elementCounter = 0; int samplingRecords = 0; bool proceed = false; fadSubgridStyle subgridStyle = fadSubgridStyle.SubgridStyleNone; fadUTMZone zone = fadUTMZone.utmZone_Undefined; XmlTextReader xmlReader = new XmlTextReader(XMLFilename); string gearClassGuid = ""; int mapCount = 0; VesselType vesselType = VesselType.NotDetermined; List <FishingGround> listFishingGrounds = new List <FishingGround>(); Sampling sampling = new Sampling(); FishingVessel fishingVessel = new FishingVessel(VesselType.NotDetermined); string gearVariationGuid = ""; string refCode = ""; string usageCodeID = ""; while (xmlReader.Read()) { if (xmlReader.NodeType == XmlNodeType.Element) { switch (xmlReader.Name) { case "FishCatchMonitoring": SamplingEventArgs sev = new SamplingEventArgs(SamplingRecordStatus.StartImport); sev.SamplingToFromXML = this; sev.TargetAreaName = TargetAreaName; OnExportSamplingStatus?.Invoke(null, sev); string targetAreaCode = xmlReader.GetAttribute("TargetAreaCode"); subgridStyle = (fadSubgridStyle)Enum.Parse(typeof(fadSubgridStyle), xmlReader.GetAttribute("SubGridStyle")); zone = (fadUTMZone)Enum.Parse(typeof(fadUTMZone), xmlReader.GetAttribute("UTMZone")); if (NewTargetArea && !TargetArea.AddNewTargetArea(TargetAreaName, TargetAreaGuid, targetAreaCode, subgridStyle, zone)) { } else { TargetArea = new TargetArea(TargetAreaGuid); TargetArea.TargetAreaName = TargetAreaName; TargetArea.TargetAreaLetter = targetAreaCode; } break; case "FishingGroundMaps": break; case "FishingGroundMap": string ulg = xmlReader.GetAttribute("ulg"); string lrg = xmlReader.GetAttribute("lrg"); string description = xmlReader.GetAttribute("description"); FishingGrid.AddGrid25Map(TargetAreaGuid, subgridStyle, zone, ulg, lrg, description, mapCount == 0); mapCount++; break; case "Enumerators": break; case "Enumerator": string enumeratorGUID = xmlReader.GetAttribute("EnumeratorGuid"); string enumeratorName = xmlReader.GetAttribute("Name"); DateTime hiredate = DateTime.Parse(xmlReader.GetAttribute("DateHired")); bool active = bool.Parse(xmlReader.GetAttribute("Active")); Enumerators.SaveNewTargetAreaEnumerator(TargetAreaGuid, enumeratorName, hiredate, active, enumeratorGUID); break; case "LandingSites": break; case "LandingSite": string landingsiteGuid = xmlReader.GetAttribute("LandingSiteGuid"); string landingsiteName = xmlReader.GetAttribute("LandingSiteName"); int munNo = int.Parse(xmlReader.GetAttribute("MunicipalityNumber")); string sx = xmlReader.GetAttribute("x_coordinate"); string sy = xmlReader.GetAttribute("y_coordinate"); double?x = sx.Length == 0 ? null : (double?)double.Parse(sx); double?y = sy.Length == 0 ? null : (double?)double.Parse(sy); Landingsite.AddNewLandingSite(TargetAreaGuid, landingsiteGuid, landingsiteName, munNo, x, y); break; case "FishingGears": SamplingEventArgs sve = new SamplingEventArgs(SamplingRecordStatus.BeginFishingGears); sve.RecordCount = int.Parse(xmlReader.GetAttribute("GearVariationsCount")); OnExportSamplingStatus?.Invoke(null, sve); break; case "GearLocalNames": sve = new SamplingEventArgs(SamplingRecordStatus.BeginGearLocalNames); sve.RecordCount = int.Parse(xmlReader.GetAttribute("LocalNameCount")); OnExportSamplingStatus?.Invoke(null, sve); break; case "GearLocalName": string gearLocalName = xmlReader.GetAttribute("LocalName"); NewFisheryObjectName nfo = new NewFisheryObjectName(gearLocalName, FisheryObjectNameType.GearLocalName); Gears.SaveNewLocalName(nfo, xmlReader.GetAttribute("LocalNameGuid")); sve = new SamplingEventArgs(SamplingRecordStatus.GearLocalName); sve.GearLocalName = gearLocalName; OnExportSamplingStatus?.Invoke(null, sve); break; case "GearClasses": break; case "GearClass": gearClassGuid = xmlReader.GetAttribute("ClassGuid"); string gearClassName = xmlReader.GetAttribute("ClassName"); string gearClassLetter = xmlReader.GetAttribute("ClassLetter"); GearClass.AddGearClass(gearClassName, gearClassLetter, gearClassGuid); break; case "GearVariation": string gearVariationName = xmlReader.GetAttribute("name"); gearVariationGuid = xmlReader.GetAttribute("guid"); Gears.AddGearVariation(gearClassGuid, gearVariationName, gearVariationGuid); sve = new SamplingEventArgs(SamplingRecordStatus.FishingGears); sve.GearVariationName = gearVariationName; OnExportSamplingStatus?.Invoke(null, sve); break; case "Specifications": break; case "Specification": GearSpecification gs = new GearSpecification(xmlReader.GetAttribute("ElementName"), xmlReader.GetAttribute("ElementType"), xmlReader.GetAttribute("SpecRowGUID"), int.Parse(xmlReader.GetAttribute("Sequence"))); gs.Notes = xmlReader.GetAttribute("Description"); ManageGearSpecsClass.SaveGearSpec(gearVariationGuid, gs); break; case "GearRefCodes": break; case "GearRefCode": refCode = xmlReader.GetAttribute("RefCode"); Gears.SaveNewGearReferenceCode(refCode, gearVariationGuid, bool.Parse(xmlReader.GetAttribute("IsSubVariation").ToString())); break; case "RefCodeUsage": usageCodeID = xmlReader.GetAttribute("UsageRowID"); if (usageCodeID.Length > 0) { var addUsageResult = Gears.AddGearCodeUsageTargetArea(refCode, TargetArea.TargetAreaGuid, usageCodeID); usageCodeID = addUsageResult.NewRow; } break; case "LocalNamesInUse": break; case "LocalNameUsed": if (usageCodeID.Length > 0) { Gears.AddUsageLocalName(usageCodeID, xmlReader.GetAttribute("LocalNameGuid"), xmlReader.GetAttribute("UsageGuid")); } break; case "Taxa": break; case "TaxaItem": int taxaNumber = int.Parse(xmlReader.GetAttribute("TaxaNo")); string taxaName = xmlReader.GetAttribute("Taxa"); TaxaCategory.AddTaxa(taxaNumber, taxaName); break; case "AllCatchNames": sve = new SamplingEventArgs(SamplingRecordStatus.BeginCatchNames); sve.RecordCount = int.Parse(xmlReader.GetAttribute("NamesOfCatchCount")); OnExportSamplingStatus?.Invoke(null, sve); break; case "CatchName": string nameGuid = xmlReader.GetAttribute("NameGuid"); string name1 = xmlReader.GetAttribute("Name1"); string name2 = xmlReader.GetAttribute("Name2"); int?taxaNo = null; if (int.TryParse(xmlReader.GetAttribute("TaxaNumber"), out int tn)) { taxaNo = tn; } string identification = xmlReader.GetAttribute("Identification"); bool inFishbase = bool.Parse(xmlReader.GetAttribute("IsListedInFishbase")); int?fbNumber = null; if (int.TryParse(xmlReader.GetAttribute("FBSpeciesNumber"), out int v)) { fbNumber = v; } bool success = CatchName.AddCatchName(nameGuid, identification, name1, name2, taxaNo, inFishbase, fbNumber); sve = new SamplingEventArgs(SamplingRecordStatus.CatchNames); sve.CatchName = $"{name1} {name2}"; OnExportSamplingStatus?.Invoke(null, sve); break; case "Samplings": samplingRecords = int.Parse(xmlReader.GetAttribute("SamplingRecordsCount")); OnExportSamplingStatus?.Invoke(null, new SamplingEventArgs(SamplingRecordStatus.BeginSamplings, samplingRecords)); break; case "Sampling": sampling = new Sampling(xmlReader.GetAttribute("TargetAreaGUID"), xmlReader.GetAttribute("SamplingGUID"), DateTime.Parse(xmlReader.GetAttribute("SamplingDateTime")), xmlReader.GetAttribute("LandingSiteGuid"), xmlReader.GetAttribute("ReferenceNumber")); sampling.TargetAreaGuid = TargetAreaGuid; sampling.EnumeratorGuid = xmlReader.GetAttribute("EnumeratorGuid"); sampling.SamplingType = CatchMonitoringSamplingType.FisheryDependent; if (xmlReader.GetAttribute("SamplingType") != null) { sampling.SamplingType = (CatchMonitoringSamplingType)Enum.Parse(typeof(CatchMonitoringSamplingType), xmlReader.GetAttribute("SamplingType")); } if (DateTime.TryParse(xmlReader.GetAttribute("DateEncoded"), out DateTime result)) { sampling.DateEncoded = result; } if (DateTime.TryParse(xmlReader.GetAttribute("GearSetDateTime"), out result)) { sampling.GearSettingDateTime = result; } if (DateTime.TryParse(xmlReader.GetAttribute("GearHaulDateTime"), out result)) { sampling.GearHaulingDateTime = result; } sampling.GearVariationGuid = xmlReader.GetAttribute("GearVariationGuid"); if (bool.TryParse(xmlReader.GetAttribute("HasLiveFish"), out bool hlf)) { sampling.HasLiveFish = hlf; } sampling.Notes = xmlReader.GetAttribute("Notes"); if (int.TryParse(xmlReader.GetAttribute("NumberOfFishers"), out int nf)) { sampling.NumberOfFishers = nf; } if (int.TryParse(xmlReader.GetAttribute("NumberOfHauls"), out int nh)) { sampling.NumberOfHauls = nh; } if (int.TryParse(xmlReader.GetAttribute("WeightCatch"), out int wc)) { sampling.CatchWeight = wc; } if (int.TryParse(xmlReader.GetAttribute("WeightSample"), out int ws)) { sampling.SampleWeight = ws; } break; case "FishingVessel": if (Enum.TryParse(xmlReader.GetAttribute("VesselType"), out VesselType t)) { vesselType = t; } fishingVessel = new FishingVessel(vesselType); fishingVessel.Engine = xmlReader.GetAttribute("Engine"); if (int.TryParse(xmlReader.GetAttribute("EngineHp"), out int hp)) { fishingVessel.EngineHorsepower = hp; } var dimension = xmlReader.GetAttribute("Dimension_BDL").Split(new char[] { 'x', ' ' }); if (dimension[0].Length > 0) { fishingVessel.Breadth = double.Parse(dimension[0]); fishingVessel.Depth = double.Parse(dimension[3]); fishingVessel.Length = double.Parse(dimension[6]); } sampling.FishingVessel = fishingVessel; break; case "FishingGrounds": listFishingGrounds.Clear(); break; case "FishingGround": int? sg = null; string fg = xmlReader.GetAttribute("Name"); if (fg.Length > 0) { if (int.TryParse(xmlReader.GetAttribute("SubGrid"), out int s)) { sg = s; } listFishingGrounds.Add(new FishingGround(fg, sg)); } break; case "CatchComposition": sampling.FishingGroundList = listFishingGrounds; Samplings sp = new Samplings(); if (sp.UpdateEffort(true, sampling)) { OnExportSamplingStatus?.Invoke(null, new SamplingEventArgs(SamplingRecordStatus.Samplings, sampling.ReferenceNumber)); } break; case "Catch": break; case "LengthFrequency": break; case "LengthFrequencyItem": break; case "GonadalMaturityStage": break; case "GMSItem": break; } elementCounter++; } //if (elementCounter > 0 && !proceed) //{ // OnExportSamplingStatus?.Invoke(null, new SamplingEventArgs(ExportSamplingStatus.Error, "XML file does not contain fish catch monitoring data", 0)); // proceed = false; //} } OnExportSamplingStatus?.Invoke(null, new SamplingEventArgs(SamplingRecordStatus.EndImport)); xmlReader.Close(); return(proceed); }
private bool SpeciesOccurenceMapping() { string sql = ""; if (Aggregate) { if (MapInSelectedTargetArea) { sql = $@"SELECT tblAOI.AOIName, tblSampling.FishingGround, Count(tblSampling.SamplingGUID) AS n, tblAOI.UTMZone FROM (tblSampling INNER JOIN tblAOI ON tblSampling.AOI = tblAOI.AOIGuid) INNER JOIN tblCatchComp ON tblSampling.SamplingGUID = tblCatchComp.SamplingGUID WHERE tblCatchComp.NameGUID = {{{ItemToMapGuid}}} AND Year([SamplingDate]) In ({YearsToCSV()}) AND tblSampling.FishingGround Is Not Null AND tblAOI.UTMZone Is Not Null AND tblAOI.AOIGuid={{{SelectedTargetAreaGuid}}} GROUP BY tblAOI.AOIName, tblSampling.FishingGround, tblAOI.UTMZone"; } else { sql = $@"SELECT tblAOI.AOIName, tblSampling.FishingGround, Count(tblSampling.SamplingGUID) AS n, tblAOI.UTMZone FROM (tblSampling INNER JOIN tblCatchComp ON tblSampling.SamplingGUID = tblCatchComp.SamplingGUID) INNER JOIN tblAOI ON tblSampling.AOI = tblAOI.AOIGuid WHERE Year([SamplingDate]) In ({YearsToCSV()}) AND tblSampling.FishingGround Is Not Null AND tblAOI.UTMZone Is Not Null AND tblCatchComp.NameGUID={{{ItemToMapGuid}}} GROUP BY tblAOI.AOIName, tblSampling.FishingGround, tblAOI.UTMZone"; } } else { if (MapInSelectedTargetArea) { sql = $@"SELECT tblAOI.AOIName, tblEnumerators.EnumeratorName, tblSampling.*, tblLandingSites.LSName, tblGearClass.GearClassName, tblGearVariations.Variation, tblAOI.UTMZone FROM tblEnumerators RIGHT JOIN ((tblAOI INNER JOIN tblLandingSites ON tblAOI.AOIGuid = tblLandingSites.AOIGuid) INNER JOIN ((tblGearClass INNER JOIN tblGearVariations ON tblGearClass.GearClass = tblGearVariations.GearClass) INNER JOIN (tblSampling INNER JOIN tblCatchComp ON tblSampling.SamplingGUID = tblCatchComp.SamplingGUID) ON tblGearVariations.GearVarGUID = tblSampling.GearVarGUID) ON tblLandingSites.LSGUID = tblSampling.LSGUID) ON tblEnumerators.EnumeratorID = tblSampling.Enumerator WHERE tblSampling.AOI={{{SelectedTargetAreaGuid}}} AND tblAOI.UTMZone Is Not Null AND tblCatchComp.NameGUID={{{ItemToMapGuid}}} AND Year([SamplingDate]) In ({YearsToCSV()}) AND tblSampling.FishingGround Is Not Null ORDER BY tblAOI.AOIName, tblGearClass.GearClassName, tblGearVariations.Variation, tblSampling.SamplingDate"; } else { sql = $@"SELECT tblAOI.AOIName, tblEnumerators.EnumeratorName, tblSampling.*, tblLandingSites.LSName, tblGearClass.GearClassName, tblGearVariations.Variation, tblAOI.UTMZone FROM tblEnumerators RIGHT JOIN ((tblAOI INNER JOIN tblLandingSites ON tblAOI.AOIGuid = tblLandingSites.AOIGuid) INNER JOIN ((tblGearClass INNER JOIN tblGearVariations ON tblGearClass.GearClass = tblGearVariations.GearClass) INNER JOIN (tblSampling INNER JOIN tblCatchComp ON tblSampling.SamplingGUID = tblCatchComp.SamplingGUID) ON tblGearVariations.GearVarGUID = tblSampling.GearVarGUID) ON tblLandingSites.LSGUID = tblSampling.LSGUID) ON tblEnumerators.EnumeratorID = tblSampling.Enumerator WHERE tblCatchComp.NameGUID={{{ItemToMapGuid}}} AND Year([SamplingDate]) In ({YearsToCSV()}) AND tblSampling.FishingGround Is Not Null AND tblAOI.UTMZone Is Not Null ORDER BY tblAOI.AOIName, tblGearClass.GearClassName, tblGearVariations.Variation, tblSampling.SamplingDate"; } } try { var sf = new Shapefile(); if (sf.CreateNew("", ShpfileType.SHP_POINT)) { sf.GeoProjection = MapControl.GeoProjection; var ifldTargetArea = -1; var ifldCount = -1; var ifldFishingGround = -1; var ifldSpeciesName = -1; var ifldGearClass = -1; var ifldGearVariation = -1; var ifldCatchWt = -1; var ifldReferenceNumber = -1; var ifldSamplingDate = -1; var ifldVesselType = -1; var ifldLandindSite = -1; var ifldEnumerator = -1; if (Aggregate) { ifldTargetArea = sf.EditAddField("TargetArea", FieldType.STRING_FIELD, 1, 100); ifldFishingGround = sf.EditAddField("FG", FieldType.STRING_FIELD, 1, 8); ifldSpeciesName = sf.EditAddField("Species", FieldType.STRING_FIELD, 1, 100); ifldCount = sf.EditAddField("n", FieldType.INTEGER_FIELD, 1, 4); } else { ifldReferenceNumber = sf.EditAddField("RefNo", FieldType.STRING_FIELD, 1, 20); ifldEnumerator = sf.EditAddField("Enumerator", FieldType.STRING_FIELD, 1, 30); ifldSpeciesName = sf.EditAddField("Species", FieldType.STRING_FIELD, 1, 100); ifldTargetArea = sf.EditAddField("TargetArea", FieldType.STRING_FIELD, 1, 100); ifldLandindSite = sf.EditAddField("LandingSite", FieldType.STRING_FIELD, 1, 50); ifldSamplingDate = sf.EditAddField("SamplingDate", FieldType.DATE_FIELD, 1, 1); ifldGearClass = sf.EditAddField("GearClass", FieldType.STRING_FIELD, 1, 25); ifldGearVariation = sf.EditAddField("GearVariation", FieldType.STRING_FIELD, 1, 35); ifldFishingGround = sf.EditAddField("FishingGround", FieldType.STRING_FIELD, 1, 8); ifldCatchWt = sf.EditAddField("CatchWeight", FieldType.DATE_FIELD, 2, 10); ifldVesselType = sf.EditAddField("Vessel", FieldType.STRING_FIELD, 1, 25); } using (OleDbConnection conn = new OleDbConnection(global.ConnectionString)) { conn.Open(); var adapter = new OleDbDataAdapter(sql, conn); DataTable dt = new DataTable(); adapter.Fill(dt); if (dt.Rows.Count > 0) { for (int n = 0; n < dt.Rows.Count; n++) { DataRow dr = dt.Rows[n]; var fg = dr["FishingGround"].ToString(); var zone = dr["UTMZone"].ToString(); fadUTMZone utmZone = FishingGrid.ZoneFromZoneName(zone); FishingGrid.UTMZone = utmZone; var latlong = FishingGrid.Grid25ToLatLong(fg, utmZone); var shp = new Shape(); if (shp.Create(ShpfileType.SHP_POINT) && shp.AddPoint(latlong.longitude, latlong.latitude) >= 0) { var iShp = sf.EditAddShape(shp); if (Aggregate) { if (sf.EditCellValue(ifldTargetArea, iShp, dr["AOIName"].ToString())) { sf.EditCellValue(ifldCount, iShp, (int)dr["n"]); sf.EditCellValue(ifldSpeciesName, iShp, ItemName); sf.EditCellValue(ifldFishingGround, iShp, fg); } } else { sf.EditCellValue(ifldSpeciesName, iShp, ItemName); sf.EditCellValue(ifldEnumerator, iShp, dr["EnumeratorName"].ToString()); sf.EditCellValue(ifldTargetArea, iShp, dr["AOIName"].ToString()); sf.EditCellValue(ifldFishingGround, iShp, fg); sf.EditCellValue(ifldGearClass, iShp, dr["GearClassName"].ToString()); sf.EditCellValue(ifldGearVariation, iShp, dr["Variation"].ToString()); sf.EditCellValue(ifldReferenceNumber, iShp, dr["RefNo"].ToString()); sf.EditCellValue(ifldSamplingDate, iShp, string.Format("{0:MMM-dd-yyyy}", (DateTime)dr["SamplingDate"])); sf.EditCellValue(ifldCatchWt, iShp, (double)dr["WtCatch"]); sf.EditCellValue(ifldVesselType, iShp, FishingVessel.VesselTypeFromVesselTypeNumber((int)dr["VesType"])); sf.EditCellValue(ifldLandindSite, iShp, dr["LSName"].ToString()); } } } } } sf.DefaultDrawingOptions.PointShape = tkPointShapeType.ptShapeCircle; ClassificationType classificationType = ClassificationType.None; if (Aggregate) { ShapefileLayerHelper.CategorizeNumericPointLayer(sf, ifldCount); sf.DefaultDrawingOptions.LineVisible = true; sf.DefaultDrawingOptions.LineColor = new Utils().ColorByName(tkMapColor.White); sf.CollisionMode = tkCollisionMode.AllowCollisions; classificationType = ClassificationType.JenksFisher; } else { sf.DefaultDrawingOptions.PointSize = 8; } var h = MapLayersHandler.AddLayer(sf, $"Species mapping: {ItemName} ({YearsToCSV()})", mappingMode: fad3MappingMode.occurenceMappingSpeciesAggregated); MapLayersHandler[h].ClassificationType = classificationType; MapControl.Redraw(); } } catch (Exception ex) { Logger.Log(ex.Message, "OcuurenceMapping", "SpeciesOccurence"); } return(true); }
public static Shapefile MapThisGear(string aoiGuid, string gearVarGuid, List <int> samplingYear, bool aggregate = false, bool notInclude1 = false, bool RemoveInland = false) { var query = ""; var dt = new DataTable(); var sf = new Shapefile(); using (var conection = new OleDbConnection(global.ConnectionString)) { try { conection.Open(); var years = ""; foreach (var item in samplingYear) { years += $"{item},"; } years = years.Trim(','); if (aggregate) { if (!notInclude1) { query = $@"SELECT tblSampling.FishingGround, Count(tblSampling.SamplingGUID) AS n FROM tblSampling GROUP BY tblSampling.AOI, tblSampling.GearVarGUID, Year([SamplingDate]), tblSampling.FishingGround HAVING tblSampling.AOI={{{aoiGuid}}} AND tblSampling.GearVarGUID= {{{gearVarGuid}}} AND Year([SamplingDate]) In ({years})"; } else { query = $@"SELECT tblSampling.FishingGround, Count(tblSampling.SamplingGUID) AS n FROM tblSampling GROUP BY tblSampling.FishingGround, tblSampling.AOI, tblSampling.GearVarGUID, Year([SamplingDate]) HAVING Count(tblSampling.SamplingGUID) > 1 AND tblSampling.AOI = {{{aoiGuid}}} AND tblSampling.GearVarGUID = {{{gearVarGuid}}} AND Year([SamplingDate]) In ({years})"; } } else { query = $@"SELECT tblGearClass.GearClassName, tblGearVariations.Variation, tblAOI.AOIName, tblSampling.RefNo, tblSampling.SamplingDate, tblSampling.SamplingTime, tblSampling.FishingGround, tblSampling.TimeSet, tblSampling.DateSet, tblSampling.TimeHauled, tblSampling.DateHauled, tblSampling.NoHauls, tblSampling.NoFishers, tblSampling.Engine, tblSampling.hp, tblSampling.WtCatch, tblSampling.WtSample, tblLandingSites.LSName, temp_VesselType.VesselType FROM tblGearClass INNER JOIN (tblGearVariations INNER JOIN (((tblAOI INNER JOIN tblLandingSites ON tblAOI.AOIGuid = tblLandingSites.AOIGuid) INNER JOIN tblSampling ON tblLandingSites.LSGUID = tblSampling.LSGUID) INNER JOIN temp_VesselType ON tblSampling.VesType = temp_VesselType.VesselTypeNo) ON tblGearVariations.GearVarGUID = tblSampling.GearVarGUID) ON tblGearClass.GearClass = tblGearVariations.GearClass WHERE tblSampling.AOI= {{{aoiGuid}}} AND tblSampling.GearVarGUID= {{{gearVarGuid}}} AND Year([SamplingDate]) In ({years})"; } var adapter = new OleDbDataAdapter(query, conection); adapter.Fill(dt); var fishingGround = ""; var iShp = 0; var pointAdded = false; var iFldFG = 0; var iFLdCount = 0; fadUTMZone utmZone = FishingGrid.UTMZone; if (sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT)) { sf.GeoProjection = global.MappingForm.GeoProjection; if (aggregate) { iFldFG = sf.EditAddField("fishingGround", FieldType.STRING_FIELD, 1, 9); iFLdCount = sf.EditAddField("n", FieldType.INTEGER_FIELD, 1, 1); } else { } for (int i = 0; i < dt.Rows.Count; i++) { DataRow dr = dt.Rows[i]; fishingGround = dr["FishingGround"].ToString(); var proceed = false; if (RemoveInland && !FishingGrid.MinorGridIsInland(fishingGround)) { proceed = true; } else if (!RemoveInland) { proceed = true; } if (proceed) { var shp = new Shape(); if (shp.Create(ShpfileType.SHP_POINT)) { if (sf.GeoProjection.IsGeographic) { var result = FishingGrid.Grid25ToLatLong(fishingGround, utmZone); pointAdded = shp.AddPoint(result.longitude, result.latitude) >= 0; } else { } if (pointAdded) { iShp = sf.EditAddShape(shp); if (iShp >= 0) { if (aggregate) { sf.EditCellValue(iFldFG, iShp, fishingGround); sf.EditCellValue(iFLdCount, iShp, (int)dr["n"]); } else { } } } } } } } } catch (Exception ex) { Logger.Log(ex.Message, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name); } } if (sf.NumShapes >= 0) { return(sf); } else { return(null); } }
private void OnbuttonGrid25_Click(object sender, EventArgs e) { bool gridNameAccepted = false; var msg = ""; bool proceed = true; switch (((Button)sender).Name) { case "buttonAdd": if (textBoxColumn.Text.Length > 0 && textBoxGridNo.Text.Length > 0 && textBoxRow.Text.Length > 0) { GridName = textBoxGridNo.Text + "-" + textBoxColumn.Text + textBoxRow.Text; //get lon,lat of grid25 point var pt = FishingGrid.Grid25ToLatLong(GridName, _parent_form.TargetArea.UTMZone); //cofirm if grid25 point is inside fishing ground extent of the target area if (IsInside(pt.longitude, pt.latitude)) { var subgridStyle = FishingGrid.SubGridStyle; //if (FishingGrid.SubGridStyle == fadSubgridSyle.SubgridStyleNone && lvGrids.Items.ContainsKey(GridName)) if (subgridStyle == fadSubgridStyle.SubgridStyleNone && lvGrids.Items.ContainsKey(GridName)) { msg = "Grid name already exists. Please use another"; proceed = false; } //else if (FishingGrid.SubGridStyle != fadSubgridSyle.SubgridStyleNone) else if (subgridStyle != fadSubgridStyle.SubgridStyleNone) { if (textBoxSubGrid.Text.Length > 0) { if (lvGrids.Items.ContainsKey($"{GridName}-{textBoxSubGrid.Text}")) { msg = "Grid name already exists. Please use another"; proceed = false; } } else { if (lvGrids.Items.ContainsKey(GridName)) { msg = "Grid name already exists. Please use another"; proceed = false; } } } if (proceed && FishingGrid.MinorGridIsInland(GridName)) { if (global.MapIsOpen) { global.MappingForm.MapFishingGround(GridName, FishingGrid.UTMZone, GridName, true); DialogResult dr = MessageBox.Show($"{GridName} is located inland\r\n\r\n" + "Accept this location?", "Verify fishing ground location", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dr == DialogResult.Yes) { ListViewItem lvi = new ListViewItem(); if (FishingGrid.SubGridStyle != fadSubgridStyle.SubgridStyleNone) { lvi = lvGrids.Items.Add($"{GridName}-{textBoxSubGrid.Text}", $"{GridName}-{textBoxSubGrid.Text}", null); } else { lvi = lvGrids.Items.Add(GridName, GridName, null); } gridNameAccepted = true; lvi.Tag = "new"; textBoxColumn.Text = ""; textBoxRow.Text = ""; textBoxGridNo.Text = ""; textBoxSubGrid.Text = ""; textBoxGridNo.Select(); } else { global.MappingForm.MapLayersHandler.RemoveLayer(GridName); } } else { msg = $"{GridName} is not accepted because it is located inland"; } } else if (proceed) { if (textBoxSubGrid.Text.Length > 0) { GridName += $"-{textBoxSubGrid.Text}"; } if (global.MapIsOpen) { global.MappingForm.MapFishingGround(GridName, FishingGrid.UTMZone, GridName); } if (_selectedItem != null) { lvGrids.Items[_selectedItem.Name].With(o => { o.Text = GridName; o.Name = GridName; _selectedItem = null; }); } else { ListViewItem lvi = new ListViewItem(); //if (FishingGrid.SubGridStyle == fadSubgridSyle.SubgridStyleNone) if (subgridStyle == fadSubgridStyle.SubgridStyleNone) { lvi = lvGrids.Items.Add(GridName, GridName, null); lvi.Tag = "new"; } else { if (textBoxSubGrid.Text.Length == 0) { lvi = lvGrids.Items.Add(GridName, GridName, null); } else { lvi = lvGrids.Items.Add($"{GridName}-{textBoxSubGrid.Text}", $"{GridName}-{textBoxSubGrid.Text}", null); } lvi.Tag = "new"; } } gridNameAccepted = true; textBoxColumn.Text = ""; textBoxRow.Text = ""; textBoxGridNo.Text = ""; textBoxSubGrid.Text = ""; textBoxGridNo.Select(); } } else { msg = "Fishing ground is outside extent"; } } else { msg = "Please fill up all fields"; } if (gridNameAccepted && textBoxSubGrid.Text.Length > 0) { SubGrid = int.Parse(textBoxSubGrid.Text); } break; case "buttonRemove": lvGrids.Items.Remove(_selectedItem); if (global.MapIsOpen) { global.MappingForm.MapLayersHandler.RemoveLayer(_selectedItem.Text); } _selectedItem = null; break; case "buttonRemoveAll": lvGrids.Items.Clear(); _selectedItem = null; break; } if (msg.Length > 0) { MessageBox.Show(msg, "Validation error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
/// <summary> /// Creates minor grid cells inside major grids intersected with land shapefiles /// </summary> private static void PopulateMinorGrid() { MinorGridsShapefile.EditClear(); FishingGrid.UTMZone = UTMZone; int ifldGridNo = Grid25Shapefile.FieldIndexByName["grid_no"]; var gridNumber = 0; //enumerate all intersected major grids for (int n = 0; n < _intersectedMajorGrids.Length; n++) { gridNumber = (int)Grid25Shapefile.CellValue[Grid25Shapefile.FieldIndexByName["grid_no"], _intersectedMajorGrids[n]]; //get the origin of the current major grid var origin = FishingGrid.MajorGridOrigin(gridNumber); //build a minor grid, a point at a time. Here we will be creating 5 points, one point for each corner of the grid. //The 5th point is needed to close the polygon. for (int row = 25; row > 0; row--) { for (int col = 0; col < 25; col++) { var shp = new Shape(); if (shp.Create(ShpfileType.SHP_POLYGON)) { for (int pt = 0; pt < 5; pt++) { switch (pt) { case 0: case 4: shp.AddPoint(origin.x + (col * 2000), origin.y + ((25 - row) * 2000)); break; case 1: shp.AddPoint(origin.x + (col * 2000) + 2000, origin.y + ((25 - row) * 2000)); break; case 2: shp.AddPoint(origin.x + (col * 2000) + 2000, origin.y + ((25 - row) * 2000) + 2000); break; case 3: shp.AddPoint(origin.x + (col * 2000), origin.y + ((25 - row) * 2000) + 2000); break; } } //add the new shape to the shapefile. iShp is the index of the newest added shape var iShp = MinorGridsShapefile.EditAddShape(shp); //a new shape will have an index (iShp) of zero or greater if (iShp >= 0) { //name the cell MinorGridsShapefile.EditCellValue(_iFldName, iShp, $"{gridNumber.ToString()}-{(char)('A' + col)}{row}"); //set the inland attribute to false MinorGridsShapefile.EditCellValue(_iFldInland, iShp, false); } } } } } //raise the event that minor grids were created if (StatusUpdate != null) { CreateInlandGridEventArgs e = new CreateInlandGridEventArgs(); e.Status = "Minor grids created"; e.GridCount = MinorGridsShapefile.NumShapes; StatusUpdate(e); } }
public bool MapSamplingFishingGround(string samplingGuid, fadUTMZone utmZone, string layerName) { var success = false; string refNo = ""; List <string> fg = new List <string>(); DataTable dt = new DataTable(); using (var conection = new OleDbConnection(global.ConnectionString)) { try { conection.Open(); var sql = $"Select RefNo from tblSampling WHERE SamplingGUID = {{{samplingGuid}}}"; var adapter = new OleDbDataAdapter(sql, conection); adapter.Fill(dt); DataRow dr = dt.Rows[0]; refNo = dr["RefNo"].ToString(); sql = $@"SELECT FishingGround FROM tblSampling WHERE SamplingGUID={{{samplingGuid}}} UNION ALL SELECT GridName from tblGrid WHERE SamplingGUID={{{samplingGuid}}}"; dt.Rows.Clear(); adapter = new OleDbDataAdapter(sql, conection); adapter.Fill(dt); for (int i = 0; i < dt.Rows.Count; i++) { dr = dt.Rows[i]; fg.Add(dr["FishingGround"].ToString()); } } catch (Exception ex) { Logger.Log(ex.Message, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name); } } if (fg.Count > 0) { var sf = new Shapefile(); if (sf.CreateNew("", ShpfileType.SHP_POINT)) { MapLayersHandler.RemoveLayer(layerName); sf.GeoProjection = _geoProjection; var ifldLabel = sf.EditAddField("Label", FieldType.STRING_FIELD, 1, 15); sf.FieldByName["Label"].Alias = "Fishing ground"; var ifldRefNo = sf.EditAddField("RefNo", FieldType.STRING_FIELD, 1, 20); sf.FieldByName["RefNo"].Alias = "Reference number"; foreach (var item in fg) { var shp = new Shape(); if (shp.Create(ShpfileType.SHP_POINT)) { var iShp = 0; var result = FishingGrid.Grid25ToLatLong(item, utmZone); iShp = shp.AddPoint(result.longitude, result.latitude); if (iShp >= 0 && sf.EditInsertShape(shp, 0)) { sf.EditCellValue(ifldLabel, iShp, item); sf.EditCellValue(ifldRefNo, iShp, refNo); sf.CollisionMode = tkCollisionMode.AllowCollisions; } } } sf.DefaultDrawingOptions.SetDefaultPointSymbol(tkDefaultPointSymbol.dpsCircle); sf.DefaultDrawingOptions.FillColor = new Utils().ColorByName(tkMapColor.Red); sf.DefaultDrawingOptions.PointSize = 7; sf.DefaultDrawingOptions.LineVisible = false; success = MapLayersHandler.AddLayer(sf, layerName, true, true) >= 0; if (MapControl == null) { MapControl = global.MappingForm.MapControl; } if (!MapControl.Extents.ToShape().Contains(sf.Extents.ToShape())) { Point pt = sf.Extents.ToShape().Center; Extents ext = MapControl.Extents; ext.MoveTo(pt.x, pt.y); MapControl.Extents = ext; } } } return(success); }