public IFeatureProvider ConstructSourceProvider(IGeometryServices geometryServices)
        {
            header("Construct PostGis source provider\n" +
                   "* Author Felix Obermaier 2009\n" +
                   "* Ingenieurgruppe IVV GmbH & Co. KG\n" +
                   "* http://www.ivv-aachen.de");

            string connectionString = GetValue(
                "Please enter the connection string for the source database file.",
                Settings.Default.SourceConnectionString);

            string schema = GetValue("Please enter the schema name",
                                     Settings.Default.SourceSchema);

            string tableName = GetValue("Please enter the table name.", null);

            _oidColumn = GetValue("Please enter the id column name.", null);

            string geometryColumn = GetValue("Please enter the geometry column name.", null);

            Type             type;
            PostGisDbUtility dbUtility = new PostGisDbUtility();

            using (IDbConnection conn = dbUtility.CreateConnection(connectionString))
            {
                using (IDbCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = string.Format("SELECT \"{0}\" FROM \"{1}\".\"{2}\" LIMIT 1;", _oidColumn, schema,
                                                    tableName);
                    cmd.CommandType = CommandType.Text;
                    conn.Open();
                    type = cmd.ExecuteScalar().GetType();
                }
            }

            _sourceProviderOidType = type;

            Type t           = typeof(PostGisProvider <>);
            Type specialized = t.MakeGenericType(type);

            _sourceProvider =
                (IFeatureProvider)
                Activator.CreateInstance(specialized,
                                         geometryServices.DefaultGeometryFactory,
                                         connectionString, schema, tableName,
                                         _oidColumn,
                                         geometryColumn,
                                         geometryServices.CoordinateTransformationFactory);
            _sourceProvider.Open();

            _sourceProvider.CoordinateTransformation =
                SetCoordinateTransfromation(_sourceProvider.OriginalSpatialReference);

            _sourceProvider.Open();

            return(_sourceProvider);
        }
        public IFeatureProvider ConstructSourceProvider(IGeometryServices geometryServices)
        {
            Console.WriteLine(
                "Please enter the connection string for the source server. Press Enter to use the following:");
            Console.WriteLine(Settings.Default.SourceConnectionString);

            string connectionString = Console.ReadLine();

            if (connectionString == "")
            {
                connectionString = Settings.Default.SourceConnectionString;
            }
            else
            {
                Settings.Default.SourceConnectionString = connectionString;
            }
            Settings.Default.Save();

            Console.WriteLine("Please enter the data tables' schema");
            string dtschema = Console.ReadLine();

            Console.WriteLine("Please enter the table name.");
            string tableName = Console.ReadLine();

            Console.WriteLine("Please enter the id column name. (CaSe sensitive)");
            _oidColumn = Console.ReadLine();
            Console.WriteLine("Please enter the geometry column name. (CaSe sensitive)");
            string geometryColumn = Console.ReadLine();

            Console.WriteLine("Please enter the SRID (e.g EPSG:4326)");
            string srid = Console.ReadLine();

            Type type;
            SqlServerDbUtility dbUtility = new SqlServerDbUtility();

            using (IDbConnection conn = dbUtility.CreateConnection(connectionString))
            {
                using (IDbCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = string.Format("SELECT TOP 1 [{0}] FROM [{1}].[{2}] ", _oidColumn, dtschema,
                                                    tableName);
                    cmd.CommandType = CommandType.Text;
                    conn.Open();
                    type = cmd.ExecuteScalar().GetType();
                }
            }

            Type t           = typeof(MsSqlServer2008Provider <>);
            Type specialized = t.MakeGenericType(type);

            _sourceProvider =
                (IFeatureProvider)
                Activator.CreateInstance(specialized, geometryServices[srid], connectionString, dtschema, tableName,
                                         _oidColumn, geometryColumn);
            _sourceProvider.Open();
            _sourceProviderOidType = type;
            return(_sourceProvider);
        }
        public void IProviderMethodsPassThroughAdapter()
        {
            MockRepository            mocks         = new MockRepository();
            IFeatureProvider          adapted       = mocks.CreateMock <IFeatureProvider>();
            ICoordinateTransformation transformStub =
                MockRepository.GenerateStub <ICoordinateTransformation>();
            Expression queryStub =
                MockRepository.GenerateStub <Expression>();
            Object objectStub =
                MockRepository.GenerateStub <Object>();
            IExtents extentsStub =
                MockRepository.GenerateStub <IExtents>();
            ICoordinateSystem coordinateSystemStub =
                MockRepository.GenerateStub <ICoordinateSystem>();

            using (mocks.Unordered())
            {
                adapted.Close();
                Expect.Call(adapted.ConnectionId)
                .Return("connectionid");
                adapted.CoordinateTransformation = transformStub;
                Expect.Call(adapted.CoordinateTransformation)
                .Return(transformStub);
                Expect.Call(adapted.ExecuteQuery(queryStub))
                .Return(objectStub);
                Expect.Call(adapted.GetExtents())
                .Return(extentsStub);
                Expect.Call(adapted.IsOpen)
                .Return(true);
                adapted.Open();
                Expect.Call(adapted.SpatialReference)
                .Return(coordinateSystemStub);
                //adapted.Srid = 1;
                Expect.Call(adapted.Srid)
                .Return("2");
            }
            mocks.ReplayAll();

            AsyncFeatureProviderAdapter adapter = new AsyncFeatureProviderAdapter(adapted);

            adapter.Close();
            Assert.Equal("connectionid", adapter.ConnectionId);
            adapter.CoordinateTransformation = transformStub;
            Assert.Same(transformStub, adapter.CoordinateTransformation);
            Assert.Same(objectStub, adapter.ExecuteQuery(queryStub));
            Assert.Same(extentsStub, adapter.GetExtents());
            Assert.True(adapter.IsOpen);
            adapter.Open();
            Assert.Same(coordinateSystemStub, adapter.SpatialReference);
            //adapter.Srid = 1;
            Assert.Equal("2", adapter.Srid);

            mocks.VerifyAll();
        }
예제 #4
0
        private void AddLayer()
        {
            using (ChooseDataSource choose = new ChooseDataSource())
            {
                if (choose.ShowDialog() == DialogResult.OK)
                {
                    IFeatureProvider prov = choose.Provider;
                    string           name = choose.ProviderName;

                    workQueue.AddWorkItem(
                        string.Format("Loading Datasource {0}", name),
                        delegate
                    {
                        GeometryLayer lyr =
                            new GeometryLayer(
                                name,
                                prov);
                        lyr.Features.IsSpatiallyIndexed = false;
                        prov.Open();


                        InvokeIfRequired(new Action(delegate
                        {
                            if (Map.Layers.Count == 0)
                            {
                                if (lyr.SpatialReference != null)
                                {
                                    Map.SpatialReference = lyr.SpatialReference;
                                }
                            }

                            Map.Layers.Insert(0, lyr);

                            lyr.Style = RandomStyle.RandomGeometryStyle();
                            //lyr.Style = setGeometryStyle(lyr);

                            if (Map.Layers.Count == 1)
                            {
                                mapViewControl1.Map = Map;

                                layersView1.Map = Map;
                                MapView.ZoomToExtents();
                            }
                        }));
                    }, EnableDisableCommandsRequiringLayers
                        ,
                        delegate(Exception ex) { MessageBox.Show(string.Format("An error occured\n{0}\n{1}", ex.Message, ex.StackTrace)); });
                }
            }
        }
