コード例 #1
0
ファイル: MapDraw.cs プロジェクト: FangWenjun/Monitor
        /// <summary>
        /// 在地图上添加图片
        /// </summary>
        /// <param name="data"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public int AddPicture(ClassPoint data, string path)
        {
            pointData    = new ClassPoint[1];
            PointData[0] = new ClassPoint();
            pointData[0] = data;

            Shape shp = new Shape();             //创建shp图层

            shp.Create(ShpfileType.SHP_POINT);
            var pnt = new Point();

            pnt.x = data.x;
            pnt.y = data.y;
            int index = 0;

            shp.InsertPoint(pnt, ref index);
            sf.EditInsertShape(shp, ref shapindex);

            ShapefileCategory ct = sf.Categories.Add("0");
            var utils            = new Utils();

            ct.DrawingOptions           = sf.DefaultDrawingOptions;
            ct.DrawingOptions.PointType = tkPointSymbolType.ptSymbolPicture;
            Image img = new Image();

            img.Open(path);
            ct.DrawingOptions.Picture       = img;
            ct.DrawingOptions.PointRotation = 45.0;
            sf.CollisionMode = tkCollisionMode.AllowCollisions;
            sf.set_ShapeCategory2(shapindex, "0");

            layerHandle = Map.AddLayer(sf, true);
            return(layerHandle);
        }
コード例 #2
0
ファイル: Grid25.cs プロジェクト: raffyMartinez/GPX-Manager
        private static void ConfigureGridAppearance()
        {
            MajorGrid.With(sf =>
            {
                //appearance for unselected grids
                sf.DefaultDrawingOptions.FillVisible = false;
                sf.DefaultDrawingOptions.LineWidth   = 2;
                sf.DefaultDrawingOptions.LineColor   = new Utils().ColorByName(tkMapColor.Red);
                var fldIndex = sf.FieldIndexByName["grid_no"];
                sf.GenerateLabels(fldIndex, tkLabelPositioning.lpCenter);
                sf.Labels.FontSize     = 12;
                sf.Labels.FontBold     = true;
                sf.Labels.FrameVisible = false;

                //create a category which will set the appearance of selected grids
                if (sf.StartEditingTable(null))
                {
                    var category = new ShapefileCategory
                    {
                        Name       = "Selected grid",
                        Expression = @"[toGrid] =""T"""
                    };
                    category.DrawingOptions.FillColor        = new Utils().ColorByName(tkMapColor.Red);
                    category.DrawingOptions.FillTransparency = 25;
                    category.DrawingOptions.LineWidth        = 2;
                    category.DrawingOptions.LineColor        = new Utils().ColorByName(tkMapColor.Red);
                    sf.Categories.Add2(category);
                }
            });
        }
コード例 #3
0
ファイル: FeatureCategory.cs プロジェクト: zylimit/MapWindow5
 internal FeatureCategory(ShapefileCategory category, int index)
 {
     if (category == null)
     {
         throw new NullReferenceException();
     }
     _category = category;
     _index    = index;
 }
