コード例 #1
0
ファイル: BasicClasses.cs プロジェクト: JokerDLord/GISbook
        //写文件函数主框架
        public static void WriteFile(GISLayer layer, string filename)
        {
            FileStream   fsr = new FileStream(filename, FileMode.Create); //根据文件名创建文件流
            BinaryWriter bw  = new BinaryWriter(fsr);

            WriteFileHeader(layer, bw);           //写入头文件
            GISTools.WriteString(layer.Name, bw); //写入图层名字
            WriteFields(layer.Fields, bw);        //写入字段
            WriteFeatures(layer, bw);
            bw.Close();
            fsr.Close();
        }
コード例 #2
0
ファイル: LayerDialog.cs プロジェクト: JokerDLord/GISbook
        private void Clicked(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem == null)
            {
                return;
            }
            GISLayer layer = Document.getLayer(listBox1.SelectedItem.ToString());

            layer.Selectable         = checkBox1.Checked;
            layer.Visible            = checkBox2.Checked;
            layer.DrawAttributeOrNot = checkBox3.Checked;
            layer.LabelIndex         = comboBox1.SelectedIndex;
        }
コード例 #3
0
ファイル: BasicClasses.cs プロジェクト: JokerDLord/GISbook
        static void WriteFileHeader(GISLayer layer, BinaryWriter bw)//bw是与文件相连的文件写入工具
        {
            MyFileHeader mfh = new MyFileHeader();

            mfh.MinX         = layer.Extent.getMinX();
            mfh.MinY         = layer.Extent.getMinY();
            mfh.MaxX         = layer.Extent.getMaxX();
            mfh.MaxY         = layer.Extent.getMaxY();
            mfh.FeatureCount = layer.FeatureCount();
            mfh.Shapetype    = (int)(layer.ShapeType);
            mfh.FieldCount   = layer.Fields.Count;
            bw.Write(GISTools.ToBytes(mfh));
        }
コード例 #4
0
        private void BtchangeEsymbol_Click(object sender, EventArgs e)
        {
            int        symbolsize  = Convert.ToInt32(tbsymbolsize.Text);
            int        cls         = Convert.ToInt32(tbclass.Text);
            Color      symbolcolor = btsymbolfillcolor.BackColor;
            List <int> sizes       = layer.getSymbolSize(cbattributeEsymbol.SelectedIndex, symbolsize, cls);

            //新建一个esymbollayer,在点密度中的点将以一个点图层的形式显示出来
            GISLayer esymbollayer = new GISLayer("Esymbol", SHAPETYPE.point, layer.Extent);

            esymbollayer.Selectable   = false;                    //设置为不可选择
            esymbollayer.ThematicType = THEMATICTYPE.EqualSymbol; //设置为等比变换型专题地图
            //为esymbollayer中每一个对象设置一个thematic
            for (int i = 0; i < layer.Features.Count; i++)
            {
                esymbollayer.Thematics.Add(i, new GISThematic(Color.Black, sizes[i], symbolcolor));
                Console.WriteLine(sizes[i]);
            }

            //创建symbols点对象,作为esymbollayer的features
            //默认将符号放于polygon的重心位置
            List <GISFeature> symbols = new List <GISFeature>();

            for (int i = 0; i < layer.Features.Count; i++)
            {
                GISPolygon polygon = (GISPolygon)layer.Features[i].spatialpart;
                GISVertex  vertex  = new GISVertex(polygon.centroid);
                symbols.Add(new GISFeature(new GISPoint(vertex), null));
            }

            esymbollayer.Features = symbols;

            //先移除之前已有的点密度图层
            for (int i = Document.layers.Count - 1; i > 0; i--)
            {
                if (Document.layers[i].Name == "Esymbol")
                {
                    Document.layers.RemoveAt(i);
                }
            }
            Document.layers.Add(esymbollayer);//将esymbollayer添加到document中 在更新地图绘制时会自动绘制layers里面的所有图层
            //更新地图绘制
            if (sender.Equals(previewes))
            {
                PreviewWindow.UpdateMap();
            }
            else if (sender.Equals(btchangeEsymbol))
            {
                Mapwindow.UpdateMap();
            }
        }
