MapXtreme for java 图元和搜索

地图图元是地图上的一个地图对象。如点、线或区域等。在 MapXtreme 中,地图图元表示为 Feature 对
象。

Feature 对象的方法
Feature 对象的方法包含有关制表和几何数据的信息。下表对列出了这些方法:
getAttribute 获取赋予列索引的指定属性。
getAttributeCount 获取与此图元相关的属性数量。
getGeometry 获取相关的几何对象,如果图元没有几何对象则为空。
getLabelRendition 获取为此图元的标注指定的样式。如果没有用于该标注的样式,则返回为空。
getPrimaryKey 获取用于此图元的 PrimaryKey 对象(唯一 ID)。如果该图元没有
PrimaryKey,则将会返回空值。
getRaster 如果存在,则返回与该图元关联的栅格对象,如果图元没有栅格则返回为空。
getRendition 返回此图元的样式。如果没有用于该图元的样式,则返回为空。每个 Feature 对象可有一个 Rendition 对象。Rendition 对象描述图元的显示特征

代码示例: 从图元获取信息

Layers layers = mapj.getLayers();
Layer myLayer = layers.getLayer("hunan");
// 获取图层table信息
TableInfo myTableInfo = myLayer.getTableInfo();
// 存储table 属性字段
Vector<String> columnNames = new Vector<String>();
int columnCount = myTableInfo.getColumnCount();
String col;
for (int j = 0; j < columnCount; j++) {
	col = myTableInfo.getColumnName(j);
	columnNames.addElement(col);
}
// 搜索• searchAll,searchWithinRadius,searchWithinRegion,
// searchWithinRectangle,searchAtPoint• searchByAttribute
//queryParams 使用QueryParams 类来过滤这些信息,以提高程序的性能
//QueryParams queryParams = new QueryParams(true, false,true,true, true, true, SearchType.entire);
//FeatureSet fs = layer.searchWithinRegion(cols,searchFeature.getGeometry(),  queryParams);
RewindableFeatureSet features = new RewindableFeatureSet(myLayer
		.searchAll(columnNames, null));
Feature fistF = features.getNextFeature();
while (fistF != null) {
	Geometry geom = fistF.getGeometry();
	// Point:Geometry.TYPE_POINT=
	// 1,Line:Geometry.TYPE_LINE=2,Polygon:TYPE_REGION=3
	if (geom.getType() == Geometry.TYPE_POINT) {
		PointGeometry pntGeometry = (PointGeometry) geom;
		DoubleRect rect = pntGeometry.getBounds();
		DoublePoint dblPnt = pntGeometry.getCentroid();
	} else {
		VectorGeometry vectorGeometry = (VectorGeometry) geom;
		DoubleRect rect = vectorGeometry.getBounds();
		double[] pnts = null;
		int offset = 0;
		int numPts;
		for (int i = 0; i < vectorGeometry.getPointListCount(); ++i) {
			PointList pntList = vectorGeometry.getNextPointList();
			numPts = pntList.getPointCount();
			pnts = new double[numPts];
			// 坐标信息,存入数组
			pntList.getNextPoints(pnts, offset, numPts/2);
		}
		for (int j = 0; j < pnts.length; j++) {
			System.out.println(pnts[j]);
		}
	}
	fistF = features.getNextFeature();
}


搜索:使用搜索功能可以按照地理信息检索特定的数据。例如,如果要查找 25 米半径范围内的所有基站,那么将执行搜索操作。搜索是 FeatureLayer 对象的方法。它们返回 FeatureSet 对象。MapXtreme 的基本功能是选择地图上的图元,以便可对其执行其它任务。用户可以单击地图来选择一个或多个图元(点、线、区域等)。搜索结果通常解释为选择内容。以下 Layer 对象的方法提供了各种搜索图层并返回 FeatureSet 集合的方式。
searchAll
searchWithinRadius
searchWithinRegion
searchWithinRectangle
searchAtPoint

(1)、searchAll 返回图层中所有图元的 FeatureSet 集合。如果应用程序需要循环整个图层,可使用此搜索方法。
myLayer.searchAll(columnNames, QueryParams.ALL_PARAMS);
(2)、searchWithinRadius 返回在点对象的指定距离之内构成图元的 FeatureSet 集合。使用此搜索可查找离指定位置最近的餐饮,或者返回一家商店某一半径范围内的客户数。
DoublePoint dblPt = new DoublePoint(-73.889444, 42.765555);
double dRadius = 10.03;
FeatureSet fs = myLayer.searchWithinRadius(columnNames, dblPt, dRadius, LinearUnit.mile, QueryParams.ALL_PARAMS);
(3)、searchWithinRegion 返回在一个图元的几何范围内构成图元的 FeatureSet 集合。使用此方法可返回特定区域(如邮政编码)内的客户数,或返回用 FeatureFactory 创建的区域内包含的图元。
Geometry vGeom = null;//某一个区域
FeatureSet vfs = myLayer.searchWithinRegion(columnNames, vGeom, QueryParams.ALL_PARAMS); 
(4)、searchWithinRectangle 返回指定矩形边界内的 FeatureSet 集合。使用此方法可在给定地图窗口内进行搜索或预检缩放级别,以查看它是否包含某些要关注的点。
DoubleRect dRect = new DoubleRect(-74.092662, 42.765555, -73.668898,42.856420);
FeatureSet dfs = myLayer.searchWithinRectangle(columnNames, dRect,QueryParams.ALL_PARAMS);
(5)、searchAtPoint 返回构成指定点上的图元的 FeatureSet 集合。使用此方法可以测试与某个点 交叉的所有对象。
DoublePoint dp = new DoublePoint(12.3456, -67.890);
FeatureSet pfs = myLayer.searchAtPoint(columnNames, dp, QueryParams.ALL_PARAMS);
(6)、searchByAttribute 返回其属性与给定属性相匹配的 FeatureSet 集合。使用此方法可以选择带有公用属性信息的所有图元。例如,如果拥有一张包含家庭收入列的表,即可使用 searchByAttribute 来返回家庭收入等于 100,000 美元的所有记录。
Attribute mySearchAttr = new Attribute(100000);
String searchCol = "Annual_Income";
FeatureSet afs = myLayer.searchByAttribute(columnNames, searchCol, mySearchAttr, null);


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值