Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [udig-devel] layer from sql query

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


Back to the top