[udig-devel] layer from sql query

Jesse Eichar jeichar.w at gmail.com
Wed May 7 00:00:12 PDT 2008


Currently it is not so simple to do I'm afraid.  It is possible to  
obtain the Postgis Connection from the IService and create a view in  
the database.

Thinking about this, it is probably the easiest to make a View from  
the datastore.  This is different from making a View in the database.   
What it does is it essentially adds a where clause to all the queries  
that are made for that layer.  The restriction is that it has to be  
based on the Geotools filter.

To get started with this first create the layer.
Next you put a filter on the layer style blackboard.
Now add the layer to the map(or refresh it if it is already in the map)

So assuming the layer has been created:

Filter filter =  
FilterFactoryFinder.createFilterFactory().createFidFilter(
                 f.getID());
layer 
.getStyleBlackboard 
().put(ProjectBlackboardConstants.LAYER__DATA_QUERY, filter);


That's all.  So now that layer will only show the one feature  
identified by the fid filter.  Any filter can be used.  An intro to  
filters is available at:  http://geotools.codehaus.org/Filters+and+Expressions 
  becareful it is possible that some of the information on the page is  
for a new version of Geotools.  But the idea is there and I saw some  
of the examples are correct.  Let me know if you have any questions.


FYI, On geotools trunk I an working on making it possible to construct  
layers from arbitrary SQL statements so that layers can be constructed  
from joins and other more advanced sql.  But it is not ready yet.

Jesse

On 7-May-08, at 3:27 AM, Geoff Hay wrote:

> Hi
> Is there an easy way to add a new postGIS layer at runtime that is  
> based on an SQL query? I’d like to enter a value for the where  
> clause of an SQL statement from my pluggin and have a new layer  
> created from the results of the query. Is there a simple way to do  
> this? I’ve seen lots of code that uses feature sources and  
> georesources etc but it seems overly complex, hence this question!
> cheers
>
> geoff
> _______________________________________________
> User-friendly Desktop Internet GIS (uDig)
> http://udig.refractions.net
> http://lists.refractions.net/mailman/listinfo/udig-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.refractions.net/pipermail/udig-devel/attachments/20080507/9a4842de/attachment.html


More information about the udig-devel mailing list