阅读:2766回复:1
[求助]IRawPixels.Write方法
<H2>IRawPixels.Write方法</H2>
<DIV>IRawPixels.Write Method<BR>If transactioning is enabled, this write is persisted temporarily to a memory cache that allows undo support; otherwise, the data is persisted directly to disk at this time.<BR>If transactioning is enabled,是什么意思?怎么就能让它enable,我想调用这个方法后,结果在内存里暂时存在,但是我现在write完之后,都是永久保存,怎么样可以暂时保存?谢谢。</DIV> |
|
1楼#
发布于:2008-03-29 11:12
<P> IPoint op=new PointClass();<BR> op.X=100;<BR> op.Y=20;<BR> ISpatialReferenceFactory isrf=new SpatialReferenceEnvironmentClass();<BR> ISpatialReference isr=isrf.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);<BR> IWorkspaceFactory iwf = new RasterWorkspaceFactoryClass();<BR> IRasterWorkspace2 irws = (IRasterWorkspace2)iwf.OpenFromFile("c:\\temp", 0);<BR> IRasterDataset irds = irws.CreateRasterDataset("test", "GRID", op, 252, 202, 0.0995, 0.0995, 1, rstPixelType.PT_FLOAT, isr, true);<BR> IRaster ir = irds.CreateDefaultRaster();<BR> IRasterBandCollection rbc = (IRasterBandCollection)ir;<BR> IRawPixels irpixels = (IRawPixels)rbc.Item(0);<BR> IRasterProps irProps = (IRasterProps)irpixels;<BR> IPnt rasterOP = new PntClass();<BR> rasterOP.SetCoords(0, 0);<BR> IPnt rasterSize = new PntClass();<BR> rasterSize.SetCoords(irProps.Width, irProps.Height);<BR> IPixelBlock3 pixBlock =(IPixelBlock3) irpixels.CreatePixelBlock(rasterSize);</P>
<P> pixBlock.set_PixelData(0, (System.Object)dat[0]);<BR> System.Object cachePointer = irpixels.AcquireCache();<BR> irpixels.Write(rasterOP, (IPixelBlock)pixBlock);<BR> irpixels.ReturnCache(cachePointer);<BR> <BR> cachePointer = null;</P> <P> irProps = null;<BR> irpixels = null;<BR> rbc = null;<BR> ir = null;<BR> irds = null;<BR> GC.Collect();</P> <P> IRasterLayer m_raster = new RasterLayerClass();<BR> m_raster.CreateFromFilePath("c:\\temp\\test");<BR> axMapControl1.AddLayer(m_raster); <BR> If transactioning is enabled是启用事务机制 System.Object cachePointer = irpixels.AcquireCache();<BR> irpixels.Write(rasterOP, (IPixelBlock)pixBlock);<BR> irpixels.ReturnCache(cachePointer);</P> <P>System.Object cachePointer = irpixels.AcquireCache();是开始,irpixels.ReturnCache(cachePointer);是结束。不要这2句直接write的话,就直接保存。</P> <P>不过在我这里我发现有点问题,就是不管是直接write还是用事务机制,如果不解除除对新建Raster的的各个AO对象的引用(就是代码中的cachePointer = null;.....;GC.Collect();,当然等到程序结束也是可以的,那时候对所有AO对象的引用自然就解除了) ,对Pixel值的更改是不会被保存的,就好像用缓存写了文件最后忘记Flush了一样,不知道是不是Bug。我用的win2003+ArcGIS desktop 9.2+ArcEngine 9.2.</P> <P>我猜LZ的意思是想在内存中建立一个临时的Raster,那应该在CreateRasterDataset("test", "GRID", op, 252, 202, 0.0995, 0.0995, 1, rstPixelType.PT_FLOAT, isr, true)时把"GRID"换成"MEM"就可以了。<BR><BR> </P> |
|