Beispiel #1
0
        /// <summary>
        /// 创建栅格字段
        /// </summary>
        /// <param name="pRasterFielsName">栅格字段名</param>
        /// <param name="pSpatialRes">栅格空间参考</param>
        /// <param name="eError"></param>
        /// <returns>返回字段</returns>
        private IField2 CreateRasterField(string pRasterFielsName, ISpatialReference pSpatialRes, bool isManaged)
        {
            IField2     pField     = new FieldClass();
            IFieldEdit2 pFieldEdit = pField as IFieldEdit2;

            pFieldEdit.Name_2      = pRasterFielsName;
            pFieldEdit.AliasName_2 = pRasterFielsName;
            pFieldEdit.Type_2      = esriFieldType.esriFieldTypeRaster;

            IRasterDef pRasterDef = new RasterDefClass();

            pRasterDef.Description = "this is Raster catalog";
            if (pSpatialRes == null)
            {
                //如果空间参考为空,则设置为UnknownCoordinateSystemClass
                pSpatialRes = new UnknownCoordinateSystemClass();
            }
            //only for PGDB
            pRasterDef.IsManaged        = isManaged;
            pRasterDef.SpatialReference = pSpatialRes;
            pFieldEdit.RasterDef        = pRasterDef;
            pField = pFieldEdit as IField2;

            return(pField);
        }
