示例#1
0
 public void SetWgs84Projection(Wgs84Projection projection)
 {
     _epsgCode = (int)projection;
     _projection.SetWgs84Projection((tkWgs84Projection)projection);
 }
        /// <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);
        }
示例#3
0
 public void SetWgs84Projection(Wgs84Projection projection)
 {
     _projection.SetWgs84Projection((tkWgs84Projection)projection);
 }