Beispiel #1
0
        private void 加载shp数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string path         = Application.StartupPath + "\\data\\国界\\bou1_4l.shp";
            string XMLLayerInfo = "<PlugData><LayerName>" + path + "</LayerName><PlugType>shape</PlugType><AttributesToLoad>AREA,STATE_NAME,POP1990,POP2000</AttributesToLoad><StreamedLayer>0</StreamedLayer></PlugData>";

            iLyr = IInfoTree.CreateLayer("国界", XMLLayerInfo, 0);//在根目录下装载shp数据
            string path2         = Application.StartupPath + "\\data\\国界与省界\\bou2_4l.shp";
            string XMLLayerInfo2 = "<PlugData><LayerName>" + path2 + "</LayerName><PlugType>shape</PlugType><AttributesToLoad>AREA,STATE_NAME,POP1990,POP2000</AttributesToLoad><StreamedLayer>0</StreamedLayer></PlugData>";

            iLyr2 = IInfoTree.CreateLayer("国界与省界", XMLLayerInfo2, 0);//在根目录下装载shp数据
            string path3         = Application.StartupPath + "\\data\\首都和省级行政中心\\res1_4m.shp";
            string XMLLayerInfo3 = "<PlugData><LayerName>" + path3 + "</LayerName><PlugType>shape</PlugType><AttributesToLoad>AREA,STATE_NAME,POP1990,POP2000</AttributesToLoad><StreamedLayer>0</StreamedLayer></PlugData>";

            iLyr3 = IInfoTree.CreateLayer("首都和省级行政中心", XMLLayerInfo3, 0);//在根目录下装载shp数据
            string path4         = Application.StartupPath + "\\data\\主要公路\\roa_4m.shp";
            string XMLLayerInfo4 = "<PlugData><LayerName>" + path4 + "</LayerName><PlugType>shape</PlugType><AttributesToLoad>AREA,STATE_NAME,POP1990,POP2000</AttributesToLoad><StreamedLayer>0</StreamedLayer></PlugData>";

            iLyr4 = IInfoTree.CreateLayer("主要公路", XMLLayerInfo4, 0);//在根目录下装载shp数据
            string path5         = Application.StartupPath + "\\data\\主要铁路\\rai_4m.shp";
            string XMLLayerInfo5 = "<PlugData><LayerName>" + path5 + "</LayerName><PlugType>shape</PlugType><AttributesToLoad>AREA,STATE_NAME,POP1990,POP2000</AttributesToLoad><StreamedLayer>0</StreamedLayer></PlugData>";

            iLyr5 = IInfoTree.CreateLayer("主要铁路", XMLLayerInfo5, 0);//在根目录下装载shp数据
            iLyr.Load();
            iLyr2.Load();
            iLyr3.Load();
            iLyr4.Load();
            iLyr5.Load();
        }
