`
Virgo_S
  • 浏览: 1137803 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

ArcGIS Server 专题图的实现

阅读更多
测试完毕.地图服务是用ArcGis自带的USA.mxd.还留有的问题就是不能清除,需要重启服务清除。

专题地图:是突出反映一种或几种主题要素的地图,地图的主题要素是根据专门用途的需要确定的,它们应表达的详细,其它的地理要素则根据表达主题的需要作为地理基础选绘。
http://blog.csdn.net/mader/archive/2008/10/16/3084501.aspx
http://webgis.xdz.com.cn/


近日研究了在ArcGIS Server web adf (9.2)专题图实现,整理如下: (以柱状图为例,饼状图和直方图类似),希望对大家有所帮助!
package com.esri.webadf.sample;

import java.util.List;
import com.esri.adf.web.ags.data.AGSLocalMapResource;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebLayerInfo;
import com.esri.adf.web.data.query.WebQuery;
import com.esri.adf.web.faces.event.MapEvent;
import com.esri.arcgis.carto.ChartRenderer;
import com.esri.arcgis.carto.FeatureLayer;
import com.esri.arcgis.carto.ILayer;
import com.esri.arcgis.carto.IRendererFields;
import com.esri.arcgis.carto.MapServer;
import com.esri.arcgis.display.BarChartSymbol;
import com.esri.arcgis.display.IChartSymbol;
import com.esri.arcgis.display.ILineSymbol;
import com.esri.arcgis.display.IMarkerSymbol;
import com.esri.arcgis.display.IRgbColor;
import com.esri.arcgis.display.ISymbolArray;
import com.esri.arcgis.display.RgbColor;
import com.esri.arcgis.display.SimpleFillSymbol;
import com.esri.arcgis.display.SimpleLineSymbol;
import com.esri.arcgis.geodatabase.ICursor;
import com.esri.arcgis.geodatabase.IRowBuffer;
import com.esri.arcgis.geodatabase.QueryFilter;


public class BarChart {

	private WebContext webContext = null;

	public WebContext getWebContext() {
		return webContext;
	}

	public void setWebContext(WebContext webContext) {
		this.webContext = webContext;
	}

	public void createBarChart(MapEvent event) {

		
		try {
			//得到制作专题图的图层ID
			//		  。。。。。。。。。。
			WebQuery query = event.getWebContext().getWebQuery();
			List<WebLayerInfo> layerList = query.getQueryLayers();
			for(int i=0;i<layerList.size();i++){
				WebLayerInfo info = layerList.get(i);
				info.getName();
			}
			int layerID = 3;

			//得到专题图分析元素的属性名称列表
			String[] fieldName = new String[2];
			fieldName[0] = "POP1990";
			fieldName[1] = "POP1999";

			//得到专题图分析的图层对象(FeatureLayer)
			AGSLocalMapResource res = (AGSLocalMapResource) this.webContext.getResources().get("ags1");
			MapServer mapServer = res.getLocalMapServer();
			ILayer fiLayer;
			fiLayer = mapServer.getLayer(mapServer.getMapName(0), layerID);
			FeatureLayer fLayer = (FeatureLayer) fiLayer;

			//创建ChartRenderer对象  注意:在web adf中创建AO对象用AGSLocalMapResource对象的createArcObject(String)方法
			ChartRenderer chartRender = (ChartRenderer) res.createArcObject(ChartRenderer.getClsid());

			//在IRendererFileds中指定柱状图各列显示字段值   
			IRendererFields rendererFields = chartRender;
			rendererFields.addField(fieldName[0], null);
			rendererFields.setFieldAlias(0, rendererFields.getField(0));
			rendererFields.addField(fieldName[1], null);
			rendererFields.setFieldAlias(1, rendererFields.getField(1));

			//查出各元素指定属性最大值  必须的
			QueryFilter queryFilter = (QueryFilter) res.createArcObject(QueryFilter.getClsid());
			queryFilter.addField(fieldName[0]);
			queryFilter.addField(fieldName[1]);
			ICursor cursor = fLayer.ITable_search(queryFilter, true);
			int numFields = 2; //柱状图列的个数
			int[] fieldIndecies = new int[numFields];
			fieldIndecies[0] = fLayer.findField(fieldName[0]);
			fieldIndecies[1] = fLayer.findField(fieldName[1]);
			double maxValue = 0;
			boolean firstValue = true;
			IRowBuffer row = cursor.nextRow();
			while (row != null) {
				for (int fieldIndex = 0; fieldIndex < numFields; fieldIndex++) {
					double fieldValue = Double.parseDouble(row.getValue(
							fieldIndecies[fieldIndex]).toString());
					if (firstValue) {
						maxValue = fieldValue;
						firstValue = false;
					}
					if (fieldValue > maxValue)
						maxValue = fieldValue;
				}
				row = cursor.nextRow();
			}

			//实例化图表对象
			BarChartSymbol barChartSymbol = (BarChartSymbol) res.createArcObject(BarChartSymbol.getClsid());

			IChartSymbol chartSymbol = barChartSymbol;
			barChartSymbol.setWidth(10);
			IMarkerSymbol markerSymbol = barChartSymbol;
			chartSymbol.setMaxValue(maxValue);
			markerSymbol.setSize(60);

			//设置柱状图每列填充颜色及线颜色
			SimpleFillSymbol fillSymbol1 = (SimpleFillSymbol) res.createArcObject(SimpleFillSymbol.getClsid());
			IRgbColor rgbColor1 = (IRgbColor) res.createArcObject(RgbColor.getClsid());

			rgbColor1.setRed(255);
			rgbColor1.setGreen(0);
			rgbColor1.setBlue(0);
			rgbColor1.setUseWindowsDithering(true);

			ILineSymbol ilinesym1 = (ILineSymbol) res.createArcObject(SimpleLineSymbol.getClsid());
			ilinesym1.setColor(rgbColor1);
			ilinesym1.setWidth(1);
			fillSymbol1.setOutline(ilinesym1);

			fillSymbol1.setColor(rgbColor1);
			barChartSymbol.addSymbol(fillSymbol1);

			SimpleFillSymbol fillSymbol2 = (SimpleFillSymbol) res.createArcObject(SimpleFillSymbol.getClsid());

			IRgbColor rgbColor2 = (RgbColor) res.createArcObject(RgbColor.getClsid());

			rgbColor2.setRed(238);
			rgbColor2.setGreen(195);
			rgbColor2.setBlue(235);
			rgbColor2.setUseWindowsDithering(true);

			ILineSymbol ilinesym2 = (ILineSymbol) res.createArcObject(SimpleLineSymbol.getClsid());
			ilinesym2.setColor(rgbColor2);
			ilinesym2.setWidth(1);
			fillSymbol2.setOutline(ilinesym2);
			fillSymbol2.setColor(rgbColor2);
			barChartSymbol.addSymbol(fillSymbol2);

			chartRender.setChartSymbolByRef(chartSymbol);
			chartRender.setUseOverposter(false);
			//设置FeatureRenderer ChartRenderer对象
			fLayer.setRendererByRef(chartRender);
			//刷新地图显示图表
//			map1.refresh();
			this.webContext.refresh();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}



到此完成柱状专题图实现
分享到:
评论
3 楼 skying8603 2010-09-25  
Arcgis javascript1.5 API能不能生成arcgis的专题图啊?请指教
2 楼 sorh 2009-09-03  
哎  我这里的问题是 专题图上去了以后 删不掉。。。。
1 楼 langkins 2009-05-25  
刚开始做gis web 应用, 正要做专题图,看了你的代码受益良多,但是我不知道用怎样的方式让刷新的效果显示到页面上去?望指教。
回复帖子或者Email都可以,mail:langkins@yahoo.com.cn,
不胜感谢!

相关推荐

Global site tag (gtag.js) - Google Analytics