comparison Postarc/Postarc/GUI/FormNewPostGISFeatClass.cs @ 0:1aca3d413885 tip

Initial import of Postarc
author Christian Lins <christian.lins@intevation.de>
date Fri, 05 Oct 2012 23:55:06 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1aca3d413885
1 /*
2 * Postarc
3 *
4 * Author:
5 * Christian Lins <christian.lins@intevation.de>
6 *
7 * Copyright:
8 * Copyright (C) 2012 Intevation GmbH <http://www.intevation.de/>
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 using System;
25 using System.Collections.Generic;
26 using System.ComponentModel;
27 using System.Data;
28 using System.Drawing;
29 using System.Linq;
30 using System.Text;
31 using System.Windows.Forms;
32 using ESRI.ArcGIS.Carto;
33 using ESRI.ArcGIS.Geodatabase;
34 using ESRI.ArcGIS.Geometry;
35 using Postarc.Feature;
36
37 namespace Postarc.GUI
38 {
39 public partial class FormNewPostGISFeatClass : Form
40 {
41 public FormNewPostGISFeatClass()
42 {
43 InitializeComponent();
44 this.cmbGeometryType.SelectedIndex = 0;
45 }
46
47 private void btnCreate_Click(object sender, EventArgs e)
48 {
49 if (cmbGeometryType.SelectedItem == null)
50 {
51 MessageBox.Show("Please choose the Shape type of the new FeatureClass!", "Shape type", MessageBoxButtons.OK, MessageBoxIcon.Warning);
52 return;
53 }
54 if (txtLayerName.Text == null || txtLayerName.Text.Equals(""))
55 {
56 MessageBox.Show("Please enter a name for the new layer!", "Layer name", MessageBoxButtons.OK, MessageBoxIcon.Warning);
57 return;
58 }
59 if (txtFCName.Text == null || txtFCName.Text.Equals(""))
60 {
61 MessageBox.Show("Please enter a name for the FeatureClass!", "FeatureClass name", MessageBoxButtons.OK, MessageBoxIcon.Warning);
62 return;
63 }
64
65 esriGeometryType shapeType = esriGeometryType.esriGeometryNull;
66 if (cmbGeometryType.SelectedItem.Equals("POINT"))
67 {
68 shapeType = esriGeometryType.esriGeometryPoint;
69 }
70 else if (cmbGeometryType.SelectedItem.Equals("POLYGON"))
71 {
72 shapeType = esriGeometryType.esriGeometryPolygon;
73 }
74 else if (cmbGeometryType.SelectedItem.Equals("POLYLINE"))
75 {
76 shapeType = esriGeometryType.esriGeometryPolyline;
77 }
78
79 //PostarcClassDescription.Register();
80
81 IFeatureClass featClass;
82 //if (cmbGeometryTable.SelectedText!= null)
83 {
84 featClass = new Postarc.Feature.FeatureClass(
85 this.cmbDatabaseConnections.SelectedItem as PostGISConnection,
86 this.cmbGeometryTable.SelectedItem as string);
87 }
88 //else
89 //{
90 // featClass = new PostGISFeatureClass(shapeType);
91 //}
92
93 // Load field definitions from geometry table
94
95 Visible = false;
96 Application.DoEvents();
97
98 // Create FeatureLayer that encapsulates our FeatureClass
99 IFeatureLayer featLayer = new Postarc.Feature.FeatureLayer();
100 featLayer.FeatureClass = featClass;
101 featLayer.Name = txtLayerName.Text;
102
103 // Add FeatureLayer to active map document
104 ArcMap.Document.FocusMap.AddLayer(featLayer);
105 }
106
107 private void btnEditConnections_Click(object sender, EventArgs e)
108 {
109 PostGISConnection conn = this.cmbDatabaseConnections.SelectedItem as PostGISConnection;
110 if (conn != null)
111 {
112 FormConnectionProperties connProp = new FormConnectionProperties(conn);
113 connProp.ShowDialog();
114 }
115 else
116 {
117 MessageBox.Show("Please select a connection profile first!");
118 }
119 }
120
121 private void FormNewPostGISFeatClass_Shown(object sender, EventArgs e)
122 {
123 int selIndex;
124
125 // Fill the database connections to the combo box and preselect one
126 selIndex = this.cmbDatabaseConnections.SelectedIndex;
127 this.cmbDatabaseConnections.Items.Clear();
128 this.cmbDatabaseConnections.Items.AddRange(Settings.LoadSavedProfiles().ToArray());
129 this.cmbDatabaseConnections.Items.Add(new PostGISConnection());
130 this.cmbDatabaseConnections.SelectedIndex = 0;
131 if (selIndex >= 0)
132 {
133 this.cmbDatabaseConnections.SelectedIndex = selIndex;
134 }
135 }
136
137 private void FormNewPostGISFeatClass_FormClosing(object sender, FormClosingEventArgs e)
138 {
139 e.Cancel = true;
140 Visible = false;
141 }
142
143 private void cmbDatabaseConnections_SelectedIndexChanged(object sender, EventArgs e)
144 {
145 if (cmbDatabaseConnections.SelectedIndex >= 0)
146 {
147 PostGISConnection conn = cmbDatabaseConnections.SelectedItem as PostGISConnection;
148 this.cmbGeometryTable.Items.Clear();
149 this.cmbGeometryTable.Items.AddRange(conn.QueryTables().ToArray());
150 this.cmbGeometryTable.SelectedIndex = 0;
151 }
152 }
153 }
154 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)