Hi Uwe,

Uwe Dalluege schrieb:
Hi Nils,

you can "save dataset as shape-file"
when you use "my" PostGISPlugIn.

1. RightMouseClick on a category then "Load Dataset(s)... (green cross).
Choose PostGIS Table (ComboBox behind "Format:").
Then you can load a PostGIS-Table.

2. RightMouseClick at the PostGIS-Layer then "Save Dataset As...".
Choose "ESRI Shapefile" (ComboBox behind "Format:") and you can save the layer as shapefile.
Sorry, you are right, in general this function works with layers loaded with your PlugIn. But I have geotables with postgres-BIGINT-fields in my project and for these I get a Class Cast Exception (java.lang.Long cannot be cast to java.lang.Integer) trying to save them as shapefile.

But you are right: you can not refresh the PostGISLayer with this PlugIn.
I have written a workaround for refreshing layers loaded by your PlugIn. If sombody else is interested in that, see the attachment. And: Yes, I know that it's a bad habbit to put some structured programming in static methods of a final Class ;-)

Regards
Nils

Regards

Uwe Dalluege



--
Dipl.-Biol. Nils Kuhn
Hohe Weide 25
20253 Hamburg

public static Layer refreshPostgisLayer(Layer lyr,WorkbenchContext context) {
                System.out.println("lyr.getName(): "+lyr.getName());
                System.out.println("lyr.getDataSourceQuery().getQuery(): 
"+lyr.getDataSourceQuery().getQuery());
                Category cat = 
context.getLayerNamePanel().getLayerManager().getCategory(lyr);
                String strCategoryName = cat.getName();
                int intPositionOfTheLayerToRefresh = cat.indexOf(lyr); 
                try {
                        
                        String strLayerName=lyr.getName();
                        DataSourceQuery targetQuery = lyr.getDataSourceQuery();
                        
                        //remove the layer
                        //**************************************
                        
lyr.getLayerManager().dispose(context.getWorkbench().getFrame(), lyr);
                        
                        //adding the layer again
                        //**************************************
                        com.vividsolutions.jump.io.datasource.Connection 
connection = targetQuery.getDataSource().getConnection();
                        try {
                                
                                ArrayList exceptions = new ArrayList();
                                FeatureCollection dataset = 
targetQuery.getDataSource().installCoordinateSystem(
                                                       
connection.executeQuery(targetQuery.getQuery(),
                                                       exceptions, 
                                                       null), 
                                                       
CoordinateSystemRegistry.instance(context.getBlackboard()));
                        if (dataset != null) {
                                //creating the refreshed layer, adding it to 
the LayerManager, removing it and adding it again at the right position of the 
category
                                //(it would be nice to have a method for adding 
a layer to the LayerManager directly at a certain category-position)
                                System.out.println("strCategoryName: 
"+strCategoryName);
                                
lyr=context.getLayerManager().addLayer(strCategoryName,strLayerName,dataset);
                                lyr.setDataSourceQuery(targetQuery);
                                lyr.setFeatureCollectionModified(false);
                                context.getLayerManager().remove(lyr);
                                
context.getLayerManager().getCategory(strCategoryName).add(intPositionOfTheLayerToRefresh,
 lyr);
                        }
                        
                        } finally {
                                connection.close();
                        }
                } catch (Exception e) {
                        JOptionPane
                                        .showMessageDialog(null,
                                                        "An error occurred 
refreshing the layer \""+lyr.getName()+"\" ("
                                                                        + 
e.getMessage() + ")!", "Truncation",
                                                        
JOptionPane.ERROR_MESSAGE);
                        e.printStackTrace();
                }
                return lyr;
        }
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to