<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://ojwiki.soldin.de/index.php?action=history&amp;feed=atom&amp;title=Extending_a_FeatureCollection_by_Adding_new_Attributes</id>
	<title>Extending a FeatureCollection by Adding new Attributes - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://ojwiki.soldin.de/index.php?action=history&amp;feed=atom&amp;title=Extending_a_FeatureCollection_by_Adding_new_Attributes"/>
	<link rel="alternate" type="text/html" href="https://ojwiki.soldin.de/index.php?title=Extending_a_FeatureCollection_by_Adding_new_Attributes&amp;action=history"/>
	<updated>2026-04-15T05:08:01Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://ojwiki.soldin.de/index.php?title=Extending_a_FeatureCollection_by_Adding_new_Attributes&amp;diff=325&amp;oldid=prev</id>
		<title>Mentaer: Created page with &#039;== The Problem ==  I imported a shapefile and put its contents in a jump FeatureCollection. With these Features I’m doing some calculations and now I want to add the result as …&#039;</title>
		<link rel="alternate" type="text/html" href="https://ojwiki.soldin.de/index.php?title=Extending_a_FeatureCollection_by_Adding_new_Attributes&amp;diff=325&amp;oldid=prev"/>
		<updated>2009-10-18T21:47:27Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;#039;== The Problem ==  I imported a shapefile and put its contents in a jump FeatureCollection. With these Features I’m doing some calculations and now I want to add the result as …&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== The Problem ==&lt;br /&gt;
&lt;br /&gt;
I imported a shapefile and put its contents in a jump FeatureCollection. With these Features I’m doing some calculations and now I want to add the result as a new attribute to the features, so I can export it as a new shapefile.&lt;br /&gt;
&lt;br /&gt;
So basically I want to add a new field to attribute table and fill it with values.&lt;br /&gt;
&lt;br /&gt;
But I just can’t figure it out! I played with with the addAttribute Method of the FeatureSchema, but that didn’t really work. &lt;br /&gt;
&lt;br /&gt;
== The Solution ==&lt;br /&gt;
&lt;br /&gt;
you need to do the following:&lt;br /&gt;
* create a new FeatureSchema based on the old one&lt;br /&gt;
* create a new FeatureDataset with that FeatureSchema&lt;br /&gt;
* copy every feature from old to new FeatureSchema (use the function FeatureCollectionTools.copyFeatureAndSetFeatureSchema for this)&lt;br /&gt;
* add the features to the new FeatureSchema&lt;br /&gt;
* display&lt;br /&gt;
&lt;br /&gt;
a code example can be found below&lt;br /&gt;
&lt;br /&gt;
Another option, with respect to updating, may be to look on how the &amp;quot;View / Edit Schema&amp;quot;-Function from the mouse menu works (class: com.vividsolutions.jump.workbench.ui.plugin.ViewSchemaPlugIn)&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
* the input is pFeatures&lt;br /&gt;
* I assume that this code is in the &amp;quot;run&amp;quot; or &amp;quot;execute&amp;quot; method of a plugin.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
FeatureSchema fsNew=(FeatureSchema)pFeatures.getFeatureSchema().clone();&lt;br /&gt;
fsNew.addAttribute(&amp;quot;huhuattribut&amp;quot;,AttributeType.STRING);&lt;br /&gt;
resultFC = new FeatureDataset(fsNew);&lt;br /&gt;
//-- set the attribute for every feature in the collection&lt;br /&gt;
for (Iterator iterator = pFeatures.iterator(); iterator.hasNext();) {&lt;br /&gt;
    Feature ftemp = (Feature) iterator.next();&lt;br /&gt;
    //-- copies the original feature to the new feature schema&lt;br /&gt;
    Feature fcore = FeatureCollectionTools.copyFeatureAndSetFeatureSchema(ftemp, fsNew);&lt;br /&gt;
    //-- in case the geometry changed:&lt;br /&gt;
    fcore.setGeometry(core);&lt;br /&gt;
    //-- set the new attribute           &lt;br /&gt;
    fcore.setAttribute(&amp;quot;huhuattribut&amp;quot;, &amp;quot;helloworld&amp;quot;);&lt;br /&gt;
    resultFC.add(fcore);&lt;br /&gt;
}&lt;br /&gt;
//-- display&lt;br /&gt;
context.addLayer(StandardCategoryNames.RESULT, &amp;quot;newLayer&amp;quot;, resultFC);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mentaer</name></author>
	</entry>
</feed>