예제 #1
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();
                    }
                }
            }
        }
예제 #2
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;
        }
예제 #3
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;
        }
예제 #4
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);
        }
예제 #5
0
        /// <summary>
        /// Reads the complete feature set from the database
        /// </summary>
        /// <param name="featureSetInfo">information about the table</param>
        /// <param name="sql">the sql query</param>
        /// <returns>the resulting feature set</returns>
        public IFeatureSet ReadFeatureSet(GeometryColumnInfo featureSetInfo, string sql)
        {
            var fType = GetGeometryType(featureSetInfo.GeometryType);
            SpatiaLiteFeatureSet fs = new SpatiaLiteFeatureSet(fType)
            {
                IndexMode = true, // setting the initial index mode..
                Name      = featureSetInfo.TableName,
                Filename  = SqLiteHelper.GetSqLiteFileName(ConnectionString),
                LayerName = featureSetInfo.TableName
            };

            using (var cmd = CreateCommand(ConnectionString, sql))
            {
                cmd.Connection.Open();

                var wkbr = new SpatiaLiteWkbReader();

                var rdr = cmd.ExecuteReader();

                var columnNames = PopulateTableSchema(fs, featureSetInfo.GeometryColumnName, rdr);
                while (rdr.Read())
                {
                    var wkb  = rdr[featureSetInfo.GeometryColumnName] as byte[];
                    var geom = wkbr.Read(wkb);

                    var newFeature = fs.AddFeature(geom);

                    // populate the attributes
                    foreach (var colName in columnNames)
                    {
                        newFeature.DataRow[colName] = rdr[colName];
                    }
                }

                cmd.Connection.Close();

                // assign projection
                if (featureSetInfo.Srid > 0)
                {
                    var proj = ProjectionInfo.FromEpsgCode(featureSetInfo.Srid);
                    fs.Projection = proj;
                }

                return(fs);
            }
        }
예제 #6
0
 private void BQueryClick(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);
             var    frm = new FrmQuery(cs, App.Map);
             frm.Show();
         }
     }
 }
예제 #7
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();
            }
        }