コード例 #5
0
ファイル: BasicClasses.cs プロジェクト: JokerDLord/GISbook
        public static GISLayer ReadShapefile(string shpfilename)
        {
            FileStream      fsr       = new FileStream(shpfilename, FileMode.Open); //打开shp文件
            BinaryReader    br        = new BinaryReader(fsr);                      //获取文件流后用二进制读取工具
            ShapefileHeader sfh       = ReadFileHeader(br);                         //调用之前的函数 获取头文件
            SHAPETYPE       ShapeType = (SHAPETYPE)Enum.Parse(                      //类型整数变对应的枚举值
                typeof(SHAPETYPE), sfh.ShapeType.ToString());
            GISExtent extent      = new GISExtent(sfh.Xmax, sfh.Xmin, sfh.Ymax, sfh.Ymin);
            string    dbffilename = shpfilename.Replace(".shp", ".dbf");                             //更改后缀
            DataTable table       = ReadDBF(dbffilename);
            GISLayer  layer       = new GISLayer(shpfilename, ShapeType, extent, ReadFields(table)); //gislayer的构造参数分别是名字 图层类型 范围 *GISField的泛型
            int       rowindex    = 0;                                                               //当前读取的记录位置

            while (br.PeekChar() != -1)
            {
                RecordHeader rh            = ReadRecordHeader(br);
                int          RecordLength  = FromBigToLittle(rh.RecordLength) * 2 - 4;
                byte[]       RecordContent = br.ReadBytes(RecordLength);//将记录内容读入字节数组

                if (ShapeType == SHAPETYPE.point)
                {
                    GISPoint   onepoint   = ReadPoint(RecordContent);
                    GISFeature onefeature = new GISFeature(onepoint, ReadAttribute(table, rowindex));
                    layer.AddFeature(onefeature);
                }
                if (ShapeType == SHAPETYPE.line)
                {
                    List <GISLine> lines = ReadLines(RecordContent);
                    for (int i = 0; i < lines.Count; i++)
                    {
                        GISFeature onefeature = new GISFeature(lines[i], ReadAttribute(table, rowindex));
                        layer.AddFeature(onefeature);
                    }
                }
                if (ShapeType == SHAPETYPE.polygon)
                {
                    List <GISPolygon> polygons = ReadPolygons(RecordContent);
                    for (int i = 0; i < polygons.Count; i++)
                    {
                        GISFeature onefeature = new GISFeature(polygons[i], ReadAttribute(table, rowindex));
                        layer.AddFeature(onefeature);
                    }
                }
                rowindex++;
            }

            br.Close();
            fsr.Close();   //归还文件权限于操作系统
            return(layer); //最后返回一个图层文件
        }
コード例 #6
0
ファイル: BasicClasses.cs プロジェクト: JokerDLord/GISbook
        public static GISLayer ReadFile(string filename)
        {
            FileStream      fsr       = new FileStream(filename, FileMode.Open);
            BinaryReader    br        = new BinaryReader(fsr);
            MyFileHeader    mfh       = (MyFileHeader)(GISTools.FromBytes(br, typeof(MyFileHeader)));       //读取文件头
            SHAPETYPE       ShapeType = (SHAPETYPE)Enum.Parse(typeof(SHAPETYPE), mfh.Shapetype.ToString()); //获取空间实体类型shapetype和
            GISExtent       Extent    = new GISExtent(mfh.MinX, mfh.MaxX, mfh.MinY, mfh.MaxY);              //地图范围extent
            string          layername = GISTools.ReadString(br);                                            //读取图层名
            List <GISField> Fields    = ReadFields(br, mfh.FieldCount);                                     //读取字段信息
            GISLayer        layer     = new GISLayer(layername, ShapeType, Extent, Fields);

            ReadFeatures(layer, br, mfh.FeatureCount);
            br.Close();
            fsr.Close();
            return(layer);
        }