コード例 #4
0
        public static void CreatePointShapefile(AxMap Map, List <GisPoint>[] ListData, int num)
        {
            var  sf     = new Shapefile();                                         //创建一个新的shp文件
            bool result = sf.CreateNewWithShapeID("", ShpfileType.SHP_MULTIPOINT); //初始化shp文件

            for (int j = 0; j < num - 1; j++)
            {
                Shape shp = new Shape(); //创建shp图层
                shp.Create(ShpfileType.SHP_MULTIPOINT);
                for (int i = 0; i < ListData[j].Count; i++)
                {
                    var pnt = new Point();
                    pnt.x   = ListData[j][i].X;
                    pnt.y   = ListData[j][i].Y;
                    pnt.Key = "fang";
                    int index = 0;
                    shp.InsertPoint(pnt, ref index);
                }
                sf.EditAddShape(shp);
                if (j == 0)
                {
                    var utils            = new Utils();
                    ShapefileCategory ct = sf.Categories.Add("0");
                    ct.DrawingOptions.FillType  = tkFillType.ftGradient;
                    ct.DrawingOptions.FillColor = utils.ColorByName(tkMapColor.Green);
                    sf.set_ShapeCategory(0, 0);
                }
                else if (j == 1)
                {
                    var utils            = new Utils();
                    ShapefileCategory ct = sf.Categories.Add("1");
                    ct.DrawingOptions.FillType  = tkFillType.ftStandard;
                    ct.DrawingOptions.FillColor = utils.ColorByName(tkMapColor.Blue);
                    sf.set_ShapeCategory(1, 1);
                }
                else if (j == 2)
                {
                    var utils            = new Utils();
                    ShapefileCategory ct = sf.Categories.Add("2");
                    ct.DrawingOptions.FillType  = tkFillType.ftStandard;
                    ct.DrawingOptions.FillColor = utils.ColorByName(tkMapColor.Yellow);
                    sf.set_ShapeCategory(2, 2);
                }
                else
                {
                    var utils            = new Utils();
                    ShapefileCategory ct = sf.Categories.Add("3");
                    ct.DrawingOptions.FillType  = tkFillType.ftStandard;
                    ct.DrawingOptions.FillColor = utils.ColorByName(tkMapColor.Red);
                    sf.set_ShapeCategory(3, 3);
                }
            }
            sf.DefaultDrawingOptions.SetDefaultPointSymbol(tkDefaultPointSymbol.dpsTriangleUp);
            Map.AddLayer(sf, true);
            Map.SendMouseMove = true;
        }
コード例 #5
0
        //Creates a shape file that contains all flights lat and long points and then generates a feald in the table that contains all flights images
        private void CreatePointShapefile()
        {
            axMap1.Projection   = tkMapProjection.PROJECTION_WGS84;
            axMap1.TileProvider = tkTileProvider.OpenStreetMap;
            var positions = pR.GetPositionsFromDB();
            var sfPoints  = new Shapefile();

            sfPoints.CreateNewWithShapeID("", ShpfileType.SHP_POINT);
            // creating points and inserting them in the shape
            foreach (Position position in positions)
            {
                int count = 0;
                var pnt   = new Point();
                pnt.x = Convert.ToDouble(position.longitude);
                pnt.y = Convert.ToDouble(position.latitude);
                Shape shp = new Shape();
                shp.Create(ShpfileType.SHP_POINT);
                int index = 0;
                shp.InsertPoint(pnt, ref index);
                sfPoints.EditInsertShape(shp, ref count);
                count++;
            }
            var _idShape = axMap1.AddLayer(sfPoints, true);
            int indexo   = sfPoints.Table.FieldIndexByName["MWShapeId"];
            var names    = new HashSet <string>();

            for (int i = 0; i < sfPoints.Table.NumRows; i++)
            {
                names.Add(sfPoints.Table.CellValue[indexo, i].ToString());
            }
            string[] files = Directory.GetFiles(@"D:\Faks\Druga godina\Treci Semestar\Programiranje_u_NET_okolini\Konstrukcijska_Vjezba\FlightTracker\FlightTracker\Resources\imagesOfPlanes");
            foreach (string file in files)
            {
                string name = Path.GetFileNameWithoutExtension(file);
                if (Path.GetExtension(file).ToLower() == ".png" && names.Contains(name))
                {
                    MapWinGIS.Image img = new MapWinGIS.Image();
                    if (img.Open(file, ImageType.USE_FILE_EXTENSION, true, null))
                    {
                        ShapefileCategory ct = new ShapefileCategory();
                        ct = sfPoints.Categories.Add(name);
                        ct.DrawingOptions.PointType     = tkPointSymbolType.ptSymbolPicture;
                        ct.DrawingOptions.PictureScaleX = 0.8;
                        ct.DrawingOptions.PictureScaleY = 0.8;
                        ct.DrawingOptions.DrawingMode   = tkVectorDrawingMode.vdmGDIPlus;
                        sfPoints.CollisionMode          = tkCollisionMode.AllowCollisions;
                        ct.Expression             = "[MWShapeId]=" + name;
                        ct.DrawingOptions.Picture = img;

                        sfPoints.DefaultDrawingOptions = ct.DrawingOptions;
                    }
                }
            }
            sfPoints.Categories.ApplyExpressions();
            axMap1.KnownExtents = tkKnownExtents.keCroatia;
        }
コード例 #6
0
 public void AddNullCategory()
 {
     _nullCategory      = new ShapefileCategory();
     _nullCategory.Name = "nullCategory";
     //_nullCategory.DrawingOptions.FillColor = new Utils().ColorByName(tkMapColor.White);
     _nullCategory.DrawingOptions.FillVisible = false;
     _nullCategory.DrawingOptions.LineVisible = false;
     _categories.Add2(_nullCategory);
     _nullCategoryIndex = _categories.Count - 1;
     _sheetMapSummary.Add("Null", 0);
 }
コード例 #7
0
        // <summary>
        // Split a shapefile into several ones according the values the specified attribute.
        // </summary>
        public void SplitByAttribute(AxMap axMap1, string dataPath)
        {
            axMap1.Projection             = tkMapProjection.PROJECTION_NONE;
            axMap1.GrabProjectionFromData = true;

            string filename = dataPath + "natural.shp";

            if (!File.Exists(filename))
            {
                MessageBox.Show("Couldn't file the file: " + filename);
            }
            else
            {
                Shapefile sf = new Shapefile();
                sf.Open(filename, null);

                int fieldIndex = sf.Table.FieldIndexByName["type"];
                sf.Categories.Generate(fieldIndex, tkClassificationType.ctUniqueValues, 0);
                sf.Categories.ApplyExpressions();

                ColorScheme scheme = new ColorScheme();
                scheme.SetColors2(tkMapColor.White, tkMapColor.Black);

                for (int i = 0; i < sf.Categories.Count; i++)
                {
                    Shapefile sfNew       = sf.Clone();
                    int       layerHandle = axMap1.AddLayer(sfNew, true);

                    for (int shapeIndex = 0; shapeIndex < sf.NumShapes; shapeIndex++)
                    {
                        if (sf.ShapeCategory[shapeIndex] == i)
                        {
                            Shape shape = sf.Shape[shapeIndex].Clone();
                            int   index = sfNew.NumShapes;
                            sfNew.EditInsertShape(shape, ref index);
                        }
                    }

                    ShapefileCategory category = sf.Categories.Item[i];
                    string            name     = category.Name.Substring(category.Name.IndexOf("=") + 1);

                    uint color = scheme.get_RandomColor((i + 1) / sf.Categories.Count);
                    sfNew.DefaultDrawingOptions.FillColor = color;

                    axMap1.set_LayerName(layerHandle, name);

                    //sfNew.SaveAs(path + name + ".shp", null);    // saves shapefile
                }
                ShowLegend();
                axMap1.ZoomToMaxExtents();
                axMap1.Redraw();
            }
        }
コード例 #8
0
        private void addExpression(Shapefile sf, string name, string expression, string rgb)
        {
            // rgb example: rgb(37, 49, 232)
            rgb = rgb.Replace("rgb(", "").Replace(" ", "").Replace(")", "");
            string[] rgbv = rgb.Split(',');


            ShapefileCategory ct = sf.Categories.Add(name);

            ct.Expression = expression;
            System.Drawing.Color co = Color.FromArgb(50, Int32.Parse(rgbv[0]), Int32.Parse(rgbv[1]), Int32.Parse(rgbv[2]));
            ct.DrawingOptions.FillColor = Convert.ToUInt32(ColorTranslator.ToOle(co));
            ct.DrawingOptions.LineColor = Convert.ToUInt32(ColorTranslator.ToOle(co));
        }
