private bool AddSelectedLayoutGrid(string layoutCellName) { _grid25Layers.Clear(); _grid25Layers.Add("Minor grid", $"{layoutCellName}_gridlines.shp"); _grid25Layers.Add("Major grid", $"{layoutCellName}_majorgrid.shp"); _grid25Layers.Add("Labels", $"{layoutCellName}_gridlabels.shp"); _grid25Layers.Add("MBR", $"{layoutCellName}_gridboundary.shp"); string gridStateFile = $@"{SourceFolder}\{layoutCellName}_gridstate.xml"; if (File.Exists(gridStateFile) && !_gridStateFinishedReading) { XmlTextReader xmlReader = new XmlTextReader(gridStateFile); while (xmlReader.Read()) { if (xmlReader.NodeType == XmlNodeType.Element) { switch (xmlReader.Name) { case "FishingGroundGridMap": _minorGridLabelDistance = float.Parse(xmlReader.GetAttribute("minorGridLabelDistance")) / (60 * 1852); _minorGridLabelFontBold = xmlReader.GetAttribute("minorGridLabelFontBold") != "0"; _minorGridThickness = float.Parse(xmlReader.GetAttribute("minorGridThickness")) / 100; _majorGridThickness = float.Parse(xmlReader.GetAttribute("majorGridThickness")) / 100; _majorGridLineColor = uint.Parse(xmlReader.GetAttribute("majorGridLineColor")); _minorGridLineColor = uint.Parse(xmlReader.GetAttribute("minorGridLineColor")); _minorGridLabelColor = uint.Parse(xmlReader.GetAttribute("minorGridLabelColor")); _borderColor = uint.Parse(xmlReader.GetAttribute("borderColor")); _borderThickness = float.Parse(xmlReader.GetAttribute("borderThickness")) / 100; _majorGridLabelSize = int.Parse(xmlReader.GetAttribute("majorGridLabelSize")); _majorGridLabelColor = uint.Parse(xmlReader.GetAttribute("majorGridLabelColor")); _minorGridLabelSize = int.Parse(xmlReader.GetAttribute("minorGridLabelSize")); _majorGridLabelFontBold = false; _subGridLineColor = uint.Parse(xmlReader.GetAttribute("subGridLineColor")); _subGridLineThickness = float.Parse(xmlReader.GetAttribute("subGridLineThickness")) / 100; break; } } } _gridStateFinishedReading = true; } var sf = new Shapefile(); string file = $@"{SourceFolder}\{_grid25Layers["Minor grid"]}"; if (File.Exists(file) && sf.Open(file)) { _hMinorGrid = MapLayersHandler.AddLayer(sf, "Minor grid", true, true); MapLayersHandler[_hMinorGrid].IsGrid25Layer = true; SetupShapefileLayerForPrinting(MapLayersHandler[_hMinorGrid]); sf = new Shapefile(); file = $@"{SourceFolder}\{_grid25Layers["Major grid"]}"; if (File.Exists(file) && sf.Open(file)) { _hMajorGrid = MapLayersHandler.AddLayer(sf, "Major grid", true, true); MapLayersHandler[_hMajorGrid].IsGrid25Layer = true; SetupShapefileLayerForPrinting(MapLayersHandler[_hMajorGrid]); } sf = new Shapefile(); file = $@"{SourceFolder}\{_grid25Layers["Labels"]}"; if (File.Exists(file) && sf.Open(file)) { _hGridLabels = MapLayersHandler.AddLayer(sf, "Labels", true, true); MapLayersHandler[_hGridLabels].IsGrid25Layer = true; SetupShapefileLayerForPrinting(MapLayersHandler[_hGridLabels]); int reprojectedCount = 0; MBR = sf.Reproject(_mapcontrol.GeoProjection, ref reprojectedCount); } sf = new Shapefile(); file = $@"{SourceFolder}\{_grid25Layers["MBR"]}"; if (File.Exists(file) && sf.Open(file)) { _hMBR = MapLayersHandler.AddLayer(sf, "MBR", true, true); MapLayersHandler[_hMBR].IsGrid25Layer = true; SetupShapefileLayerForPrinting(MapLayersHandler[_hMBR]); } SymbolizeGrid(); return(true); } else { return(false); } }
public bool MapFisherBoatDistribution(List <FisherVesselInventoryItem> distributionList, string itemToMap) { Shapefile sf = new Shapefile(); if (sf.CreateNew("", ShpfileType.SHP_POINT)) { sf.GeoProjection = _mapControl.GeoProjection; int ifldProjectName = sf.EditAddField("Inventory project", FieldType.STRING_FIELD, 1, 50); int ifldProvince = sf.EditAddField("Province", FieldType.STRING_FIELD, 1, 30); int ifldMunicipalityName = sf.EditAddField("Municipality", FieldType.STRING_FIELD, 1, 30); int ifldMuni = sf.EditAddField("Muni", FieldType.STRING_FIELD, 1, 4); int ifldX = sf.EditAddField("x", FieldType.DOUBLE_FIELD, 9, 12); int ifldY = sf.EditAddField("y", FieldType.DOUBLE_FIELD, 9, 12); int ifldFishers = sf.EditAddField("Fishers", FieldType.INTEGER_FIELD, 1, 7); int ifldCommercial = sf.EditAddField("Commercial", FieldType.INTEGER_FIELD, 1, 7); int ifldMunicipalMot = sf.EditAddField("Municipal Motorized", FieldType.INTEGER_FIELD, 1, 7); int ifldMunicipalNonMot = sf.EditAddField("Municipal Non-motorized", FieldType.INTEGER_FIELD, 1, 7); foreach (var item in distributionList) { Shape sh = new Shape(); if (sh.Create(ShpfileType.SHP_POINT) && sh.AddPoint(item.X, item.Y) >= 0) { var iShp = sf.EditAddShape(sh); if (iShp >= 0) { sf.EditCellValue(ifldProjectName, iShp, item.InventoryProjectName); sf.EditCellValue(ifldProvince, iShp, item.ProvinceName); sf.EditCellValue(ifldMunicipalityName, iShp, item.Municipality); sf.EditCellValue(ifldMuni, iShp, Database.Classes.LGUs.ShortenPlaceName(item.Municipality)); sf.EditCellValue(ifldX, iShp, item.X); sf.EditCellValue(ifldY, iShp, item.Y); sf.EditCellValue(ifldFishers, iShp, item.CountFisher); sf.EditCellValue(ifldCommercial, iShp, item.CountCommercial); sf.EditCellValue(ifldMunicipalMot, iShp, item.CountMunicipalMotorized); sf.EditCellValue(ifldMunicipalNonMot, iShp, item.CountMunicipalNonMotorized); } } } sf.DefaultDrawingOptions.PointShape = tkPointShapeType.ptShapeCircle; sf.DefaultDrawingOptions.FillColor = new Utils().ColorByName(tkMapColor.Blue); sf.DefaultDrawingOptions.LineColor = new Utils().ColorByName(tkMapColor.White); sf.DefaultDrawingOptions.LineVisible = true; sf.CollisionMode = tkCollisionMode.AllowCollisions; int fld = 0; string itemName = ""; switch (itemToMap) { case "fishers": itemName = "Total number of fishers"; fld = ifldFishers; break; case "commercial": fld = ifldCommercial; itemName = "Total number of commercial fishing vessels"; break; case "municipalMotorized": fld = ifldMunicipalMot; itemName = "Total number of municipal motorized vessels"; break; case "municipalNonMotorized": fld = ifldMunicipalNonMot; itemName = "Total number of municipal non-motorized vessels"; break; } Database.Classes.ClassificationType classificationType = Database.Classes.ClassificationType.NaturalBreaks; if (itemToMap == "fishers" || ComparisonAmongLGUs) { ShapefileLayerHelper.CategorizeNumericPointLayer(sf, fld); } else { ShapefileLayerHelper.CategorizeNumericPointLayer(sf, FisherVesselDataFisherJenksBreaks, fld, BreakSourceMaximum); classificationType = Database.Classes.ClassificationType.JenksFisher; } InventoryLayerHandle = _layersHandler.AddLayer(sf, itemName); _layersHandler[InventoryLayerHandle].IgnoreZeroWhenClassifying = true; _layersHandler[InventoryLayerHandle].ClassificationType = classificationType; if (Labels != null) { sf.Labels.Clear(); _layersHandler.ShapeFileLableHandler.LabelShapefile(_labelXML); } _layersHandler.SetAsPointLayerFromDatabase(_layersHandler[InventoryLayerHandle]); } return(sf.NumShapes > 0); }
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); }