示例#1
0
        public void Init()
        {
            // Open workspace and feature class.
            IWorkspaceFactory wksf = new PostGisWorkspaceFactory();

            //Open from zigFile
            //ws = wksf.OpenFromFile(@"C:\ziggis\ZigGis\example.zig", 0);

            //Open from PropertySet
            IPropertySet ps = new PropertySetClass();

            ps.SetProperty("server", "localhost");
            ps.SetProperty("database", "TUTORIAL");
            ps.SetProperty("user", "psqluser");
            ps.SetProperty("password", "psqluser");
            ps.SetProperty("port", "5432");
            ps.SetProperty("configfile", @"C:\ziggis\ZigGis\logging.config");
            ws = wksf.Open(ps, 0);

            IFeatureWorkspace fwks = ws as IFeatureWorkspace;

            fc = fwks.OpenFeatureClass("zone");
            // Create the new layer (default renderer is ISimpleRenderer)
            layer = new PostGisFeatureLayer();
            layer.FeatureClass = fc;
            layer.Name         = fc.AliasName;
        }
 private void parseZigFile()
 {
     try
     {
         string pth = _zigFilePath;
         // Open workspace
         IWorkspaceFactory wksf = new PostGisWorkspaceFactory();
         IFeatureWorkspace fwks = (IFeatureWorkspace)wksf.OpenFromFile(pth, 0);
         // Open workspace
         IWorkspace ws = fwks as IWorkspace;
         _wkspc    = ws;
         _host     = ws.ConnectionProperties.GetProperty("server").ToString();
         _port     = Convert.ToInt32(ws.ConnectionProperties.GetProperty("port"));
         _database = ws.ConnectionProperties.GetProperty("database").ToString();
         _username = ws.ConnectionProperties.GetProperty("user").ToString();
         _password = ws.ConnectionProperties.GetProperty("password").ToString();
         //IEnumDatasetName edsn = ws.get_DatasetNames(esriDatasetType.esriDTFeatureClass);
         //IDatasetName dsn;
         //// Load PostGIS layer names
         //clbLayers.Items.Clear();
         //while ((dsn = edsn.Next()) != null)
         //{
         //    clbLayers.Items.Add(dsn.Name);
         //}
     }
     catch (COMException COMex)
     {
         //MessageBox.Show("Error " + COMex.ErrorCode.ToString() + ": " + COMex.Message);
     }
     catch (System.Exception ex)
     {
         //MessageBox.Show("Error: " + ex.Message);
     }
 }
示例#3
0
        /// <summary>
        /// Load a PostGis layer in the test MapControl
        /// </summary>
        private void LoadPostGisLayer()
        {
            // Open workspace and feature class.
            IWorkspaceFactory wksf = new PostGisWorkspaceFactory();

            //Open from zig file
            IFeatureWorkspace fwks = (IFeatureWorkspace)wksf.OpenFromFile(@"C:\ziggis\ZigGis\example2.zig", 0);

            /*
             * //Open from PropertySet
             * IPropertySet ps = new PropertySetClass();
             * ps.SetProperty("server", "localhost");
             * ps.SetProperty("database", "TUTORIAL");
             * ps.SetProperty("user", "psqluser");
             * ps.SetProperty("password", "psqluser");
             * ps.SetProperty("port", "5432");
             * ps.SetProperty("configfile", @"C:\ziggis\ZigGis\logging.config");
             * IFeatureWorkspace fwks = (IFeatureWorkspace)wksf.Open(ps, 0);
             */

            IFeatureClass fc = fwks.OpenFeatureClass("paolo.canada");
            // Create the new layer (default renderer is ISimpleRenderer)
            IFeatureLayer layer = new PostGisFeatureLayer();

            layer.FeatureClass = fc;
            layer.Name         = fc.AliasName;
            ILayer           ly  = layer as ILayer;
            IGeoFeatureLayer gfl = layer as IGeoFeatureLayer;

            //doSimpleRenderer(gfl);
            doUniqueValueRenderer(gfl);
            //IFeatureRenderer fr = new VerySimpleCustomRenderer();
            //gfl.Renderer = fr;
            axMapControl1.AddLayer(gfl as ILayer, 0);
            //SelectFeaturesFromFeatureClass(fc, fwks as IWorkspace);
            //SelectFeaturesFromFeatureLayer(layer);
        }