コード例 #9
0
        // <summary>
        // Creates and displayes custom line patterns
        // </summary>
        public void LinePattern(AxMap axMap1, string iconPath)
        {
            axMap1.Projection = tkMapProjection.PROJECTION_NONE;

            var sf = this.CreateLines();

            axMap1.AddLayer(sf, true);

            var utils = new Utils();

            // railroad pattern
            LinePattern pattern = new LinePattern();

            pattern.AddLine(utils.ColorByName(tkMapColor.Black), 6.0f, tkDashStyle.dsSolid);
            pattern.AddLine(utils.ColorByName(tkMapColor.White), 5.0f, tkDashStyle.dsDot);

            ShapefileCategory ct = sf.Categories.Add("Railroad");

            ct.DrawingOptions.LinePattern    = pattern;
            ct.DrawingOptions.UseLinePattern = true;
            sf.set_ShapeCategory(0, 0);

            // river pattern
            pattern = new LinePattern();
            pattern.AddLine(utils.ColorByName(tkMapColor.DarkBlue), 6.0f, tkDashStyle.dsSolid);
            pattern.AddLine(utils.ColorByName(tkMapColor.LightBlue), 4.0f, tkDashStyle.dsSolid);

            ct = sf.Categories.Add("River");
            ct.DrawingOptions.LinePattern    = pattern;
            ct.DrawingOptions.UseLinePattern = true;
            sf.set_ShapeCategory(1, 1);

            // road with direction
            pattern = new LinePattern();
            pattern.AddLine(utils.ColorByName(tkMapColor.Gray), 8.0f, tkDashStyle.dsSolid);
            pattern.AddLine(utils.ColorByName(tkMapColor.Yellow), 7.0f, tkDashStyle.dsSolid);
            LineSegment segm = pattern.AddMarker(tkDefaultPointSymbol.dpsArrowRight);

            segm.Color          = utils.ColorByName(tkMapColor.Orange);
            segm.MarkerSize     = 10;
            segm.MarkerInterval = 32;

            ct = sf.Categories.Add("Direction");
            ct.DrawingOptions.LinePattern    = pattern;
            ct.DrawingOptions.UseLinePattern = true;
            sf.set_ShapeCategory(2, 2);
        }
コード例 #10
0
        /// <summary>
        /// Generate label categories for the given set of shapefile categories
        /// </summary>
        /// <param name="mapWin">The reference to MapWindow</param>
        /// <param name="layerHandle">The handle of the layer</param>
        internal static void GenerateCategories(LegendControl.Legend legend, int layerHandle)
        {
            Layer     lyr = legend.GetLayer(layerHandle);
            Shapefile sf  = lyr.GetObject() as MapWinGIS.Shapefile;
            Labels    lb  = sf.Labels;

            sf.Labels.ClearCategories();
            for (int i = 0; i < sf.Categories.Count; i++)
            {
                ShapefileCategory cat      = sf.Categories.get_Item(i);
                LabelCategory     labelCat = lb.AddCategory(cat.Name);
                labelCat.Expression = cat.Expression;
            }

            SymbologySettings settings = Globals.get_LayerSettings(layerHandle);
            ColorBlend        blend    = (ColorBlend)settings.LabelsScheme;

            if (blend != null)
            {
                ColorScheme scheme = ColorSchemes.ColorBlend2ColorScheme(blend);
                if (settings.LabelsRandomColors)
                {
                    lb.ApplyColorScheme(tkColorSchemeType.ctSchemeRandom, scheme);
                }
                else
                {
                    lb.ApplyColorScheme(tkColorSchemeType.ctSchemeGraduated, scheme);
                }
            }

            if (settings.LabelsVariableSize)
            {
                for (int i = 0; i < lb.NumCategories; i++)
                {
                    lb.get_Category(i).FontSize = (int)((double)sf.Labels.FontSize +
                                                        (double)settings.LabelsSizeRange / ((double)lb.NumCategories - 1) * (double)i);
                }
            }

            // Expressions aren't supported by labels yet, therefore we need to copy indices from the symbology
            for (int i = 0; i < lb.Count; i++)
            {
                MapWinGIS.Label label = lb.get_Label(i, 0);
                label.Category = sf.get_ShapeCategory(i);
            }
        }
