java调用AE动态配准栅格图片经纬度空间信息

10 篇文章 0 订阅

一般而言一张图片或者栅格是没有空间坐标信息的,通过arcmap打开只能知道图片的大小,并不知道当前这张图片所处的空间位置。我们如果知道当前图片坐标位置,通过java调用AE接口是可以配置图片的空间信息的,下面就具体介绍如何实现。

所使用的环境是:arcgis10.0,jdk1.6。

首先拷贝AE java开发包,具体位置在”C:\Program Files\ArcGIS\Engine10.0\java\lib“这是我安装的目录。

JAVA代码实现如下:

import java.io.File;

import com.esri.arcgis.datasourcesraster.IRasterGeometryProc;
import com.esri.arcgis.datasourcesraster.IRasterProps;
import com.esri.arcgis.datasourcesraster.IRasterPropsProxy;
import com.esri.arcgis.datasourcesraster.RasterGeometryProc;
import com.esri.arcgis.datasourcesraster.RasterWorkspaceFactory;
import com.esri.arcgis.datasourcesraster.esriGeoTransTypeEnum;
import com.esri.arcgis.geodatabase.IRaster;
import com.esri.arcgis.geodatabase.IRasterDataset;
import com.esri.arcgis.geodatabase.IRasterWorkspace2;
import com.esri.arcgis.geodatabase.IRasterWorkspace2Proxy;
import com.esri.arcgis.geodatabase.IWorkspaceFactory;
import com.esri.arcgis.geometry.IPointCollection;
import com.esri.arcgis.geometry.ISpatialReference;
import com.esri.arcgis.geometry.ISpatialReferenceFactory2;
import com.esri.arcgis.geometry.Multipoint;
import com.esri.arcgis.geometry.Point;
import com.esri.arcgis.geometry.SpatialReferenceEnvironment;
import com.esri.arcgis.interop.AutomationException;

public class ImgToRaster {
	
	public IRasterWorkspace2 openRasterWorkspace(String path) throws Exception {
		IWorkspaceFactory workspaceFact = new RasterWorkspaceFactory();
		return new IRasterWorkspace2Proxy(workspaceFact.openFromFile(path, 0));
	}
	
	/**
	 * 处理配置方法
	 * @param rasterFilePaht
	 * @param raster
	 * @param targetPoints
	 * @param staType
	 * @throws Exception
	 */
	public void georeferenceRaster(String rasterFilePaht, IRaster raster,
			IPointCollection targetPoints , String staType) throws Exception {

		// sourcePoints: represents source control points
		// targetPoints: represents target control points
		IRasterProps rasterProps = new IRasterPropsProxy(raster);
		int width = rasterProps.getWidth(); // 当前栅格数据集的列数
		int height = rasterProps.getHeight(); // 当前栅格数据集的行数
		IPointCollection sourcePoints = new Multipoint();
		Point point = new Point();
		// 1
		point.putCoords(0.000000, 0.000000);
		sourcePoints.addPoint(point, null, null);
		// 2
		point = new Point();
		point.putCoords(width, 0.000000);
		sourcePoints.addPoint(point, null, null);
		// 3
		point = new Point();
		point.putCoords(0.000000, -height);
		sourcePoints.addPoint(point, null, null);
		// 4
		point = new Point();
		point.putCoords(width, -height);
		sourcePoints.addPoint(point, null, null);

		// -----
		IRasterGeometryProc rasterPropc = new RasterGeometryProc();
		rasterPropc.warp(sourcePoints, targetPoints,
				esriGeoTransTypeEnum.esriGeoTransPolyOrder1, raster);
		// rasterPropc.register(raster);
		if ( staType.equals("HJ")) {
			rasterPropc.rectify(rasterFilePaht, "PNG", raster);
		} else {
			rasterPropc.rectify(rasterFilePaht, "JPG", raster);
		}
		
		
	}
	
	/**
	 * 
	 * @param inputPath  输入需要配准图片的路径
	 * @param rasterName 图片的名称
	 * @param outPutPath 输入配准完之后的路径
	 * @param pointBean  配准的角点坐标
	 * @param imgType    配准图片后缀
	 */
	public boolean changeRaster (String inputPath , String rasterName, String outPutPath, PointBean pointBean ,String staType) {
		
		String path = inputPath;
		ISpatialReferenceFactory2 srFactory = null;
		IRasterWorkspace2 rasterWs = null;
		IRasterDataset rastDataset = null;
		String exportRasterFile = outPutPath + rasterName;
		try {
			if (new File(outPutPath).exists() == false) {
				new File(outPutPath).mkdirs();
			}
			srFactory = new SpatialReferenceEnvironment();
			rasterWs = openRasterWorkspace(path);
			
			rastDataset = rasterWs.openRasterDataset(rasterName);
			IRaster raster = rastDataset.createDefaultRaster();
			
			//
			IRasterProps rasterProps = new IRasterPropsProxy(raster);
			int dHeight = rasterProps.getHeight();
			int dWidth = rasterProps.getWidth();

			// --配准目标点
			ISpatialReference ref = srFactory
					.createGeographicCoordinateSystem(4326);
			Point point = null;
			IPointCollection targetPoints = new Multipoint();

			// 1-左上角坐标
			point = new Point();
			point.setSpatialReferenceByRef(ref);
			point.putCoords(pointBean.getTopLeftX(), pointBean.getTopLeftY());
			targetPoints.addPoint(point, null, null);

			// 2-右上角坐标
			point = new Point();
			point.setSpatialReferenceByRef(ref);
			point.putCoords(pointBean.getTopRightX(), pointBean.getTopRightY());
			targetPoints.addPoint(point, null, null);

			// 3-左下角坐标
			point = new Point();
			point.setSpatialReferenceByRef(ref);
			point.putCoords(pointBean.getBottomLeftX(), pointBean.getBottomLeftY());
			targetPoints.addPoint(point, null, null);

			// 4-右下角坐标
			point = new Point();
			point.setSpatialReferenceByRef(ref);
			point.putCoords(pointBean.getBottomRightX(), pointBean.getBottomRightY());
			targetPoints.addPoint(point, null, null);

			// --配准生成栅格文件
			georeferenceRaster(exportRasterFile, raster, targetPoints , staType);
			return  true;
		}  catch (AutomationException e) {
			if (new File(path+"/"+rasterName).isFile()) {
				new File(path+"/"+rasterName).delete();
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			srFactory = null;
			rasterWs = null;
			rastDataset = null;
		}
		return false;
	}
	
	public static void main(String[] args) {
		//图片经纬度范围
		PointBean pointBean = new PointBean();
		pointBean.setTopLeftX(112.118862);
		pointBean.setTopLeftY(59.473191);
		
		pointBean.setTopRightX(121.205099);
		pointBean.setTopRightY(59.496730);
		
		pointBean.setBottomLeftX(112.647156);
		pointBean.setBottomLeftY(55.279405);
		
		pointBean.setBottomRightX(120.749494);
		pointBean.setBottomRightY(55.299451);
		//方法调用	
		ImgToRaster test =new ImgToRaster();
		test.changeRaster("D:\\IMG\\", "HJ1B-CCD1-10-42-20121112-L20000885140.JPG", "D:\\IMG\\bak\\", pointBean, "jpg");
	}

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值