org.geotools.filter
Class SQLEncoderPostgis

Object
  extended by SQLEncoder
      extended by SQLEncoderPostgis
All Implemented Interfaces:
FilterVisitor, FilterVisitor2
Direct Known Subclasses:
SQLEncoderPostgisGeos

public class SQLEncoderPostgis
extends SQLEncoder
implements FilterVisitor

Encodes a filter into a SQL WHERE statement for postgis. This class adds the ability to turn geometry filters into sql statements if they are bboxes.

Author:
Chris Holmes, TOPP
Module:
modules/plugin/postgis (gt-postgis.jar)
TODO:
TODO: integrated with SQLEncoderPostgisGeos.java, as there no real reason to have two different classes. We just need to do testing to make sure both handle everything. At the very least have the geos one extend more intelligently.

Field Summary
protected  boolean looseBbox
          Whether the BBOX filter should be strict (using the exact geom), or loose (using the envelopes)
protected  boolean supportsGEOS
          Whether the installed PostGIS has GEOS support.
 
Fields inherited from class SQLEncoder
capabilities, comparisions, context, featureType, IO_ERROR, mapper, out
 
Constructor Summary
SQLEncoderPostgis()
          Empty constructor TODO: rethink empty constructor, as BBOXes _need_ an SRID, must make client set it somehow.
SQLEncoderPostgis(boolean looseBbox)
           
SQLEncoderPostgis(int srid)
          Constructor with srid.
 
Method Summary
protected  FilterCapabilities createFilterCapabilities()
          Sets the capabilities of this filter.
 boolean getSupportsGEOS()
           
 boolean isLooseBbox()
          Gets whether the Filter.BBOX query will be strict and use an intersects or 'loose' and just operate against the geometry envelopes.
 void setDefaultGeometry(String name)
          Sets the default geometry, so that filters with null for one of their expressions can assume that the default geometry is intended.
 void setLooseBbox(boolean isLooseBbox)
          Sets whether the Filter.BBOX query should be 'loose', meaning that it should just doing a bounding box against the envelope.
 void setSRID(int srid)
          Sets a spatial reference system ESPG number, so that the geometry can be properly encoded for postgis.
 void setSupportsGEOS(boolean supports)
           
 void visit(CompareFilter filter)
          Writes the SQL for a Compare Filter.
 void visit(GeometryFilter filter)
          Turns a geometry filter into the postgis sql bbox statement.
 void visit(LikeFilter filter)
          Writes the SQL for the Like Filter.
 void visit(LiteralExpression expression)
          Checks to see if the literal is a geometry, and encodes it if it is, if not just sends to the parent class.
 void visitLiteralGeometry(LiteralExpression expression)
          Checks to see if the literal is a geometry, and encodes it if it is, if not just sends to the parent class.
 
Methods inherited from class SQLEncoder
encode, encode, encode, encode, escapeName, getCapabilities, getColnameEscape, getFIDMapper, setColnameEscape, setFeatureType, setFIDMapper, setSqlNameEscape, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface FilterVisitor
visit, visit, visit, visit, visit, visit, visit, visit, visit
 

Field Detail

looseBbox

protected boolean looseBbox
Whether the BBOX filter should be strict (using the exact geom), or loose (using the envelopes)


supportsGEOS

protected boolean supportsGEOS
Whether the installed PostGIS has GEOS support. Default is false for backwards compatibility.

Constructor Detail

SQLEncoderPostgis

public SQLEncoderPostgis()
Empty constructor TODO: rethink empty constructor, as BBOXes _need_ an SRID, must make client set it somehow. Maybe detect when encode is called?


SQLEncoderPostgis

public SQLEncoderPostgis(boolean looseBbox)

SQLEncoderPostgis

public SQLEncoderPostgis(int srid)
Constructor with srid.

Parameters:
srid - spatial reference id to encode geometries with.
Method Detail

createFilterCapabilities

