`

arcgis server 服务

 
阅读更多
package com.hdmap.fymas;

import java.io.IOException;

import com.esri.arcgis.geodatabase.Feature;
import com.esri.arcgis.geodatabase.FeatureClass;
import com.esri.arcgis.geodatabase.FeatureCursor;
import com.esri.arcgis.geodatabase.Field;
import com.esri.arcgis.geodatabase.Fields;
import com.esri.arcgis.geodatabase.IDataset;
import com.esri.arcgis.geodatabase.IDatasetName;
import com.esri.arcgis.geodatabase.IEnumDataset;
import com.esri.arcgis.geodatabase.IEnumDatasetName;
import com.esri.arcgis.geodatabase.IFeatureBuffer;
import com.esri.arcgis.geodatabase.IFeatureCursor;
import com.esri.arcgis.geodatabase.IWorkspace;
import com.esri.arcgis.geodatabase.esriDatasetType;
import com.esri.arcgis.geodatabase.esriFieldType;
import com.esri.arcgis.geodatabasedistributed.GeoDataServer;
import com.esri.arcgis.geometry.IPoint;
import com.esri.arcgis.geometry.Point;
import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.server.IServerContext;
import com.esri.arcgis.server.IServerObjectManager;
import com.esri.arcgis.server.ServerConnection;
import com.esri.arcgis.system.Cleaner;
import com.esri.arcgis.system.ServerInitializer;

public class GeoDataServerMain {

	
	private static String user = "cmt";// 
	private static String password = "a";// 
	private static String domain = "172.16.17.156";
	private static String host = "172.16.17.156";
	private static String servicesName = "qin/usaqiny";
	private static ServerConnection conn = null;
	private static IServerContext serverContext = null;
	private static IServerObjectManager som = null;
	private static GeoDataServer gdbserver = null;
	private static IWorkspace workspace = null;

	public static void initGeoDataServer() {
		/*** 连接到ArcGISSever */
		try {
			new ServerInitializer().initializeServer(domain, user, password);
			conn = new ServerConnection();
			conn.connect(host);
			som = conn.getServerObjectManager();
			serverContext = som.createServerContext(servicesName,
					"GeoDataServer");
			gdbserver = (GeoDataServer) serverContext.getServerObject();

			workspace = gdbserver.getDefaultWorkingWorkspace();
			System.out.print("已连接到ArcGIS Sever");
		} catch (Exception e) {
			e.printStackTrace();
			gdbserver = null;
			workspace = null;
			som = null;
		}
	}

	public static void main(String[] args) throws Exception {
		// GeoDataServerMain it = new GeoDataServerMain();
		initGeoDataServer();
		browseFileGDB(workspace);
		insertFeaturesUsingCursor(workspace);
		browseFileGDB(workspace);
		serverContext.releaseContext();
	}

	/**
	 * 显示所有的图层
	 * @param workspace
	 */
	public static void browseFileGDB(IWorkspace workspace) {
		try {

			IEnumDatasetName enumDatasetName = workspace
					.getDatasetNames(esriDatasetType.esriDTAny);

			IDatasetName dsName = enumDatasetName.next();
			while (dsName != null) {
				System.out.println("Dataset Name: " + dsName.getName());

				dsName = enumDatasetName.next();
			}

			IEnumDataset enumDataset = workspace
					.getDatasets(esriDatasetType.esriDTFeatureClass);

			IDataset ds = enumDataset.next();
			while (ds != null) {
				FeatureClass fClass = new FeatureClass(ds);
				query(fClass);
				int fCount = fClass.featureCount(null);

				System.out.println("FeatureClass " + fClass.getAliasName()
						+ " has " + fCount + " features.");

				ds = enumDataset.next();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**查询数据
	 * @param featureClass
	 * @throws AutomationException
	 * @throws IOException
	 */
	public static void query(FeatureClass featureClass)
			throws AutomationException, IOException {

		FeatureCursor featureCursor = new FeatureCursor(featureClass.search(
				null, true));
		Feature feature = (Feature) featureCursor.nextFeature();
		Fields fields = (Fields) featureCursor.getFields();
		int fieldCount = fields.getFieldCount();

		for (int index = 0; index < fieldCount; index++) {
			Field field = (Field) fields.getField(index);
			String fieldName = field.getName();
			System.out.print(fieldName + "\t");
		}
		System.out.println();
		while (feature != null) {
			StringBuffer row = new StringBuffer();

			for (int index = 0; index < fieldCount; index++) {
				int fieldType = feature.getFields().getField(index).getType();

				switch (fieldType) {
				case esriFieldType.esriFieldTypeDate:
				case esriFieldType.esriFieldTypeDouble:
				case esriFieldType.esriFieldTypeGlobalID:
				case esriFieldType.esriFieldTypeGUID:
				case esriFieldType.esriFieldTypeInteger:
				case esriFieldType.esriFieldTypeOID:
				case esriFieldType.esriFieldTypeSingle:
				case esriFieldType.esriFieldTypeSmallInteger:
				case esriFieldType.esriFieldTypeString:
					row.append(feature.getValue(index) + "\t");
					break;

				case esriFieldType.esriFieldTypeBlob:
					row.append("(blob)" + "\t");
					break;

				case esriFieldType.esriFieldTypeGeometry:
					row.append("(geometry)" + "\t");
					break;

				case esriFieldType.esriFieldTypeRaster:
					row.append("(raster)" + "\t");
					break;
				}
			}

			if (row.length() > 0) {
				System.out.println(row);
			}

			feature = (Feature) featureCursor.nextFeature();
		}
	}

	/**
	 * 插入数据
	 * @param workspace
	 * @throws Exception
	 */
	private static void insertFeaturesUsingCursor(IWorkspace workspace)
			throws Exception {
		IEnumDataset enumDataset = workspace
				.getDatasets(esriDatasetType.esriDTFeatureClass);
		IDataset ds = enumDataset.next();// 这里就有一个图层,所以就这么写了,应该获得图层然后进行操作 
		
		while (ds != null) {
			
			FeatureClass featureClass = new FeatureClass(ds);
			IFeatureBuffer featureBuffer = featureClass.createFeatureBuffer();

			IFeatureCursor insertCursor = featureClass
					.IFeatureClass_insert(false);
            // 这里是关键
			// 不能  Point point= new Point();
			IPoint point = (IPoint) serverContext
					.createObject(Point.getClsid());
			point.setX(100);
			point.setY(200);
			featureBuffer.setShapeByRef(point);
			insertCursor.insertFeature(featureBuffer);
			ds = enumDataset.next();
			insertCursor.flush();
			Cleaner.release(insertCursor);
		}
	}
}

 

package com.hdmap.fymas;

import java.io.IOException;
import java.util.List;

import com.esri.arcgis.carto.FeatureLayer;
import com.esri.arcgis.carto.IFeatureLayer;
import com.esri.arcgis.geodatabase.Feature;
import com.esri.arcgis.geodatabase.FeatureClass;
import com.esri.arcgis.geodatabase.FeatureCursor;
import com.esri.arcgis.geodatabase.Field;
import com.esri.arcgis.geodatabase.Fields;
import com.esri.arcgis.geodatabase.IDataset;
import com.esri.arcgis.geodatabase.IDatasetName;
import com.esri.arcgis.geodatabase.IEnumDataset;
import com.esri.arcgis.geodatabase.IEnumDatasetName;
import com.esri.arcgis.geodatabase.IFeatureBuffer;
import com.esri.arcgis.geodatabase.IFeatureClass;
import com.esri.arcgis.geodatabase.IFeatureCursor;
import com.esri.arcgis.geodatabase.IWorkspace;
import com.esri.arcgis.geodatabase.esriDatasetType;
import com.esri.arcgis.geodatabase.esriFieldType;
import com.esri.arcgis.geodatabasedistributed.GeoDataServer;
import com.esri.arcgis.geometry.IPoint;
import com.esri.arcgis.geometry.Point;
import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.server.IServerContext;
import com.esri.arcgis.server.IServerObjectManager;
import com.esri.arcgis.server.ServerConnection;
import com.esri.arcgis.system.Cleaner;
import com.esri.arcgis.system.ServerInitializer;
import com.hdmap.fymas.fire.bean.FirePoint;
import com.hdmap.fymas.utils.ReadFromFileUtil;

public class GeoDataServerMain {

	private static String user = "cmt";//
	private static String password = "a";//
	private static String domain = "172.16.17.156";
	private static String host = "172.16.17.156";
	private static String servicesName = "qin/usaqiny";
	private static ServerConnection conn = null;
	private static IServerContext serverContext = null;
	private static IServerObjectManager som = null;
	private static GeoDataServer gdbserver = null;
	private static IWorkspace workspace = null;

	public static void initGeoDataServer() {
		/*** 连接到ArcGISSever */
		try {
			new ServerInitializer().initializeServer(domain, user, password);
			conn = new ServerConnection();
			conn.connect(host);
			som = conn.getServerObjectManager();
			serverContext = som.createServerContext(servicesName,
					"GeoDataServer");
			gdbserver = (GeoDataServer) serverContext.getServerObject();

			workspace = gdbserver.getDefaultWorkingWorkspace();
			System.out.print("已连接到ArcGIS Sever");
		} catch (Exception e) {
			e.printStackTrace();
			gdbserver = null;
			workspace = null;
			som = null;
		}
	}

	public static void main(String[] args) throws Exception {
		// GeoDataServerMain it = new GeoDataServerMain();
		initGeoDataServer();
		browseFileGDB(workspace);
		String fileName = "D:/FIR_PLST_FY3A_MERSI_1000M_EJ_P001_20110426024500.TXT";
		List alist = ReadFromFileUtil.readFirePointByLines(fileName);
		System.out.println(alist);

		// insertFeaturesUsingCursor(workspace);
		insertFirePoint(workspace, alist);
		browseFileGDB(workspace);
		serverContext.releaseContext();
	}

	/**
	 * 插入数据
	 * 
	 * @param workspace
	 * @throws Exception
	 */
	@SuppressWarnings("unused")
	private static void insertFeaturesUsingCursor(IWorkspace workspace,
			String featureName) throws Exception {
		FeatureClass featureClass = getFeatureClassByName(workspace,
				featureName);
		IFeatureBuffer featureBuffer = featureClass.createFeatureBuffer();
		IFeatureCursor insertCursor = featureClass.IFeatureClass_insert(false);
		// 这里是关键
		// 不能 Point point= new Point();
		IPoint point = (IPoint) serverContext.createObject(Point.getClsid());
		point.setX(100);
		point.setY(200);
		featureBuffer.setShapeByRef(point);
		insertCursor.insertFeature(featureBuffer);

		insertCursor.flush();
		Cleaner.release(insertCursor);

	}

	/**
	 * 根据FeatureClassName 获得FeatureClass
	 * 
	 * @param workspace
	 * @param FeatureClassName
	 * @return
	 * @throws AutomationException
	 * @throws IOException
	 */
	public static FeatureClass getFeatureClassByName(IWorkspace workspace,
			String FeatureClassName) throws AutomationException, IOException {

		IEnumDataset enumDataset = workspace
				.getDatasets(esriDatasetType.esriDTFeatureClass);
		IDataset ds = enumDataset.next();//
		FeatureClass featureClass = null;
		while (ds != null) {
			if (FeatureClassName.equals(ds.getName())) {
				featureClass = new FeatureClass(ds);

			}
			ds = enumDataset.next();
		}
		return featureClass;
	}

	/**
	 * 显示所有的图层
	 * 
	 * @param workspace
	 */
	public static void browseFileGDB(IWorkspace workspace) {
		try {

			IEnumDatasetName enumDatasetName = workspace
					.getDatasetNames(esriDatasetType.esriDTAny);

			IDatasetName dsName = enumDatasetName.next();
			while (dsName != null) {
				System.out.println("Dataset Name: " + dsName.getName());

				dsName = enumDatasetName.next();
			}

			IEnumDataset enumDataset = workspace
					.getDatasets(esriDatasetType.esriDTFeatureClass);

			IDataset ds = enumDataset.next();
			while (ds != null) {
				FeatureClass fClass = new FeatureClass(ds);
				query(fClass);
				int fCount = fClass.featureCount(null);

				System.out.println("FeatureClass " + fClass.getAliasName()
						+ " has " + fCount + " features.");

				ds = enumDataset.next();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 查询数据
	 * 
	 * @param featureClass
	 * @throws AutomationException
	 * @throws IOException
	 */
	public static void query(FeatureClass featureClass)
			throws AutomationException, IOException {

		FeatureCursor featureCursor = new FeatureCursor(featureClass.search(
				null, true));
		Feature feature = (Feature) featureCursor.nextFeature();
		Fields fields = (Fields) featureCursor.getFields();
		int fieldCount = fields.getFieldCount();

		for (int index = 0; index < fieldCount; index++) {
			Field field = (Field) fields.getField(index);
			String fieldName = field.getName();
			System.out.print(fieldName + "\t");
		}
		System.out.println();
		while (feature != null) {
			StringBuffer row = new StringBuffer();
			for (int index = 0; index < fieldCount; index++) {
				int fieldType = feature.getFields().getField(index).getType();

				switch (fieldType) {
				case esriFieldType.esriFieldTypeDate:
				case esriFieldType.esriFieldTypeDouble:
				case esriFieldType.esriFieldTypeGlobalID:
				case esriFieldType.esriFieldTypeGUID:
				case esriFieldType.esriFieldTypeInteger:
				case esriFieldType.esriFieldTypeOID:
				case esriFieldType.esriFieldTypeSingle:
				case esriFieldType.esriFieldTypeSmallInteger:
				case esriFieldType.esriFieldTypeString:
					row.append(feature.getValue(index) + "\t");
					break;

				case esriFieldType.esriFieldTypeBlob:
					row.append("(blob)" + "\t");
					break;

				case esriFieldType.esriFieldTypeGeometry:
					row.append("(geometry)" + "\t");
					break;

				case esriFieldType.esriFieldTypeRaster:
					row.append("(raster)" + "\t");
					break;
				}
			}

			if (row.length() > 0) {
				System.out.println(row);
			}

			feature = (Feature) featureCursor.nextFeature();
		}
	}

	/**
	 * 插入火点数据
	 * 
	 * @param workspace
	 * @throws Exception
	 */
	@SuppressWarnings("unused")
	private static void insertFirePoint(IWorkspace workspace,
			List<FirePoint> fpList) throws Exception {
		// IEnumDataset enumDataset = workspace
		// .getDatasets(esriDatasetType.esriDTFeatureClass);
		// IDataset ds = enumDataset.next();// 这里就有一个图层,所以就这么写了,应该获得图层然后进行操作

		String fName = "fire_p";
		// while (ds != null) {
		FeatureClass featureClass = getFeatureClassByName(workspace, fName);
		// FeatureClass featureClass = new FeatureClass(ds);
		IFeatureBuffer featureBuffer = featureClass.createFeatureBuffer();

		IFeatureCursor insertCursor = featureClass.IFeatureClass_insert(false);

		for (int i = 0; i < fpList.size(); i++) {
			// 这里是关键
			FirePoint fp = fpList.get(i);
			IPoint point = (IPoint) serverContext
					.createObject(Point.getClsid());

			point.setX(fp.getX());
			point.setY(fp.getY());
			featureBuffer.setShapeByRef(point);
			insertCursor.insertFeature(featureBuffer);
		}

		// ds = enumDataset.next();
		insertCursor.flush();

		Cleaner.release(insertCursor);
		// }
	}
}

 

分享到:
评论

相关推荐

    重启ArcGis Server 服务工具

    - 在命令行中,定位到 AGSSOM.exe 所在的路径,例如 "C:\arcgisserver\directories\arcgisserver\tools\agsadmin"(具体路径取决于你的安装位置)。 - 输入命令 `AGSSOM.exe -admin -s &lt;server_url&gt; -u &lt;username&gt;...

    局域网内以ArcGIS Server Local的方式连接ArcGIS Server服务器

    在局域网环境中,当Web站点与ArcGIS Server服务不在同一台机器上时,或者是在多人协作开发的情况下需要共享同一台服务器上的服务时,就需要进行特定的配置。这种配置的目的在于确保Web站点能够顺利地访问到ArcGIS ...

    openlayers 调用 arcgis server wms服务简单图解

    首先,为了实现OpenLayers与ArcGIS Server的集成,你需要确保在创建ArcGIS Server服务时已经启用了WMS服务。这通常在Authoring或Publishing服务时完成。在ArcCatalog中,你可以选择要发布的服务,并在设置选项中勾选...

    ArcEngine连接ArcGIS Server服务

    总之,ArcEngine连接ArcGIS Server服务是GIS应用开发的重要环节,它允许开发者利用服务器上的地图服务构建定制化的GIS应用程序,满足特定的业务需求。理解并熟练掌握这个过程,对于提升GIS开发技能至关重要。

    ArcGIS Server10.2.1跨域设置.7z

    然而,由于浏览器的同源策略限制,Web应用通常不能直接访问不同源(域名、协议或端口不同)的资源,这在尝试从Web应用访问ArcGIS Server服务时会遇到问题。为解决这个问题,ArcGIS Server10.2.1提供了跨域设置。 ...

    C/S平台下通过C#连接ArcGIS Server服务

    ### C/S平台下通过C#连接ArcGIS Server服务的知识点详解 #### 一、概述 在客户端/服务器(C/S)架构中,通过C#语言实现与ArcGIS Server的服务连接是一项重要的技术。此技术允许开发人员利用ArcGIS Server提供的...

    解决arcgis server跨域问题

    1、停掉ArcGIS Server的服务。 2、 打开&lt;ArcGIS Server&gt; \framework\runtime\tomcat\conf\web.xml,注册跨域bean 3、lib下拷贝 cors-filter-2.5.jar java-property-utils-1.9.1.jar包 4、启动ArcGIS Server的服务。 5...

    访问ArcGIS server服务的ArcEngine网络分析服务

    总的来说,访问ArcGIS Server服务的ArcEngine网络分析服务是一项涉及多个步骤和技术的复杂任务。开发者需要熟悉ArcGIS API,理解网络分析原理,并具备良好的编程和GIS应用设计能力。通过Route_GISClient这样的客户端...

    如何在OsgEarth中加载谷歌卫星地图的ArcGISServer服务教程

    在 OsgEarth 中加载谷歌卫星地图的 ArcGISServer 服务教程是指通过使用水经注万能地图下载器下载的谷歌卫星地图瓦片数据,在 ArcGIS 中发布服务,并在 OsgEarth 中加载发布好的瓦片服务。以下是相关知识点: 1. ...

    ARCGIS Server服务接口设计

    ARCGIS Server服务接口设计是一份关于如何为开发者提供ARCGIS Server服务接口设计指导的文档,本文将详细解读文档所涉及的知识点。 首先,文档开篇就提出了对ARCGIS Server服务接口的总体介绍,强调了ARCGIS Server...

    ArcGIS_Server中的各种服务简介

    本篇文章将详细介绍 ArcGIS Server 中的各种服务及其功能。 1. 地图服务 (Map Service) 地图服务是 ArcGIS Server 的核心服务之一,它基于地图文档 (.mxd, .pmf) 提供地图内容的访问。地图服务可以以多种方式展示,...

    ArcGis服务迁移流程.doc

    ArcGis server服务迁移,不用再一个一个的重新发服务,新装好server服务器后,只需三步即可迁移,简单方便

    ArcGisServer 跨网段访问问题及解决

    ArcGisServer 跨网段访问问题及解决 在 ArcGisServer 中,跨网段访问问题是一个常见的问题,该问题的解决方案对许多开发者和管理员来说都是非常重要的。今天,我们将详细讨论 ArcGisServer 跨网段访问问题及解决...

    ArcGISServer与java

    《ArcGISServer服务扩展与Java深度解析》 ArcGISServer是Esri公司推出的地理信息系统(GIS)服务器产品,它允许用户通过网络共享、管理和发布地理数据与服务。Java作为一门广泛应用于企业级开发的语言,与ArcGIS...

    ArcGIS Server 10.5安装包下载地址和ECP文件.rar

    7. **启动和验证**:安装完成后,启动ArcGIS Server服务,并通过Web浏览器访问管理界面,验证安装是否成功。 8. **发布和管理服务**:通过ArcGIS Server Manager或ArcGIS Desktop创建和发布地图服务,与其他用户...

    Arcgis Server动态加载图层

    在ArcGIS Server中,动态加载图层是一种优化地图服务性能的技术。它允许用户根据需要在运行时动态地添加、删除或更改地图中的图层,而不是一次性加载所有数据。这种技术对于处理大量数据或者需要实时更新的地图应用...

    如何用java控制 Arcgis Server 服务的状态?

    用Arcgis Server 提供的 REST API 直接调用Arcgis Server 服务状态

Global site tag (gtag.js) - Google Analytics