コード例 #11
0
        public System.Drawing.Color AddCategory(double min, double max)
        {
            var cat = new ShapefileCategory();

            cat.MinValue  = min;
            cat.MaxValue  = max;
            cat.Name      = _categories.Count.ToString();
            cat.ValueType = tkCategoryValue.cvRange;
            _categories.Add2(cat);

            cat.DrawingOptions.FillColor   = _scheme.get_GraduatedColor((double)(_categories.Count) / double.Parse(txtCategoryCount.Text));
            cat.DrawingOptions.LineColor   = cat.DrawingOptions.FillColor;
            cat.DrawingOptions.LineWidth   = 1.1F;
            cat.DrawingOptions.LineVisible = false;
            _sheetMapSummary.Add(cat.Name, 0);

            return(Colors.UintToColor(cat.DrawingOptions.FillColor));
        }
コード例 #12
0
        /// <summary>
        /// 绘制单元格
        /// </summary>
        private void dgvCategories_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.ColumnIndex != CMN_STYLE)
            {
                return;
            }
            if (e.RowIndex >= 0 && e.RowIndex < _shapefile.Categories.Count)
            {
                System.Drawing.Image img = e.Value as System.Drawing.Image;
                if (img == null)
                {
                    return;
                }

                ShapefileCategory cat = _shapefile.Categories.get_Item(e.RowIndex);
                if (cat == null)
                {
                    return;
                }
                ShapeDrawingOptions sdo = cat.DrawingOptions;

                Graphics g = Graphics.FromImage(img);
                g.Clear(Color.White);
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                g.SmoothingMode     = SmoothingMode.HighQuality;

                if (_shapefile.ShapefileType == ShpfileType.SHP_POLYGON)
                {
                    sdo.DrawRectangle(g.GetHdc(), 0, 0, img.Width - 1, img.Height - 1, true, img.Width, img.Height, Colors.ColorToUInteger(dgvCategories.BackgroundColor));
                }
                else if (_shapefile.ShapefileType == ShpfileType.SHP_POLYLINE)
                {
                    sdo.DrawLine(g.GetHdc(), 0, 0, img.Width - 1, img.Height - 1, true, img.Width, img.Height, Colors.ColorToUInteger(dgvCategories.BackgroundColor));
                }
                else if (_shapefile.ShapefileType == ShpfileType.SHP_POINT)
                {
                    sdo.DrawPoint(g.GetHdc(), 0.0f, 0.0f, img.Width, img.Height, Colors.ColorToUInteger(dgvCategories.BackgroundColor));
                }

                g.ReleaseHdc();
                g.Dispose();
            }
        }
コード例 #13
0
        private void ChangeCategoryStyle(int row)
        {
            ShapefileCategory cat = _shapefile.Categories.get_Item(row);

            if (cat == null)
            {
                return;
            }

            Form form = FormHelper.GetSymbologyForm(_legend, _layerHandle, _shapefile.ShapefileType, cat.DrawingOptions, true);

            form.Text = "Category drawing options";

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                dgvCategories.Invalidate();
                RedrawMap();
            }
            form.Dispose();
        }
コード例 #14
0
        public override void createStyle(Shapefile sf)
        {
            LinePattern pattern = new LinePattern();

            pattern.AddLine(utils.ColorByName(tkMapColor.Black), 6.0f, tkDashStyle.dsSolid);
            pattern.AddLine(utils.ColorByName(tkMapColor.White), 5.0f, tkDashStyle.dsDot);


            ShapeDrawingOptions options = sf.DefaultDrawingOptions;

            sf.Labels.Generate("[Index]", tkLabelPositioning.lpInteriorPoint, false);
            sf.Labels.FontOutlineColor   = utils.ColorByName(tkMapColor.Black);
            sf.Labels.FontOutlineVisible = true;
            sf.Labels.FontSize           = 12;
            sf.Labels.FontColor          = utils.ColorByName(tkMapColor.White);
            sf.Labels.FrameVisible       = false;
            // standard fill
            options.FillTransparency = 70;
            options.LineWidth        = 2;
            options.LineVisible      = true;
            options.LineColor        = utils.ColorByName(tkMapColor.Black);
            options.LineStipple      = tkDashStyle.dsSolid;


            ShapefileCategory ct = sf.Categories.Add("Danger");

            ct.Expression = "[Index] >= 7";
            ct.DrawingOptions.FillColor = utils.ColorByName(tkMapColor.Red);


            ct            = sf.Categories.Add("Medium");
            ct.Expression = "[Index] < 7";
            ct.DrawingOptions.FillColor = utils.ColorByName(tkMapColor.Yellow);


            ct            = sf.Categories.Add("Low");
            ct.Expression = "[Index] < 3";
            ct.DrawingOptions.FillColor = utils.ColorByName(tkMapColor.Green);

            sf.Categories.ApplyExpressions();
        }
