Hi,

May be you can do something even more direct if you put the featureCollection in an indexed list

ArrayList list = new ArrayList(featureCollection.getFeatures())

Then use the sample in JTable javadoc to build the model :

TableModel dataModel = new AbstractTableModel() {
          public int getColumnCount() { return 10; } // FeatureSchema column 
count
          public int getRowCount() { return 10;}     // list.size()
          public Object getValueAt(int row, int col) { return new 
Integer(row*col); }  // list.get(row).getAttribute(col)
      };

But if it is to be used in OpenJUMP, there is probably some benefits to use AttributeTable

MM

Le 13/12/2017 à 11:07, edgar.sol...@web.de a écrit :
hey Peppe,

looks proper. performancewise i would no convert Lists to Arrays, but iterate 
them directly. always keep in mind that datasets might get huge.

..ede

On 13.12.2017 11:01, Giuseppe Aruta wrote:
Hi Ede
I checked. It looks complicate for me to load a featurecollection into a JTable.
I found a quick way from Sextante gui, that I modified.
It generates a loop to fill all JTable records with feature values.
I post the code below.

  public static TableModel setTableModelFromFeatureCollection(
             FeatureCollection featureCollection) {
         final DefaultTableModel model = new DefaultTableModel();
         String[] fields;
         int iCount;
         iCount = featureCollection.getFeatures().size();
         FeatureSchema schema = featureCollection.getFeatureSchema();
         ArrayList<String> ar = new ArrayList<String>();
         String name;
         for (int j = 0; j < schema.getAttributeNames().size(); j++) {
             name = schema.getAttributeName(j).toString();
             ar.add(name);
         }
         fields = ar.toArray(new String[0]);
         final String[][] data = new String[iCount][fields.length];
         Feature[] featArray = featureCollection.getFeatures().toArray(
                 new Feature[0]);
         for (int i = 0; i < featArray.length; i++) {
             Feature feat = featArray[i];
             for (int j = 0; j < schema.getAttributeCount(); j++) {
                 data[i][j] = feat.getAttribute(j).toString();
             }
         }
         model.setDataVector(data, fields);
         return model;
     }

Peppe

2017-12-12 18:23 GMT+01:00 <edgar.sol...@web.de <mailto:edgar.sol...@web.de>>:

     Peppe,

     did you check the AttributeTable plugin? if there is, it will probably be 
in use there?

     ..ede

     On 12.12.2017 17:50, Giuseppe Aruta wrote:
     > Hi all
     > does OJ alreay have a way to load a featurecollection into a JTable?
     > I know Geotools has a such way 
(http://docs.geotools.org/stable/userguide/tutorial/filter/query.html 
<http://docs.geotools.org/stable/userguide/tutorial/filter/query.html>):
     >
     > JTable table
     > SimpleFeatureCollection features ....
     > FeatureCollectionTableModel model = new 
FeatureCollectionTableModel(features);
     > table.setModel(model); (*)
     >
     > I don't want to use geotools neither to "reinvent the wheel". Do we have 
something similar (and simple)?
     > thanks in advance.
     >
     > Peppe
     >
     > (*) Geometry attributes are saved as string
     >
     >
     > 
------------------------------------------------------------------------------
     > Check out the vibrant tech community on one of the world's most
     > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
     >
     >
     >
     > _______________________________________________
     > Jump-pilot-devel mailing list
     > Jump-pilot-devel@lists.sourceforge.net 
<mailto:Jump-pilot-devel@lists.sourceforge.net>
     > https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel 
<https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel>
     >


     
------------------------------------------------------------------------------
     Check out the vibrant tech community on one of the world's most
     engaging tech sites, Slashdot.org! http://sdm.link/slashdot
     _______________________________________________
     Jump-pilot-devel mailing list
     Jump-pilot-devel@lists.sourceforge.net 
<mailto:Jump-pilot-devel@lists.sourceforge.net>
     https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel 
<https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel>




------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot



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


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to