コード例 #7
0
ファイル: LayerDialog.cs プロジェクト: JokerDLord/GISbook
        private void Clicked(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem == null)
            {
                return;
            }
            GISLayer layer = Document.getLayer(listBox1.SelectedItem.ToString());

            layer.Selectable         = checkBox1.Checked;
            layer.Visible            = checkBox2.Checked;
            layer.DrawAttributeOrNot = checkBox3.Checked;
            layer.LabelIndex         = comboBox1.SelectedIndex;

            layer.Thematic.InsideColor  = btfillcolor.BackColor;
            layer.Thematic.OutsideColor = btboundcolor.BackColor;
            layer.Thematic.Size         = ((tbdrawsize.Text == "") ? layer.Thematic.Size : Int32.Parse(tbdrawsize.Text));
        }
コード例 #8
0
        internal void OpenAdvancedThematic(GISDocument document, GISLayer layer)
        {
            AdvancedThematic ATWindow = null;

            //如果高级专题制图窗口没有初始化 则初始化
            if (ATWindow == null)
            {
                ATWindow = new AdvancedThematic(document, this, layer);
            }
            //如果高级专题制图被释放了 则初始化
            if (ATWindow.IsDisposed)
            {
                ATWindow = new AdvancedThematic(document, this, layer);
            }
            ATWindow.Show();
            ATWindow.BringToFront();
        }
コード例 #9
0
ファイル: LayerDialog.cs プロジェクト: JokerDLord/GISbook
        private void Btaddlayer_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "GIS File (*." + GISConst.SHPFILE + ",*." + GISConst.MYFILE + ")|*."
                                    + GISConst.SHPFILE + ";*." + GISConst.MYFILE;
            openFileDialog.RestoreDirectory = false;
            openFileDialog.FilterIndex      = 1;
            openFileDialog.Multiselect      = false;
            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            GISLayer layer = Document.Addlayer(openFileDialog.FileName);

            listBox1.Items.Insert(0, layer.Name);
            listBox1.SelectedIndex = 0;
        }
コード例 #10
0
        private void btchangedotdensity_Click(object sender, EventArgs e)
        {
            int   dotdensity = Convert.ToInt32(tbdotdensity.Text);
            int   dotsize    = Convert.ToInt32(tbdotsize.Text);
            Color dotcolor   = btdotfillcolor.BackColor;
            //获取归一化后的属性数据 作为每一个控件对象内点数量的权重
            List <int> normalizations = layer.getNormalized(cbattributedot.SelectedIndex, dotdensity);

            if (normalizations == null)
            {
                MessageBox.Show("基于该属性无法绘制点密度地图!!");
                return;
            }

            //新建一个dotlayer,在点密度中的点将以一个点图层的形式显示出来
            GISLayer dotlayer = new GISLayer("dotdensity", SHAPETYPE.point, layer.Extent);

            dotlayer.Selectable     = false;                   //设置为不可选择
            dotlayer.ThematicType   = THEMATICTYPE.DotDensity; //设置为点密度型专题地图
            dotlayer.defaultThmatic = new GISThematic(dotcolor, dotsize, dotcolor);
            List <GISFeature> dotpoints = GISTools.MakeRandomDensityDot(layer,
                                                                        cbattributedot.SelectedIndex, normalizations);

            dotlayer.Features = dotpoints;

            //先移除之前已有的点密度图层
            for (int i = Document.layers.Count - 1; i > 0; i--)
            {
                if (Document.layers[i].Name == "dotdensity")
                {
                    Document.layers.RemoveAt(i);
                }
            }
            Document.layers.Add(dotlayer);//将dotlayer添加到document中 在更新地图绘制时会自动绘制layers里面的所有图层
            //更新地图绘制
            if (sender.Equals(previewds))
            {
                PreviewWindow.UpdateMap();
            }
            else if (sender.Equals(btchangedotdensity))
            {
                Mapwindow.UpdateMap();
            }
        }
