Hi!

I wrote a FeatureCollectionBuilder and a FeatureCollectionSchemaEditor for
that in Groovy using the Builder design pattern (
http://groovy.codehaus.org/Builders).

Look at this example code (from the unit tests). You can add and remove
Attributes to the FeatureSchema.

<pre>
private featureCollection

def setup() {
    this.featureCollection = new FeatureCollectionBuilder().build {
        schema {
            attribute("id", AttributeType.INTEGER)
            attribute("name", AttributeType.STRING)
        }
        features {
            feature(id: 1, name: "foo")
            feature(id: 2, name: "bar")
            feature(id: 3, name: "baz")
            feature(id: 4, name: "quux")
        }
    }
}

def "Add an attribute to the FeatureSchema"() {
    when:
    def collectionEditor = new
FeatureCollectionSchemaEditor(this.featureCollection)
    collectionEditor.modifySchema {
        addSchemaAttribute("street", AttributeType.STRING)
    }

    then:
    def newFeatureSchema =
collectionEditor.getFeatureCollection().getFeatureSchema()
    collectionEditor.getAttributeNames(newFeatureSchema) == ["id", "name",
"street"]
}
</pre>

If somebody wants to use it, I can upload the sourcecode (but it depends on
the groovy jar).

2010/6/2 Larry Becker <becker.la...@gmail.com>

> For tips on how to do this see:
> http://sourceforge.net/apps/mediawiki/jump-pilot/index.php?title=Extending_a_FeatureCollection_by_Adding_new_Attributes
>
>
> On Wed, Jun 2, 2010 at 9:17 AM, Larry Becker <becker.la...@gmail.com>wrote:
>
>> Hi Caroline,
>>
>>   You seem to be making progress on your project.  Your current problem is
>> that when you alter a schema it only affects new features.  You need to
>> replace the old schema in each feature with the new one before copying
>> attributes.
>>
>> regards,
>> Larry
>>
>> 2010/6/2 Caroline Julliê Freitas Ribeiro <krolj...@gmail.com>
>>
>>>  I tried to put a new attribute to a old Feature, I altered the Schema
>>> but looks like the size of the array whete stay the data of the Feature is
>>> not actualized.
>>>
>>> I got the following Stack trace:
>>>
>>> java.lang.ArrayIndexOutOfBoundsException: 3
>>>         at
>>> com.vividsolutions.jump.feature.BasicFeature.getAttribute(BasicFeature.java:82)
>>>         at
>>> com.vividsolutions.jump.workbench.ui.LayerTableModel$4.getValue(LayerTableModel.java:170)
>>>         at
>>> com.vividsolutions.jump.workbench.ui.LayerTableModel$MyColumn.getValueAt(LayerTableModel.java:75)
>>>         at
>>> com.vividsolutions.jump.workbench.ui.ColumnBasedTableModel.getValueAt(ColumnBasedTableModel.java:141)
>>>         at
>>> com.vividsolutions.jump.workbench.ui.GUIUtil.chooseGoodColumnWidths(GUIUtil.java:408)
>>>         at
>>> com.vividsolutions.jump.workbench.ui.AttributeTablePanel.initColumnWidths(AttributeTablePanel.java:415)
>>>         at
>>> com.vividsolutions.jump.workbench.ui.AttributeTablePanel.<init>(AttributeTablePanel.java:307)
>>>         at
>>> com.vividsolutions.jump.workbench.ui.AttributePanel.addTablePanel(AttributePanel.java:154)
>>>         at
>>> com.vividsolutions.jump.workbench.ui.AttributePanel.layerAdded(AttributePanel.java:136)
>>>         at
>>> com.vividsolutions.jump.workbench.ui.AttributeTab$5.layerAdded(AttributeTab.java:143)
>>>         at
>>> com.vividsolutions.jump.workbench.ui.InfoModel.add(InfoModel.java:88)
>>>         at
>>> com.vividsolutions.jump.workbench.ui.cursortool.FeatureInfoTool.gestureFinished(FeatureInfoTool.java:81)
>>>         at
>>> com.vividsolutions.jump.workbench.ui.cursortool.AbstractCursorTool.fireGestureFinished(AbstractCursorTool.java:446)
>>>         at
>>> com.vividsolutions.jump.workbench.ui.cursortool.SpecifyFeaturesTool.mouseClicked(SpecifyFeaturesTool.java:95)
>>>         at
>>> com.vividsolutions.jump.workbench.ui.cursortool.LeftClickFilter.mouseClicked(LeftClickFilter.java:81)
>>>         at
>>> com.vividsolutions.jump.workbench.ui.cursortool.DelegatingTool.mouseClicked(DelegatingTool.java:97)
>>>         at
>>> java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
>>>         at java.awt.Component.processMouseEvent(Component.java:6266)
>>>         at javax.swing.JComponent.processMouseEvent(JComponent.java:3255)
>>>         at java.awt.Component.processEvent(Component.java:6028)
>>>         at java.awt.Container.processEvent(Container.java:2041)
>>>         at java.awt.Component.dispatchEventImpl(Component.java:4630)
>>>         at java.awt.Container.dispatchEventImpl(Container.java:2099)
>>>         at java.awt.Component.dispatchEvent(Component.java:4460)
>>>         at
>>> java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
>>>         at
>>> java.awt.LightweightDispatcher.processMouseEvent(Container.java:4247)
>>>         at
>>> java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
>>>         at java.awt.Container.dispatchEventImpl(Container.java:2085)
>>>         at java.awt.Window.dispatchEventImpl(Window.java:2475)
>>>         at java.awt.Component.dispatchEvent(Component.java:4460)
>>>         at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
>>>         at
>>> java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
>>>         at
>>> java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
>>>         at
>>> java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
>>>         at
>>> java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
>>>         at
>>> java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
>>>         at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
>>>
>>> This is the code where I got the problem:
>>>
>>>  Layer l = (Layer)cboLayers.getSelectedItem();
>>>         FeatureCollectionWrapper col = l.getFeatureCollectionWrapper();
>>>         FeatureSchema schema = col.getFeatureSchema();
>>>         instalEsquema(schema,rs);
>>>         List lista =col.getFeatures();
>>>         while (rs.next()){
>>>             for(Object o: lista){
>>>                 Feature f = (Feature) o;
>>>                 Feature fNew;
>>>                 String att =
>>> f.getAttribute(cboAtributos.getSelectedItem().toString()).toString();
>>>                 if (att.equals(rs.getString(txtCampo.getText()))){
>>>                     for(int i
>>> =nroAtributosAntes;i<schema.getAttributeCount();i++){
>>>                         f.setAttribute(i,
>>> rs.getString(schema.getAttributeName(i))); //Here is the problem
>>>                     }
>>>                 }
>>>             }
>>>         }
>>>
>>>     private void instalEsquema(FeatureSchema schema, ResultSet rs) throws
>>> SQLException {
>>>     //Here everything works fine....
>>>         nroAtributosAntes = schema.getAttributeCount();
>>>         ResultSetMetaData meta = rs.getMetaData();
>>>         for(int i =1;i<=meta.getColumnCount();i++){
>>>             schema.addAttribute(meta.getColumnLabel(i),
>>> AttributeType.STRING);
>>>         }
>>>     }
>>>
>>>
>>> Thanks
>>>
>>> --
>>> Caroline Julliê de Freitas Ribeiro
>>> Graduando em Análise e Desenvolvimento de Sistemas
>>>
>>> Instituto Federal Minas Gerais - IFMG
>>> Campus Bambuí
>>>
>>>
>>> ------------------------------------------------------------------------------
>>>
>>>
>>> _______________________________________________
>>> Jump-pilot-devel mailing list
>>> Jump-pilot-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>>>
>>>
>>
>
>
> ------------------------------------------------------------------------------
>
>
> _______________________________________________
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>
>
------------------------------------------------------------------------------

_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to