Пример #1
0
        /// <summary>
        /// Saves the given feature class to a SpatiaLite database
        /// </summary>
        /// <param name="fs"></param>
        /// <returns></returns>
        public async Task <bool> TrySaveSpatialClass(DotSpatial.Data.IFeatureSet fs)
        {
            SQLiteConnection conn;

            if (!TryOpen(out conn))
            {
                return(false);
            }

            using (conn)
            {
                Helper.SpatiaLiteHelper helper = new Helper.SpatiaLiteHelper();

                if (helper.CheckIfFeatureSetExists(conn, fs))
                {
                    this.ErrorMessage = "Unable to save spatial class: the class already exists in the dataset.";
                    return(false);
                }

                bool ok = false;
                await Task.Run(() =>
                {
                    ok = helper.TrySaveFeatureSet(conn, fs);
                });

                if (!ok)
                {
                    this.ErrorMessage = "Unable to save spatial class: " + helper.ErrorMessage;
                    return(false);
                }

                return(true);
            }
        }
Пример #2
0
        /// <summary>
        /// Loads a spatial dataset from the database.
        /// </summary>
        /// <param name="dataset"></param>
        /// <returns></returns>
        public bool TryLoadSpatialDataset(out List <IFeatureSet> dataset)
        {
            var theDataset = new List <IFeatureSet>();
            SQLiteConnection conn;

            if (!TryOpen(out conn))
            {
                dataset = null;
                return(false);
            }

            using (conn)
            {
                Helper.SpatiaLiteHelper helper = new Helper.SpatiaLiteHelper();

                var classInfo = helper.ListFeatureSets(conn);

                bool ok = true;
                foreach (var info in classInfo)
                {
                    DotSpatial.Data.IFeatureSet featureSet;
                    if (!helper.TryReadFeatureSet(conn, info, out featureSet))
                    {
                        this.ErrorMessage = string.Format("Unable to read feature set {0} from database: {1}", info.TableName, helper.ErrorMessage);
                        log.Error(this.ErrorMessage);
                        ok = false;
                        break;
                    }
                    featureSet.Name = info.TableName;
                    theDataset.Add(featureSet);
                }

                if (!ok)
                {
                    dataset = null;
                    return(false);
                }

                dataset = theDataset;
                return(true);
            }
        }