Beispiel #2
0
        /// <summary>
        /// 加载shape文件添加模型
        /// 模型数据要与shape在同一路径下
        /// 2012-09-21 张航宇
        /// 添加Z修正 -56
        /// </summary>
        /// <param name="FileName"></param>
        ///
        public void LoadShapeAdd3model(ISGWorld61 sgworld, ITerraExplorer te, string FileName)
        {
            IInformationTree5 infoTree5 = te as IInformationTree5;

            if (string.IsNullOrEmpty(FileName))
            {
                return;
            }
            if (File.Exists(FileName))
            {
                bool   PathType     = true;
                string PathFileName = "";
                string GroupName    = "模型组群" + System.Guid.NewGuid().ToString().Substring(0, 6);
                infoTree5.CreateGroup(GroupName, 0);
                int    GroupID         = sgworld.ProjectTree.FindItem(GroupName);
                string ModelFilename   = "";
                string UNModelFilename = "";
                string _XMLLayerInfo   = "<PlugData>" +

                                         "<PlugType>shape</PlugType>" +

                                         "<LayerName>" + FileName + "</LayerName>" +

                                         "<Server></Server>" +

                                         "<user></user>" +

                                         "<password></password>" +

                                         "<TableName></TableName>" +

                                         "<AttributesToLoad>*</AttributesToLoad >" +

                                         "<Feature>1</Feature >" +

                                         "<Annotation>1</Annotation>" +

                                         "<SaveItems>0</SaveItems>" +

                                         "<GroupKey>LAT-LONG</GroupKey>" +

                                         "<SysKey>LAT-LONG</SysKey>" +

                                         "<DatumKey>WGS84</DatumKey>" +

                                         "<UnitKey>METERS</UnitKey>" +

                                         "<UseZValue>0</UseZValue>" +

                                         "<AltitudeUnit>Meters</AltitudeUnit>" +

                                         "<Reproject>1</Reproject>" +

                                         "<StreamedLayer>0</StreamedLayer></PlugData >";
                ILayer5 iLyr = infoTree5.CreateLayer("3DModleGoto", _XMLLayerInfo, GroupID);//在根目录下装载shp数据
                iLyr.Load();
                IFeature61 sqfeature61 = null;
                int        itemid      = sgworld.ProjectTree.FindItem("" + GroupName + "\\3DModleGoto");

                ILayer61 m_layer61 = sgworld.ProjectTree.GetLayer(itemid);
                m_layer61.Streaming = false;

                IFeatureGroups61 pFeatureGroups61 = m_layer61.FeatureGroups;

                IFeatureGroup61 pFeatureGroup61 = pFeatureGroups61.Point as IFeatureGroup61;
                if (pFeatureGroup61 == null)
                {
                    MessageBox.Show("当前操作要求是正确的点图层");
                    return;
                }
                else
                {
                    if (pFeatureGroup61.Count == 0)
                    {
                        MessageBox.Show("图层为空!");
                        return;
                    }
                    else
                    {
                        sqfeature61 = pFeatureGroup61[0] as IFeature61;
                        IFeatureAttributes61 m_FeatureAttributes = sqfeature61.FeatureAttributes;
                        int      AttributesCount = m_FeatureAttributes.Count;
                        string[] FiledArry       = new string[AttributesCount];
                        for (int f = 0; f < AttributesCount; f++)
                        {
                            IFeatureAttribute61 m_FeatureAttribute = m_FeatureAttributes[f] as IFeatureAttribute61;
                            FiledArry[f] = m_FeatureAttribute.Name;
                        }
                        Skyline.Core.UI.FrmAddModelShape pFrmAddModelShape = new Skyline.Core.UI.FrmAddModelShape();
                        pFrmAddModelShape.GetFiledName = FiledArry;
                        pFrmAddModelShape.ShowDialog();
                        PathFileName = pFrmAddModelShape.Filed;
                        PathType     = pFrmAddModelShape.PathType;
                        pFrmAddModelShape.Dispose();

                        int m_FeatureCount     = pFeatureGroup61.Count;
                        int ImportFeatureCount = pFeatureGroup61.Count;
                        for (int i = 0; i < m_FeatureCount; i++)
                        {
                            sqfeature61 = pFeatureGroup61[i] as IFeature61;
                            IFeatureAttributes61     _FeatureAttributes = sqfeature61.FeatureAttributes;
                            TerraExplorerX.IGeometry _Geometry          = sqfeature61.GeometryZ;
                            TerraExplorerX.IPoint    pPoint             = _Geometry as TerraExplorerX.IPoint;
                            //IPosition61 TPosition61 = sgworld.Window.PixelToWorld(pPoint.X, pPoint.Y, WorldPointType.WPT_ALL).Position;
                            IPosition61         TPosition61       = sgworld.Creator.CreatePosition(pPoint.X, pPoint.Y, -56, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, 0, 0);
                            IFeatureAttribute61 _FeatureAttribute = _FeatureAttributes.GetFeatureAttribute(PathFileName);
                            UNModelFilename = _FeatureAttribute.Value.ToString();
                            if (PathType)
                            {
                                ModelFilename = System.IO.Path.GetDirectoryName(FileName) + "\\" + UNModelFilename;
                            }
                            else
                            {
                                ModelFilename = UNModelFilename;
                            }

                            try
                            {
                                sgworld.Creator.CreateModel(TPosition61, ModelFilename, 1, ModelTypeCode.MT_NORMAL, GroupID, UNModelFilename);
                            }
                            catch
                            {
                                ImportFeatureCount--;
                                continue;
                            }
                        }
                        MessageBox.Show(ImportFeatureCount + "个模型加载成功," + (m_FeatureCount - ImportFeatureCount) + "个模型加载失败!");

                        /****20130227杨漾(添加文件有效性判断,分步判断图层有效性,增加加载统计情况提示)****/
                    }
                }
            }
        }