首页 / 浏览问题 / 移动GIS / 问题详情
android提交图斑失败
30EXP 2020年08月05日

android端添加对象,版本是1010v

这是我的添加操作:
 

mapControl.setAction(Action.DRAWPLOYGON);
Layer layer = mapControl.getMap().getLayers().get(0);
layer.setEditable(true);

这是我的提交操作:
 

if (mapControl.getAction().equals(Action.PAN)||mapControl.getAction().equals(Action.NULL)) {
    Toast.makeText(mContext, "请选择编辑对象", Toast.LENGTH_SHORT).show();
}
else {
    boolean aa=mapControl.submit();
    if (!aa) {
        Log.i("++++++", "save fail");
    }
    mapControl.setAction(Action.PAN);
    mapControl.getMap().refresh();
}

总是提示保存失败,请问这是什么原因?

1个回答

您好,麻烦请确认以下几个问题:
1.请问一下在提交之前有改变对象的节点或者绘制新的几何对象吗?
2.将数据源复制到电脑,然后通过iDesktop桌面软件打开该数据源,然后将移动端编辑的数据集添加到地图窗口,开启编辑,看一下在桌面软件中能否添加对象。
9,127EXP 2020年08月06日

你好,我刚刚将工作空间从World.smwu换成了changchun.smwu,再将编辑的图层设置为和范例代码一样的图层

mapControl.getMap().getLayers().get("Region@edit");

就提交成功了,代码和之前的一样没有变。

我想请问这个提交成功与否是和工作控件和图层都会有关系的吗?

如果你的图层类型和编辑的类型不一致或者图层不可编辑也会造成提交失败的。建议您那边在绘制的时候根据图层的数据集类型来进行绘制

好的,非常感谢你的回答。

还有一个问题,前面的添加图斑方式是采用“自由绘面”的方式,我实际应用中是根据gps定位的经纬度来自动绘面。

我在技术文档使用GeoRegion对象

GeoRegion geoRegion = new GeoRegion();
Point2Ds point2Ds = new Point2Ds();
//其起始点和终止点重合
Point2D changsha = new Point2D(112.98626, 28.25591);
Point2D shanghai = new Point2D(121.48941, 31.40527);
Point2D taibei = new Point2D(121.520076, 25.030724);
Point2D guangzhou = new Point2D(113.27324, 23.15792);
point2Ds.add(changsha);
point2Ds.add(shanghai);
point2Ds.add(taibei);
point2Ds.add(guangzhou);
point2Ds.add(changsha);
geoRegion.addPart(point2Ds);

但是目前为止我不知道怎么将这个geoRegion对象添加到图层,或者和图层怎么关联

通过坐标点构建的几何对象有两种方式添加到地图中:
1.添加到临时图层进行展示,TrackingLayer.add()
2.获取需要存储几何对象的面数据集的记录集recordset,然后通过recordset.addNew()方法将几何对象添加到数据集中

你好,我可能需要的是通过recordset.addNew()方法将几何对象添加到数据集中,我查看了

recordset官方文档,按照文档的代码尝试了一下没有任何反应,我的工作空间是

/SampleData/MapEdit/changchun.smwu

下面是我的代码:

        GeoRegion geoRegion = new GeoRegion();
        Point2Ds point2Ds = new Point2Ds();
        //其起始点和终止点重合
        for (int i = 0; i < point2DList.size(); i++) {
            point2Ds.add(point2DList.get(i));
        }
        point2Ds.add(point2DList.get(0));
        geoRegion.addPart(point2Ds);
        double area = geoRegion.getArea();
        Log.e("123", "面积:" + area);

        Datasource datasource = workspace.getDatasources().get(0);
        // 从中取出名为“World”(面数据集)的矢量数据集 dataset_world,和名为“Example”(面数据集)的矢量数据集 dataset
//        DatasetVector dataset_world = (DatasetVector) datasource.getDatasets().get("World");
        DatasetVector dataset_world = (DatasetVector) datasource.getDatasets().get(0);
//        DatasetVector dataset = (DatasetVector) datasource.getDatasets().get("Example");
        DatasetVector dataset = (DatasetVector) datasource.getDatasets().get(1);

        // 得到“Example”对应的所有记录集以及“World”中 SmID=1 的记录
        Recordset recordset = dataset.getRecordset(false, CursorType.DYNAMIC);
        QueryParameter parameter = new QueryParameter();
        parameter.setAttributeFilter("SmID=1");
        parameter.setCursorType(CursorType.STATIC);
        Recordset recordset_world = dataset_world.query(parameter);

        // 将记录位置移到第一位
        recordset.moveFirst();

        // 将当前记录删除
        recordset.delete();

        // 将“World”中 SmID=1 的记录添加到 recordset 中并提交
        Geometry geometry = recordset_world.getGeometry();
        recordset.edit();
        recordset.addNew(geometry);
        recordset.update();

        // 关闭记录集,释放几何对象、记录集
        recordset.close();
        geometry.dispose();
        recordset.dispose();
        recordset_world.dispose();

        mapControl.getMap().refresh();
...