首先,我们有一个山东省的地图
地区界图层如图所示:
这是地区界图层在数据集中的表格,地区界图层就是根据数据集中的表格而显示地图。
从表格中我们可以看到每一个地区界都有自己的一行记录,分别有它们的面积,周长,和地区名称,我们要做的就是通过某一个点坐标的经纬度来判断这个点所在哪个地区界中
首先,建立一个点的数据集合,我们起名为ttggtt ,
然后再地图层上画入4条计入,然后得ttggtt数据表如图所示:
这里我们故意添加一列city属性,我们要做的就是这个点属于哪个地区界就把这个地图界的名称放入city属性中
我们看到,在济南和潍坊还有威海等4个地方都加了点,这些点就对应了ttggtt数据集中的点计入
下面我们工作如代码所示:
首先对ttggtt数据集合进行查询,返回全部数据行中的smx,smy,smid三个属性
public void query(String LayerParamname,String[] returnfields)
{
IMapService ims = ServiceFactory.getRemoteMapService(serverAddress ,serverPort, mapServiceName,mapName);
QueryParam queryParam = new QueryParam();
// 查询图层参数
QueryLayerParam[] queryLayerParams = new QueryLayerParam[1];
QueryLayerParam queryLayerParam = new QueryLayerParam();
// 查询图层名
// queryLayerParam.name = LayerParamname;
// 查询的属性过滤条件
queryLayerParam.name =LayerParamname;
SqlParam sqlParam = new SqlParam();
sqlParam.returnFields= new String[]{"SmX","SmY","SmID"};
queryLayerParam.sqlParam = sqlParam;
queryLayerParams[0] = queryLayerParam;
queryParam.queryLayerParams = queryLayerParams;
try {
ResultSet resultSet =ims.query(queryParam, mapName);
this.resultSet=resultSet;
System.out.println( this.resultSet.currentCount);
}
catch (Exception e) {
e.printStackTrace();
}
然后,对地区界图层进行查询,然后将返回的city属性的结果更新到ttggtt数据集中,
public void query(ResultSet resultset){
IMapService ims = ServiceFactory.getRemoteMapService(serverAddress ,serverPort, mapServiceName,mapName);
IDataService datasv= ServiceFactory.getRemoteDataService(serverAddress,serverPort,"dataService1","custcaregis");
System.out.println(resultset.totalCount);
for (int i = 0; i <resultset.totalCount; i++) {
System.out.println(i);
String [] fieldValues=new String[]{resultset.recordSets[0].records[i].fieldValues[0],resultset.recordSets[0].records[i].fieldValues[1]};
//System.out.println(fieldValues[1]);
Point2D center= new Point2D(Double.parseDouble(fieldValues[0]), Double.parseDouble(fieldValues[1])) ;
// System.out.println(center.y);
Geometry polygon = Geometry.fromPoint2D(center);
// 查询参数
QueryParam queryParam = new QueryParam();
// 查询图层参数
QueryLayerParam[] queryLayerParams = new QueryLayerParam[1];
QueryLayerParam queryLayerParam = new QueryLayerParam();
// 查询图层名
queryLayerParam.name = "地区界@custcaregis";
SqlParam sqlParam = new SqlParam();
// sqlParam.whereClause = "SmID <100";
sqlParam.returnFields=new String[]{"名称"};
queryLayerParam.sqlParam = sqlParam;
queryLayerParams[0] = queryLayerParam;
queryParam.queryLayerParams = queryLayerParams;
try {
reSet = ims.queryByGeometry(polygon, SpatialQueryMode.WITHIN, queryParam, mapName);
// reSet =ims.query(queryParam, mapName);
} catch (Exception e) {
e.printStackTrace();
}
String [] fieldNames=new String[]{"city"};
String [] fieldValue=new String[]{reSet.recordSets[0].records[0].fieldValues[0]};
System.out.println(reSet.recordSets[0].records[0].fieldValues[0]);
/// System.out.println(reSet.recordSets[0].records[0].fieldValues[0]);
// 构造实体对象
Entity[] regionEntities = new Entity[1];
Entity regionEntity = new Entity(polygon,fieldNames,fieldValue);
regionEntity.id=Integer.parseInt(resultset.recordSets[0].records[i].fieldValues[2]);
regionEntities[0] = regionEntity;
try {
EditResult resultaddEntities = datasv.updateEntities(regionEntities, "ttggtt","custcaregis" );
System.out.println(resultaddEntities);
}
catch (Exception e) {
e.printStackTrace();
}
} //end for
}
最后结果如图所示:
转载于:https://www.cnblogs.com/j3eee/archive/2009/08/17/1548098.html