protected FilterCapabilities createFilterCapabilities()
Description copied from class: SQLEncoder
Sets the capabilities of this filter.

Overrides:
createFilterCapabilities in class SQLEncoder
Returns:
FilterCapabilities for this Filter
See Also:
SQLEncoder.createFilterCapabilities()

setLooseBbox

public void setLooseBbox(boolean isLooseBbox)
Sets whether the Filter.BBOX query should be 'loose', meaning that it should just doing a bounding box against the envelope. If set to false then the BBOX query will perform a full intersects against the geometry, ensuring that it is exactly correct. If true then the query will likely perform faster, but may not be exactly correct.

Parameters:
isLooseBbox - whether the bbox should be loose or strict.

isLooseBbox

public boolean isLooseBbox()
Gets whether the Filter.BBOX query will be strict and use an intersects or 'loose' and just operate against the geometry envelopes.

Returns:
true if this encoder is going to do loose filtering.

setSRID

public void setSRID(int srid)
Sets a spatial reference system ESPG number, so that the geometry can be properly encoded for postgis. If geotools starts actually creating geometries with valid srids then this method will no longer be needed.

Parameters:
srid - the integer code for the EPSG spatial reference system.

setDefaultGeometry

public void setDefaultGeometry(String name)
Sets the default geometry, so that filters with null for one of their expressions can assume that the default geometry is intended.

Parameters:
name - the name of the default geometry Attribute.
TODO:
REVISIT: pass in a featureType so that geometries can figure out their own default geometry?

setSupportsGEOS

public void setSupportsGEOS(boolean supports)

getSupportsGEOS

public boolean getSupportsGEOS()

visit

public void visit(GeometryFilter filter)
           throws RuntimeException
Turns a geometry filter into the postgis sql bbox statement.

Specified by:
visit in interface FilterVisitor
Overrides:
visit in class SQLEncoder
Parameters:
filter - the geometry filter to be encoded.
Throws:
RuntimeException - for IO exception (need a better error)
See Also:
FilterVisitor.visit(org.geotools.filter.GeometryFilter)

visitLiteralGeometry

public void visitLiteralGeometry(LiteralExpression expression)
                          throws IOException
Checks to see if the literal is a geometry, and encodes it if it is, if not just sends to the parent class.

Overrides:
visitLiteralGeometry in class SQLEncoder
Parameters:
expression - the expression to visit and encode.
Throws:
IOException - for IO exception (need a better error)

visit

public void visit(LikeFilter filter)
           throws UnsupportedOperationException
Description copied from class: SQLEncoder
Writes the SQL for the Like Filter. Assumes the current java implemented wildcards for the Like Filter: . for multi and .? for single. And replaces them with the SQL % and _, respectively. Currently does nothing, and should not be called, not included in the capabilities.

Specified by:
visit in interface FilterVisitor
Overrides:
visit in class SQLEncoder
Parameters:
filter - the Like Filter to be visited.
Throws:
UnsupportedOperationException - always, as likes aren't implemented yet.

visit

public void visit(LiteralExpression expression)
           throws RuntimeException
Checks to see if the literal is a geometry, and encodes it if it is, if not just sends to the parent class.

Specified by:
visit in interface FilterVisitor
Overrides:
visit in class SQLEncoder
Parameters:
expression - the expression to visit and encode.
Throws:
RuntimeException - for IO exception (need a better error)

visit

public void visit(CompareFilter filter)
           throws RuntimeException
Writes the SQL for a Compare Filter. DJB: note, postgis overwrites this implementation because of the way null is handled. This is for filters and filters are handled. They will come here with "property = null". NOTE: SELECT * FROM WHERE isnull; -- postgresql SELECT * FROM
WHERE isnull(); -- oracle???

Specified by:
visit in interface FilterVisitor
Overrides:
visit in class SQLEncoder
Parameters:
filter - the comparison to be turned into SQL.
Throws:
RuntimeException - for io exception with writer


Copyright © 1996-2009 Geotools. All Rights Reserved.