/// <summary> /// Intersect minor grids with the currently selected land shapefile. Returns true if current land shape contains minor grid /// </summary> private static bool GetMinorGridsWithinLand() { var objSelected = new object(); var ifldInland = MinorGridsShapefile.FieldIndexByName["inland"]; //this operation selects those minor grids within the selected land shape. MinorGridsShapefile.SelectByShapefile(LandShapefile, tkSpatialRelation.srWithin, true, ref objSelected); try { _withinMinorGrids = (int[])objSelected; for (int n = 0; n < _withinMinorGrids.Length; n++) { MinorGridsShapefile.EditCellValue(ifldInland, _withinMinorGrids[n], true); MinorGridsShapefile.ShapeSelected[_withinMinorGrids[n]] = true; } if (StatusUpdate != null) { CreateInlandGridEventArgs e = new CreateInlandGridEventArgs(); e.Status = "Inland grids created"; e.GridCount = _withinMinorGrids.Length; StatusUpdate(e); } return(true); } catch (Exception ex) { Logger.Log(ex.Message, "CreateInlandPointDatabase.cs", "GetMinorGridsWithinLand"); return(false); } }
/// <summary> ///Minor grids that are inside land will be copied to another shapefile of inland minor grids /// </summary> private static void ProcessInlandGrids() { bool proceed = true; if (_inlandMinorGrids.NumShapes == 0) { try { _inlandMinorGrids = MinorGridsShapefile.ExportSelection(); } catch { proceed = false; } } else { _inlandMinorGrids = _inlandMinorGrids.Merge(false, MinorGridsShapefile, true); } if (proceed) { _inlandMinorGrids.DefaultDrawingOptions.FillVisible = false; _inlandMinorGrids.DefaultDrawingOptions.LineWidth = 1.1f; _inlandMinorGrids.DefaultDrawingOptions.LineColor = new Utils().ColorByName(tkMapColor.Red); } }
/// <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); } }