Beispiel #1
0
        void PostGISDataset_ConnectionStringChanged(gView.Framework.OGC.DB.OgcSpatialDataset sender, string provider)
        {
            try
            {
                _factory = Npgsql.NpgsqlFactory.Instance;

                #region Version
                try
                {
                    object obj = base.ExecuteFunction("select postgis_version()");
                    if (obj is string)
                    {
                        if (obj.ToString().StartsWith("2."))
                        {
                            _majorVersion = 2;
                        }
                        else
                        {
                            _majorVersion = 1;
                        }
                    }
                }
                catch
                {
                    _majorVersion = 1;
                }
                #endregion
            }
            catch
            {
                _factory = null;
            }
        }
Beispiel #2
0
        void PostGISDataset_ConnectionStringChanged(gView.Framework.OGC.DB.OgcSpatialDataset sender, string provider)
        {
            try
            {
                _connectionString = DbConnectionString.ParseNpgsqlConnectionString(_connectionString);
                _factory          = Npgsql.NpgsqlFactory.Instance;

                #region Version

                try
                {
                    object obj = base.ExecuteFunction("select postgis_version()");
                    if (obj is string)
                    {
                        string version = obj.ToString();
                        if (!int.TryParse(version.Split('.')[0], out _majorVersion))
                        {
                            _majorVersion = 1;
                        }
                    }
                }
                catch
                {
                    _majorVersion = 1;
                }

                #endregion
            }
            catch
            {
                _factory = null;
            }
        }
Beispiel #3
0
        public IDataset2 EmptyCopy()
        {
            OgcSpatialDataset dataset = CreateInstance();

            dataset.ConnectionString = ConnectionString;
            dataset.Open();

            return(dataset);
        }
Beispiel #4
0
        async public Task <IDataset2> EmptyCopy()
        {
            OgcSpatialDataset dataset = CreateInstance();
            await dataset.SetConnectionString(ConnectionString);

            await dataset.Open();

            return(dataset);
        }
Beispiel #5
0
        void PostGISDataset_ConnectionStringChanged(gView.Framework.OGC.DB.OgcSpatialDataset sender, string provider)
        {
            try
            {
                switch (provider.ToLower())
                {
                case "odbc":
                    _factory = DbProviderFactories.GetFactory("System.Data.Odbc");
                    break;

                case "oledb":
                    _factory = DbProviderFactories.GetFactory("System.Data.OleDb");
                    break;

                default:
                    //_factory = DbProviderFactories.GetFactory("Npgsql");
                    _factory = Npgsql.NpgsqlFactory.Instance;
                    break;
                }

                #region Version
                try
                {
                    object obj = base.ExecuteFunction("select postgis_version()");
                    if (obj is string)
                    {
                        if (obj.ToString().StartsWith("2."))
                        {
                            _majorVersion = 2;
                        }
                        else
                        {
                            _majorVersion = 1;
                        }
                    }
                }
                catch
                {
                    _majorVersion = 1;
                }
                #endregion
            }
            catch
            {
                _factory = null;
            }
        }