コード例 #11
0
        bool FromMapWindow = true;//记录选择数据集的来源
        public AttributeForm(GISLayer _layer, GISPanel mapwindow)
        {
            InitializeComponent();
            Layer     = _layer;
            MapWindow = mapwindow;
            //for (int i = 0; i < layer.Fields.Count; i++) //添加一系列的列
            //{
            //    dataGridView1.Columns.Add(layer.Fields[i].name, layer.Fields[i].name);
            //}
            //for (int i = 0; i < layer.FeatureCount(); i++)
            //{
            //    dataGridView1.Rows.Add();
            //    for (int j = 0; j < layer.Fields.Count; j++)
            //    {
            //        dataGridView1.Rows[i].Cells[j].Value = layer.GetFeature(i).getAttribute(j);
            //    }

            //}
        }
コード例 #12
0
ファイル: LayerDialog.cs プロジェクト: JokerDLord/GISbook
        private void Btexportlayer_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem == null)
            {
                return;
            }
            SaveFileDialog savefiledialog1 = new SaveFileDialog();

            savefiledialog1.Filter           = "GIS file (*." + GISConst.MYFILE + ")|*." + GISConst.MYFILE;
            savefiledialog1.FilterIndex      = 1;
            savefiledialog1.RestoreDirectory = false;

            if (savefiledialog1.ShowDialog() == DialogResult.OK)
            {
                GISLayer layer = Document.getLayer(listBox1.SelectedItem.ToString());
                GISMyFile.WriteFile(layer, savefiledialog1.FileName);
                MessageBox.Show("Done! " + savefiledialog1.FileName + " saved!");
            }
        }
コード例 #13
0
ファイル: LayerDialog.cs プロジェクト: JokerDLord/assignment
        private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //用以应对listbox选择改变的情况 更改相应的项
            if (listBox1.SelectedItem == null)
            {
                return;
            }
            GISLayer layer = Document.getLayer(listBox1.SelectedItem.ToString());//根据选中情况获取对应的layer

            checkBox1.Checked = layer.Selectable;
            checkBox2.Checked = layer.Visible;
            checkBox3.Checked = layer.DrawAttributeOrNot;
            comboBox1.Items.Clear();
            for (int i = 0; i < layer.Fields.Count; i++)
            {
                comboBox1.Items.Add(layer.Fields[i].name);
                comboBox3.Items.Add(layer.Fields[i].name);
            }
            comboBox1.SelectedIndex = (layer.Fields.Count > 0) ? layer.LabelIndex : -1;
            comboBox3.SelectedIndex = (layer.Fields.Count > 0) ? layer.ThematicFieldIndex : -1;
            fileaddr.Text           = layer.Path;
            textBox1.Text           = layer.Name;

            if (layer.ThematicType == THEMATICTYPE.UnifiedValue)
            {
                comboBox2.SelectedIndex = 0;
                GISThematic Thematic = layer.Thematics[layer.ThematicType];
                btfillcolor.BackColor  = Thematic.InsideColor;
                tbdrawsize.Text        = Thematic.Size.ToString();
                btboundcolor.BackColor = Thematic.OutsideColor;
            }
            else if (layer.ThematicType == THEMATICTYPE.UniqueValue)
            {
                comboBox2.SelectedIndex = 1;
            }
            else if (layer.ThematicType == THEMATICTYPE.GradualColor)
            {
                comboBox2.SelectedIndex = 2;
                tblevelnumber.Text      = layer.Thematics.Count.ToString();
            }
        }
コード例 #14
0
ファイル: BasicClasses.cs プロジェクト: JokerDLord/GISbook
 //读取所有的gisfeature的空间信息和属性值
 static void ReadFeatures(GISLayer layer, BinaryReader br, int FeatureCount)
 {
     for (int featureindex = 0; featureindex < FeatureCount; featureindex++)
     {
         GISFeature feature = new GISFeature(null, null);
         if (layer.ShapeType == SHAPETYPE.point)
         {
             feature.spatialpart = new GISPoint(new GISVertex(br));
         }
         else if (layer.ShapeType == SHAPETYPE.line)
         {
             feature.spatialpart = new GISLine(ReadMultipleVertexes(br));
         }
         else if (layer.ShapeType == SHAPETYPE.polygon)
         {
             feature.spatialpart = new GISPolygon(ReadMultipleVertexes(br));
         }
         feature.attributepart = ReadAttributes(layer.Fields, br);
         layer.AddFeature(feature);
     }
 }
