public virtual void TestApplySchema()
        {
            Skip.If(_fixture.Skip, _fixture.SkipReason);

            var fsId = "Library://UnitTests/Data/TestMaestro" + GetTestPrefix() + "ApplySchema.FeatureSource";
            var conn = _fixture.CreateTestConnection();

            if (conn.ResourceService.ResourceExists(fsId))
            {
                conn.ResourceService.DeleteResource(fsId);
            }

            ClassDefinition cls    = null;
            FeatureSchema   schema = null;

            CreateTestDataStore(conn, fsId, ref schema, ref cls);

            cls.AddProperty(new DataPropertyDefinition("ExtraProp", "")
            {
                DataType   = DataPropertyType.String,
                IsNullable = false,
                Length     = 255
            });

            //Apply changes
            IApplySchema cmd = (IApplySchema)conn.CreateCommand((int)CommandType.ApplySchema);

            cmd.Schema          = schema;
            cmd.FeatureSourceId = fsId;
            cmd.Execute();

            ClassDefinition cls2 = conn.FeatureService.GetClassDefinition(cmd.FeatureSourceId, "Class1");

            Assert.NotNull(cls2);
            Assert.False(ClassDefinition.ReferenceEquals(cls, cls2));

            Assert.Equal(cls.Name, cls2.Name);
            Assert.Equal(cls.DefaultGeometryPropertyName, cls2.DefaultGeometryPropertyName);
            Assert.Equal(cls.Properties.Count, cls2.Properties.Count);
            Assert.Equal(cls.IdentityProperties.Count, cls2.IdentityProperties.Count);
            foreach (var prop in cls.Properties)
            {
                var prop2 = cls2.FindProperty(prop.Name);
                Assert.Equal(prop.Name, prop2.Name);
                Assert.Equal(prop.Type, prop2.Type);
            }
        }
示例#2
0
        void RunExport(string fileName)
        {
            CadastralMapModel mapModel = CadastralMapModel.Current;

            using (ICreateDataStore cmd = m_Connection.CreateCommand(CommandType.CommandType_CreateDataStore) as ICreateDataStore)
            {
                try
                {
                    cmd.DataStoreProperties.SetProperty("File", fileName);
                    cmd.Execute();
                }
                catch (OSGeo.FDO.Common.Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // The connection after the created is ConnectionState_Closed, so open it!
            m_Connection.ConnectionInfo.ConnectionProperties.SetProperty("File", fileName);
            m_Connection.Open();

            // Define coordinate system
            using (ICreateSpatialContext cmd = m_Connection.CreateCommand(CommandType.CommandType_CreateSpatialContext) as ICreateSpatialContext)
            {
                ISpatialSystem ss = mapModel.SpatialSystem;
                cmd.CoordinateSystem = ss.Name; // CSMap key name
                cmd.ExtentType       = SpatialContextExtentType.SpatialContextExtentType_Static;
                IWindow         mapExtent = mapModel.Extent;
                IDirectPosition minxy     = m_Factory.CreatePositionXY(mapExtent.Min.X, mapExtent.Min.Y);
                IDirectPosition maxxy     = m_Factory.CreatePositionXY(mapExtent.Max.X, mapExtent.Max.Y);
                IEnvelope       extent    = m_Factory.CreateEnvelope(minxy, maxxy);
                IGeometry       gx        = m_Factory.CreateGeometry(extent);
                cmd.Extent              = m_Factory.GetFgf(gx);
                cmd.XYTolerance         = 0.000001; // resolution?
                cmd.CoordinateSystemWkt = EditingController.Current.GetCoordinateSystemText();
                cmd.Execute();
            }

            // Define feature schema
            FeatureSchema fs = new FeatureSchema("Steve", "This is a test");

            FeatureClass fc = new FeatureClass("FC", "Test feature class");

            fs.Classes.Add(fc);
            GeometricPropertyDefinition gp = new GeometricPropertyDefinition("Geometry", "Polygon property");

            // When you stick more than one geometric type into the output, you can't
            // convert to SHP (not with FDO Toolbox anyway).
            //gp.GeometryTypes = (int)GeometricType.GeometricType_Surface;
            gp.GeometryTypes = (int)GeometricType.GeometricType_All;
            fc.Properties.Add(gp);
            fc.GeometryProperty = gp;

            // c.f. FdoToolbox ExpressUtility
            DataPropertyDefinition dp = new DataPropertyDefinition("ID", "Test ID");

            dp.DataType        = DataType.DataType_Int32;
            dp.Nullable        = false;
            dp.ReadOnly        = true;
            dp.IsAutoGenerated = true;
            fc.Properties.Add(dp);

            // Feature class requires an identity column for the insert
            fc.IdentityProperties.Add(dp);

            using (IApplySchema cmd = m_Connection.CreateCommand(CommandType.CommandType_ApplySchema) as IApplySchema)
            {
                cmd.FeatureSchema = fs;
                cmd.Execute();
            }

            mapModel.Index.QueryWindow(null, SpatialType.Polygon | SpatialType.Point, ExportFeature);

            m_Connection.Flush();
            m_Connection.Close();
        }
示例#3
0
        public static string addSchemtoSDF(string SDFFile, string schemaName, string schemaDesc)
        {
            try
            {
                FeatureSchema      schema1    = new FeatureSchema(schemaName, schemaDesc);
                IConnectionManager conmanager = FeatureAccessManager.GetConnectionManager();

                //sdf fdo connection
                using (IConnection connect = SDFConnection(SDFFile))
                {
                    //get connection dict
                    IConnectionPropertyDictionary conprop = connect.ConnectionInfo.ConnectionProperties;

                    connect.Open();

                    //check connection state
                    OSGeo.FDO.Connections.ConnectionState connstate = connect.ConnectionState;
                    if (connstate != OSGeo.FDO.Connections.ConnectionState.ConnectionState_Open)
                    {
                        result = "\nCannot read SDF File \n" + SDFFile;
                    }
                    else
                    {
                        //add spatial context to the schema
                        SDF.SDFSchemaManager.spatial_context(connect);

                        result = "Read SDF File \n" + SDFFile;

                        //create command to alter schema
                        IApplySchema applyschema = (IApplySchema)connect.CreateCommand(CommandType.CommandType_ApplySchema) as IApplySchema;

                        //FeatureClassCollection fcoll;
                        ClassCollection fcoll = schema1.Classes;

                        //create all feature class
                        FeatureClass class_points     = new FeatureClass("Points", "Point information");
                        FeatureClass class_alignment  = new FeatureClass("Alignments", "Alignment information");
                        FeatureClass class_parcels    = new FeatureClass("Parcels", "Parcels information");
                        FeatureClass class_pipes      = new FeatureClass("Pipes", "Pipes information");
                        FeatureClass class_structures = new FeatureClass("Structures", "Structures information");

                        //add properties here
                        Schema_manager.add_property(class_points, connect);
                        Schema_manager.add_property(class_alignment, connect);
                        Schema_manager.add_property(class_parcels, connect);
                        Schema_manager.add_property(class_pipes, connect);
                        Schema_manager.add_property(class_structures, connect);

                        schema1.Classes.Add(class_points);
                        schema1.Classes.Add(class_alignment);
                        schema1.Classes.Add(class_parcels);
                        schema1.Classes.Add(class_pipes);
                        schema1.Classes.Add(class_structures);

                        //create property definition for each feature class

                        applyschema.FeatureSchema = schema1;
                        applyschema.Execute();
                        result = "Successfully Created SDF file with blank Schema \n" + SDFFile;
                    }
                    connect.Close();
                }
            }
            catch (SystemException ex)
            {
            }
            return(result);
        }