コード例 #15
0
ファイル: MenuForm.cs プロジェクト: phantom1999/busbaf
        private void PointIco(string icopath)
        {
            int index = _shape.Table.FieldIndexByName["cat"];
            var names = new HashSet <string>();

            for (int i = 0; i < _shape.Table.NumRows; i++)
            {
                names.Add(_shape.Table.CellValue[index, i].ToString());
            }

            string[] files = Directory.GetFiles(icopath);
            foreach (string file in files)
            {
                string name = Path.GetFileNameWithoutExtension(file);
                if (Path.GetExtension(file).ToLower() == ".png" && names.Contains(name))
                {
                    MapWinGIS.Image img = new MapWinGIS.Image();
                    if (img.Open(file, ImageType.USE_FILE_EXTENSION, true, null))
                    {
                        ShapefileCategory ct = new ShapefileCategory();
                        ct = _shape.Categories.Add(name);

                        ct.DrawingOptions.PointType = tkPointSymbolType.ptSymbolPicture;

                        ct.DrawingOptions.PictureScaleX = 0.8;
                        ct.DrawingOptions.PictureScaleY = 0.8;

                        ct.DrawingOptions.DrawingMode = tkVectorDrawingMode.vdmGDIPlus;

                        _shape.CollisionMode      = tkCollisionMode.AllowCollisions;
                        ct.Expression             = " [cat]=" + name;
                        ct.DrawingOptions.Picture = img;

                        _shape.DefaultDrawingOptions = ct.DrawingOptions;
                    }
                }

                _shape.Categories.ApplyExpressions();
            }
        }
コード例 #16
0
        // <summary>
        // Calculates a minimal distance from each building to the river.
        // </summary>
        public void MinimalDistance(AxMap axMap1, string dataPath, ToolStripStatusLabel label)
        {
            axMap1.Projection             = tkMapProjection.PROJECTION_NONE;
            axMap1.GrabProjectionFromData = true;

            string filename1 = dataPath + "waterways.shp";
            string filename2 = dataPath + "buildings.shp";

            if (!File.Exists(filename1) || !File.Exists(filename2))
            {
                MessageBox.Show("The necessary files (waterways.shp, building.shp) are missing: " + dataPath);
            }
            else
            {
                Shapefile sfRivers = new Shapefile();
                sfRivers.Open(filename1, null);

                Utils utils = new Utils();
                sfRivers.DefaultDrawingOptions.LineColor = utils.ColorByName(tkMapColor.Blue);
                sfRivers.DefaultDrawingOptions.LineWidth = 5.0f;

                Shapefile sfBuildings = new Shapefile();
                sfBuildings.Open(filename2, null);

                // adds a field in the table
                Field field = new Field();
                field.Name      = "RiverDist";
                field.Type      = FieldType.DOUBLE_FIELD;
                field.Precision = 10;

                int fieldIndex = sfBuildings.NumFields;
                sfBuildings.StartEditingShapes(true, null);
                sfBuildings.EditInsertField(field, ref fieldIndex, null);

                ShapefileCategory ct = sfBuildings.Categories.Add("Named buildings");
                ct.Expression = "[Name] <> \"\"";
                sfBuildings.Categories.ApplyExpressions();

                sfRivers.StartEditingShapes(false, null);
                for (int i = 0; i < sfBuildings.NumShapes; i++)
                {
                    if (sfBuildings.ShapeCategory[i] == 0)
                    {
                        label.Text = "Processing building: " + (i + 1) + " / " + sfBuildings.NumShapes;
                        Application.DoEvents();

                        Shape  shp     = sfBuildings.Shape[i];
                        double minDist = Double.MaxValue;

                        for (int j = 0; j < sfRivers.NumShapes; j++)
                        {
                            Shape  shp2     = sfRivers.Shape[j];
                            double distance = shp.Distance(shp2);
                            if (distance < minDist)
                            {
                                minDist = distance;
                            }
                        }

                        if (minDist != Double.MaxValue)
                        {
                            sfBuildings.EditCellValue(fieldIndex, i, minDist);
                        }
                    }
                    else
                    {
                        sfBuildings.EditCellValue(fieldIndex, i, 0.0);
                    }
                }
                sfRivers.StopEditingShapes(false, true, null);

                sfBuildings.Categories.Generate(fieldIndex, tkClassificationType.ctNaturalBreaks, 8);
                ColorScheme scheme = new ColorScheme();
                scheme.SetColors2(tkMapColor.Blue, tkMapColor.Yellow);
                sfBuildings.Categories.ApplyColorScheme(tkColorSchemeType.ctSchemeGraduated, scheme);

                sfBuildings.Labels.Generate("[Name] + \"\n\" + [RiverDist] + \" m\"", tkLabelPositioning.lpCentroid, true);
                sfBuildings.Labels.TextRenderingHint = tkTextRenderingHint.SystemDefault;

                sfBuildings.VisibilityExpression = "[Name] <> \"\"";

                axMap1.AddLayer(sfRivers, true);
                axMap1.AddLayer(sfBuildings, true);

                label.Text = "";
            }
        }
