/// <summary> /// Add PostGIS Layer to ArcMap /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ok_Click(object sender, EventArgs e) { Hide(); owner.application.RefreshWindow(); try { // Create a new layer for each checked PostGIS layers in the list if (clbLayers.CheckedItems.Count > 0) { foreach (string layerToAdd in clbLayers.CheckedItems) { IFeatureClass fc = fwks.OpenFeatureClass(layerToAdd); IFeatureLayer layer = new PostGisFeatureLayer(); //IFeatureLayer layer = new FeatureLayerClass(); IGeoFeatureLayer gfl = layer as IGeoFeatureLayer; /* * // Paolo - remove this * IFeatureRenderer fr = new VerySimpleCustomRenderer(); * gfl.Renderer = fr; * //end of sample.... */ /* * //COD (101,103...) * IUniqueValueRenderer uvr = new CustomUniqueValueRenderer(); * uvr.FieldCount = 1; * uvr.set_Field(0, "code"); * uvr.DefaultSymbol = (ISymbol)CreateSimpleFillSymbol(0, 0, 255); * uvr.UseDefaultSymbol = true; * //add values * uvr.AddValue("CA06", "CA06", (ISymbol)CreateSimpleFillSymbol(255, 0, 0)); * uvr.AddValue("CA05", "CA05", (ISymbol)CreateSimpleFillSymbol(0, 255, 0)); * //render * gfl.Renderer = (IFeatureRenderer)uvr; */ layer.FeatureClass = fc; layer.Name = fc.AliasName; // Add the new layer. IMxDocument doc = (IMxDocument)owner.application.Document; doc.AddLayer(layer); } } else { MessageBox.Show("No PostGIS layers added."); } } catch (COMException COMex) { MessageBox.Show("Error " + COMex.ErrorCode.ToString() + ": " + COMex.Message); } catch (System.Exception ex) { MessageBox.Show("Error: " + ex.Message); } }
/// <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); }