
地图图元是地图上的一个地图对象。如点、线或区域等。在 MapXtreme 中,地图图元表示为 Feature 对
象。
Feature 对象的方法
Feature 对象的方法包含有关制表和几何数据的信息。下表对列出了这些方法:
getAttribute 获取赋予列索引的指定属性。
getAttributeCount 获取与此图元相关的属性数量。

getGeometry 获取相关的几何对象,如果图元没有几何对象则为空。mapxtreme
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 的基本功能是选择地图上的图元,以便可对其执行其它任务。mapxtreme用户可以单击地图来选择一个或多个图元(点、线、区域等)。搜索结果通常解释为选择内容。以下 Layer 对象的方法提供了各种搜索图层并返回 FeatureSet 集合的方式。
searchAll
searchWithinRadius
searchWithinRegion
searchWithinRectangle
searchAtPoint
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-28142-1.html
一股浓香
恶狗