コード例 #17
0
 /// <summary>
 /// Adds the category to the collection.
 /// </summary>
 /// <param name="Category">The category.</param>
 /// \new494 Added in version 4.9.4
 public void Add2(ShapefileCategory Category)
 {
     throw new NotImplementedException();
 }
コード例 #18
0
 /// <summary>
 /// Gets index of the specified category within a collection.
 /// </summary>
 /// <param name="Category">Category to find index for.</param>
 /// <returns>Index of category.</returns>
 /// \new491 Added in version 4.9.1
 public int get_CategoryIndex(ShapefileCategory Category)
 {
     throw new NotImplementedException();
 }
コード例 #19
0
 /// <summary>
 /// Replaces the category with the specified index with the new one.
 /// </summary>
 /// <param name="Index">The index of the category to replace.</param>
 /// <param name="pVal">The new category.</param>
 public void set_Item(int Index, ShapefileCategory pVal)
 {
     throw new NotImplementedException();
 }
コード例 #20
0
 /// <summary>
 /// Inserts a category at the specified index in the collection.
 /// </summary>
 /// <param name="Index">The index.</param>
 /// <param name="Category">The category to be inserted.</param>
 /// <returns>True on success.</returns>
 /// \new494 Added in version 4.9.4
 public bool Insert2(int Index, ShapefileCategory Category)
 {
     throw new NotImplementedException();
 }
