예제 #1
0
        public void Search(object query)
        {
            if (!(query is Filter))
            {
                throw new ArgumentException("Only queries of type 'OSGeo.FDO.Filter' are supported.");
            }

            Filter filter = (Filter)query;

            _selectCommand.Filter = filter;
            _featureReader        = _selectCommand.Execute();
        }
예제 #2
0
        public static DataTable GetDataFromFile(string filename)
        {
            Guard.ArgumentNotNull(filename, "filename");

            // Create an FDO connection to the SHP provider
            var mgr = FeatureAccessManager.GetConnectionManager();

            using (var connection = mgr.CreateConnection("OSGeo.SHP"))
            {
                // Set connection properties
                var props = connection.ConnectionInfo.ConnectionProperties;
                props.SetProperty("DefaultFileLocation", filename);

                // Open the connection
                connection.Open();

                // Check the connection state
                if (connection.ConnectionState == ConnectionState.ConnectionState_Open)
                {
                    Console.WriteLine("Connection was opened successfully.");
                }
                else
                {
                    Console.WriteLine("Connection failed to open.");
                }

                // Create the Select command
                using (ISelect select = (ISelect)connection.CreateCommand(CommandType.CommandType_Select))
                {
                    //TODO: fix
                    //Invalid Feature schema element name 'ef02f72c-67e8-4967-89d5-610b57aa5bcf.6.48F1FC14219145F1663E0030FCAA50D5'; must not contain '.'.
                    // Set the feature class name
                    select.SetFeatureClassName(System.IO.Path.GetFileNameWithoutExtension(filename));

                    // Execute the Select command
                    using (IFeatureReader reader = select.Execute())
                    {
                        DataTable table = new DataTable();
                        PrepareGrid(table, reader);

                        // Read the features
                        try
                        {
                            while (reader.ReadNext())
                            {
                                ProcessSQLReader(table, reader);
                            }
                            return(table);
                        }
                        catch (OSGeo.FDO.Common.Exception ex)
                        {
                            throw ex;
                        }
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Gets all the coordinate systems in the database
        /// </summary>
        /// <returns></returns>
        public BindingList <CoordinateSystemDefinition> GetAllProjections()
        {
            if (_Projections != null)
            {
                return(_Projections);
            }

            _Projections = new BindingList <CoordinateSystemDefinition>();
            using (var conn = CreateSqliteConnection())
            {
                LoggingService.InfoFormatted("Loading all Coordinate Systems from {0}", dbpath);
                conn.Open();
                string name = string.Empty;
                string desc = string.Empty;
                string wkt  = string.Empty;

                using (ISelect select = (ISelect)conn.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType_Select))
                {
                    select.SetFeatureClassName("Projections");
                    using (var reader = select.Execute())
                    {
                        while (reader.ReadNext())
                        {
                            name = reader.GetString("Name");
                            desc = reader.GetString("Description");
                            wkt  = reader.GetString("WKT");
                            _Projections.Add(new CoordinateSystemDefinition(name, desc, wkt));
                        }
                        reader.Close();
                    }
                }
                conn.Close();
            }

            return(_Projections);
        }