コード例 #1
0
        async public Task <object> GetInstanceAsync()
        {
            if (_dataset != null)
            {
                _dataset.Dispose();
            }

            _dataset = new GeoJsonServiceDataset();
            await _dataset.SetConnectionString(_connectionString);

            await _dataset.Open();

            return(_dataset);
        }
コード例 #2
0
ファイル: ExplorerObjects.cs プロジェクト: jugstalt/gview5
        async public Task <object> GetInstanceAsync()
        {
            if (_dataset != null)
            {
                _dataset.Dispose();
            }

            _dataset = new MongoDbDataset();
            await _dataset.SetConnectionString(_connectionString);

            await _dataset.Open();

            ((MongoDbDataset)_dataset).BeforeCreateFeatureClass = BeforeCreateFeatureClass;

            return(_dataset);
        }
コード例 #3
0
        async public Task <bool> ImportToNewFeatureclass(IFeatureDatabase fdb, string dsname, string fcname, IFeatureClass sourceFC, FieldTranslation fieldTranslation, bool project, List <IQueryFilter> filters, ISpatialIndexDef sIndexDef, geometryType?sourceGeometryType = null)
        {
            if (!_cancelTracker.Continue)
            {
                return(true);
            }

            if (fdb is AccessFDB)
            {
                ISpatialIndexDef dsSpatialIndexDef = await((AccessFDB)fdb).SpatialIndexDef(dsname);
                if (sIndexDef == null)
                {
                    sIndexDef = dsSpatialIndexDef;
                }
                else if (sIndexDef.GeometryType != dsSpatialIndexDef.GeometryType)
                {
                    _errMsg = "Spatial-Index-Definition-GeometryTypes are not compatible!";
                    return(false);
                }
            }
            if (sIndexDef == null)
            {
                sIndexDef = new gViewSpatialIndexDef();
            }

            bool msSpatial = false;

            if (fdb is SqlFDB &&
                (sIndexDef.GeometryType == GeometryFieldType.MsGeography ||
                 sIndexDef.GeometryType == GeometryFieldType.MsGeometry))
            {
                msSpatial = true;
            }
            else
            {
                int maxAllowedLevel = ((fdb is SqlFDB || fdb is pgFDB) ? 62 : 30);
                if (sIndexDef.Levels > maxAllowedLevel)
                {
                    ISpatialReference defSRef = sIndexDef.SpatialReference;
                    sIndexDef = new gViewSpatialIndexDef(
                        sIndexDef.SpatialIndexBounds,
                        Math.Min(sIndexDef.Levels, maxAllowedLevel),
                        sIndexDef.MaxPerNode,
                        sIndexDef.SplitRatio);
                    ((gViewSpatialIndexDef)sIndexDef).SpatialReference = defSRef;
                }
            }

            try
            {
                fcname = fcname.Replace(".", "_");

                IFeatureDataset destDS = await fdb.GetDataset(dsname);

                if (destDS == null)
                {
                    _errMsg = fdb.LastErrorMessage;
                    return(false);
                }

                IDatasetElement destLayer = await destDS.Element(fcname);

                if (destLayer != null)
                {
                    if (ReportRequest != null)
                    {
                        RequestArgs args = new RequestArgs(
                            "Featureclass " + fcname + " already exists in " + dsname + "\nDo want to replace it?",
                            MessageBoxButtons.YesNoCancel,
                            DialogResult.Cancel);
                        ReportRequest(this, args);
                        switch (args.Result)
                        {
                        case DialogResult.No:
                            return(true);

                        case DialogResult.Cancel:
                            _errMsg = "Import is canceled by the user...";
                            return(false);
                        }
                    }
                }

                GeometryDef geomDef = new GeometryDef(sourceFC);
                if (geomDef.GeometryType == geometryType.Unknown && sourceGeometryType != null)
                {
                    geomDef.GeometryType = sourceGeometryType.Value;
                }

                int fcID = -1;
                if (destLayer != null)
                {
                    if (fdb is AccessFDB)
                    {
                        fcID = await((AccessFDB)fdb).ReplaceFeatureClass(destDS.DatasetName,
                                                                         fcname,
                                                                         geomDef,
                                                                         (fieldTranslation == null) ?
                                                                         ((sourceFC.Fields != null) ? (IFields)sourceFC.Fields.Clone() : new Fields()) :
                                                                         fieldTranslation.DestinationFields);
                        if (fcID < 0)
                        {
                            _errMsg = "Can't replace featureclass " + fcname + "...\r\n" + fdb.LastErrorMessage;
                            destDS.Dispose();
                            return(false);
                        }
                    }
                    else
                    {
                        await fdb.DeleteFeatureClass(fcname);
                    }
                }
                if (fcID < 0)
                {
                    fcID = await fdb.CreateFeatureClass(destDS.DatasetName,
                                                        fcname,
                                                        geomDef,
                                                        (fieldTranslation == null)?
                                                        ((sourceFC.Fields != null) ? (IFields)sourceFC.Fields.Clone() : new Fields()) :
                                                        fieldTranslation.DestinationFields);
                }
                if (fcID < 0)
                {
                    _errMsg = "Can't create featureclass " + fcname + "...\r\n" + fdb.LastErrorMessage;
                    destDS.Dispose();
                    return(false);
                }

                destLayer = await destDS.Element(fcname);

                if (destLayer == null || !(destLayer.Class is IFeatureClass))
                {
                    _errMsg = "Can't load featureclass " + fcname + "...\r\n" + destDS.LastErrorMessage;
                    destDS.Dispose();
                    return(false);
                }
                IFeatureClass destFC = destLayer.Class as IFeatureClass;

                if (project && destFC.SpatialReference != null && !destFC.SpatialReference.Equals(sourceFC.SpatialReference))
                {
                    _transformer = GeometricTransformerFactory.Create();
                    //_transformer.FromSpatialReference = sourceFC.SpatialReference;
                    //_transformer.ToSpatialReference = destFC.SpatialReference;
                    _transformer.SetSpatialReferences(sourceFC.SpatialReference, destFC.SpatialReference);
                }

                if (!Envelope.IsNull(sIndexDef.SpatialIndexBounds) &&
                    sIndexDef.SpatialReference != null && !sIndexDef.SpatialReference.Equals(destFC.SpatialReference))
                {
                    if (!sIndexDef.ProjectTo(destFC.SpatialReference))
                    {
                        _errMsg = "Can't project SpatialIndex Boundaries...";
                        destDS.Dispose();
                        return(false);
                    }
                }

                DualTree           tree  = null;
                BinaryTree2Builder tree2 = null;

                if (msSpatial)
                {
                    ((SqlFDB)fdb).SetMSSpatialIndex((MSSpatialIndex)sIndexDef, destFC.Name);
                    await((SqlFDB)fdb).SetFeatureclassExtent(destFC.Name, sIndexDef.SpatialIndexBounds);
                }
                else
                {
                    if (_treeVersion == TreeVersion.BinaryTree)
                    {
                        tree = await SpatialIndex(sourceFC, sIndexDef.MaxPerNode, filters);

                        if (tree == null)
                        {
                            return(false);
                        }
                    }
                    else if (_treeVersion == TreeVersion.BinaryTree2)
                    {
                        if (_schemaOnly && sourceFC.Dataset.Database is IImplementsBinarayTreeDef)
                        {
                            BinaryTreeDef tDef = await((IImplementsBinarayTreeDef)sourceFC.Dataset.Database).BinaryTreeDef(sourceFC.Name);
                            tree2 = new BinaryTree2Builder(tDef.Bounds, tDef.MaxLevel, tDef.MaxPerNode, tDef.SplitRatio);
                        }
                        else
                        {
                            tree2 = await SpatialIndex2(fdb, sourceFC, sIndexDef, filters);

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

                    // Vorab einmal alle "Bounds" festlegen, damit auch
                    // ein aufzubauender Layer geviewt werden kann
                    if (_treeVersion == TreeVersion.BinaryTree2 && fdb is AccessFDB)
                    {
                        if (ReportAction != null)
                        {
                            ReportAction(this, "Insert spatial index nodes");
                        }
                        List <long> nids = new List <long>();
                        foreach (BinaryTree2BuilderNode node in tree2.Nodes)
                        {
                            nids.Add(node.Number);
                        }
                        await((AccessFDB)fdb).ShrinkSpatialIndex(fcname, nids);

                        if (ReportAction != null)
                        {
                            ReportAction(this, "Set spatial index bounds");
                        }
                        //((AccessFDB)fdb).SetSpatialIndexBounds(fcname, "BinaryTree2", tree2.Bounds, sIndexDef.SplitRatio, sIndexDef.MaxPerNode, tree2.maxLevels);
                        await((AccessFDB)fdb).SetSpatialIndexBounds(fcname, "BinaryTree2", tree2.Bounds, tree2.SplitRatio, tree2.MaxPerNode, tree2.maxLevels);
                        await((AccessFDB)fdb).SetFeatureclassExtent(fcname, tree2.Bounds);
                    }
                }
                if (_cancelTracker.Continue)
                {
                    bool result = true;
                    if (!_schemaOnly)
                    {
                        if (msSpatial)
                        {
                            result = await CopyFeatures(sourceFC, fdb, destFC, fieldTranslation, filters);
                        }
                        else if (_treeVersion == TreeVersion.BinaryTree)
                        {
                            if (String.IsNullOrEmpty(sourceFC.IDFieldName)) // SDE Views haben keine ID -> Tree enthält keine Features
                            {
                                result = await CopyFeatures(sourceFC, fdb, destFC, fieldTranslation, filters);
                            }
                            else
                            {
                                result = await CopyFeatures(sourceFC, fdb, destFC, fieldTranslation, tree);
                            }
                        }
                        else if (_treeVersion == TreeVersion.BinaryTree2)
                        {
                            if (String.IsNullOrEmpty(sourceFC.IDFieldName)) // SDE Views haben keine ID -> Tree enthält keine Features
                            {
                                result = await CopyFeatures(sourceFC, fdb, destFC, fieldTranslation, filters);
                            }
                            else
                            {
                                result = await CopyFeatures2(sourceFC, fdb, destFC, fieldTranslation, tree2);
                            }
                        }
                        if (!result)
                        {
                            await fdb.DeleteFeatureClass(fcname);

                            destDS.Dispose();
                            return(false);
                        }
                    }
                }

                destDS.Dispose();

                if (_cancelTracker.Continue && fdb is AccessFDB)
                {
                    if (ReportAction != null)
                    {
                        ReportAction(this, "Calculate extent");
                    }
                    await((AccessFDB)fdb).CalculateExtent(destFC);

                    if (msSpatial == false)
                    {
                        if (_treeVersion == TreeVersion.BinaryTree)
                        {
                            if (ReportAction != null)
                            {
                                ReportAction(this, "Set spatial index bounds");
                            }
                            await((AccessFDB)fdb).SetSpatialIndexBounds(fcname, "BinaryTree", tree.Bounds, sIndexDef.SplitRatio, sIndexDef.MaxPerNode, 0);

                            if (ReportAction != null)
                            {
                                ReportAction(this, "Insert spatial index nodes");
                            }
                            await((AccessFDB)fdb).__intInsertSpatialIndexNodes2(fcname, tree.Nodes);
                        }
                    }
                    return(true);
                }
                else
                {
                    await fdb.DeleteFeatureClass(fcname);

                    _errMsg = "Import is canceled by the user...";
                    return(false);
                }
            }
            finally
            {
                if (_transformer != null)
                {
                    _transformer.Release();
                    _transformer = null;
                }
            }
        }
コード例 #4
0
        private bool ImportToNewFeatureclass(IFeatureDataset destDS, string fcname, IFeatureClass sourceFC, FieldTranslation fieldTranslation, bool project, List <IQueryFilter> filters, DatasetNameCase namecase)
        {
            if (!_cancelTracker.Continue)
            {
                return(true);
            }

            switch (namecase)
            {
            case DatasetNameCase.upper:
                fcname = fcname.ToUpper();
                fieldTranslation.ToUpper();
                break;

            case DatasetNameCase.lower:
                fcname = fcname.ToLower();
                fieldTranslation.ToLower();
                break;

            case DatasetNameCase.classNameUpper:
                fcname = fcname.ToUpper();
                break;

            case DatasetNameCase.classNameLower:
                fcname = fcname.ToLower();
                break;

            case DatasetNameCase.fieldNamesUpper:
                fieldTranslation.ToUpper();
                break;

            case DatasetNameCase.fieldNamesLower:
                fieldTranslation.ToLower();
                break;
            }
            try
            {
                fcname = fcname.Replace(".", "_");

                if (destDS == null)
                {
                    _errMsg = "Argument Exception";
                    return(false);
                }
                IFeatureDatabase fdb = destDS.Database as IFeatureDatabase;
                if (!(fdb is IFeatureUpdater))
                {
                    _errMsg = "Database don't implement IFeatureUpdater...";
                    return(false);
                }

                IDatasetElement destLayer = destDS[fcname] as IDatasetElement;
                if (destLayer != null)
                {
                    if (ReportRequest != null)
                    {
                        RequestArgs args = new RequestArgs(
                            "Featureclass " + fcname + " already exists in database\nDo want to replace it?",
                            MessageBoxButtons.YesNoCancel,
                            DialogResult.Cancel);
                        ReportRequest(this, args);
                        switch (args.Result)
                        {
                        case DialogResult.No:
                            return(true);

                        case DialogResult.Cancel:
                            _errMsg = "Import is canceled by the user...";
                            return(false);
                        }
                    }
                }

                if (destLayer != null)
                {
                    fdb.DeleteFeatureClass(fcname);
                }
                int fcID = fdb.CreateFeatureClass(destDS.DatasetName,
                                                  fcname,
                                                  sourceFC,
                                                  (fieldTranslation == null) ?
                                                  ((sourceFC.Fields != null) ? (IFields)sourceFC.Fields.Clone() : new Fields()) :
                                                  fieldTranslation.DestinationFields);
                if (fcID < 0)
                {
                    _errMsg = "Can't create featureclass " + fcname + "...\r\n" + fdb.lastErrorMsg;
                    destDS.Dispose();
                    return(false);
                }

                destLayer = destDS[fcname] as IDatasetElement;

                if (destLayer == null || !(destLayer.Class is IFeatureClass))
                {
                    _errMsg = "Can't load featureclass " + fcname + "...\r\n" + destDS.lastErrorMsg;
                    destDS.Dispose();
                    return(false);
                }
                IFeatureClass destFC = destLayer.Class as IFeatureClass;

                if (project && destFC.SpatialReference != null && !destFC.SpatialReference.Equals(sourceFC.SpatialReference))
                {
                    _transformer = new GeometricTransformer();
                    //_transformer.FromSpatialReference = sourceFC.SpatialReference;
                    //_transformer.ToSpatialReference = destFC.SpatialReference;
                    _transformer.SetSpatialReferences(sourceFC.SpatialReference, destFC.SpatialReference);
                }

                if (_cancelTracker.Continue)
                {
                    bool result = true;

                    if (fdb is IFeatureImportEvents)
                    {
                        ((IFeatureImportEvents)fdb).BeforeInsertFeaturesEvent(sourceFC, destFC);
                    }

                    if (!_schemaOnly)
                    {
                        result = CopyFeatures(sourceFC, fdb, destFC, fieldTranslation, filters);
                    }
                    if (!result)
                    {
                        fdb.DeleteFeatureClass(fcname);
                        destDS.Dispose();
                        return(false);
                    }

                    if (fdb is IFeatureImportEvents)
                    {
                        ((IFeatureImportEvents)fdb).AfterInsertFeaturesEvent(sourceFC, destFC);
                    }
                }

                if (fdb is IFileFeatureDatabase)
                {
                    if (!((IFileFeatureDatabase)fdb).Flush(destFC))
                    {
                        _errMsg = "Error executing flush for file database...";
                        return(false);
                    }
                }
                destDS.Dispose();

                if (_cancelTracker.Continue)
                {
                    return(true);
                }
                else
                {
                    fdb.DeleteFeatureClass(fcname);
                    _errMsg = "Import is canceled by the user...";
                    return(false);
                }
            }
            finally
            {
                if (_transformer != null)
                {
                    _transformer.Release();
                    _transformer = null;
                }
            }
        }