Beispiel #6
0
        async public static Task <ISpatialReference> TrySelectSpatialReference(OgcSpatialDataset dataset, OgcSpatialFeatureclass fc)
        {
            try
            {
                DbCommand sridCommand = dataset.SelectSpatialReferenceIds(fc);
                if (sridCommand != null)
                {
                    using (DbConnection connection = dataset.ProviderFactory.CreateConnection())
                    {
                        connection.ConnectionString = dataset.ConnectionString;
                        sridCommand.Connection      = connection;
                        await connection.OpenAsync();

                        using (DbDataReader reader = await sridCommand.ExecuteReaderAsync())
                        {
                            while (await reader.ReadAsync())
                            {
                                object sridObj = reader["srid"];
                                if (sridObj != null && sridObj != DBNull.Value)
                                {
                                    int srid = Convert.ToInt32(sridObj);
                                    if (srid > 0)
                                    {
                                        var sRef = gView.Framework.Geometry.SpatialReference.FromID("epsg:" + srid.ToString());
                                        if (sRef != null)
                                        {
                                            return(sRef);
                                        }
                                    }
                                }
                            }
                        }

                        connection.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
            }
            return(null);
        }
Beispiel #7
0
        async public static Task <IFeatureClass> Create(OgcSpatialDataset dataset, DataRow geometry_columns_row)
        {
            var featureClass = new OgcSpatialFeatureclass(dataset, geometry_columns_row);

            featureClass._dataset = dataset;

            if (featureClass._dataset == null || geometry_columns_row == null)
            {
                return(featureClass);
            }

            try
            {
                featureClass._lastException = null;

                string schema = String.Empty;
                try
                {
                    if (!String.IsNullOrEmpty(featureClass._dataset.OgcDictionary("geometry_columns.f_table_schema")))
                    {
                        schema = geometry_columns_row[featureClass._dataset.OgcDictionary("geometry_columns.f_table_schema")].ToString();
                    }
                    if (!String.IsNullOrEmpty(schema))
                    {
                        schema += ".";
                    }
                }
                catch { schema = ""; }
                featureClass._name       = schema + geometry_columns_row[featureClass._dataset.OgcDictionary("geometry_columns.f_table_name")].ToString();
                featureClass._shapefield = geometry_columns_row[featureClass._dataset.OgcDictionary("geometry_columns.f_geometry_column")].ToString();
                featureClass._idfield    = featureClass._dataset.OgcDictionary("gid");

                // Read Primary Key -> PostGIS id is not always "gid";
                string pKey = featureClass.GetPKey();
                if (!String.IsNullOrWhiteSpace(pKey) && !pKey.Equals(featureClass._idfield))
                {
                    featureClass._idfield = pKey;
                }

                featureClass._geometry_columns_type = geometry_columns_row[featureClass._dataset.OgcDictionary("geometry_columns.type")].ToString().ToUpper();
                switch (featureClass._geometry_columns_type)
                {
                case "MULTIPOLYGON":
                case "POLYGON":
                case "MULTIPOLYGONM":
                case "POLYGONM":
                    featureClass._geomType = geometryType.Polygon;
                    break;

                case "MULTILINESTRING":
                case "LINESTRING":
                case "MULTILINESTRINGM":
                case "LINESTRINGM":
                    featureClass._geomType = geometryType.Polyline;
                    break;

                case "POINT":
                case "POINTM":
                case "MULTIPOINT":
                case "MULTIPOINTM":
                    featureClass._geomType = geometryType.Point;
                    break;

                default:
                    featureClass._geomType = geometryType.Unknown;
                    break;
                }

                featureClass._hasZ = (int)geometry_columns_row[featureClass._dataset.OgcDictionary("geometry_columns.coord_dimension")] == 3;

                try
                {
                    int srid = int.Parse(geometry_columns_row[featureClass._dataset.OgcDictionary("geometry_columns.srid")].ToString());
                    if (srid > 0)
                    {
                        featureClass._sRef = gView.Framework.Geometry.SpatialReference.FromID("epsg:" + srid.ToString());
                    }
                    else
                    {
                        featureClass._sRef = await TrySelectSpatialReference(dataset, featureClass);
                    }
                }
                catch { }
                await featureClass.ReadSchema();
            }
            catch (Exception ex)
            {
                featureClass._lastException = ex;
                string msg = ex.Message;
            }

            return(featureClass);
        }
Beispiel #8
0
 private OgcSpatialFeatureclass(OgcSpatialDataset dataset, DataRow geometry_columns_row)
 {
 }
Beispiel #9
0
        public OgcSpatialFeatureclass(OgcSpatialDataset dataset, DataRow geometry_columns_row)
        {
            _dataset = dataset;

            if (_dataset == null || geometry_columns_row == null)
            {
                return;
            }
            try
            {
                _lastException = null;

                _name       = geometry_columns_row[_dataset.OgcDictionary("geometry_columns.f_table_name")].ToString();
                _shapefield = geometry_columns_row[_dataset.OgcDictionary("geometry_columns.f_geometry_column")].ToString();
                _idfield    = _dataset.OgcDictionary("gid");

                _geometry_columns_type = geometry_columns_row[_dataset.OgcDictionary("geometry_columns.type")].ToString().ToUpper();
                switch (_geometry_columns_type)
                {
                case "MULTIPOLYGON":
                case "POLYGON":
                case "MULTIPOLYGONM":
                case "POLYGONM":
                    _geomType = geometryType.Polygon;
                    break;

                case "MULTILINESTRING":
                case "LINESTRING":
                case "MULTILINESTRINGM":
                case "LINESTRINGM":
                    _geomType = geometryType.Polyline;
                    break;

                case "POINT":
                case "POINTM":
                    _geomType = geometryType.Point;
                    break;

                default:
                    _geomType = geometryType.Unknown;
                    break;
                }

                _hasZ = (int)geometry_columns_row[_dataset.OgcDictionary("geometry_columns.coord_dimension")] == 3;

                try
                {
                    int srid = int.Parse(geometry_columns_row[_dataset.OgcDictionary("geometry_columns.srid")].ToString());
                    if (srid > 0)
                    {
                        _sRef = gView.Framework.Geometry.SpatialReference.FromID("epsg:" + srid.ToString());
                    }
                    else
                    {
                        _sRef = TrySelectSpatialReference(dataset, this);
                    }
                }
                catch { }
                ReadSchema();
            }
            catch (Exception ex)
            {
                _lastException = ex;
                string msg = ex.Message;
            }
        }