Example #1
0
        private void confirmCategory()
        {
            string[] shp = new string[2];
            shp[0] = System.IO.Path.GetDirectoryName(shpPathText.Text);
            shp[1] = System.IO.Path.GetFileName(shpPathText.Text);

            if (shp[0] == null)
            {
                return;
            }
            IFeatureClass  pFC         = mg.openShapefile(shp[0], shp[1]);
            IFeatureCursor pFeatureCur = pFC.Search(null, false);
            IFeature       pFeature    = pFeatureCur.NextFeature();

            Hashtable i = mg.Index(pFC);

            readExcel t = new readExcel();

            t.OpenExcel(excelText.Text);
            List <TrashInfo> trashItems = t.readTrashTables();

            t.closeExcel();

            IQueryFilter tQueryFilter = new QueryFilterClass();

            tQueryFilter.WhereClause = "";
            tQueryFilter.AddField(pFC.OIDFieldName);
            //Invoke(new MethodInvoker(() =>
            //{
            //    proWork.Maximum = pFC.FeatureCount(tQueryFilter);
            //    proWork.Value = 0;
            //}));

            //int number = 1;
            while (pFeature != null)
            {
                ResultItem value = new ResultItem();
                value = mg.getFields(i, pFeature);

                #region 查找与excel中匹配的数据
                TrashInfo right = trashItems.Find(
                    delegate(TrashInfo T)
                {
                    return(T.Figure == value.Figure);
                });

                pFeature.set_Value((int)i["垃圾类别"], right.Category); //如果垃圾类别没设置,则取消注释
                pFeature.Store();
                #endregion
                //Invoke(new MethodInvoker(() =>
                //{
                //    proWork.Value = number++;
                //}));
                pFeature = pFeatureCur.NextFeature();
            }
        }
Example #2
0
        private void AddLocationFigure()
        {
            string[] shp = new string[2];
            shp[0] = System.IO.Path.GetDirectoryName(shpPathText.Text);
            shp[1] = System.IO.Path.GetFileName(shpPathText.Text);

            if (shp[0] == null)
            {
                return;
            }
            IFeatureClass  pFC         = openShapefile(shp[0], shp[1]);
            IFeatureCursor pFeatureCur = pFC.Search(null, false);
            IFeature       pFeature    = pFeatureCur.NextFeature();

            i = mg.Index(pFC);

            while (pFeature != null)
            {
                ResultItem value = new ResultItem();
                value = mg.getFields(i, pFeature);

                #region 添加位置
                if (value.Location.X == 0 || value.Location.Y == 0 || value.Project_XY.X == 0 || value.Project_XY.Y == 0 || value.District == " " || (int)i["区名"] == -1)
                {
                    MessageBox.Show(@"在shapefile文件中添加经纬度(Longitude\Latitude)、平面坐标(X\Y)、图号(图号)、垃圾类别(垃圾类别)、位置(位置)和区名(区名) 字段项!");
                    return;
                }
                string pAddress = LocationService.GetLocation(value.Location.Y, value.Location.X); //基于百度API,根据经纬度获取位置信息
                pFeature.set_Value((int)i["位置"], pAddress);
                pFeature.Store();
                #endregion

                #region 添加图号
                string content = null;
                content += Judge(value.District);
                int temp;
                if (!ht.ContainsKey(value.District))
                {
                    ht.Add(value.District, 1);
                }
                else
                {
                    temp  = (int)ht[value.District];
                    temp += 1;
                    ht[value.District] = temp;
                }
                content += ht[value.District].ToString().PadLeft(3, '0');
                pFeature.set_Value((int)i["图号"], content);
                pFeature.Store();
                #endregion

                pFeature = pFeatureCur.NextFeature();
            }
        }
