public FeatureRuntimeCompilationMiddleware(RequestDelegate next, IFeatureUpdater featureUpdater,
                                            ILogger <FeatureRuntimeCompilationMiddleware> logger)
 {
     _next           = next;
     _logger         = logger;
     _featureUpdater = featureUpdater;
 }
示例#2
0
 public FeatureRuntimeCompilationWatcher(IFeatureMetadataProvider metadataProvider,
                                         IFeatureUpdater featureUpdater, ILogger <FeatureRuntimeCompilationWatcher> logger)
 {
     _metadataProvider = metadataProvider;
     _featureUpdater   = featureUpdater;
     _logger           = logger;
 }
示例#3
0
        async private Task <int> CopyFeatures(IFeatureCursor fCursor, long NID, IFeatureUpdater fdb, IFeatureClass dest, FieldTranslation fTrans, int featcounter)
        {
            IFeature feat;

            List <IFeature> features = new List <IFeature>();

            while ((feat = await fCursor.NextFeature()) != null)
            {
                if (!_cancelTracker.Continue)
                {
                    break;
                }

                feat.Fields.Add(new FieldValue("$FDB_NID", NID));

                if (_transformer != null)
                {
                    feat.Shape = _transformer.Transform2D(feat.Shape) as IGeometry;
                }

                if (fTrans != null)
                {
                    fTrans.RenameFields(feat);
                }
                features.Add(feat);
                if (features.Count >= this.FeatureBufferSize)
                {
                    if (!await fdb.Insert(dest, features))
                    {
                        _errMsg = "Fatal error: destdb insert failed...\n" + fdb.LastErrorMessage;
                        return(-1);
                    }
                    features.Clear();
                }
                featcounter++;
                if ((featcounter % this.FeatureBufferSize) == 0 && ReportProgress != null)
                {
                    ReportProgress(this, featcounter);
                }
            }

            if (features.Count > 0 && _cancelTracker.Continue)
            {
                if (!await fdb.Insert(dest, features))
                {
                    _errMsg = "Fatal error: destdb insert failed...\n" + fdb.LastErrorMessage;
                    return(-1);
                }
                features.Clear();
            }

            return(featcounter);
        }
示例#4
0
        async private Task <bool> CopyFeatures2(IFeatureClass source, IFeatureUpdater fdb, IFeatureClass dest, FieldTranslation fTrans, BinaryTree2Builder treeBuilder)
        {
            List <BinaryTree2BuilderNode> nodes;

            if (treeBuilder == null || (nodes = treeBuilder.Nodes) == null)
            {
                _errMsg = "Spatial Index is not defined...";
                return(false);
            }

            if (ReportAction != null)
            {
                ReportAction(this, "Copy Features (" + dest.Name + ")");
            }
            int featcounter = 0;

            foreach (BinaryTree2BuilderNode node in nodes)
            {
                if (!_cancelTracker.Continue)
                {
                    break;
                }

                RowIDFilter filter = new RowIDFilter(source.IDFieldName);
                filter.IDs       = node.OIDs;
                filter.SubFields = "*";

                using (IFeatureCursor fCursor = await source.GetFeatures(filter))
                {
                    if (fCursor == null)
                    {
                        _errMsg = "Fatal error: sourcedb query failed...";
                        return(false);
                    }

                    int copycounter = await CopyFeatures(fCursor, node.Number, fdb, dest, fTrans, featcounter);

                    if (copycounter < 0)
                    {
                        fCursor.Dispose();
                        return(false);
                    }
                    featcounter = copycounter;

                    fCursor.Dispose();
                }
            }
            if (ReportProgress != null)
            {
                ReportProgress(this, featcounter);
            }
            return(true);
        }
示例#5
0
        private static async Task <bool> Store(IFeatureUpdater featureUpdater, IFeatureClass fc, List <IFeature> featureBag, int counter)
        {
            Console.Write($"...{ counter }");

            if (!await featureUpdater.Insert(fc, featureBag))
            {
                throw new Exception($"Unable to insert features: { featureUpdater.LastErrorMessage }");
            }

            featureBag.Clear();

            return(true);
        }
