手机imobile无法添加线 [已关闭]

0 投票
162 浏览
您好,我使用的是Demo的数据源,现在是想添加线条,但是addNew()返回值为false,求告知!谢谢
m_mapControl = m_mapview.getMapControl();
m_workspace = new Workspace();
m_mapControl.getMap().setWorkspace(m_workspace);

DatasourceConnectionInfo dsInfo = new DatasourceConnectionInfo();
dsInfo.setServer(sdcard + "/SampleData/GeometryInfo/World.udb");
dsInfo.setEngineType(EngineType.UDB);
Datasource datasource = m_workspace.getDatasources().open(dsInfo);
DatasetVector dataset = null;
if (datasource != null) {
    dataset = (DatasetVector) datasource.getDatasets().get("Capitals");
    m_mapControl.getMap().close();
    m_mapControl.getMap().getLayers().add(dataset, true);
    m_mapControl.getMap().viewEntire();

    Point2Ds point2Ds = new Point2Ds();
    Point2D point2D = new Point2D(108.888398, 34.228818);
    point2Ds.add(point2D);
    prjCoordSys = m_mapControl.getMap().getPrjCoordSys();
    boolean forward = CoordSysTranslator.forward(point2Ds, prjCoordSys);
    m_mapControl.getMap().setCenter(point2Ds.getItem(0));
    m_mapControl.getMap().setScale(1 / 57373.046875);
    m_mapControl.getMap().refresh();
}
if (dataset != null) {
    Recordset recordset = dataset.getRecordset(false, CursorType.DYNAMIC);
    GeoPoint geoPoint = new GeoPoint(new Point2D(7056.451, 34690.675));
    boolean b = recordset.addNew(geoPoint);
    recordset.update();
    Point2Ds point2Ds = new Point2Ds();
    point2Ds.add(new Point2D(7056.451, 34690.675));
    point2Ds.add(new Point2D(6254.780, 54220.603));

    // boolean forward = CoordSysTranslator.forward(point2Ds, prjCoordSys);
    GeoLine geoLine = new GeoLine(point2Ds);
    GeoStyle geoStyle_L = new GeoStyle();
    geoStyle_L.setLineColor(new Color(255, 0, 0));
    geoStyle_L.setLineSymbolID(15);
    geoStyle_L.setLineWidth(1.0);
    geoLine.setStyle(geoStyle_L);
    b = recordset.addNew(geoLine);
    LogUtil.i("b: " + b);
    if (b) {
        recordset.update();
        m_mapControl.getMap().setViewBounds(recordset.getBounds());
        m_mapControl.getMap().refresh();
    }
    recordset.dispose();
}
问题关闭原因: 自己已解决
最新提问 8月 29, 2017 分类:  162次浏览 | 用户: xiaowu_zhu (4 分)
已关闭 8月 29, 2017 用户:xiaowu_zhu

1个回答

0 投票
你好,从实现的代码中看,是实现的代码逻辑有问题,在简单的矢量数据集(如:点、线、面数据集)中,只能添加对应的几何对象(点、线、面对象),而你的代码中线对象却添加到点数据集对应的记录集recordset中,所以返回失败,如果要存储线对象,需要添加到线数据集对应的记录集中,数据源中如果没有线数据集需要新建一个线数据集来存储。
最新回答 8月 29, 2017 用户: 王国新 名扬四海 (1,854 分)
按照您的说法,我改成如下了,可是返回的还是false, 起初,我怀疑是图层的问题,于是我就换成了官方Demo中的,可是还是没有解决,麻烦您再帮忙看看。谢谢
if (dataset != null) {
    Recordset recordset = dataset.getRecordset(false, CursorType.DYNAMIC);
    Point2Ds point2Ds = new Point2Ds();
    point2Ds.add(new Point2D(7056.451, 34690.675));
    point2Ds.add(new Point2D(6254.780, 54220.603));
    GeoLine geoLine = new GeoLine(point2Ds);
    boolean b = recordset.addNew(geoLine);
    LogUtil.i("b: " + b);
    if (b) {
        recordset.update();
        m_mapControl.getMap().setViewBounds(recordset.getBounds());
        m_mapControl.getMap().refresh();
    }
    recordset.dispose();
}
...