예제 #1
0
        internal static ILayer OpenLayerFile(string path)
        {
            // Create a new GxLayer
            ESRI.ArcGIS.Catalog.IGxLayer gxLayer = new ESRI.ArcGIS.Catalog.GxLayerClass();

            ESRI.ArcGIS.Catalog.IGxFile gxFile = (ESRI.ArcGIS.Catalog.IGxFile)gxLayer; //Explicit Cast

            // Set the path for where the layerfile is located on disk
            gxFile.Path = path;


            if (!(gxLayer.Layer == null))
            {
                return(gxLayer.Layer);
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
파일: Form1.cs 프로젝트: richdb/gdb_arcgis
        void Button5Click(object sender, EventArgs e)
        {
            string waarde, SQL, naam, status, map;
            int nummer;
            IEnvelope env;
            IActiveView pActiveView;
            IPoint punt;
            IMap pMap;
            PropertySet pPropertySet;
            IWorkspaceFactory pSdeFact;
            IWorkspace pWorkspace;
            IFeatureWorkspace pFeatureWorkspace;
            IFeatureLayer pFeatureLayer;
            IFeatureClass pFeatureClass;
            ESRI.ArcGIS.Catalog.IGxLayer pGxLayer;
            ESRI.ArcGIS.Catalog.IGxFile pGxFile;
            double minx, miny, maxx, maxy;

            if (listBox1.SelectedIndex == -1) {
                MessageBox.Show("Selecteer eerst een dataset uit de lijst.", "Foutmelding");
                return;
            }
            try {
                this.Cursor = Cursors.WaitCursor;
                naam = "";
                status = "";
                nummer = listBox1.SelectedIndex;
                waarde = listBox1.Items[nummer].ToString();
                SQL = "SELECT NAAM, FYSIEKE_LOCATIE FROM DATASET WHERE DATASET_TITEL = '" + waarde + "'";
                mycommand = new OleDbCommand (SQL, mydb);
                OleDbDataReader myreader = mycommand.ExecuteReader();
                try {
                    while (myreader.Read()) {
                        naam = myreader.GetString(0).ToString();
                        status = myreader.GetString(1).ToString();
                    }
                }
                catch (Exception ex){
                    MessageBox.Show (ex.ToString(), "Foutmelding");
                    this.Cursor = Cursors.Default;
                }
                finally {
                    myreader.Close();
                }

                map = layer + status + "\\" + naam + ".lyr";

                try{
                    if (System.IO.File.Exists(@map)) {
                        pActiveView = hookHelper.ActiveView;
                        env = pActiveView.Extent;
                        punt = env.LowerLeft;
                        minx = punt.X;
                        miny = punt.Y;

                        punt = env.UpperRight;
                        maxx = punt.X;
                        maxy = punt.Y;

                        pGxLayer = new ESRI.ArcGIS.Catalog.GxLayerClass();
                        pGxFile = (ESRI.ArcGIS.Catalog.IGxFile)pGxLayer;
                        pGxFile.Path = map;

                        pMap = hookHelper.FocusMap;
                        pMap.AddLayer(pGxLayer.Layer);

                        pActiveView.Extent.XMin = minx;
                        pActiveView.Extent.XMax = maxx;
                        pActiveView.Extent.YMin = miny;
                        pActiveView.Extent.YMax = maxy;

                        pActiveView.Refresh();
                        this.Cursor = Cursors.Default;
                    }
                    else {
                        MessageBox.Show("Er is geen opmaakbestand van de geselecteerde dataset aanwezig. De dataset wordt nu zonder opmaak uit de geo-database gehaald.","Informatie");
                        SQL = "SELECT ALT_TITEL FROM DATASET WHERE DATASET_TITEL = '" + waarde + "'";
                        mycommand = new OleDbCommand (SQL, mydb);
                        OleDbDataReader myreader1 = mycommand.ExecuteReader();
                        try {
                            while (myreader1.Read()) {
                                pActiveView = hookHelper.ActiveView;

                                pPropertySet = new PropertySetClass();
                                pPropertySet.SetProperty("SERVER", "chios");
                                pPropertySet.SetProperty("INSTANCE", "5151");
                                pPropertySet.SetProperty("DATABASE", "");
                                pPropertySet.SetProperty("USER", "gisuser");
                                pPropertySet.SetProperty("PASSWORD", "zonnetje");
                                pPropertySet.SetProperty("VERSION", "SDE.DEFAULT");

                                env = pActiveView.Extent;
                                punt = env.LowerLeft;
                                minx = punt.X;
                                miny = punt.Y;

                                punt = env.UpperRight;
                                maxx = punt.X;
                                maxy = punt.Y;

                                pSdeFact = new SdeWorkspaceFactoryClass();
                                pWorkspace = pSdeFact.Open(pPropertySet, 0);
                                pFeatureWorkspace = pWorkspace as IFeatureWorkspace;

                                pFeatureClass = pFeatureWorkspace.OpenFeatureClass(myreader1.GetString(0).ToString());

                                pMap = hookHelper.FocusMap;

                                pFeatureLayer = new FeatureLayerClass();
                                pFeatureLayer.FeatureClass = pFeatureClass;

                                pFeatureLayer.Name = pFeatureClass.AliasName;
                                pFeatureLayer.Visible = true;
                                pFeatureLayer.Selectable = true;
                                pMap.AddLayer(pFeatureLayer);

                                pActiveView.Extent.XMin = minx;
                                pActiveView.Extent.XMax = maxx;
                                pActiveView.Extent.YMin = miny;
                                pActiveView.Extent.YMax = maxy;

                                pActiveView.Refresh();
                                this.Cursor = Cursors.Default;
                            }
                        }
                        catch (Exception ex){
                            MessageBox.Show (ex.ToString(), "Foutmelding");
                            this.Cursor = Cursors.Default;
                        }
                        finally {
                            myreader.Close();
                        }

                    }

                }
                catch (Exception ex) {
                    MessageBox.Show (ex.ToString(), "Foutmelding");
                    this.Cursor = Cursors.Default;
                }
            }
            catch {
                MessageBox.Show("Er is geen PDF voor deze dataset aanwezig.", "Foutmelding");
                this.Cursor = Cursors.Default;
            }
        }