Exemplo n.º 1
0
        private void buttonX_ok_Click(object sender, EventArgs e)
        {
            CGmpPoint xml    = new CGmpPoint();
            bool      result = xml.ReadGmpXML(XMLPath);
            Regex     regNum = new Regex("^[0-9]");

            if (regNum.IsMatch(textBoxX3.Text) == true)
            {
                MessageBox.Show("数据集名称不能以数字开头命名", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (result == true)
            {
                try
                {
                    IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
                    gdbPath = textBoxX2.Text;
                    IFeatureWorkspace        pFeatureWorkspace        = workspaceFactory.OpenFromFile(gdbPath, 0) as IFeatureWorkspace;
                    ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironment();

                    //ISpatialReference pSpatialReference = new UnknownCoordinateSystemClass();
                    ISpatialReference pSpatialReference = ClsGDBDataCommon.CreateProjectedCoordinateSystem();
                    pSpatialReference.SetDomain(-8000000, 8000000, -800000, 8000000);
                    IFeatureDataset pFeatureDataset = pFeatureWorkspace.CreateFeatureDataset(textBoxX3.Text, pSpatialReference);
                    IFeatureClass   pFeatureclass   = CreatePointFeatureClass(pFeatureDataset, xml);
                    IFeatureClass   pFCLine         = CreatLineFC(pFeatureDataset, pFeatureclass);
                    if (pFeatureclass == null || pFCLine == null)
                    {
                        MessageBox.Show("数据生成失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    IFeatureLayer pFPointLayer = new FeatureLayerClass();
                    pFPointLayer.FeatureClass = pFeatureclass;
                    pFPointLayer.Name         = textBoxX3.Text + "_Gmppoint";

                    IFeatureLayer pFLintLayer = new FeatureLayerClass();
                    pFLintLayer.FeatureClass = pFCLine;
                    pFLintLayer.Name         = textBoxX3.Text + "_GmpLine";

                    m_pMapCtl.AddLayer(pFLintLayer as ILayer, 0);
                    m_pMapCtl.AddLayer(pFPointLayer as ILayer, 0);
                    m_pMapCtl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);

                    if (cmbImpSymbol.Text != null && symFilePath != null)
                    {
                        ImpSymbolFromFile(symFilePath, pFPointLayer, pFLintLayer);
                    }


                    //MessageBox.Show("数据已经生成", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            }
        }
Exemplo n.º 2
0
        public IFeatureClass CreatePointFeatureClass(IFeatureDataset pFeatureDataset, CGmpPoint xml)
        {
            try
            {
                //建立shape字段
                IFields     pFields     = new FieldsClass();
                IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;
                IField      pField      = new FieldClass();
                IFieldEdit  pFieldEdit  = (IFieldEdit)pField;
                pFieldEdit.Name_2 = "Shape";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                //设置Geometry definition
                IGeometryDef     pGeometryDef     = new GeometryDefClass();
                IGeometryDefEdit pGeometryDefEdit = (IGeometryDefEdit)pGeometryDef;
                pGeometryDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPoint; //点、线、面
                pGeometryDefEdit.SpatialReference_2 = ClsGDBDataCommon.CreateProjectedCoordinateSystem();
                pFieldEdit.GeometryDef_2            = pGeometryDef;
                pFieldsEdit.AddField(pField);

                //新建字段
                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "PointType";       //点类型
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                //新建字段
                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "类型";       //点类型
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "speed";       //行驶速度
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "规划开始时间";    //规划开始时间
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "规划时长";       //规划时长
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "行走开始时间";       //行走开始时间
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "行走时长";       //行走时长
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "探测开始时间";       //行走时长
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "探测时长";       //行走时长
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "探测结束时间";       //行走时长
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "太阳方位角";       //太阳方位角
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "地球方位角";       //地球方位角
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);


                IFeatureClass pFeatureClass = pFeatureDataset.CreateFeatureClass(textBoxX3.Text + "_Gmppoint", pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                for (int j = 0; j < xml.GmpPointS.Count; j++)
                {
                    IPoint pPoint = new PointClass();
                    pPoint.X = xml.GmpPointS[j].dPointX;
                    pPoint.Y = xml.GmpPointS[j].dPointY;
                    IFeature pFeature = pFeatureClass.CreateFeature();
                    pFeature.Shape = pPoint;
                    pFeature.Store();
                    AddAttributeTable(pFeature, xml.GmpPointS[j], j);
                }

                return(pFeatureClass);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(null);
            }
        }