Example #3
0
        private void ThreadTest()
        {
            string[] shp = new string[2];
            shp[0] = System.IO.Path.GetDirectoryName(shpPathText.Text);
            shp[1] = System.IO.Path.GetFileName(shpPathText.Text);

            if (shp[0] == null)
            {
                return;
            }
            IFeatureClass  pFC         = openShapefile(shp[0], shp[1]);
            IFeatureCursor pFeatureCur = pFC.Search(null, false);
            IFeature       pFeature    = pFeatureCur.NextFeature();

            i = mg.Index(pFC);

            ////计算要素总数
            IQueryFilter tQueryFilter = new QueryFilterClass();

            tQueryFilter.WhereClause = "";
            tQueryFilter.AddField(pFC.OIDFieldName);
            Invoke(new MethodInvoker(() =>
            {
                proWork.Maximum = pFC.FeatureCount(tQueryFilter);
                proWork.Value   = 0;
            }));
            int number = 1;

            while (pFeature != null)
            {
                ResultItem value = new ResultItem();
                value = mg.getFields(i, pFeature);

                if (value.Location.X == 0 || value.Location.Y == 0 || (int)i["位置"] == -1)
                {
                    MessageBox.Show("在shapefile文件中添加经纬度字段“Longitude”、“Latitude”和 “位置”字段!");
                    return;
                }
                string pAddress = LocationService.GetLocation(value.Location.Y, value.Location.X); //基于百度API,根据经纬度获取位置信息
                pFeature.set_Value((int)i["位置"], pAddress);
                pFeature.Store();
                Invoke(new MethodInvoker(() =>
                {
                    proWork.Value = number++;
                }));
                pFeature = pFeatureCur.NextFeature();
            }

            MessageBox.Show("添加完成!");
        }
Example #4
0
        private void ThreadTest()
        {
            if (!phase.Text.Contains("-"))
            {
                MessageBox.Show("期数格式不正确");
                return;
            }
            times = phase.Text.Substring(phase.Text.IndexOf("-") + 1);

            string[] shp = new string[2];
            shp[0] = System.IO.Path.GetDirectoryName(shpPathText.Text);
            shp[1] = System.IO.Path.GetFileName(shpPathText.Text);

            if (shp[0] == null)
            {
                return;
            }
            IFeatureClass  pFC         = openShapefile(shp[0], shp[1]);
            IFeatureCursor pFeatureCur = pFC.Search(null, false);
            IFeature       pFeature    = pFeatureCur.NextFeature();

            i = mg.Index(pFC);

            //计算要素总数
            IQueryFilter tQueryFilter = new QueryFilterClass();

            tQueryFilter.WhereClause = "";
            tQueryFilter.AddField(pFC.OIDFieldName);
            Invoke(new MethodInvoker(() =>
            {
                proWork.Maximum = pFC.FeatureCount(tQueryFilter);
                proWork.Value   = 0;
            }));

            int number = 1;

            while (pFeature != null)
            {
                ResultItem value = new ResultItem();
                value = mg.getFields(i, pFeature);

                #region 添加位置
                if (value.Location.X == 0 || value.Location.Y == 0 || value.Project_XY.X == 0 || value.Project_XY.Y == 0 || value.RegionID == " " || (int)i["镇名"] == -1)
                {
                    MessageBox.Show(@"在shapefile文件中添加经纬度(Longitude\Latitude)、平面坐标(X\Y)、图号(图号)、垃圾类别(垃圾类别)、位置(位置)和镇名(镇名) 字段项!");
                    return;
                }
                string pAddress = LocationService.GetLocation(value.Location.Y, value.Location.X); //基于百度API,根据经纬度获取位置信息
                pFeature.set_Value((int)i["位置"], pAddress);
                pFeature.Store();
                #endregion

                #region 添加图号
                if (value.Figure != " " || value.Figure != null)
                {
                    Invoke(new MethodInvoker(() =>
                    {
                        proWork.Value = number++;
                    }));
                    pFeature = pFeatureCur.NextFeature();
                    continue;
                }
                string content = null;
                content += Judge(value.RegionID);
                int temp;
                if (!ht.ContainsKey(value.RegionID))
                {
                    ht.Add(value.RegionID, 1);
                }
                else
                {
                    temp  = (int)ht[value.RegionID];
                    temp += 1;
                    ht[value.RegionID] = temp;
                }
                content += ht[value.RegionID].ToString().PadLeft(3, '0') + "-" + times;
                pFeature.set_Value((int)i["图号"], content);
                pFeature.Store();
                #endregion

                Invoke(new MethodInvoker(() =>
                {
                    proWork.Value = number++;
                }));
                pFeature = pFeatureCur.NextFeature();
            }
            if (!Directory.Exists(@"D:\青浦区垃圾巡查\" + phase.Text + "期"))
            {
                Directory.CreateDirectory(@"D:\青浦区垃圾巡查\" + phase.Text + "期");
            }
            MessageBox.Show("完成!");
        }