示例#6
0
        private bool CopyFeatures(IFeatureClass source, IFeatureUpdater fdb, IFeatureClass dest, FieldTranslation fTrans, DualTree tree)
        {
            if (tree == null || tree.Nodes == null)
            {
                _errMsg = "Spatial Index is not defined...";
                return(false);
            }

            if (ReportAction != null)
            {
                ReportAction(this, "Copy Features (" + dest.Name + ")");
            }
            int featcounter = 0;

            foreach (SpatialIndexNode node in tree.Nodes)
            {
                if (!_cancelTracker.Continue)
                {
                    break;
                }

                RowIDFilter filter = new RowIDFilter(source.IDFieldName);
                filter.IDs       = node.IDs;
                filter.SubFields = "*";

                using (IFeatureCursor fCursor = source.GetFeatures(filter))
                {
                    if (fCursor == null)
                    {
                        _errMsg = "Fatal error: sourcedb query failed...";
                        return(false);
                    }
                    if (!CopyFeatures(fCursor, node.NID, fdb, dest, fTrans, ref featcounter))
                    {
                        fCursor.Dispose();
                        return(false);
                    }
                    fCursor.Dispose();
                }
            }
            if (ReportProgress != null)
            {
                ReportProgress(this, featcounter);
            }
            return(true);
        }
        async private Task SearchImages(IFeatureUpdater fdb, IFeatureClass rasterFC, DirectoryInfo di, Dictionary <string, Guid> providers)
        {
            if (!_cancelTracker.Continue)
            {
                return;
            }

            if (ReportAction != null)
            {
                ReportAction(this, "Scan Directory: " + di.FullName);
            }

            foreach (string filter in _formats)
            {
                int count = 0;
                foreach (FileInfo fi in di.GetFiles("*." + filter))
                {
                    if (_cancelTracker != null && !_cancelTracker.Continue)
                    {
                        return;
                    }

                    if (await InsertImage(fdb, rasterFC, fi, providers))
                    {
                        count++;
                    }

                    if (!_cancelTracker.Continue)
                    {
                        return;
                    }
                }
            }
            foreach (DirectoryInfo sub in di.GetDirectories())
            {
                await SearchImages(fdb, rasterFC, sub, providers);
            }
        }