コード例 #21
0
        // <summary>
        // Selects buildings which lie within specified distance from the parks.
        // </summary>
        public void SelectByDistance(AxMap axMap1, string dataPath)
        {
            axMap1.Projection             = tkMapProjection.PROJECTION_NONE;
            axMap1.GrabProjectionFromData = true;

            string filename1 = dataPath + "buildings.shp";
            string filename2 = dataPath + "natural.shp";

            if (!File.Exists(filename1) || !File.Exists(filename2))
            {
                MessageBox.Show("Failed to open shapefile (natural.shp, buildings.shp): " + dataPath);
                return;
            }

            var sfBuildings = new Shapefile();

            sfBuildings.Open(filename1, null);

            var sfParks = new Shapefile();

            sfParks.Open(filename2, null);
            ShapefileCategory ct = sfParks.Categories.Add("Parks");

            // choose parks and make them green
            ct.Expression = "[Type] = \"Park\"";
            var utils = new Utils();

            ct.DrawingOptions.FillColor = utils.ColorByName(tkMapColor.Green);
            sfParks.Categories.ApplyExpression(0);

            // hide the rest types of objects on the layer
            sfParks.DefaultDrawingOptions.Visible = false;

            double maxDistance = 150.0;        // in meters

            bool editing = sfBuildings.StartEditingShapes(true, null);

            sfBuildings.UseQTree = true;   // this will build a spatial index to speed up selection

            for (int i = 0; i < sfParks.NumShapes; i++)
            {
                int index = sfParks.ShapeCategory[i];
                if (index == 0)
                {
                    object result = null;
                    Shape  shp    = sfParks.Shape[i];
                    if (sfBuildings.SelectShapes(shp.Extents, maxDistance, SelectMode.INTERSECTION, ref result))
                    {
                        int[] shapes = result as int[];
                        if (shapes == null)
                        {
                            return;
                        }
                        for (int j = 0; j < shapes.Length; j++)
                        {
                            if (!sfBuildings.ShapeSelected[shapes[j]])
                            {
                                Shape  shp2 = sfBuildings.Shape[shapes[j]];
                                double dist = shp.Distance(shp2);
                                if (dist < maxDistance)
                                {
                                    sfBuildings.set_ShapeSelected(shapes[j], true);
                                }
                            }
                        }
                    }
                }
            }

            axMap1.AddLayer(sfParks, true);
            axMap1.AddLayer(sfBuildings, true);
            axMap1.ZoomToMaxExtents();
        }
コード例 #22
0
ファイル: FeatureCategory.cs プロジェクト: zylimit/MapWindow5
 public FeatureCategory(string name)
 {
     _category = new ShapefileCategory {
         Name = name
     };
 }
コード例 #23
0
        // <summary>
        // Assigns markers for points
        // </summary>
        public void PointIcons(AxMap axMap1, string dataPath, string iconPath)
        {
            axMap1.Projection = tkMapProjection.PROJECTION_GOOGLE_MERCATOR;

            if (!Directory.Exists(iconPath))
            {
                MessageBox.Show("Icons folder wasn't found: " + iconPath);
                return;
            }

            string roads     = dataPath + "roads.shp";
            string buildings = dataPath + "buildings.shp";

            if (File.Exists(roads))
            {
                Shapefile sfRoads = new Shapefile();
                sfRoads.Open(roads, null);
                sfRoads.DefaultDrawingOptions.LineWidth = 5;
                //axMap1.AddLayer(sfRoads, true);

                Shapefile sfBuildings = new Shapefile();
                sfBuildings.Open(buildings, null);
                axMap1.AddLayer(sfBuildings, true);
            }

            Shapefile sf       = new Shapefile();
            string    filename = dataPath + "points.shp";

            if (!sf.Open(filename, null))
            {
                MessageBox.Show("Failed to open shapefile: " + sf.ErrorMsg[sf.LastErrorCode]);
            }
            else
            {
                int layerHandle = axMap1.AddLayer(sf, true);
                sf = axMap1.get_Shapefile(layerHandle);     // in case a copy of shapefile was created by GlobalSettings.ReprojectLayersOnAdding

                int index = sf.Table.FieldIndexByName["Type"];
                var names = new HashSet <string>();

                for (int i = 0; i < sf.Table.NumRows; i++)
                {
                    names.Add((string)sf.Table.CellValue[index, i]);
                }

                string[] files = Directory.GetFiles(iconPath);
                foreach (string file in files)
                {
                    string name = Path.GetFileNameWithoutExtension(file);
                    if (Path.GetExtension(file).ToLower() == ".png" && names.Contains(name))
                    {
                        Image img = new Image();
                        if (img.Open(file, ImageType.USE_FILE_EXTENSION, true, null))
                        {
                            ShapefileCategory ct = sf.Categories.Add(name);
                            ct.Expression = "[Type] = \"" + name + "\"";
                            ct.DrawingOptions.PointType = tkPointSymbolType.ptSymbolPicture;
                            ct.DrawingOptions.Picture   = img;
                        }
                    }
                }

                sf.DefaultDrawingOptions.Visible = false;   // hide all the unclassified points
                sf.Categories.ApplyExpressions();
                axMap1.Redraw();
            }
        }