WebGIS小结之六(查询地图图层)

1.        Search介绍
有时可能做一些搜索,如搜索配送中心周围的零售店。MapXtreme提供了丰富的搜索功能。搜索的结果可以转换为被选中状态,从而显示在地图上。SearchLayer对象的方法,有:
 searchAll
 searchWithinRadius
 searchWithinRegion
 searchWithinRectangle
 searchAtPoint
 searchByAttribute
 searchByPrimaryKey

使用这些查询都需要给出要返回的字段集合和执行的查询动作。返回的字段集合需要放在Vector对象中。下面的例子返回的是表中所有的字段:

//Assume myLayer is a Layer object.

TableInfo myTableInfo = myLayer.getTableInfo( );

Vector columnNames = new Vector( );

int columnCount = myTableInfo.getColumnCount( );

String col;

for (int j=0; j<columnCount; j++)

{

col = myTableInfo.getColumnName(j);

columnNames.addElement(col);

}

在默认情况下,执行查询时后得到的FeatureSet包含GeometryRenditionLabelRenditionPrimaryKeyraster Data等,所以需要使用QueryParams 类来过滤这些信息,以提高程序的性能。

进行查询时可以通过QueryParams指定查询类型SearchTypeMbr表示搜索最小外接矩形和搜索范围相交的图元;patial表示搜索和搜索范围相交的图元;entire表示搜索完全在搜索范围的的图元。

下面代码示例如何使用QueryParams

QueryParams qp = new QueryParams(bGeometry,bRendition,bPrimarykey,bLabelPoint,bRasterInfo,bLabelRendition, SearchType.entire);

下面示例了如何过滤信息:

// find all Features entirely within a given search region, return a single Attribute column //and noRendition information.

Vector cols = new Vector();

cols.addElement(“County”);

Feature searchFeature  =mapj.getFeatureFactory().createRegion(points, rend,attribs,null);

QueryParams queryParams = new QueryParams(true, false,true,true, true, true, SearchType.entire);

FeatureSet fs = layer.searchWithinRegion(cols,searchFeature.getGeometry(),  queryParams);

2. Search方法

:        searchAll

示例:

//Assume fs is a FeatureSet object.Assume columnNames is a vector of the columns //to be returned.Assume qp is the QueryParams object.Assume myLayer is a Layer //object.

try

{

fs = myLayer.searchAll(columnNames,qp);

}

catch(exception e)

{

e.printStackTrace();

}

 

:==>searchWithinRadius

示例:

//Assume fs is a FeatureSet object. Assume columnNames is a vector of the desired //columns  to be returned. Assume qp is the QueryParams object.Assume myLayer //is a Layer object.

DoublePoint dblPt = new DoublePoint(-73.889444,42.765555);

double dRadius = 10.03;

try

{

fs = myLayer.searchWithinRadius(columnNames,dblPt,dRadius,LinearUnit.mile,qp);

}

catch(exception e)

{

e.printStackTrace();

}

 

==> searchWithinRegion

示例:

private boolean layerSearchWithinRegion()

{

//Assume fs is a FeatureSet object.Assume columnNames is a vector of the columns //to be  returned.Assume qp is the QueryParams object.Assume myLayer is a Layer //object.Assume vGeom is a VectorGeometry of TYPE_REGION

try

{

fs =myLayer.searchWithinRegion(columnNames,vGeom,qp);

}

catch(Exception e)

{

e.printStackTrace();

return false;

}

return true;

}

 

==> searchWithinRectangle

示例:

//Assume fs is a FeatureSet object.Assume columnNames is a vector of the columns //to be returned.Assume qp is the QueryParams object.Assume myLayer is a Layer //object.

DoubleRect dRect = new DoubleRect(-74.092662,42.765555,-73.668898,42.856420);

try

{

fs =myLayer.searchWithinRectangle(columnNames,dRect,qp);

}

catch(exception e)

{

e.printStackTrace();

}

 

==>searchAtPoint

示例:

//Assume fs is a FeatureSet object.Assume columnNames is a vector of the columns //to be returned.Assume qp is the QueryParams object.Assume myLayer is a Layer //object.

DoublePoint dp = new DoublePoint(12.3456,-67.890);

try

{

fs = myLayer.searchAtPoint(columnNames,dp,qp);

}

catch(exception e)

{

e.printStackTrace();

}

 

==> searchByAttribute

示例:

//Assume fs is a FeatureSet object.Assume columnNames is a vector of the columns to //be  returned.Assume qp is the QueryParams object.Assume myLayer is a Layer //object.Assume attr is the attribute to search against.Assume colName is the column to //search against.

try

{

fs =myLayer.searchByAttribute(columnNames,colName,attr,qp);

}

catch(Exception e)

{

e.printStackTrace();

return false;

}

==>searchByPrimaryKey

示例:

可以使用searchByPrimaryKey返回特定的FeatureSet

private boolean layerSearchByPrimaryKey()

{

// Assume fs is a FeatureSet object. Assume columnNames is a vector of the //columns to be returned. Assume qp is the QueryParams object. Assume myLayer //is a Layer object. Assume colName is the column to search against. Assume pk is a //PrimaryKey from a previous search.

 

PrimaryKey[] arraypk = new PrimaryKey[1];

arraypk[0] = pk;

try

{

fs = myLayer.searchByPrimaryKey(columnNames,arraypk,qp);

}

catch(Exception e)

{

e.printStackTrace();

return false;

}

return true;

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值