Re: [JPP-Devel] Featurecollection to JTable

2017-12-13 Thread edgar . soldin
Peppe,

but still Mike is right. for best performance you should wrap the 
FeatureCollection in a TableModel and _not_ duplicate all attributes in memory 
as you do now.

..ede

On 13.12.2017 15:45, Giuseppe Aruta wrote:
> On the previous way I can exclude all the search/build of geometry string and 
> it could be faster (I don't need to get all those POLYGON etc)
> 
> 
>  public static TableModel setTableModelFromFeatureCollection() {
> 
>     final DefaultTableModel model = new DefaultTableModel();
> 
>     String[] fields;
>     int iCount;
> 
>     iCount = featureCollection.getFeatures().size();
>     FeatureSchema schema = featureCollection.getFeatureSchema();
>     ArrayList ar = new ArrayList();
>     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]);
>     // fields = new String[ar.size()];
>     // fields = ar.toArray(fields);
> 
>     final String[][] data = new String[iCount][fields.length];
> 
>     // Feature[] featArray = featureCollection.getFeatures().toArray(
>     // new Feature[0]);
> 
>     for (int i = 0; i < featureCollection.size(); i++) {
>     // < featArray.length; i++) {
>     Feature feat = featureCollection.getFeatures().get(i);
>     // featArray[i];
> 
>     for (int j = 0; j < schema.getAttributeCount(); j++) {
>     if (feat.getSchema().getAttributeType(j) != 
> AttributeType.GEOMETRY) {
>     data[i][j] = feat.getAttribute(j).toString();
>     } else {
>     String geomType = feat.getGeometry().getClass().getName();
>     int dotPos = geomType.lastIndexOf(".");
>     if (dotPos > 0) {
>     geomType = geomType.substring(dotPos + 1);
>     }
> 
>     data[i][j] = geomType.toUpperCase();
>     }
> 
>     }
> 
>     }
> 
>     model.setDataVector(data, fields);
>     return model;
>     }
> 
> 
> ---
> 
> Anyhow I found an inner OJ way (using LayerTableModel  and creating a new 
> layer from the featurecollection)
> 
>     Layer layer = new Layer("name", Color.gray, featureCollection, 
> context.getLayerManager());
>     LayerTableModel layerMode = new LayerTableModel(layer);
>     List features = resultFC.getFeatures();
>     layerMode .addAll(features);
>     AttributeTablePanel panel = new AttributeTablePanel(layerMode , true,
>     context.getWorkbenchContext());
> 
> It has to pass through the creatuon of a new Layer, even if not loaded into 
> the view.
> Strangely if I don't add first the featurecollection to the new layer and 
> than the features (as list) again to the layer, TablePanel will be empty or I 
> have back an error
> 
> 2017-12-13 13:22 GMT+01:00 Michaël Michaud  >:
> 
> 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();

Re: [JPP-Devel] Featurecollection to JTable

2017-12-13 Thread Giuseppe Aruta
On the previous way I can exclude all the search/build of geometry string
and it could be faster (I don't need to get all those POLYGON etc)


 public static TableModel setTableModelFromFeatureCollection() {

final DefaultTableModel model = new DefaultTableModel();

String[] fields;
int iCount;

iCount = featureCollection.getFeatures().size();
FeatureSchema schema = featureCollection.getFeatureSchema();
ArrayList ar = new ArrayList();
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]);
// fields = new String[ar.size()];
// fields = ar.toArray(fields);

final String[][] data = new String[iCount][fields.length];

// Feature[] featArray = featureCollection.getFeatures().toArray(
// new Feature[0]);

for (int i = 0; i < featureCollection.size(); i++) {
// < featArray.length; i++) {
Feature feat = featureCollection.getFeatures().get(i);
// featArray[i];

for (int j = 0; j < schema.getAttributeCount(); j++) {
if (feat.getSchema().getAttributeType(j) !=
AttributeType.GEOMETRY) {
data[i][j] = feat.getAttribute(j).toString();
} else {
String geomType =
feat.getGeometry().getClass().getName();
int dotPos = geomType.lastIndexOf(".");
if (dotPos > 0) {
geomType = geomType.substring(dotPos + 1);
}

data[i][j] = geomType.toUpperCase();
}

}

}

model.setDataVector(data, fields);
return model;
}


---

Anyhow I found an inner OJ way (using LayerTableModel  and creating a new
layer from the featurecollection)

Layer layer = new Layer("name", Color.gray, featureCollection,
context.getLayerManager());
LayerTableModel layerMode = new LayerTableModel(layer);
List features = resultFC.getFeatures();
layerMode .addAll(features);
AttributeTablePanel panel = new AttributeTablePanel(layerMode ,
true,
context.getWorkbenchContext());

It has to pass through the creatuon of a new Layer, even if not loaded into
the view.
Strangely if I don't add first the featurecollection to the new layer and
than the features (as list) again to the layer, TablePanel will be empty or
I have back an error

2017-12-13 13:22 GMT+01:00 Michaël Michaud :

> 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 ar = new ArrayList();
> 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 < 

Re: [JPP-Devel] Featurecollection to JTable

2017-12-13 Thread Michaël Michaud

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 ar = new ArrayList();
     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 >:

 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 
):
 >
 > 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 

 > 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

Re: [JPP-Devel] Featurecollection to JTable

2017-12-13 Thread edgar . soldin
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 ar = new ArrayList();
>     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 >:
> 
> 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 
> ):
> >
> > 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 
> 
> > 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


Re: [JPP-Devel] Featurecollection to JTable

2017-12-13 Thread Giuseppe Aruta
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 ar = new ArrayList();
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 :

> 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):
> >
> > 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
> > 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


Re: [JPP-Devel] Featurecollection to JTable

2017-12-12 Thread edgar . soldin
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):
> 
> 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
> 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


[JPP-Devel] Featurecollection to JTable

2017-12-12 Thread Giuseppe Aruta
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):

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
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel