public IFeatureProvider ConstructSourceProvider(IGeometryServices geometryServices)
        {
            header("Construct SpatiaLite2 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.",
                         Properties.Settings.Default.SourceConnectionString);

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

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

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

            _sourceProvider = new SpatiaLite2Provider(geometryServices.DefaultGeometryFactory,
                                                      connectionString, "main", tableName, _oidColumn, geometryColumn,
                                                      geometryServices.CoordinateTransformationFactory);

            Console.WriteLine(string.Format(
                                  "\nThe defined source provider serves shapes of the following type:\n{0}",
                                  _sourceProvider.ValidGeometryType.ToString()));

            _sourceProvider.CoordinateTransformation =
                SetCoordinateTransfromation(_sourceProvider.OriginalSpatialReference);

            _sourceProvider.Open();

            return(_sourceProvider);
        }
        public IWritableFeatureProvider ConstructTargetProvider(Type oidType, IGeometryFactory geometryFactory,
                                                                ICoordinateSystemFactory csFactory,
                                                                FeatureDataTable schemaTable)
        {
            header("Construct SpatiaLite2 target 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 target database file.\nRemember 'Connection Timeout=0' for large datasets.", Properties.Settings.Default.TargetConnectionString);

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

            SpatiaLite2ShapeType shapeType = GetShapeType();

            SpatiaLite2IndexType spatialIndex = GetSpatialIndex();

            SpatiaLite2Provider.CreateDataTable(schemaTable, tableName,
                                                connectionString, SpatiaLite2Provider.DefaultGeometryColumnName,
                                                shapeType, spatialIndex);

            _targetProvider = new SpatiaLite2Provider(geometryFactory, connectionString, tableName);

            _targetProvider.Open();
            return(_targetProvider);
        }
        public void T04_InsertInDataSource()
        {
            SpatiaLite2Provider prov = new SpatiaLite2Provider(
                _geometryFactory, @"Data Source=test.sqlite", "TestFeatureDataTable");

            GeometryLayer gl = new GeometryLayer("test", prov);

            gl.Select(new AllAttributesExpression());
            gl.Features.AcceptChanges();

            FeatureDataRow fdr = gl.Features.NewRow();

            fdr[0]       = 999;
            fdr.Geometry = gl.GeometryFactory.WktReader.Read("POINT (-2 13)");
            fdr[1]       = fdrLabel(fdr);
            gl.Features.AddRow(fdr);

            prov.Insert(gl.Features.GetChanges());

            //gl.SelectedFilter = new FeatureQueryExpression(
            //    new AttributeBinaryExpression(
            //        new PropertyNameExpression("OID"),
            //        BinaryOperator.Equals,
            //        (Int64)999));
            //Assert.AreEqual(5, gl.SelectedFeatures.Count);

            fdr = gl.Features.Find(999);
            Assert.IsNotNull(fdr);
        }
Exemplo n.º 4
0
        public void TestSqLite()
        {
            GeometryServices services = new GeometryServices();

            SpatiaLite2Provider search = new SpatiaLite2Provider(services.DefaultGeometryFactory,
                                                                 ConfigurationManager.ConnectionStrings["sqLite"].
                                                                 ConnectionString,
                                                                 "main",
                                                                 "regions", "OID", "XGeometryX");

            search.SpatiaLiteIndexType = SpatiaLite2IndexType.MBRCache;

            BinaryExpression binaryExpression =
                new BinaryExpression(new PropertyNameExpression("VHG5"),
                                     BinaryOperator.GreaterThan, new LiteralExpression <int>(6));

            ProviderPropertiesExpression providerProps =
                new ProviderPropertiesExpression(
                    new ProviderPropertyExpression[] { });


            ProviderQueryExpression prov = new ProviderQueryExpression(providerProps, new AllAttributesExpression(),
                                                                       binaryExpression);

            object obj = search.ExecuteQuery(prov);

            Assert.IsNotNull(obj);
        }
