Esempio n. 1
0
        //when clicking "OK"
        private void btnOK_Click(object sender, EventArgs e)
        {
            queryResult = null;
            SpatiaLiteHelper slh = new SpatiaLiteHelper();
            queryResult = slh.ReadFeatureSet(connString, txtQuery.Text);

            dgQueryResult.DataSource = queryResult.DataTable;

            //SpatiaLiteHelper slh = new SpatiaLiteHelper();

            //foreach (DataGridViewRow r in dgGeometryColumns.Rows)
            //{
            //    if (r.Selected)
            //    {
            //        GeometryColumnInfo item = r.DataBoundItem as GeometryColumnInfo;
            //        if (item != null)
            //        {
            //            IFeatureSet fs = slh.ReadFeatureSet(connString, item);

            //            IMapFeatureLayer lay = mainMap.Layers.Add(fs);
            //            //lay.EditMode = false;

            //        }
            //    }
            //}
        }
Esempio n. 2
0
        public frmQuery(string dbConnection, IMap map)
        {
            InitializeComponent();

            connString = dbConnection;
            mainMap    = map;

            SpatiaLiteHelper          slh = new SpatiaLiteHelper();
            List <GeometryColumnInfo> geometryColumnList = slh.GetGeometryColumns(dbConnection);

            //get names of tables
            List <string> tableNameList = slh.GetTableNames(connString);

            foreach (string tableName in tableNameList)
            {
                try
                {
                    List <string> colNames   = slh.GetColumnNames(connString, tableName);
                    TreeNode      nTableName = treeTables.Nodes.Add(tableName);
                    foreach (string cn in colNames)
                    {
                        nTableName.Nodes.Add(cn);
                    }
                }
                catch { }
            }
        }
Esempio n. 3
0
        //when clicking "OK"
        private void btnOK_Click(object sender, EventArgs e)
        {
            queryResult = null;
            SpatiaLiteHelper slh = new SpatiaLiteHelper();

            queryResult = slh.ReadFeatureSet(connString, txtQuery.Text);

            dgQueryResult.DataSource = queryResult.DataTable;

            //SpatiaLiteHelper slh = new SpatiaLiteHelper();

            //foreach (DataGridViewRow r in dgGeometryColumns.Rows)
            //{
            //    if (r.Selected)
            //    {
            //        GeometryColumnInfo item = r.DataBoundItem as GeometryColumnInfo;
            //        if (item != null)
            //        {
            //            IFeatureSet fs = slh.ReadFeatureSet(connString, item);

            //            IMapFeatureLayer lay = mainMap.Layers.Add(fs);
            //            //lay.EditMode = false;

            //        }
            //    }
            //}
        }
Esempio n. 4
0
        /// <summary>
        /// Shows the add layer window.
        /// </summary>
        /// <param name="sender">Sender that raised the event.</param>
        /// <param name="e">The event args.</param>
        public void ButtonClick(object sender, EventArgs e)
        {
            // check if it's a valid SpatiaLite layer
            using (OpenFileDialog fd = new OpenFileDialog
            {
                Title = Resources.OpenSpatialiteDatabase,
                Filter = Resources.SpatialiteDatabaseFilter
            })
            {
                if (fd.ShowDialog() == DialogResult.OK)
                {
                    string cs = SqLiteHelper.GetSqLiteConnectionString(fd.FileName);
                    string error;
                    var    slh = SpatiaLiteHelper.Open(cs, out error);
                    if (slh == null)
                    {
                        MessageBox.Show(string.Format(Resources.DatabaseNotValid, fd.FileName, error));
                        return;
                    }

                    using (FrmAddLayer frm = new FrmAddLayer(slh, App.Map))
                    {
                        frm.ShowDialog();
                    }
                }
            }
        }
