Пример #1
0
        protected IFeatureClass CreateTargetFeatureclass(IGeometryDef geomDef, IFields fields)
        {
            IFeatureClass sFc  = SourceFeatureClass;
            BinaryTreeDef sDef = null;

            if (sFc.Dataset != null && sFc.Dataset.Database is AccessFDB)
            {
                AccessFDB sFdb = (AccessFDB)sFc.Dataset.Database;
                sDef = sFdb.BinaryTreeDef(sFc.Name);
            }

            TargetDatasetElement e  = this.TargetDatasetElement;
            IDataset             ds = this.TargetDataset;
            IFeatureDatabase     db = this.TargetFeatureDatabase;

            if (db.CreateFeatureClass(ds.DatasetName, e.Title, geomDef, fields) == -1)
            {
                throw new Exception("Can't create target featureclass:\n" + db.lastErrorMsg);
            }

            IDatasetElement element = ds[e.Title];

            if (element == null || !(element.Class is IFeatureClass))
            {
                throw new Exception("Can't open created featureclass");
            }

            IFeatureClass tFc = element.Class as IFeatureClass;

            if (db is AccessFDB)
            {
                int maxAllowedLevel = ((db is SqlFDB) ? 62 : 30);
                if (sDef == null)
                {
                    IEnvelope sEnv = sFc.Envelope;
                    sDef = (sEnv != null) ? new BinaryTreeDef(sFc.Envelope, 10, 200, 0.55) : new BinaryTreeDef(new Envelope());
                }
                if (sDef.Bounds != null &&
                    sDef.SpatialReference != null &&
                    !sDef.SpatialReference.Equals(tFc.SpatialReference))
                {
                    if (!sDef.ProjectTo(tFc.SpatialReference))
                    {
                        throw new Exception("Can't project SpatialIndex Boundaries...");
                    }
                }
                ((AccessFDB)db).SetSpatialIndexBounds(tFc.Name, "BinaryTree2", sDef.Bounds, sDef.SplitRatio, sDef.MaxPerNode, Math.Min(sDef.MaxLevel, maxAllowedLevel));
                ((AccessFDB)db).SetFeatureclassExtent(tFc.Name, sDef.Bounds);
            }

            return(tFc);
        }