Beispiel #2
0
        public bool CopyRaster(IRasterWorkspace2 pRW, string pFileName, IRasterWorkspaceEx pWorkSpace, string pDestName)
        {
            try
            {

                IRasterDataset pRds = pRW.OpenRasterDataset(pFileName);

                IRasterProps pRasterProps = (IRasterProps)pRds.CreateDefaultRaster();
                IRasterStorageDef pRasterStorageDef = new RasterStorageDefClass();

                IRasterDef pRasterDef = new RasterDefClass();
                pRasterDef.SpatialReference = pRasterProps.SpatialReference;
                IGeometryDef pGeoDef = new GeometryDefClass();
                IGeometryDefEdit pGeoDefEdit = pGeoDef as IGeometryDefEdit;
                pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                pGeoDefEdit.AvgNumPoints_2 = 4;
                pGeoDefEdit.GridCount_2 = 1;
                pGeoDefEdit.set_GridSize(0, 1000);
                pGeoDefEdit.SpatialReference_2 = pRasterProps.SpatialReference;
                IRasterDataset pRasterDataset = pWorkSpace.SaveAsRasterDataset(pDestName, pRds.CreateDefaultRaster(), pRasterStorageDef, "", pRasterDef, pGeoDef);

                return true;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }
Beispiel #3
0
        public bool CreateRaster(IRasterDataset pRDs, IRasterWorkspaceEx pWorkSpace)
        {
            IRasterProps      pRasterProps      = (IRasterProps)pRDs.CreateDefaultRaster();
            IRasterStorageDef pRasterStorageDef = new RasterStorageDefClass();

            pRasterStorageDef.CompressionType     = esriRasterCompressionType.esriRasterCompressionJPEG2000;
            pRasterStorageDef.CompressionQuality  = 50;
            pRasterStorageDef.PyramidLevel        = 2;
            pRasterStorageDef.PyramidResampleType = rstResamplingTypes.RSP_BilinearInterpolation;
            pRasterStorageDef.TileHeight          = 128;
            pRasterStorageDef.TileWidth           = 128;
            IRasterDef pRasterDef = new RasterDefClass();

            pRasterDef.Description      = "RasterDataset";
            pRasterDef.SpatialReference = pRasterProps.SpatialReference;
            IGeometryDef     pGeoDef     = new GeometryDefClass();
            IGeometryDefEdit pGeoDefEdit = pGeoDef as IGeometryDefEdit;

            pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
            pGeoDefEdit.AvgNumPoints_2 = 4;
            pGeoDefEdit.GridCount_2    = 1;
            pGeoDefEdit.set_GridSize(0, 1000);
            pGeoDefEdit.SpatialReference_2 = pRasterProps.SpatialReference;
            IRasterDataset pRasterDataset = pWorkSpace.CreateRasterDataset("zzy", 3, rstPixelType.PT_UCHAR, pRasterStorageDef, "", pRasterDef, pGeoDef);

            pRasterDataset = pRDs;
            return(true);
        }
Beispiel #4
0
        public bool CopyRaster(IRasterWorkspace2 pRW, string pFileName, IRasterWorkspaceEx pWorkSpace, string pDestName)
        {
            try
            {
                IRasterDataset pRds = pRW.OpenRasterDataset(pFileName);


                IRasterProps      pRasterProps      = (IRasterProps)pRds.CreateDefaultRaster();
                IRasterStorageDef pRasterStorageDef = new RasterStorageDefClass();

                IRasterDef pRasterDef = new RasterDefClass();
                pRasterDef.SpatialReference = pRasterProps.SpatialReference;
                IGeometryDef     pGeoDef     = new GeometryDefClass();
                IGeometryDefEdit pGeoDefEdit = pGeoDef as IGeometryDefEdit;
                pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                pGeoDefEdit.AvgNumPoints_2 = 4;
                pGeoDefEdit.GridCount_2    = 1;
                pGeoDefEdit.set_GridSize(0, 1000);
                pGeoDefEdit.SpatialReference_2 = pRasterProps.SpatialReference;
                IRasterDataset pRasterDataset = pWorkSpace.SaveAsRasterDataset(pDestName, pRds.CreateDefaultRaster(), pRasterStorageDef, "", pRasterDef, pGeoDef);

                return(true);
            }
            catch (System.Exception ex)
            {
                return(false);
            }
        }
Beispiel #5
0
        /// <summary>
        /// 设置空间参考定义
        /// </summary>
        /// <param name="pSR"></param>
        /// <returns></returns>
        private IRasterDef CreateRasterDef(ISpatialReference pSR)
        {
            IRasterDef pRasterDef = new RasterDefClass();

            pRasterDef.Description = "rasterDataset";
            if (pSR == null)
            {
                pSR = new UnknownCoordinateSystemClass();
            }
            pRasterDef.SpatialReference = pSR;
            return(pRasterDef);
        }
Beispiel #6
0
        //������ţ�RasterCreate-05
        //������:	createRasterDef
        //�������ܣ�����raster����
        //������
        public IRasterDef createRasterDef(bool isManaged, ISpatialReference spatialReference)
        {
            // Create rasterdef
            IRasterDef rasterDef = new RasterDefClass();

            rasterDef.Description = "Raster Dataset";
            if (spatialReference == null)
                spatialReference = new UnknownCoordinateSystemClass();

            rasterDef.SpatialReference = spatialReference;
            rasterDef.IsManaged = isManaged;

            return rasterDef;
        }
Beispiel #7
0
        public static IField CreateRasterField(string pName, string pAliasName, ISpatialReference pSR)
        {
            FieldClass class2 = new FieldClass();
            IFieldEdit edit   = class2;

            edit.Name_2      = pName;
            edit.AliasName_2 = pAliasName;
            edit.Type_2      = esriFieldType.esriFieldTypeRaster;
            IRasterDef def = new RasterDefClass();

            def.IsRasterDataset             = false;
            def.SpatialReference            = pSR;
            (edit as IFieldEdit2).RasterDef = def;
            return(class2);
        }
Beispiel #8
0
        //函数编号:RasterCreate-05
        //函数名:	createRasterDef
        //函数功能:设置raster定义
        //参数:
        public IRasterDef createRasterDef(bool isManaged, ISpatialReference spatialReference)
        {
            // Create rasterdef
            IRasterDef rasterDef = new RasterDefClass();

            rasterDef.Description = "Raster Dataset";
            if (spatialReference == null)
            {
                spatialReference = new UnknownCoordinateSystemClass();
            }

            rasterDef.SpatialReference = spatialReference;
            rasterDef.IsManaged        = isManaged;

            return(rasterDef);
        }
Beispiel #9
0
        private IRasterDataset CreateRasterDataset(ref IRasterDataset pRasterDataset, string name, ref IWorkspace pWorkspace, ISpatialReference pSpatialReference)
        {
            IRasterWorkspaceEx    pRasterWorkspaceEx    = (IRasterWorkspaceEx)pWorkspace;
            IRasterDataset        newRasterDataset      = null;
            IRaster               pRaster               = pRasterDataset.CreateDefaultRaster();
            IRasterBandCollection pRasterBandCollection = (IRasterBandCollection)pRaster;
            int               numbands          = pRasterBandCollection.Count;
            IRasterProps      pRasterProps      = (IRasterProps)pRaster;
            rstPixelType      pPixelType        = pRasterProps.PixelType;
            IRasterStorageDef pRasterStorageDef = null;

            if (pRasterStorageDef == null)
            {
                pRasterStorageDef = new RasterStorageDefClass();
                pRasterStorageDef.CompressionType     = esriRasterCompressionType.esriRasterCompressionLZ77;
                pRasterStorageDef.PyramidLevel        = 2;
                pRasterStorageDef.PyramidResampleType = rstResamplingTypes.RSP_BilinearInterpolation;
                pRasterStorageDef.TileHeight          = 128;
                pRasterStorageDef.TileWidth           = 128;
            }

            IRasterDef pRasterDef = new RasterDefClass();

            pRasterDef.SpatialReference = pSpatialReference;
            pRasterDef.IsRasterDataset  = true;
            pRasterDef.Description      = "rasterdataset";
            try
            {
                newRasterDataset = pRasterWorkspaceEx.CreateRasterDataset(name, numbands, pPixelType, pRasterStorageDef, "", pRasterDef, this.createGeometryDef(pSpatialReference));
                return(newRasterDataset);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(null);
            }
        }
Beispiel #10
0
 public bool CreateRaster(IRasterDataset pRDs, IRasterWorkspaceEx pWorkSpace)
 {
     IRasterProps pRasterProps = (IRasterProps)pRDs.CreateDefaultRaster();
     IRasterStorageDef pRasterStorageDef = new RasterStorageDefClass();
     pRasterStorageDef.CompressionType = esriRasterCompressionType.esriRasterCompressionJPEG2000;
     pRasterStorageDef.CompressionQuality = 50;
     pRasterStorageDef.PyramidLevel = 2;
     pRasterStorageDef.PyramidResampleType = rstResamplingTypes.RSP_BilinearInterpolation;
     pRasterStorageDef.TileHeight = 128;
     pRasterStorageDef.TileWidth = 128;
     IRasterDef pRasterDef = new RasterDefClass();
     pRasterDef.Description = "RasterDataset";
     pRasterDef.SpatialReference = pRasterProps.SpatialReference;
     IGeometryDef pGeoDef = new GeometryDefClass();
     IGeometryDefEdit pGeoDefEdit = pGeoDef as IGeometryDefEdit;
     pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
     pGeoDefEdit.AvgNumPoints_2 = 4;
     pGeoDefEdit.GridCount_2 = 1;
     pGeoDefEdit.set_GridSize(0, 1000);
     pGeoDefEdit.SpatialReference_2 = pRasterProps.SpatialReference;
     IRasterDataset pRasterDataset = pWorkSpace.CreateRasterDataset("zzy", 3, rstPixelType.PT_UCHAR, pRasterStorageDef, "", pRasterDef, pGeoDef);
     pRasterDataset = pRDs;
     return true;
 }
Beispiel #11
0
        private IRasterDataset CreateRasterDataset(ref IRasterDataset pRasterDataset, string name, ref IWorkspace pWorkspace, ISpatialReference pSpatialReference)
        {
            IRasterWorkspaceEx pRasterWorkspaceEx = (IRasterWorkspaceEx)pWorkspace;
            IRasterDataset newRasterDataset = null;
            IRaster pRaster = pRasterDataset.CreateDefaultRaster();
            IRasterBandCollection pRasterBandCollection = (IRasterBandCollection)pRaster;
            int numbands = pRasterBandCollection.Count;
            IRasterProps pRasterProps = (IRasterProps)pRaster;
            rstPixelType pPixelType = pRasterProps.PixelType;
            IRasterStorageDef pRasterStorageDef = null;

            if (pRasterStorageDef == null)
            {
                pRasterStorageDef = new RasterStorageDefClass();
                pRasterStorageDef.CompressionType = esriRasterCompressionType.esriRasterCompressionLZ77;
                pRasterStorageDef.PyramidLevel = 2;
                pRasterStorageDef.PyramidResampleType = rstResamplingTypes.RSP_BilinearInterpolation;
                pRasterStorageDef.TileHeight = 128;
                pRasterStorageDef.TileWidth = 128;
            }

            IRasterDef pRasterDef = new RasterDefClass();
            pRasterDef.SpatialReference = pSpatialReference;
            pRasterDef.IsRasterDataset = true;
            pRasterDef.Description = "rasterdataset";
            try
            {
                newRasterDataset = pRasterWorkspaceEx.CreateRasterDataset(name, numbands, pPixelType, pRasterStorageDef, "", pRasterDef, this.createGeometryDef(pSpatialReference));
                return newRasterDataset;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }
 public static IField CreateRasterField(string pName, string pAliasName, ISpatialReference pSR)
 {
     FieldClass class2 = new FieldClass();
     IFieldEdit edit = class2;
     edit.Name_2 = pName;
     edit.AliasName_2 = pAliasName;
     edit.Type_2 = esriFieldType.esriFieldTypeRaster;
     IRasterDef def = new RasterDefClass();
     def.IsRasterDataset = false;
     def.SpatialReference = pSR;
     (edit as IFieldEdit2).RasterDef = def;
     return class2;
 }
Beispiel #13
0
        //创建数据集(矢量数据集和影像数据集)
        private void button2_Click(object sender, EventArgs e)
        {
            featureWorkspace = workspace as IFeatureWorkspace;
            rasterWorkspace  = workspace as IRasterWorkspaceEx;
            //定义空间参考
            ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
            ISpatialReference        spatialReference        = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);

            spatialReference.SetDomain(-1000, -1000, 1000, 1000);

            IEnumDatasetName enumDatasetName;
            IDatasetName     datasetName;
            string           dsName = "";

            enumDatasetName = workspace.get_DatasetNames(esriDatasetType.esriDTFeatureDataset);
            datasetName     = enumDatasetName.Next();
            bool isExist = false;

            //创建矢量数据集
            dsName = "SDE." + this.textBox6.Text;
            while (datasetName != null)
            {
                if (datasetName.Name == dsName)
                {
                    isExist = true;
                }
                datasetName = enumDatasetName.Next();
            }
            if (isExist == false)
            {
                featureDataset = featureWorkspace.CreateFeatureDataset(this.textBox6.Text, spatialReference);
            }
            //创建影像数据集
            isExist         = false;
            enumDatasetName = workspace.get_DatasetNames(esriDatasetType.esriDTRasterDataset);
            datasetName     = enumDatasetName.Next();

            dsName = "SDE." + this.textBox6.Text;
            while (datasetName != null)
            {
                if (datasetName.Name == dsName)
                {
                    isExist = true;
                }
                datasetName = enumDatasetName.Next();
            }
            if (isExist == false)
            {
                //设置存储参数
                IRasterStorageDef rasterStorageDef = new RasterStorageDefClass();
                rasterStorageDef.CompressionType     = esriRasterCompressionType.esriRasterCompressionUncompressed;
                rasterStorageDef.PyramidLevel        = 1;
                rasterStorageDef.PyramidResampleType = rstResamplingTypes.RSP_BilinearInterpolation;
                rasterStorageDef.TileHeight          = 128;
                rasterStorageDef.TileWidth           = 128;
                //设置坐标系统
                IRasterDef        rasterDef             = new RasterDefClass();
                ISpatialReference rasterDpatialRefrence = new UnknownCoordinateSystemClass();
                rasterDef.SpatialReference = rasterDpatialRefrence;

                IGeometryDef     geometryDef     = new GeometryDefClass();
                IGeometryDefEdit geometryDefedit = (IGeometryDefEdit)geometryDef;
                geometryDefedit.AvgNumPoints_2 = 5;
                geometryDefedit.GridCount_2    = 1;
                geometryDefedit.set_GridSize(0, 1000);
                geometryDefedit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                ISpatialReference spatialReference2 = new UnknownCoordinateSystemClass();
                geometryDefedit.SpatialReference_2 = spatialReference2;
                rasterDataset = rasterWorkspace.CreateRasterDataset(this.textBox7.Text, 1, rstPixelType.PT_LONG, rasterStorageDef, "DEFAULTS", rasterDef, geometryDef);
            }
        }
        /// <summary>
        /// Creates a new raster dataset based on the template Raster. If a raster with the same outRaster name exist it will be overwritten
        /// </summary>
        /// <param name="templateRaster">a raster that has the size and shape desired</param>
        /// <param name="outWks">the output workspace</param>
        /// <param name="outRasterName">the name of the raster</param>
        /// <param name="numBands">the number of raster bands</param>
        /// <param name="pixelType">the pixel type</param>
        /// <param name="env">the extent</param>
        /// <param name="meanCellSize"> the mean Cell Size of the new raster</param>
        /// <param name="spRf"> the spatial reference of the raster</param>
        /// <returns></returns>
        public IRasterDataset createNewRaster(IEnvelope env, IPnt meanCellSize,IWorkspace outWks, string outRasterName, int numBands, rstPixelType pixelType, rasterType rType, ISpatialReference spRf)
        {
            outRasterName = getSafeOutputName(outWks, outRasterName);
            IRasterDataset3 newRstDset = null;
            if (outWks.Type == esriWorkspaceType.esriFileSystemWorkspace)
            {
                outRasterName = getSafeOutputName(outWks, outRasterName);
                string rasterTypeStr = rType.ToString();
                if (rType== rasterType.IMAGINE)
                {
                    rasterTypeStr = "IMAGINE Image";
                    outRasterName = outRasterName + ".img";
                }
                else if (rType == rasterType.TIFF)
                {
                    outRasterName = outRasterName + ".tif";
                }
                else if (rType == rasterType.GRID)
                {

                }
                else if (rType == rasterType.BMP)
                {
                    outRasterName = outRasterName + ".bmp";
                }
                else if (rType == rasterType.RST)
                {
                    outRasterName = outRasterName + ".rst";
                }
                else
                {
                    rasterTypeStr = "IMAGINE Image";
                    outRasterName = outRasterName + ".img";
                }
                double dX = meanCellSize.X;
                double dY = meanCellSize.Y;
                IRasterWorkspace2 rsWks = (IRasterWorkspace2)outWks;
                newRstDset = (IRasterDataset3)rsWks.CreateRasterDataset(outRasterName, rasterTypeStr, env.LowerLeft, System.Convert.ToInt32(env.Width / dX), System.Convert.ToInt32(env.Height / dY), dX, dY, numBands, pixelType, spRf, true);
            }
            else
            {
                IRasterWorkspaceEx rsWks = (IRasterWorkspaceEx)outWks;
                IRasterDef rsDef = new RasterDefClass();
                IRasterStorageDef rsStDef = new RasterStorageDefClass();
                rsStDef.Origin = env.LowerLeft;
                rsStDef.CellSize = meanCellSize;
                rsDef.SpatialReference = spRf;
                newRstDset = (IRasterDataset3)rsWks.CreateRasterDataset(outRasterName, numBands, pixelType, rsStDef, null, rsDef, null);
            }
            return newRstDset;
        }