I have a question for transformation raster.Like Accessories to show.I use C# program to build.The result for transformation raster have Offset,but I need is whole raster to coordinate transformation.Not raster to offset.
I use raster format is png.The file of .pgw is can't coordinate transformation.
Thanks for all
private void btnOpen_Click(object sender, EventArgs e)
{
openDialog();
IRasterDataset2 rasDs2 = rasDs as IRasterDataset2;
ISpatialReference SRf =MakeSpatialReference(esriSRProjCS3Type.esriSRProjCS_TWD1997TM_Taiwan);
ProjectRasterWithDatumTransformation(rasDs2, SRf, (IGeoTransformation)transfomation());
}
public static void ProjectRasterWithDatumTransformation(IRasterDataset2 rasterDataset, ISpatialReference outSR, IGeoTransformation geoTransformation)
{
//This example shows how to specify a datum transformation when projecting raster data.
//rasterDataset�??Represents input of a raster dataset that has a known spatial reference.
//outSR�??Represents the spatial reference of the output raster dataset.
//geoTrans�??Represents the geotransformation between the input and output spatial reference.
//Set output spatial reference.
IRaster raster = rasterDataset.CreateFullRaster();
IRasterProps rasterProps = (IRasterProps)raster;
rasterProps.SpatialReference = outSR;
//Specify the geotransformation.
ISpatialReferenceFactory2 srFactory = new SpatialReferenceEnvironmentClass();
//IGeoTransformation geoTransformation = (IGeoTransformation)
// srFactory.CreateGeoTransformation((int)geoTrans);
//Add to the geotransformation operation set.
IGeoTransformationOperationSet operationSet = new GeoTransformationOperationSetClass();
operationSet.Set(esriTransformDirection.esriTransformForward, geoTransformation);
operationSet.Set(esriTransformDirection.esriTransformReverse, geoTransformation);
//Set the geotransformation on the raster.
IRaster2 raster2 = (IRaster2)raster;
raster2.GeoTransformations = operationSet;
//Save the result.
IWorkspaceFactory wsfactory = new RasterWorkspaceFactory();
IWorkspace outputWorkspace = wsfactory.OpenFromFile(@"c:\output", 0);
ISaveAs saveas = (ISaveAs)raster;
saveas.SaveAs("test5.png", outputWorkspace, "PNG");
}
private ICoordinateFrameTransformation transfomation()
{
Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
System.Object obj = Activator.CreateInstance(factoryType);
ISpatialReferenceFactory2 pSRF = obj as ISpatialReferenceFactory2;
// Initialize and create the input and output coordinate systems.
IProjectedCoordinateSystem2 pPCSin = new ESRI.ArcGIS.Geometry.ProjectedCoordinateSystemClass();
IProjectedCoordinateSystem2 pPCSout = new ESRI.ArcGIS.Geometry.ProjectedCoordinateSystemClass();
pPCSin = (IProjectedCoordinateSystem2)pSRF.CreateProjectedCoordinateSystem((int)
esriSRProjCS3Type.esriSRProjCS_TWD1997TM_Taiwan);
pPCSout = (IProjectedCoordinateSystem2)pSRF.CreateProjectedCoordinateSystem((int)
esriSRProjCS3Type.esriSRProjCS_TWD1967TM_Taiwan);
//IGeographicCoordinateSystem2 pGCSto;
//IGeographicCoordinateSystem2 pGCSfrom;
// Retrieve the geographic coordinate systems from the
// two projected coordinate systems
//pGCSfrom = (IGeographicCoordinateSystem2)pPCSin.GeographicCoordinateSystem;
//pGCSto = (IGeographicCoordinateSystem2)pPCSout.GeographicCoordinateSystem;
// Initialize and create an appropriate geographic transformation.
ICoordinateFrameTransformation pCFT = new CoordinateFrameTransformationClass();
pCFT.PutParameters(730.160, 346.212, 472.186, 7.968009465325332199694565793688, 3.5498173155125282722429064796627, 0.40634166830677981965825251394163, 0.99998180);
pCFT.PutSpatialReferences(pPCSin, pPCSout);
pCFT.Name = "97-67";
return pCFT;
}
public ISpatialReference MakeSpatialReference(ESRI.ArcGIS.Geometry.esriSRProjCS3Type coordinateSystem)
{
ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
//Create a projected coordinate system and define its domain, resolution, and x,y tolerance.
ISpatialReferenceResolution spatialReferenceResolution = spatialReferenceFactory.CreateProjectedCoordinateSystem(System.Convert.ToInt32(coordinateSystem)) as ISpatialReferenceResolution;
spatialReferenceResolution.ConstructFromHorizon();
ISpatialReferenceTolerance spatialReferenceTolerance = spatialReferenceResolution as ISpatialReferenceTolerance;
spatialReferenceTolerance.SetDefaultXYTolerance();
ISpatialReference spatialReference = spatialReferenceResolution as ISpatialReference;
return spatialReference;
}