예제 #1
0
파일: Main.cs 프로젝트: orapow/yt
        void addLayer(Tn tn)
        {
            var    ext = tn.file.Substring(tn.file.LastIndexOf("."));
            object lay = null;

            if (ext == ".shp")
            {
                var shp = new Shapefile();
                shp.Open(tn.file);
                lay        = shp;
                tn.tp      = 3;
                tn.extents = shp.Extents;

                tn.Fields = new List <ShpLayer.Field>();
                for (var f = 0; f < shp.NumFields; f++)
                {
                    var fe = shp.Field[f];
                    tn.Fields.Add(new ShpLayer.Field()
                    {
                        Name = fe.Name, Length = fe.Width, Type = fe.Type.ToString("G")
                    });
                }

                tn.Shapges = new List <ShpLayer.Shape>();
                for (var i = 0; i < shp.NumShapes; i++)
                {
                    showtip("正在加载文件:" + tn.file + " " + i + "/" + shp.NumShapes);
                    var sp  = shp.Shape[i];
                    var spe = new ShpLayer.Shape();
                    spe.Tp     = (byte)sp.ShapeType;
                    spe.Extent = new Extend(sp.Extents.xMin, sp.Extents.yMin, sp.Extents.xMax, sp.Extents.yMax);
                    var data = new Dictionary <string, string>();
                    for (var f = 0; f < shp.NumFields; f++)
                    {
                        data.Add(shp.Field[f].Name, shp.Table.CellValue[f, i] + "");
                    }
                    spe.Data = data;
                    for (var j = 0; j < sp.NumParts; j++)
                    {
                        spe.Points.Add(j, getPoints(sp.PartAsShape[j]));
                    }
                    tn.Shapges.Add(spe);
                }
            }
            else
            {
                var img = new MapWinGIS.Image();
                img.Open(tn.file);
                var r = false;
                img.SetNoDataValue(0, ref r);
                lay        = img;
                tn.tp      = 2;
                tn.extents = img.Extents;
            }
            tn.inptr = map1.AddLayer(lay, true);
            showtip("文件:" + tn.file + " 加载完成");
        }