示例#8
0
        private bool InsertImage(IFeatureUpdater fdb, IFeatureClass rasterFC, FileInfo fi, Dictionary <string, Guid> providers)
        {
            if (!_cancelTracker.Continue)
            {
                _errMsg = "Canceled by user...";
                return(false);
            }

            if (ReportAction != null)
            {
                ReportAction(this, "Insert Image: " + fi.FullName);
            }
            if (ReportProgress != null)
            {
                ReportProgress(this, 1);
            }

            System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Jpeg;
            switch (fi.Extension.ToLower())
            {
            case ".png":
                format = System.Drawing.Imaging.ImageFormat.Png;
                break;

            case ".tif":
            case ".tiff":
                format = System.Drawing.Imaging.ImageFormat.Tiff;
                break;
            }

            #region RasterFileDataset bestimmen
            List <IRasterFileDataset> rFileDatasets = new List <IRasterFileDataset>();
            IRasterFileDataset        rFileDataset  = null;
            IRasterLayer  rasterLayer = null;
            PlugInManager compMan     = new PlugInManager();
            foreach (XmlNode ds in compMan.GetPluginNodes(Plugins.Type.IDataset))
            {
                IRasterFileDataset rds = compMan.CreateInstance(ds) as IRasterFileDataset;
                if (rds == null)
                {
                    continue;
                }

                if (rds.SupportsFormat(fi.Extension) < 0)
                {
                    continue;
                }
                if (providers != null && providers.ContainsKey(fi.Extension.ToLower()))
                {
                    if (!providers[fi.Extension.ToLower()].Equals(PlugInManager.PlugInID(rds)))
                    {
                        continue;
                    }
                }
                rFileDatasets.Add(rds);
            }
            if (rFileDatasets.Count == 0)
            {
                _errMsg = "No Rasterfile Provider for " + fi.Extension;
                return(false);
            }

            // RasterFileDataset nach priorität sortieren
            rFileDatasets.Sort(new RasterFileDatasetComparer(fi.Extension));

            // RasterFileDataset suchen, mit dem sich Bild öffnen läßt
            foreach (IRasterFileDataset rfd in rFileDatasets)
            {
                rfd.AddRasterFile(fi.FullName);

                if (rfd.Elements.Count == 0)
                {
                    //Console.WriteLine(_errMsg = fi.FullName + " is not a valid Raster File...");
                    continue;
                }
                IDatasetElement element = rfd.Elements[0];
                if (!(element is IRasterLayer))
                {
                    //Console.WriteLine(_errMsg = fi.FullName + " is not a valid Raster Layer...");
                    rFileDataset.Dispose();
                    continue;
                }

                // gefunden...
                rasterLayer  = (IRasterLayer)element;
                rFileDataset = rfd;
                break;
            }
            if (rasterLayer == null || rFileDataset == null)
            {
                Console.WriteLine(_errMsg = fi.FullName + " is not a valid Raster Layer...");
                return(false);
            }
            #endregion

            FileInfo fiWorld = null;
            double   cellX   = 1;
            double   cellY   = 1;

            IRasterFile rasterFile = null;
            if (rasterLayer is IRasterFile)
            {
                rasterFile = (IRasterFile)rasterLayer;
            }
            if (rasterLayer.RasterClass != null)
            {
                if (rasterLayer.RasterClass is IRasterFile &&
                    ((IRasterFile)rasterLayer.RasterClass).WorldFile != null)
                {
                    rasterFile = (IRasterFile)rasterLayer.RasterClass;
                }
                else
                {
                    IRasterClass c = (IRasterClass)rasterLayer.RasterClass;
                    cellX = Math.Sqrt(c.dx1 * c.dx1 + c.dx2 * c.dx2);
                    cellY = Math.Sqrt(c.dy1 * c.dy1 + c.dy2 * c.dy2);
                }
            }
            if (rasterFile != null)
            {
                try
                {
                    IRasterWorldFile world = rasterFile.WorldFile;
                    if (world != null)
                    {
                        if (!world.isGeoReferenced)
                        {
                            if (handleNonGeorefAsError)
                            {
                                _errMsg = "Can't add non georeferenced images: " + fi.FullName;
                                return(false);
                            }
                            else
                            {
                                return(true);
                            }
                        }

                        cellX = Math.Sqrt(world.dx_X * world.dx_X + world.dx_Y * world.dx_Y);
                        cellY = Math.Sqrt(world.dy_X * world.dy_X + world.dy_Y * world.dy_Y);

                        fiWorld = new FileInfo(rasterFile.WorldFile.Filename);
                        if (!fiWorld.Exists)
                        {
                            fiWorld = null;
                        }
                    }
                }
                catch
                {
                    fiWorld = null;
                }
            }

            #region Check if already Exits
            //
            // Suchen, ob Image mit gleichen Pfad schon vorhanden ist, wenn ja
            // nur weitermachen, wenn sich das änderungsdatum unterscheidet...
            //

            QueryFilter filter = new QueryFilter();
            filter.AddField("FDB_OID");
            filter.AddField("PATH");
            filter.AddField("LAST_MODIFIED");
            filter.AddField("PATH2");
            filter.AddField("LAST_MODIFIED2");

            string fullName = fi.FullName.Replace(@"\", @"\\");
            if (_fdb is AccessFDB)
            {
                filter.WhereClause = ((AccessFDB)_fdb).DbColName("PATH") + "='" + fullName + "'";
            }
            else
            {
                filter.WhereClause = "PATH='" + fullName + "'";
            }
            int deleteOID = -1;
            using (IFeatureCursor cursor = rasterFC.GetFeatures(filter))
            {
                IFeature existingFeature = cursor.NextFeature;
                if (existingFeature != null)
                {
                    DateTime dt1 = (DateTime)existingFeature["LAST_MODIFIED"];
                    if (Math.Abs(((TimeSpan)(dt1 - fi.LastWriteTimeUtc)).TotalSeconds) > 1.0)
                    {
                        deleteOID = existingFeature.OID;
                    }
                    else if (fiWorld != null &&
                             existingFeature["PATH2"] != System.DBNull.Value &&
                             existingFeature["PATH2"].ToString() != String.Empty)
                    {
                        DateTime dt2 = (DateTime)existingFeature["LAST_MODIFIED2"];
                        if (existingFeature["PATH2"].ToString().ToLower() != fiWorld.FullName.ToLower() ||
                            Math.Abs(((TimeSpan)(dt2 - fiWorld.LastWriteTimeUtc)).TotalSeconds) > 1.0)
                        {
                            deleteOID = existingFeature.OID;
                        }
                    }

                    if (deleteOID == -1)
                    {
                        Console.Write(".");
                        //Console.WriteLine(fi.FullName + " already exists...");
                        return(true);
                    }
                }
            }
            if (deleteOID != -1)
            {
                if (!fdb.Delete(rasterFC, deleteOID))
                {
                    Console.WriteLine(_errMsg = "Can't delete old record " + fi.FullName + "\n" + fdb.lastErrorMsg);
                    return(false);
                }
            }
            //
            ///////////////////////////////////////////////////////////////////
            //
            #endregion

            Feature feature = new Feature();
            feature.Shape = rasterLayer.RasterClass.Polygon;
            feature.Fields.Add(new FieldValue("PATH", fi.FullName));
            feature.Fields.Add(new FieldValue("LAST_MODIFIED", fi.LastWriteTimeUtc));
            if (fiWorld != null)
            {
                feature.Fields.Add(new FieldValue("PATH2", fiWorld.FullName));
                feature.Fields.Add(new FieldValue("LAST_MODIFIED2", fiWorld.LastWriteTimeUtc));
            }
            else
            {
                feature.Fields.Add(new FieldValue("PATH2", ""));
            }
            feature.Fields.Add(new FieldValue("RF_PROVIDER", PlugInManager.PlugInID(rFileDataset).ToString()));
            feature.Fields.Add(new FieldValue("MANAGED", _managed && (rasterLayer is IBitmap)));
            feature.Fields.Add(new FieldValue("FORMAT", fi.Extension.Replace(".", "")));
            feature.Fields.Add(new FieldValue("CELLX", cellX));
            feature.Fields.Add(new FieldValue("CELLY", cellY));
            feature.Fields.Add(new FieldValue("LEVELS", (_managed) ? Math.Max(_levels, 1) : 0));

            if (!fdb.Insert(rasterFC, feature))
            {
                Console.WriteLine("\nERROR@" + fi.FullName + ": " + fdb.lastErrorMsg);
            }
            else
            {
                if (_managed && (rasterLayer is IBitmap) && (fdb is SqlFDB))
                {
                    QueryFilter qfilter = new QueryFilter();
                    qfilter.SubFields = "FDB_OID";
                    if (_fdb is AccessFDB)
                    {
                        filter.WhereClause = ((AccessFDB)_fdb).DbColName("PATH") + "='" + fi.FullName + "'";
                    }
                    else
                    {
                        qfilter.WhereClause = "PATH='" + fi.FullName + "'";
                    }
                    IFeatureCursor cursor = ((SqlFDB)fdb).Query(rasterFC, qfilter);
                    if (cursor != null)
                    {
                        IFeature feat = cursor.NextFeature;
                        if (feat != null)
                        {
                            InsertImageDatasetBitmap(feat.OID, rasterLayer, _levels, format);
                        }
                        cursor.Dispose();
                    }
                }

                Console.WriteLine(">" + fi.FullName + " added...");
            }

            rFileDataset.Dispose();
            return(true);
        }
示例#9
0
        async private Task <bool> CopyFeatures(IFeatureClass source, IFeatureUpdater fdb, IFeatureClass dest, FieldTranslation fTrans, List <IQueryFilter> filters)
        {
            if (ReportAction != null)
            {
                ReportAction(this, "Copy Features (" + dest.Name + ")");
            }
            int featcounter = 0;

            List <IFeature> features = new List <IFeature>();

            if (filters == null || filters.Count == 0)
            {
                QueryFilter filter = new QueryFilter();
                filter.SubFields = "*";
                filters          = new List <IQueryFilter>();
                filters.Add(filter);
            }
            foreach (IQueryFilter filter in filters)
            {
                using (IFeatureCursor fCursor = await source.GetFeatures(filter))
                {
                    IFeature feature;
                    while ((feature = await fCursor.NextFeature()) != null)
                    {
                        if (!_cancelTracker.Continue)
                        {
                            break;
                        }

                        if (_transformer != null)
                        {
                            feature.Shape = _transformer.Transform2D(feature.Shape) as IGeometry;
                        }

                        if (fTrans != null)
                        {
                            fTrans.RenameFields(feature);
                        }
                        features.Add(feature);
                        if (features.Count >= this.FeatureBufferSize)
                        {
                            if (!await fdb.Insert(dest, features))
                            {
                                _errMsg = "Fatal error: destdb insert failed...\n" + fdb.LastErrorMessage;
                                return(false);
                            }
                            features.Clear();
                        }
                        featcounter++;
                        if ((featcounter % this.FeatureBufferSize) == 0 && ReportProgress != null)
                        {
                            ReportProgress(this, featcounter);
                        }
                    }
                    if (features.Count > 0 && _cancelTracker.Continue)
                    {
                        if (!await fdb.Insert(dest, features))
                        {
                            _errMsg = "Fatal error: destdb insert failed...\n" + fdb.LastErrorMessage;
                            return(false);
                        }
                        features.Clear();
                    }
                }
            }

            return(true);
        }
示例#10
0
        private bool CopyFeatures(IFeatureClass source, IFeatureUpdater fdb, IFeatureClass dest, FieldTranslation fTrans, List <IQueryFilter> filters)
        {
            if (filters == null)
            {
                QueryFilter filter = new QueryFilter();
                filter.SubFields = "*";

                filters = new List <IQueryFilter>();
                filters.Add(filter);
            }

            int             counter  = 0;
            List <IFeature> features = new List <IFeature>();

            foreach (IQueryFilter filter in filters)
            {
                using (IFeatureCursor cursor = source.GetFeatures(filter))
                {
                    IFeature feature;
                    while ((feature = cursor.NextFeature) != null)
                    {
                        if (fTrans != null)
                        {
                            fTrans.RenameFields(feature);
                        }
                        if (_transformer != null)
                        {
                            feature.Shape = _transformer.Transform2D(feature.Shape) as IGeometry;
                        }
                        features.Add(feature);
                        counter++;
                        if ((counter % this.FeatureBufferSize) == 0)
                        {
                            if (!fdb.Insert(dest, features))
                            {
                                _errMsg = "Fatal error: destdb insert failed...\n" + fdb.lastErrorMsg;
                                return(false);
                            }
                            features.Clear();
                            if (ReportProgress != null)
                            {
                                ReportProgress(this, counter);
                            }
                        }
                    }
                }
            }
            if (features.Count > 0)
            {
                if (!fdb.Insert(dest, features))
                {
                    _errMsg = "Fatal error: destdb insert failed...";
                    return(false);
                }
                features.Clear();
                if (ReportProgress != null)
                {
                    ReportProgress(this, counter);
                }
            }
            return(true);
        }