|
liuzheli :
我利用地图定义管理器制作的空间数据库的mdf文件来加载地图定义。 其中有一层是JIEDIANMAPX图层,存储在spaticl里。 在向JIEDIANMAPX图层添加图元的时候出现问题,请斑竹帮我解答啊。 代码如下: // 取得mapj的FeatureFactory FeatureFactory ff = myMap.getFeatureFactory(); //自定义属性。我查看TABINFO知道里面有三列,MC,MI_PRINX,TYPE.其中第二列为唯一ID。所以建立三个属性(这里有错误也请指正啊) Attribute att[] = new Attribute[3]; att[0] = new Attribute(); att[0].set("Ceshi"); att[1] = new Attribute(); att[1].set(99); att[2] = new Attribute(); att[2].set(0); //要插入的地理位置DoublePoint 值 DoublePoint dp = AtPoint; //以下是获取图层 Vector columns = new Vector(); Layer todoLayer = myMap.getLayers().getLayer("JIEDIANMAPX"); if (todoLayer.isEditable()==false){ System.out.println("no editable"); } TableInfo tabInfo = todoLayer.getTableInfo(); for (int i=0; i < tabInfo.getColumnCount(); i++) { System.out.println(tabInfo.getColumnName(i)+" -- "); columns.addElement(tabInfo.getColumnName(i)); } //查询图层 并把该图层的有关信息赋值给要建图元的相关属性 RewindableFeatureSet frset=new RewindableFeatureSet(todoLayer.searchAll(columns,null)); Feature ftr; ftr=frset.getNextFeature(); //定义要插入的图元的Rendition Rendition rend = RenditionImpl.getDefaultRendition(); //将该图层查询得到的Rendition 赋值给该Rendition if (ftr!=null){ rend=ftr.getRendition(); }else{ System.out.println("Rendition is null"); rend.setvalue(Rendition.SYMBOL_STRING, "@"); rend.setvalue(Rendition.FONT_SIZE, 16); rend.setvalue(Rendition.FONT_FAMILY, "MapInfo Shields"); rend.setvalue(Rendition.SYMBOL_FOREGROUND, Color.blue); } //添加图元 Feature retFeature; try { //PrimaryKey is taken as an argument by all the create methods and cannot be null PrimaryKey pkey = new PrimaryKey(att[1]); // Create Point retFeature = ff.createPoint(dp, rend,null, att, pkey); // Add the new feature to the annotation layer PrimaryKey pk = todoLayer.addFeature(retFeature); System.out.println("add sucess and primarykey:"); System.out.println(pk.equals(pkey)); }catch (Exception e) { System.out.println(e.getMessage()); } 报错 : IO异常 The Network Adapter Could not establish the connection . 我在向AnnotationTable添加的时候没有问题。 这里是因为没能与数据库建立连接吗? 我的错误出现在哪里? 其中JIEDIANMAPX图层,存储在spaticl里。我利用地图定义管理器制作的空间数据库的mdf文件来加载地图定义的。 不知道我直接加载图层的方式能不能解决这个问题,我也试一下,高手帮我解答啊。
liuzheli :
今天的错误提示变了。变成 failed to add feature to table :JIEDIANMAPX the feature geometry coordinate system does not match the table coordinate system 是我创建的点的坐标系统和要插入图层的坐标系统不一致吧? 那我该怎么做呢?
James.Liu :
添加点可以参照下面的代码,添加图层然后添加点,后来提示的错误,你应该在初始化mapj对象后,设置其坐标系,与上传到数据库之前的表的坐标系一致! try { Layer oraLayer = map.getLayers().getLayer(LayerName); if(oraLayer == null) { String mapXtremeURL = " http://liuyi:5050/mapxtreme40/servlet/mapxtreme"; java.util.Properties connectionProps = new java.util.Properties(); OraSoDataProviderHelper oraDPH = new OraSoDataProviderHelper("liuyi", 1521,"oracle8i","demo","demo",DriverType.thick); //OraSoDataProviderHelper oraDPH = new OraSoDataProviderHelper("jdbc:mipool:map",null,null); String[] idColumn = {"MI_PRINX"}; OraSoTableDescHelper oraSoTDHelper = new OraSoTableDescHelper(LayerName,false,idColumn,"GEOLOC","MI_SYMBOLOGY",com.mapinfo.dp.RenditionType.mapbasic ,null,com.mapinfo.dp.RenditionType.none,null,2,"DEMO"); MapXtremeDataProviderRef mxtDPRef = new MapXtremeDataProviderRef(oraDPH, mapXtremeURL); //map.getLayers().add(mxtDPRef, oraDPH, "OraSoLayer"); oraLayer = map.getLayers().insert(mxtDPRef, oraSoTDHelper,0, LayerName); } Feature retFeature = null; FeatureFactory ff = map.getFeatureFactory(); Attribute att[] = new Attribute[1]; att[0] = new Attribute(labelString); PrimaryKey pk = new PrimaryKey(att[0]); Rendition rend = sysOpition.GetSystemPointRendition(); Feature retFeature = null; DoublePoint dp = point; retFeature = ff.createPoint(dp, rend, att, pk); PrimaryKey primarykey = oraLayer.addFeature(retFeature); Rendition rend = sysOpition.GetSystemImgPointRendition() ; //AddOverrideTheme(map,LayerName,rend); //AddIndividualvalueTheme(map,LayerName); } catch(Exception exception) { }
liuzheli :
恩,问题解决了。就是坐标系的问题 我加了一句代码: myMap.setNumericCoordSys(CoordSys.longLatNAD27); 因为那些空间表都是我们上一组学生做的CS时候建立的,加上我也不懂坐标系。现在虽然能加到图层里,但是显示的时候却有一定偏颇。可能还是坐标系我设置的不对。要想真正解决,可能还得了解表到底采用了哪个坐标系吧。 我还是利用的读取MDF文件,直接取得该图层,没有新去加入oracle图层。不过道理都是一样的。 :) 我再好好看看你的代码,谢谢james.liu。
songqian :
多谢,也帮我解决了问题。太感谢了 |