Exemplo n.º 5
0
        private bool EnsureConnection()
        {
            bool          ok      = true;
            StringBuilder message = new StringBuilder();

            if (string.IsNullOrEmpty(tbPath.Text))
            {
                message.AppendLine("Please specifiy path to SpatiaLite database file");
                ok = false;
            }

            if (!ok)
            {
                MessageBox.Show(message.ToString(), "Errors", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(ok);
            }

            try
            {
                ok = SpatiaLite2Provider.IsSpatiallyEnabled(ServerConnectionString);
            }
            catch (SpatiaLite2Exception ex)
            {
                ok = false;
                message.AppendFormat("Error connection to server {0}", ex.Message);
            }

            if (!ok)
            {
                MessageBox.Show(message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(ok);
        }
        public void T02_CreateGeometryLayerFromSpatiaLite2()
        {
            SpatiaLite2Provider prov = new SpatiaLite2Provider(
                _geometryFactory, @"Data Source=test.sqlite", "TestFeatureDataTable");

            SharpMap.Layers.GeometryLayer gl = new SharpMap.Layers.GeometryLayer("test", prov);
            Assert.IsNotNull(gl);
            Assert.AreEqual("test", gl.LayerName);
            Assert.AreEqual(prov.Srid, gl.Srid);
        }
        public void T03_MultipleSelects()
        {
            SpatiaLite2Provider prov = new SpatiaLite2Provider(
                _geometryFactory, @"Data Source=test.sqlite", "TestFeatureDataTable");
            GeometryLayer gl = new GeometryLayer("test", prov);

            gl.Select(new AllAttributesExpression());
            gl.Features.AcceptChanges();
            Assert.AreEqual(4, gl.Features.FeatureCount);
            Assert.AreEqual(_geometryFactory.CreateExtents2D(0, -3, 15, 20), gl.Features.Extents);

            gl = new GeometryLayer(prov);
            gl.Select(
                new SpatialBinaryExpression(
                    new ExtentsExpression(prov.GeometryFactory.CreateExtents2D(-1, -1, 1, 1)),
                    SpatialOperation.Contains,
                    new ThisExpression())
                );
            Assert.AreEqual(1, gl.Features.Rows.Count);

            gl = new GeometryLayer(prov);
            gl.Select(
                new SpatialBinaryExpression(
                    new GeometryExpression(prov.GeometryFactory.WktReader.Read(("POLYGON((-1 -1, 0 1, 1 1, -1 -1))"))),
                    SpatialOperation.Contains,
                    new ThisExpression())
                );
            Assert.AreEqual(1, gl.Features.Rows.Count);

            gl = new GeometryLayer(prov);
            gl.Select(
                new SpatialBinaryExpression(
                    new GeometryExpression(prov.GeometryFactory.WktReader.Read(("POLYGON((-1 -1, -1 1, 0 1, 0 -1, -1 -1))"))),
                    SpatialOperation.Touches,
                    new ThisExpression())
                );
            Assert.AreEqual(1, gl.Features.Rows.Count, 1);

            gl = new GeometryLayer(prov);
            gl.Select(
                new SpatialBinaryExpression(
                    new ThisExpression(),
                    SpatialOperation.Within,
                    new GeometryExpression(prov.GeometryFactory.WktReader.Read(("POLYGON((-1 -1, 0 1, 1 1, -1 -1))"))))
                );
            Assert.AreEqual(0, gl.Features.Rows.Count);
        }
Exemplo n.º 8
0
        private bool GetTables()
        {
            if (!EnsureConnection())
            {
                return(false);
            }

            datasetTableAndColumns =
                SpatiaLite2Provider.GetSpatiallyEnabledTables(ServerConnectionString);

            if (datasetTableAndColumns == null)
            {
                return(false);
            }

            cbTables.Enabled       = true;
            cbTables.DataSource    = datasetTableAndColumns.Tables[0];
            cbTables.DisplayMember = "Label";
            cbTables.ValueMember   = "TableName";

            return(true);
        }
        public void T01_CreateTableFromFeatureDataTable()
        {
            FeatureDataTable fdt = createFeatureDataTable();

            SpatiaLite2Provider.CreateDataTable(fdt, @"Data Source=test.sqlite");

            SpatiaLite2Provider prov = new SpatiaLite2Provider(
                _geometryFactory, @"Data Source=test.sqlite",
                "main", fdt.TableName, fdt.PrimaryKey[0].ColumnName,
                SpatiaLite2Provider.DefaultGeometryColumnName);

            Assert.IsNotNull(prov);
            Assert.AreEqual(@"Data Source=test.sqlite", prov.ConnectionString);
            Assert.AreEqual("main", prov.TableSchema);
            Assert.AreEqual(fdt.TableName, prov.Table);
            Assert.AreEqual(SpatiaLite2Provider.DefaultSrid, prov.Srid);
            Assert.AreEqual(fdt.PrimaryKey[0].ColumnName, prov.OidColumn);
            Assert.AreEqual(SpatiaLite2Provider.DefaultGeometryColumnName, prov.GeometryColumn);

            Assert.IsTrue(prov.SpatiaLiteIndexType != SpatiaLite2IndexType.None);
            Assert.AreEqual(SpatiaLite2Provider.DefaultSpatiaLiteIndexType, prov.SpatiaLiteIndexType);
        }
        public void T05_DeleteFromDataSource()
        {
            SpatiaLite2Provider prov = new SpatiaLite2Provider(
                _geometryFactory, @"Data Source=test.sqlite", "TestFeatureDataTable");

            GeometryLayer gl = new GeometryLayer(prov);

            gl.Select(new SpatialBinaryExpression(
                          new ExtentsExpression(prov.GetExtents()), SpatialOperation.Contains, new ThisExpression()));
            gl.Features.AcceptChanges();

            //gl.Features.RemoveRow(gl.Features[4]);
            FeatureDataRow fdr = gl.Features.Find(999);

            fdr.Delete();
            //prov.Delete(gl.Features.GetChanges(DataRowState.Deleted));
            gl.Features.AcceptChanges();

            gl = new GeometryLayer(prov);
            gl.Select(new SpatialBinaryExpression(
                          new ExtentsExpression(prov.GetExtents()), SpatialOperation.Contains, new ThisExpression()));
            gl.Features.AcceptChanges();
            //Assert.AreEqual(4, gl.Features.Rows.Count);
        }
        public void T11_JD_Test()
        {
            //return;
            var search = new SpatiaLite2Provider(_geometryFactory,
                                                  @"Data Source=C:\VENUS\CodePlex\sharpMap\SharpMap\TestData\VRS2386_V11.sqlite", "main",
                                                  "regions", "OID", "XGeometryX");

            //search.SpatiaLiteIndexType = SpatiaLite2_IndexType.MBRCache;

            var binaryExpression =
                new BinaryExpression(new PropertyNameExpression("VHG5"),
                                     BinaryOperator.GreaterThan, new LiteralExpression<int>(6));

            var columns = new string[] { "Einwohner" };

            search.DefaultProviderProperties = 
                new ProviderPropertiesExpression(
                        new ProviderPropertyExpression[] { new AttributesCollectionExpression( columns ) }
                    );

            var prov = new ProviderQueryExpression(
                (ProviderPropertiesExpression)null, 
                new AllAttributesExpression(), 
                binaryExpression);

            object obj = search.ExecuteQuery(prov);

            Assert.IsNotNull(obj);
            SharpMap.Data.Providers.Db.SpatialDbFeatureDataReader sfdr = obj as SharpMap.Data.Providers.Db.SpatialDbFeatureDataReader;
            Assert.IsNotNull(sfdr);
            Int64 numRows = 0;

            DateTime start = DateTime.Now;
            while (sfdr.Read())
                numRows++;
            DateTime end = DateTime.Now;
            System.Diagnostics.Debug.WriteLine(end.Subtract(start).ToString());

            search.DefaultProviderProperties = null;

            obj = search.ExecuteQuery(prov);
            sfdr = obj as SharpMap.Data.Providers.Db.SpatialDbFeatureDataReader;
            Assert.IsTrue(numRows > 1);
            start = DateTime.Now;
            while (sfdr.Read())
                numRows++;
            end = DateTime.Now;
            System.Diagnostics.Debug.WriteLine(end.Subtract(start).ToString());

            var providerProps =
                new ProviderPropertiesExpression(
                    new ProviderPropertyExpression[]
                        {
                            new OrderByCollectionExpression(
                                new OrderByExpression("Einwohner", System.Data.SqlClient.SortOrder.Descending)),
                            new DataPageSizeExpression(10),
                            new DataPageNumberExpression(5) 

                        });
            var ape = new AttributesProjectionExpression(new String[]{"OID" ,"Einwohner", "Erwerbstätige", "Beschäftigte"});

            prov = new ProviderQueryExpression(providerProps, ape, null);

            sfdr = search.ExecuteQuery(prov) as SharpMap.Data.Providers.Db.SpatialDbFeatureDataReader;
            Assert.IsNotNull(sfdr);
            numRows = 0;
            while (sfdr.Read()) numRows++;
            Assert.AreEqual(10, numRows);
            Assert.AreEqual(4, sfdr.FieldCount);
        }
        public void T04_InsertInDataSource()
        {
            SpatiaLite2Provider prov = new SpatiaLite2Provider(
                _geometryFactory, @"Data Source=test.sqlite", "TestFeatureDataTable");

            GeometryLayer gl = new GeometryLayer("test", prov);
            gl.Select(new AllAttributesExpression());
            gl.Features.AcceptChanges();

            FeatureDataRow fdr = gl.Features.NewRow();

            fdr[0] = 999;
            fdr.Geometry = gl.GeometryFactory.WktReader.Read("POINT (-2 13)");
            fdr[1] = fdrLabel(fdr);
            gl.Features.AddRow(fdr);

            prov.Insert(gl.Features.GetChanges());

            //gl.SelectedFilter = new FeatureQueryExpression(
            //    new AttributeBinaryExpression(
            //        new PropertyNameExpression("OID"),
            //        BinaryOperator.Equals,
            //        (Int64)999));
            //Assert.AreEqual(5, gl.SelectedFeatures.Count);
            
            fdr = gl.Features.Find(999);
            Assert.IsNotNull(fdr);

        }
        public void T05_DeleteFromDataSource()
        {
            SpatiaLite2Provider prov = new SpatiaLite2Provider(
                _geometryFactory, @"Data Source=test.sqlite", "TestFeatureDataTable");
            
            GeometryLayer gl = new GeometryLayer(prov);
            gl.Select(new SpatialBinaryExpression(
                new ExtentsExpression(prov.GetExtents()), SpatialOperation.Contains, new ThisExpression()));
            gl.Features.AcceptChanges();

            //gl.Features.RemoveRow(gl.Features[4]);
            FeatureDataRow fdr = gl.Features.Find(999);
            fdr.Delete();
            //prov.Delete(gl.Features.GetChanges(DataRowState.Deleted));
            gl.Features.AcceptChanges();

            gl = new GeometryLayer(prov);
            gl.Select(new SpatialBinaryExpression(
                new ExtentsExpression(prov.GetExtents()), SpatialOperation.Contains, new ThisExpression()));
            gl.Features.AcceptChanges();
            //Assert.AreEqual(4, gl.Features.Rows.Count);

        }
        public void T03_MultipleSelects()
        {
            SpatiaLite2Provider prov = new SpatiaLite2Provider(
                _geometryFactory, @"Data Source=test.sqlite", "TestFeatureDataTable");
            GeometryLayer gl = new GeometryLayer("test", prov);

            gl.Select(new AllAttributesExpression());
            gl.Features.AcceptChanges();
            Assert.AreEqual(4, gl.Features.FeatureCount);
            Assert.AreEqual(_geometryFactory.CreateExtents2D(0,-3,15,20), gl.Features.Extents);

            gl = new GeometryLayer(prov);
            gl.Select(
                new SpatialBinaryExpression(
                    new ExtentsExpression(prov.GeometryFactory.CreateExtents2D(-1,-1,1,1)), 
                    SpatialOperation.Contains, 
                    new ThisExpression())
                    ); 
            Assert.AreEqual(1, gl.Features.Rows.Count);

            gl = new GeometryLayer(prov);
            gl.Select(
                new SpatialBinaryExpression(
                    new GeometryExpression(prov.GeometryFactory.WktReader.Read(("POLYGON((-1 -1, 0 1, 1 1, -1 -1))"))), 
                    SpatialOperation.Contains, 
                    new ThisExpression())
                    );
            Assert.AreEqual(1, gl.Features.Rows.Count);

            gl = new GeometryLayer(prov);
            gl.Select(
                new SpatialBinaryExpression(
                    new GeometryExpression(prov.GeometryFactory.WktReader.Read(("POLYGON((-1 -1, -1 1, 0 1, 0 -1, -1 -1))"))), 
                    SpatialOperation.Touches, 
                    new ThisExpression())
                    ); 
            Assert.AreEqual(1, gl.Features.Rows.Count, 1);

            gl = new GeometryLayer(prov);
            gl.Select(
                new SpatialBinaryExpression(
                    new ThisExpression(),
                    SpatialOperation.Within,
                    new GeometryExpression(prov.GeometryFactory.WktReader.Read(("POLYGON((-1 -1, 0 1, 1 1, -1 -1))"))))
                    );
            Assert.AreEqual(0, gl.Features.Rows.Count);

        }
        public void T02_CreateGeometryLayerFromSpatiaLite2()
        {
            SpatiaLite2Provider prov = new SpatiaLite2Provider(
                _geometryFactory, @"Data Source=test.sqlite", "TestFeatureDataTable");

            SharpMap.Layers.GeometryLayer gl = new SharpMap.Layers.GeometryLayer("test", prov);
            Assert.IsNotNull( gl );
            Assert.AreEqual("test", gl.LayerName);
            Assert.AreEqual(prov.Srid, gl.Srid);
        }
        public void T01_CreateTableFromFeatureDataTable()
        {
            FeatureDataTable fdt = createFeatureDataTable();
            SpatiaLite2Provider.CreateDataTable(fdt, @"Data Source=test.sqlite");

            SpatiaLite2Provider prov = new SpatiaLite2Provider(
                _geometryFactory, @"Data Source=test.sqlite", 
                "main", fdt.TableName, fdt.PrimaryKey[0].ColumnName, 
                SpatiaLite2Provider.DefaultGeometryColumnName);
            Assert.IsNotNull( prov );
            Assert.AreEqual(@"Data Source=test.sqlite", prov.ConnectionString);
            Assert.AreEqual("main", prov.TableSchema);
            Assert.AreEqual(fdt.TableName, prov.Table);
            Assert.AreEqual(SpatiaLite2Provider.DefaultSrid, prov.Srid);
            Assert.AreEqual(fdt.PrimaryKey[0].ColumnName, prov.OidColumn);
            Assert.AreEqual(SpatiaLite2Provider.DefaultGeometryColumnName, prov.GeometryColumn);

            Assert.IsTrue(prov.SpatiaLiteIndexType != SpatiaLite2IndexType.None);
            Assert.AreEqual(SpatiaLite2Provider.DefaultSpatiaLiteIndexType, prov.SpatiaLiteIndexType);

        }
Exemplo n.º 17
0
        public void TestSqLite()
        {
            GeometryServices services = new GeometryServices();

            SpatiaLite2Provider search = new SpatiaLite2Provider(services.DefaultGeometryFactory,
                                                                 ConfigurationManager.ConnectionStrings["sqLite"].
                                                                     ConnectionString,
                                                                 "main",
                                                                 "regions", "OID", "XGeometryX");
            search.SpatiaLiteIndexType = SpatiaLite2IndexType.MBRCache;

            BinaryExpression binaryExpression =
                new BinaryExpression(new PropertyNameExpression("VHG5"),
                                     BinaryOperator.GreaterThan, new LiteralExpression<int>(6));

            ProviderPropertiesExpression providerProps =
                new ProviderPropertiesExpression(
                    new ProviderPropertyExpression[] { });


            ProviderQueryExpression prov = new ProviderQueryExpression(providerProps, new AllAttributesExpression(),
                                                                       binaryExpression);

            object obj = search.ExecuteQuery(prov);

            Assert.IsNotNull(obj);
        }
        public void T11_JD_Test()
        {
            //return;
            var search = new SpatiaLite2Provider(_geometryFactory,
                                                 @"Data Source=C:\VENUS\CodePlex\sharpMap\SharpMap\TestData\VRS2386_V11.sqlite", "main",
                                                 "regions", "OID", "XGeometryX");

            //search.SpatiaLiteIndexType = SpatiaLite2_IndexType.MBRCache;

            var binaryExpression =
                new BinaryExpression(new PropertyNameExpression("VHG5"),
                                     BinaryOperator.GreaterThan, new LiteralExpression <int>(6));

            var columns = new string[] { "Einwohner" };

            search.DefaultProviderProperties =
                new ProviderPropertiesExpression(
                    new ProviderPropertyExpression[] { new AttributesCollectionExpression(columns) }
                    );

            var prov = new ProviderQueryExpression(
                (ProviderPropertiesExpression)null,
                new AllAttributesExpression(),
                binaryExpression);

            object obj = search.ExecuteQuery(prov);

            Assert.IsNotNull(obj);
            SharpMap.Data.Providers.Db.SpatialDbFeatureDataReader sfdr = obj as SharpMap.Data.Providers.Db.SpatialDbFeatureDataReader;
            Assert.IsNotNull(sfdr);
            Int64 numRows = 0;

            DateTime start = DateTime.Now;

            while (sfdr.Read())
            {
                numRows++;
            }
            DateTime end = DateTime.Now;

            System.Diagnostics.Debug.WriteLine(end.Subtract(start).ToString());

            search.DefaultProviderProperties = null;

            obj  = search.ExecuteQuery(prov);
            sfdr = obj as SharpMap.Data.Providers.Db.SpatialDbFeatureDataReader;
            Assert.IsTrue(numRows > 1);
            start = DateTime.Now;
            while (sfdr.Read())
            {
                numRows++;
            }
            end = DateTime.Now;
            System.Diagnostics.Debug.WriteLine(end.Subtract(start).ToString());

            var providerProps =
                new ProviderPropertiesExpression(
                    new ProviderPropertyExpression[]
            {
                new OrderByCollectionExpression(
                    new OrderByExpression("Einwohner", System.Data.SqlClient.SortOrder.Descending)),
                new DataPageSizeExpression(10),
                new DataPageNumberExpression(5)
            });
            var ape = new AttributesProjectionExpression(new String[] { "OID", "Einwohner", "Erwerbstätige", "Beschäftigte" });

            prov = new ProviderQueryExpression(providerProps, ape, null);

            sfdr = search.ExecuteQuery(prov) as SharpMap.Data.Providers.Db.SpatialDbFeatureDataReader;
            Assert.IsNotNull(sfdr);
            numRows = 0;
            while (sfdr.Read())
            {
                numRows++;
            }
            Assert.AreEqual(10, numRows);
            Assert.AreEqual(4, sfdr.FieldCount);
        }
Exemplo n.º 19
0
        public IFeatureProvider GetProvider()
        {
            if (EnsureTables())
            {
                string conn = ServerConnectionString;

                DataRowView drv       = (DataRowView)cbTables.SelectedItem;
                string      schema    = (string)drv["Schema"];
                string      tableName = (string)drv["TableName"];
                ;
                string geomColumn       = (string)drv["GeometryColumn"];
                int    coordDimension   = (int)(long)drv["Dimension"];
                string srid             = drv["SRID"].ToString();
                string spatialReference = drv["SpatialReference"] == DBNull.Value
                                              ?
                                          ""
                                              :
                                          (string)drv["SpatialReference"];

                GeometryServices gs = new GeometryServices();
                IGeometryFactory gf = gs[srid]; //, coordDimension];
                //if (!string.IsNullOrEmpty(spatialReference))
                //    gf.SpatialReference = gs.CoordinateSystemFactory.CreateFromWkt(spatialReference);

                string oidColumnName = (String)dgvColumns.Rows[oidcolumn].Cells[2].Value;

                List <String> columns = new List <string>();
                //List<OrderByExpression> orderby = new List<OrderByExpression>();
                foreach (DataGridViewRow dgvr in dgvColumns.Rows)
                {
                    if ((bool)dgvr.Cells["Include"].Value)
                    {
                        columns.Add((String)dgvr.Cells[2].Value);
                    }
                    //if (dgvr.Cells["SortOrder"].Value != null)
                    //    orderby.Add(new OrderByExpression((String) dgvr.Cells[1].Value,
                    //                                      (SortOrder) dgvr.Cells["SortOrder"].Value));
                }

                if (!columns.Contains(oidColumnName))
                {
                    columns.Insert(0, oidColumnName);
                }
                columns.Insert(1, geomColumn);

                ProviderPropertiesExpression ppe = null;

                //if (orderby.Count == 0)
                //{
                //    ppe = new ProviderPropertiesExpression(
                //        new ProviderPropertyExpression[]
                //            {
                //                new AttributesCollectionExpression(columns)
                //            });
                //}
                //else
                //{
                ppe = new ProviderPropertiesExpression(
                    new ProviderPropertyExpression[]
                {
                    //new OrderByCollectionExpression(orderby),
                    new AttributesCollectionExpression(columns)
                });
                //}

                IFeatureProvider prov =
                    new SpatiaLite2Provider(gf, conn, schema, tableName, oidColumnName, geomColumn,
                                            gs.CoordinateTransformationFactory)
                {
                    DefaultProviderProperties = ppe
                };

                //jd commented temporarily to get a build
                //((ISpatialDbProvider)prov).DefinitionQuery =
                //    new ProviderQueryExpression(ppe, ape, null);

                return(prov);
            }
            return(null);
        }
Exemplo n.º 20
0
        public IFeatureProvider GetProvider()
        {
            if (EnsureTables())
            {
                string conn = ServerConnectionString;

                DataRowView drv = (DataRowView) cbTables.SelectedItem;
                string schema = (string) drv["Schema"];
                string tableName = (string) drv["TableName"];
                ;
                string geomColumn = (string) drv["GeometryColumn"];
                int coordDimension = (int) (long) drv["Dimension"];
                string srid = drv["SRID"].ToString();
                string spatialReference = drv["SpatialReference"] == DBNull.Value
                                              ?
                                                  ""
                                              :
                                                  (string) drv["SpatialReference"];

                GeometryServices gs = new GeometryServices();
                IGeometryFactory gf = gs[srid]; //, coordDimension];
                //if (!string.IsNullOrEmpty(spatialReference))
                //    gf.SpatialReference = gs.CoordinateSystemFactory.CreateFromWkt(spatialReference);

                string oidColumnName = (String) dgvColumns.Rows[oidcolumn].Cells[2].Value;

                List<String> columns = new List<string>();
                //List<OrderByExpression> orderby = new List<OrderByExpression>();
                foreach (DataGridViewRow dgvr in dgvColumns.Rows)
                {
                    if ((bool) dgvr.Cells["Include"].Value) columns.Add((String) dgvr.Cells[2].Value);
                    //if (dgvr.Cells["SortOrder"].Value != null)
                    //    orderby.Add(new OrderByExpression((String) dgvr.Cells[1].Value,
                    //                                      (SortOrder) dgvr.Cells["SortOrder"].Value));
                }

                if (!columns.Contains(oidColumnName))
                    columns.Insert(0, oidColumnName);
                columns.Insert(1, geomColumn);

                ProviderPropertiesExpression ppe = null;

                //if (orderby.Count == 0)
                //{
                //    ppe = new ProviderPropertiesExpression(
                //        new ProviderPropertyExpression[]
                //            {
                //                new AttributesCollectionExpression(columns)
                //            });
                //}
                //else
                //{
                    ppe = new ProviderPropertiesExpression(
                        new ProviderPropertyExpression[]
                            {
                                //new OrderByCollectionExpression(orderby),
                                new AttributesCollectionExpression(columns)
                            });
                //}

                IFeatureProvider prov =
                    new SpatiaLite2Provider(gf, conn, schema, tableName, oidColumnName, geomColumn,
                                            gs.CoordinateTransformationFactory) {DefaultProviderProperties = ppe};

                //jd commented temporarily to get a build
                //((ISpatialDbProvider)prov).DefinitionQuery =
                //    new ProviderQueryExpression(ppe, ape, null);

                return prov;
            }
            return null;
        }
        public IFeatureProvider ConstructSourceProvider(IGeometryServices geometryServices)
        {
            header( "Construct SpatiaLite2 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.",
                         Properties.Settings.Default.SourceConnectionString);

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

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

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

            _sourceProvider = new SpatiaLite2Provider(geometryServices.DefaultGeometryFactory,
                connectionString, "main", tableName, _oidColumn, geometryColumn,
                geometryServices.CoordinateTransformationFactory);

            Console.WriteLine(string.Format(
                "\nThe defined source provider serves shapes of the following type:\n{0}",
                _sourceProvider.ValidGeometryType.ToString()));

            _sourceProvider.CoordinateTransformation = 
                SetCoordinateTransfromation(_sourceProvider.OriginalSpatialReference);

            _sourceProvider.Open();

            return _sourceProvider;
        }
        public IWritableFeatureProvider ConstructTargetProvider(Type oidType, IGeometryFactory geometryFactory,
                                                                ICoordinateSystemFactory csFactory,
                                                                FeatureDataTable schemaTable)
        {

            header( "Construct SpatiaLite2 target 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 target database file.\nRemember 'Connection Timeout=0' for large datasets.",Properties.Settings.Default.TargetConnectionString);

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

            SpatiaLite2ShapeType shapeType = GetShapeType();

            SpatiaLite2IndexType spatialIndex = GetSpatialIndex();

            SpatiaLite2Provider.CreateDataTable(schemaTable, tableName, 
                connectionString, SpatiaLite2Provider.DefaultGeometryColumnName,
                shapeType, spatialIndex);

            _targetProvider = new SpatiaLite2Provider(geometryFactory, connectionString, tableName );

            _targetProvider.Open();
            return _targetProvider;
        }