Esempio n. 5
0
        public frmQuery(string dbConnection, IMap map)
        {
            InitializeComponent();

            connString = dbConnection;
            mainMap = map;

            SpatiaLiteHelper slh = new SpatiaLiteHelper();
            List<GeometryColumnInfo> geometryColumnList = slh.GetGeometryColumns(dbConnection);

            //get names of tables
            List<string> tableNameList = slh.GetTableNames(connString);
            foreach (string tableName in tableNameList)
            {
                try
                {
                    List<string> colNames = slh.GetColumnNames(connString, tableName);
                    TreeNode nTableName = treeTables.Nodes.Add(tableName);
                    foreach (string cn in colNames)
                    {
                        nTableName.Nodes.Add(cn);
                    }
                }
                catch { }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FrmQuery"/> class.
        /// </summary>
        /// <param name="slh">The SpatiaLiteHelper that is connected to the database.</param>
        /// <param name="map">The map layers get added to.</param>
        public FrmQuery(SpatiaLiteHelper slh, IMap map)
        {
            InitializeComponent();

            _slh     = slh;
            _mainMap = map;

            List <GeometryColumnInfo> geometryColumnList = _slh.GetGeometryColumns();

            // get names of tables
            List <string> tableNameList = slh.GetTableNames();

            foreach (string tableName in tableNameList)
            {
                try
                {
                    List <string> colNames   = slh.GetColumnNames(tableName);
                    TreeNode      nTableName = treeTables.Nodes.Add(tableName);
                    foreach (string cn in colNames)
                    {
                        nTableName.Nodes.Add(cn);
                    }
                }
                catch { }
            }
        }
Esempio n. 7
0
        // when clicking "OK"
        private void BtnOkClick(object sender, EventArgs e)
        {
            _queryResult = null;
            SpatiaLiteHelper slh = new SpatiaLiteHelper();

            _queryResult = slh.ReadFeatureSet(_connString, txtQuery.Text);

            dgQueryResult.DataSource = _queryResult.DataTable;
        }
Esempio n. 8
0
        public frmAddLayer(string dbConnection, IMap map)
        {
            InitializeComponent();

            label2.Text = "Database: " + SQLiteHelper.GetSQLiteFileName(dbConnection);

            connString = dbConnection;
            mainMap = map;

            SpatiaLiteHelper slh = new SpatiaLiteHelper();
            List<GeometryColumnInfo> geometryColumnList = slh.GetGeometryColumns(dbConnection);
            dgGeometryColumns.DataSource = geometryColumnList;
        }
Esempio n. 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FrmAddLayer"/> class.
        /// </summary>
        /// <param name="slh">The SpatiaLiteHelper that is connected to the SQLite database.</param>
        /// <param name="map">The map the layer will be added to.</param>
        public FrmAddLayer(SpatiaLiteHelper slh, IMap map)
        {
            InitializeComponent();

            label2.Text = string.Format(Resources.Database0, SqLiteHelper.GetSqLiteFileName(slh.ConnectionString));

            _slh     = slh;
            _mainMap = map;

            List <GeometryColumnInfo> geometryColumnList = _slh.GetGeometryColumns();

            dgGeometryColumns.DataSource = geometryColumnList;
        }
Esempio n. 10
0
        public frmAddLayer(string dbConnection, IMap map)
        {
            InitializeComponent();

            label2.Text = "Database: " + SQLiteHelper.GetSQLiteFileName(dbConnection);

            connString = dbConnection;
            mainMap    = map;

            SpatiaLiteHelper          slh = new SpatiaLiteHelper();
            List <GeometryColumnInfo> geometryColumnList = slh.GetGeometryColumns(dbConnection);

            dgGeometryColumns.DataSource = geometryColumnList;
        }
Esempio n. 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FrmAddLayer"/> class.
        /// </summary>
        /// <param name="dbConnection">The connectionstring to the SQLite database.</param>
        /// <param name="map">The map the layer will be added to.</param>
        public FrmAddLayer(string dbConnection, IMap map)
        {
            InitializeComponent();

            label2.Text = string.Format(Resources.Database0, SqLiteHelper.GetSqLiteFileName(dbConnection));

            _connString = dbConnection;
            _mainMap    = map;

            SpatiaLiteHelper          slh = new SpatiaLiteHelper();
            List <GeometryColumnInfo> geometryColumnList = slh.GetGeometryColumns(dbConnection);

            dgGeometryColumns.DataSource = geometryColumnList;
        }
Esempio n. 12
0
        /// <summary>
        /// This static method is only meant to be used by the deserializer.
        /// </summary>
        /// <param name="filePath">Path of the file that contains the layer that gets loaded.</param>
        /// <param name="layerName">Name of the layer that should be loaded.</param>
        /// <returns>The opened layer.</returns>
        public static IFeatureSet OpenLayer(string filePath, string layerName)
        {
            var connectionString = SqLiteHelper.GetSqLiteConnectionString(filePath);

            var file = SpatiaLiteHelper.Open(connectionString, out string error);

            if (file == null)
            {
                throw new FileLoadException(string.Format(Resources.DatabaseNotValid, filePath, error));
            }

            var fs = file.ReadFeatureSet(layerName);

            return(fs);
        }
Esempio n. 13
0
        // when clicking "OK"
        private void BtnOkClick(object sender, EventArgs e)
        {
            SpatiaLiteHelper slh = new SpatiaLiteHelper();

            foreach (DataGridViewRow r in dgGeometryColumns.Rows)
            {
                if (r.Selected)
                {
                    GeometryColumnInfo item = r.DataBoundItem as GeometryColumnInfo;
                    if (item != null)
                    {
                        IFeatureSet fs = slh.ReadFeatureSet(_connString, item);
                        _mainMap.Layers.Add(fs);
                    }
                }
            }
        }
Esempio n. 14
0
        //when clicking "OK"
        private void btnOK_Click(object sender, EventArgs e)
        {
            SpatiaLiteHelper slh = new SpatiaLiteHelper();

            foreach (DataGridViewRow r in dgGeometryColumns.Rows)
            {
                if (r.Selected)
                {
                    GeometryColumnInfo item = r.DataBoundItem as GeometryColumnInfo;
                    if (item != null)
                    {
                        IFeatureSet fs = slh.ReadFeatureSet(connString, item);

                        IMapFeatureLayer lay = mainMap.Layers.Add(fs);
                        //lay.EditMode = false;
                    }
                }
            }
        }
Esempio n. 15
0
        /// <summary>
        /// When the plugin is activated.
        /// </summary>
        public override void Activate()
        {
            // try setting environment variables..
            SpatiaLiteHelper.SetEnvironmentVars();

            string spatiaLiteGroup = "SpatiaLite";

            var bOpenLayer = new SimpleActionItem("Open Layer", ButtonClick)
            {
                LargeImage   = Resources.spatialite_open_32,
                SmallImage   = Resources.spatialite_open_16,
                ToolTipText  = "Add Layer from SpatiaLite",
                GroupCaption = spatiaLiteGroup
            };

            App.HeaderControl.Add(bOpenLayer);

            // query
            var bQuery = new SimpleActionItem("SpatiaLite Query", BQueryClick)
            {
                LargeImage   = Resources.spatialite_query_32,
                SmallImage   = Resources.spatialite_query_16,
                ToolTipText  = "Run SpatiaLite Query",
                GroupCaption = spatiaLiteGroup
            };

            App.HeaderControl.Add(bQuery);

            // save layer (not implemented yet)
            var bSaveLayer = new SimpleActionItem("Save Layer", BSaveLayerClick)
            {
                LargeImage   = Resources.spatialite_save_32,
                SmallImage   = Resources.spatialite_save_16,
                ToolTipText  = "Save Layer to SpatiaLite Database",
                GroupCaption = spatiaLiteGroup
            };

            App.HeaderControl.Add(bSaveLayer);
            base.Activate();
        }
Esempio n. 16
0
        public void ButtonClick(object sender, EventArgs e)
        {
            //check if it's a valid SpatiaLite layer
            OpenFileDialog fd = new OpenFileDialog();

            fd.Title  = "Open SpatiaLite database";
            fd.Filter = "SpatiaLite database|*.sqlite";
            if (fd.ShowDialog() == DialogResult.OK)
            {
                string cs            = SQLiteHelper.GetSQLiteConnectionString(fd.FileName);
                bool   isValidSchema = SpatiaLiteHelper.CheckSpatiaLiteSchema(cs);
                if (!isValidSchema)
                {
                    MessageBox.Show("The database " + fd.FileName + " is not a valid SpatiaLite database. Table geometry_columns not found.");
                    return;
                }
                else
                {
                    frmAddLayer frm = new frmAddLayer(cs, App.Map);
                    frm.Show();
                }
            }
        }
Esempio n. 17
0
        private void BQueryClick(object sender, EventArgs e)
        {
            // check if it's a valid SpatiaLite layer
            using OpenFileDialog fd = new()
                  {
                      Title  = Resources.OpenSpatialiteDatabase,
                      Filter = Resources.SpatialiteDatabaseFilter
                  };
            if (fd.ShowDialog() == DialogResult.OK)
            {
                string cs  = SqLiteHelper.GetSqLiteConnectionString(fd.FileName);
                var    slh = SpatiaLiteHelper.Open(cs, out string error);

                if (slh == null)
                {
                    MessageBox.Show(string.Format(Resources.DatabaseNotValid, fd.FileName, error));
                    return;
                }

                using var frm = new FrmQuery(slh, App.Map);
                frm.ShowDialog();
            }
        }