olive_simple
路人甲
路人甲
  • 注册日期2006-06-19
  • 发帖数4
  • QQ
  • 铜币111枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2343回复:3

如何在FeatureLayer中添加多个Feature?

楼主#
更多 发布于:2006-06-19 17:35
如果添加多个Feature,总是出现“<FONT color=#a52a2a>java.lang.IllegalArgumentException: PrimaryKey is not unique, use update method instead.”</FONT>这个错误。在MapExtreme4.7.1的“Developer Guide”的第13章“Features and Searches”中的“Creating Features Using FeatureFactory”小节中的例子代码怎么也编译不过去,就是出现上面的错误。请大家帮菜鸟一下了^_^。谢谢了。
<br>
<P><BR>Code Example:<BR>//map is a MapJ object<BR>FeatureFactory ff = map.getFeatureFactory();<BR>// Set up Attribute object<BR>Attribute att[] = new Attribute[1];<BR>att[0] = new Attribute("Feature1");<BR>// Set up rendition object<BR>Rendition rend = RenditionImpl.getDefaultRendition();<BR>// For circles, specify the edge and fill color.<BR>rend.setvalue(Rendition.STROKE, Color.cyan);<BR>rend.setvalue(Rendition.FILL, Color.green);<BR>Feature retFeature;<BR>DoublePoint dp = new DoublePoint(-104, 45);<BR>try<BR>{<BR>// Create an Annotation layer for storing the features we're<BR>// creating<BR>AnnotationTableDescHelper annTableDesc = new AnnotationTableDescHelper("Annotations");<BR>AnnotationDataProviderHelper dpHelper = new<BR>AnnotationDataProviderHelper();<BR>LocalDataProviderRef dpRef = new LocalDataProviderRef(dpHelper);<BR>Layer annotLayer = map.getLayers().insertLayer(<BR>dpRef, annTableDesc, 0, "Annotations");<BR>PrimaryKey pkey = new PrimaryKey(att[0]);<BR>// Create a Circular Region<BR>retFeature = ff.createCircularRegion(circType, dp, circRadius,<BR>LinearUnit.mile,circResolution, rend,null, att,pkey );<BR>// Add the new feature to the annotation layer<BR>PrimaryKey pk = annotLayer.addFeature(retFeature);//<FONT color=#a52a2a>如果是只添加这一个图元不会出错</FONT><BR>// Create Point<BR>retFeature = ff.createPoint(dp, rend,null, att, pkey);<BR>pk = annotLayer.addFeature(retFeature);//<FONT color=#a52a2a>如果再添加图元,就会显示错误出现在这一行</FONT><BR>catch (Exception e)<BR>{<BR>e.printStackTrace();<BR>}</P>
<P><BR>此外,通过多次调试发现:如果按照上面的方法添加一个图元的话,编译可以通过。但是通过pk=annotLayer.addFeatrue(retFeature)添加新retFeature时,就出现了java.lang.IllegalArgumentException: PrimaryKey is not unique, use update method instead这样的错误。此外,我想问当往新建的Layer中添加图元,为啥示例代码中的语句前面要加上“pk=”,显得比较多余不?</P>
<P>谢谢指点菜鸟</P>
喜欢0 评分0
olive_simple
路人甲
路人甲
  • 注册日期2006-06-19
  • 发帖数4
  • QQ
  • 铜币111枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2006-06-19 17:45
<P>高手快进^_^</P>
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
2楼#
发布于:2006-06-26 14:09
<P>每次写入要素后,利用update更新一下吧</P>
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
goldeagle
路人甲
路人甲
  • 注册日期2006-04-06
  • 发帖数7
  • QQ
  • 铜币126枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2006-07-03 09:11
<P><FONT color=#a52a2a>PrimaryKey对象就相当于是数据库表中的主键,你添加两个feature而使用同一个PrimaryKey当然会报错咯~~</FONT></P>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部