コード例 #15
0
ファイル: LayerDialog.cs プロジェクト: JokerDLord/GISbook
        private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //用以应对listbox选择改变的情况 更改相应的项
            if (listBox1.SelectedItem == null)
            {
                return;
            }
            GISLayer layer = Document.getLayer(listBox1.SelectedItem.ToString());//根据选中情况获取对应的layer

            checkBox1.Checked = layer.Selectable;
            checkBox2.Checked = layer.Visible;
            checkBox3.Checked = layer.DrawAttributeOrNot;
            comboBox1.Items.Clear();
            for (int i = 0; i < layer.Fields.Count; i++)
            {
                comboBox1.Items.Add(layer.Fields[i].name);
            }
            comboBox1.SelectedIndex = layer.LabelIndex;
            fileaddr.Text           = layer.Path;
            textBox1.Text           = layer.Name;
        }
コード例 #16
0
ファイル: BasicClasses.cs プロジェクト: JokerDLord/GISbook
 //输出图层所有GISFeatrue
 static void WriteFeatures(GISLayer layer, BinaryWriter bw)
 {
     for (int featureindex = 0; featureindex < layer.FeatureCount(); featureindex++)
     {
         GISFeature feature = layer.GetFeature(featureindex);
         if (layer.ShapeType == SHAPETYPE.point)
         {
             ((GISPoint)feature.spatialpart).centroid.WriteVertex(bw);
         }
         else if (layer.ShapeType == SHAPETYPE.line)
         {
             GISLine line = (GISLine)(feature.spatialpart);
             WriteMultipleVertexes(line.Vertexes, bw);
         }
         else if (layer.ShapeType == SHAPETYPE.polygon)
         {
             GISPolygon polygon = (GISPolygon)(feature.spatialpart);
             WriteMultipleVertexes(polygon.Vertexes, bw);
         }
         WriteAttributes(feature.attributepart, bw);
     }
 }
コード例 #17
0
ファイル: LayerDialog.cs プロジェクト: JokerDLord/GISbook
        private void Bteditname_Click(object sender, EventArgs e)
        {
            //修改图层名
            if (listBox1.SelectedItem == null)
            {
                return;
            }
            //确保新输入的图层名不会与选中之外的其他图层名相同
            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                if (i != listBox1.SelectedIndex)
                {
                    if (listBox1.Items[i].ToString() == textBox1.Text)
                    {
                        MessageBox.Show("不能与已有图层名重复!!");
                        return;
                    }
                }
            }
            GISLayer layer = Document.getLayer(listBox1.SelectedItem.ToString());

            layer.Name            = textBox1.Text;
            listBox1.SelectedItem = textBox1.Text;
        }
コード例 #18
0
ファイル: LayerDialog.cs プロジェクト: JokerDLord/assignment
        private void Btchangethematic_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem == null)
            {
                return;
            }
            GISLayer layer = Document.getLayer(listBox1.SelectedItem.ToString());

            //唯一值地图
            if (comboBox2.SelectedIndex == 0)
            {
                layer.MakeUnifiedValueMap();
                GISThematic Thematic = layer.Thematics[layer.ThematicType];
                Thematic.InsideColor  = btfillcolor.BackColor;
                Thematic.OutsideColor = btboundcolor.BackColor;
                Thematic.Size         = (tbdrawsize.Text == "") ? Thematic.Size : Int32.Parse(tbdrawsize.Text);
            }
            //独立值地图
            else if (comboBox2.SelectedIndex == 1)
            {
                layer.MakeUniqueValueMap(comboBox3.SelectedIndex);
            }
            //分层设色地图
            else if (comboBox2.SelectedIndex == 2)
            {
                //此处对makegradualcolor的更改
                if (layer.MakeGradualColor(comboBox3.SelectedIndex, Int32.Parse(tblevelnumber.Text),
                                           Color.Black, Color.White, Color.Black) == false)
                {
                    MessageBox.Show("基于该属性无法绘制分层设色地图!!");
                    return;
                }
            }
            //更新地图绘制
            Mapwindow.UpdateMap();
        }