欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Arcgis object for java 访问栅格数据,使用GP工具,进行栅格矢量化---栅格矢量化面。

程序员文章站 2022-06-12 23:50:15
...

    直接贴代码了,不多解释了。

  

1、栅格数据的存储类型

      栅格数据一般可以存储为ESRI GRID(由一系列文件组成),TIFF格式(包括一个TIF文件和一个AUX文件),还有JPG,BMP文件,IMAGINE Image格式 在AE中一般调用ISaveAs接口来保存栅格数据。

 

2、栅格数据集和栅格编目的区别

      一个栅格数据集由一个或者多个波段(RasterBand)的数据组成,一个波段就是一个数据矩阵。对于格网数据(DEM数据)和单波段的影像数据,表现为仅仅只有一个波段数据的栅格数据集,而对于多光谱影像数据则表现为具有多个波段的栅格数据集

       栅格编目(RasterCatalog)用于显示某个研究区域内各种相邻的栅格数据,这些相邻的栅格数据没有经过拼接处理  合成一副大的影像图

 

3、IRasterWorkspaceEx与IRasterWorkspace ,IRsterWorkspace2的区别

 

1).IRasteWorkspaceEx接口主要是用来读取GeoDatabase中的栅格数据集和栅格编目

2) . IRasterWorkspace ,IRsterWorkspace2主要是用来读取以文件格式存储在本地的栅格数据

 

4、加载栅格数据(以存储在本地的栅格数据文件为例)

 

import com.esri.arcgis.carto.IRasterLayer;
import com.esri.arcgis.carto.RasterLayer;
import com.esri.arcgis.datasourcesraster.IRasterBand;
import com.esri.arcgis.datasourcesraster.IRasterBandCollection;
import com.esri.arcgis.datasourcesraster.IRasterBandCollectionProxy;
import com.esri.arcgis.datasourcesraster.RasterWorkspaceFactory;
import com.esri.arcgis.geodatabase.IDataset;
import com.esri.arcgis.geodatabase.IDatasetProxy;
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.geoprocessing.GeoProcessor;
import com.esri.arcgis.geoprocessing.tools.conversiontools.RasterToPolygon;
import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.IPropertySet;
import com.esri.arcgis.system.esriLicenseProductCode;
import com.esri.arcgis.system.esriLicenseStatus;

public class RasterMain {

	public RasterMain() {

	}

	public static void main(String[] args) {
		System.out
				.println("Starting RasterMain - An ArcObjects SDK Developer Sample");

		try {
			// Initialize engine console application
			EngineInitializer.initializeEngine();

			// Initialize ArcGIS license
			AoInitialize aoInit = new AoInitialize();
			initializeArcGISLicenses(aoInit);

			// Get DEVKITHOME Home

			System.out.println("Setup--------");
			testRasterMethods();
			System.out.println("Done.-----------");

			// Ensure any ESRI libraries are unloaded in the correct order
			aoInit.shutdown();
		} catch (Exception e) {
			System.out.println("Error: " + e.getMessage());
			System.out.println("Sample failed.  Exiting...");
			e.printStackTrace();
			System.exit(-1);
		}
	}

	private static void testRasterMethods() throws Exception {
		String rastFileDocPath = "D:\\temp\\test\\bmp";
		String rastFilePath = "DST_DBLV_FY3A_MERSI_1000M_DXX_P001_20110407054000.bmp";
		String outPolygonFeaturesPath = "D:\\temp\\test\\shp\\qincytewt999900t.shp";
		
		IRasterWorkspace2 rasterWs = openRasterWorkspace(rastFileDocPath);
		IRasterDataset rastDataset = rasterWs.openRasterDataset(rastFilePath);
		IRasterDataset rastDatasetItem1 = getRasterDatasetItem(rastDataset, 1);
		rasterToPolygon(rastDatasetItem1, outPolygonFeaturesPath);
	
	}

	private static IRasterWorkspace2 openRasterWorkspace(String rastFileDocPath)
			throws Exception {
		IWorkspaceFactory workspaceFact = new RasterWorkspaceFactory();
		
		IRasterWorkspace2 rw2 = new IRasterWorkspace2Proxy(
				workspaceFact.openFromFile(rastFileDocPath, 0));
		return rw2;
	}

	private static void rasterToPolygon(IRasterDataset rasterDataset,
			String outPolygonFeaturesPath) {
		try {
			GeoProcessor geoprocessor = new GeoProcessor();
			RasterToPolygon rasterToPolygon = new RasterToPolygon();

			String paramObject = "Value";
			String simplify = "false";

			rasterToPolygon.setOutPolygonFeatures(outPolygonFeaturesPath);
			rasterToPolygon.setRasterField(paramObject);
			IRasterLayer rasterLayer = new RasterLayer();
			rasterLayer.createFromDataset(rasterDataset);
			rasterToPolygon.setInRaster(rasterLayer);
			rasterToPolygon.setSimplify(simplify);

			//System.out.println(rasterToPolygon.getSimplify());
			geoprocessor.execute(rasterToPolygon, null);
		} catch (Exception e) {
			//System.out.println("rasterToPolygon=" + e);
		}

	}

	@SuppressWarnings("unused")
	private static void BMP_EXIFtag(IRasterDataset exifDataset) {
		try {
			IDataset dataset = new IDatasetProxy(exifDataset);

			IPropertySet propertySet = dataset.getPropertySet();
			Object[] tag_names = new Object[1];
			Object[] tag_values = new Object[1];
			propertySet.getAllProperties(tag_names, tag_values);
			String[] stringNames = (String[]) tag_names[0];
			Object[] stringValues = (Object[]) tag_values[0];
			for (int i = 0; i <= stringNames.length - 1; i++) {
				System.out.print(stringNames[i] + ":");
				System.out.println(stringValues[i]);
			}
		} catch (Exception e) {
			System.out.println("BMP_EXIFtag" + e);
		}

	}

	@SuppressWarnings("deprecation")
	private static IRasterDataset getRasterDatasetItem(
			IRasterDataset exifDataset, int num) throws Exception {
		IRasterBandCollection rasterBands = new IRasterBandCollectionProxy(
				exifDataset);
		
		IRasterBand rasterBand = rasterBands.item(num);
		System.out.println("rasterBand:" + rasterBand.getBandname());
		IRasterDataset di = rasterBand.getRasterDataset();
		return di;

	}

	/**
	 * Checks to see if an ArcGIS Engine Runtime license or an ArcView License
	 * is available. If so, then the appropriate ArcGIS License is initialized.
	 * 
	 * @param aoInit
	 *            The AoInitialize object instantiated in the main method.
	 */
	private static void initializeArcGISLicenses(AoInitialize aoInit) {
		try {
			if (aoInit
					.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngine) == esriLicenseStatus.esriLicenseAvailable)
				aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
			else if (aoInit
					.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeArcView) == esriLicenseStatus.esriLicenseAvailable)
				aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeArcView);
			else {
				System.err
						.println("Could not initialize an Engine or ArcView license. Exiting application.");
				System.exit(-1);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}

    5 详细情况可以使用esri 提供的java 帮助搜索 ,可以查询到在catalog  或者geobase 的例子。

    6 本代码有报异常的错误,但是不影响使用,依然能栅格矢量化,不知道为什么,请高手帮忙解决这个问题。