예제 #5
0
        private void DoConversion(ProviderItem input, IEnumerable <ProcessorItem> processors, ProviderItem output)
        {
            using (IConfigureFeatureSource csource = (IConfigureFeatureSource)Activator.CreateInstance(input.Builder))
            {
                IFeatureProvider psource    = csource.ConstructSourceProvider(_geometryServices);
                Type             srcOidType = GetTypeParamsOfImplementedInterface(psource.GetType(), typeof(IFeatureProvider <>))[0];
                List <IProcessFeatureDataRecords> realProcessors = new List <IProcessFeatureDataRecords>();

                foreach (ProcessorItem pi in processors)
                {
                    realProcessors.Add((IProcessFeatureDataRecords)Activator.CreateInstance(pi.ProcessorType));
                }

                FeatureDataRecordProcessor processChain = null;

                foreach (IProcessFeatureDataRecords processor in realProcessors)
                {
                    processChain = Equals(processChain, null)
                                       ? processor.Processor
                                       : ((IEnumerable <IFeatureDataRecord> o, ref int i) =>
                                          processor.Processor(processChain(o, ref i), ref i));
                }

                processChain = processChain ??
                               new FeatureDataRecordProcessor((IEnumerable <IFeatureDataRecord> o, ref int i) => o);

                if (!psource.IsOpen)
                {
                    psource.Open();
                }

                FeatureQueryExpression exp         = csource.ConstructSourceQueryExpression();
                FeatureDataTable       sourceModel = psource.CreateNewTable();
                int index = sourceModel.Columns.IndexOf(sourceModel.PrimaryKey[0]);
                IEnumerable <IFeatureDataRecord> sourceRecords = processChain(psource.ExecuteFeatureQuery(exp), ref index);

                //jd: TODO: need to test what happens if the IFeatureDataRecord shape is changed by the processor chain

                IConvertData converter = null;

                /* Some Data Providers do not respect the oidType param passed in.
                 * For instance Shapefile will always be IWritableFeatureProvider<UInt32>
                 * so we need to make sure we can coerce OID values  */



                using (
                    IConfigureFeatureTarget ctarget =
                        (IConfigureFeatureTarget)Activator.CreateInstance(output.Builder))
                {
                    Type oidType = csource.OidType;



                    using (IWritableFeatureProvider ptarget =
                               ctarget.ConstructTargetProvider(oidType, sourceModel.GeometryFactory,
                                                               _geometryServices.CoordinateSystemFactory,
                                                               sourceModel))
                    {
                        if (!ptarget.IsOpen)
                        {
                            ptarget.Open();
                        }

                        converter = GetConverter(csource.OidType, ctarget.OidType, sourceModel.NewRow(), index, sourceModel.GeometryFactory);



                        Console.WriteLine("Beginning Import.");
                        List <FeatureDataRow> features = new List <FeatureDataRow>();
                        int count = 0;
                        foreach (IFeatureDataRecord fdr in sourceRecords)
                        {
                            try
                            {
                                features.Add(converter.ConvertRecord(fdr));
                                if (++count % 100 == 0)
                                {
                                    ptarget.Insert(features);
                                    features.Clear();
                                }
                            }
                            catch (GeometryInvalidException ex)
                            {
                                Console.WriteLine("An Error Occured : " + ex.Message);
                                continue;
                            }
                        }

                        if (features.Count > 0)
                        {
                            ptarget.Insert(features);
                        }

                        count += features.Count;

                        features = null;

                        ptarget.Close();
                        Console.WriteLine(string.Format("{0} records processed", count));

                        ctarget.PostImport();
                    }
                }
            }

            Console.WriteLine("Finished");
        }
        public IFeatureProvider ConstructSourceProvider(IGeometryServices geometryServices)
        {
            header("Construct PostGis source provider\n" +
                   "* Author Felix Obermaier 2009\n" +
                   "* Ingenieurgruppe IVV GmbH & Co. KG\n" +
                   "* http://www.ivv-aachen.de");

            string connectionString = GetValue(
                "Please enter the connection string for the source database file.",
                Settings.Default.SourceConnectionString);

            string schema = GetValue("Please enter the schema name",
                                     Settings.Default.SourceSchema);

            string tableName = GetValue("Please enter the table name.", null);

            _oidColumn = GetValue("Please enter the id column name.", null);

            string geometryColumn = GetValue("Please enter the geometry column name.", null);

            Type type;
            PostGisDbUtility dbUtility = new PostGisDbUtility();
            using (IDbConnection conn = dbUtility.CreateConnection(connectionString))
            {
                using (IDbCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = string.Format("SELECT \"{0}\" FROM \"{1}\".\"{2}\" LIMIT 1;", _oidColumn, schema,
                                                    tableName);
                    cmd.CommandType = CommandType.Text;
                    conn.Open();
                    type = cmd.ExecuteScalar().GetType();
                }
            }

            _sourceProviderOidType = type;

            Type t = typeof (PostGisProvider<>);
            Type specialized = t.MakeGenericType(type);

            _sourceProvider =
                (IFeatureProvider)
                Activator.CreateInstance(specialized,
                                         geometryServices.DefaultGeometryFactory,
                                         connectionString, schema, tableName,
                                         _oidColumn,
                                         geometryColumn,
                                         geometryServices.CoordinateTransformationFactory);
            _sourceProvider.Open();

            _sourceProvider.CoordinateTransformation =
                SetCoordinateTransfromation(_sourceProvider.OriginalSpatialReference);

            _sourceProvider.Open();

            return _sourceProvider;
        }
        public IFeatureProvider ConstructSourceProvider(IGeometryServices geometryServices)
        {
            Console.WriteLine(
                "Please enter the connection string for the source server. Press Enter to use the following:");
            Console.WriteLine(Settings.Default.SourceConnectionString);

            string connectionString = Console.ReadLine();
            if (connectionString == "")
                connectionString = Settings.Default.SourceConnectionString;
            else
                Settings.Default.SourceConnectionString = connectionString;
            Settings.Default.Save();

            Console.WriteLine("Please enter the data tables' schema");
            string dtschema = Console.ReadLine();
            Console.WriteLine("Please enter the table name.");
            string tableName = Console.ReadLine();
            Console.WriteLine("Please enter the id column name. (CaSe sensitive)");
            _oidColumn = Console.ReadLine();
            Console.WriteLine("Please enter the geometry column name. (CaSe sensitive)");
            string geometryColumn = Console.ReadLine();
            Console.WriteLine("Please enter the SRID (e.g EPSG:4326)");
            string srid = Console.ReadLine();

            Type type;
            SqlServerDbUtility dbUtility = new SqlServerDbUtility();
            using (IDbConnection conn = dbUtility.CreateConnection(connectionString))
            {
                using (IDbCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = string.Format("SELECT TOP 1 [{0}] FROM [{1}].[{2}] ", _oidColumn, dtschema,
                                                    tableName);
                    cmd.CommandType = CommandType.Text;
                    conn.Open();
                    type = cmd.ExecuteScalar().GetType();
                }
            }

            Type t = typeof (MsSqlServer2008Provider<>);
            Type specialized = t.MakeGenericType(type);

            _sourceProvider =
                (IFeatureProvider)
                Activator.CreateInstance(specialized, geometryServices[srid], connectionString, dtschema, tableName,
                                         _oidColumn, geometryColumn);
            _sourceProvider.Open();
            _sourceProviderOidType = type;
            return _sourceProvider;
        }