org.geotools.filter
Class SQLEncoderPostgis

java.lang.Object
  extended byorg.geotools.filter.SQLEncoder
      extended byorg.geotools.filter.SQLEncoderPostgis
All Implemented Interfaces:
FilterVisitor
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
Task:
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)
 
Fields inherited from class org.geotools.filter.SQLEncoder
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 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(java.lang.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 visit(GeometryFilter filter)
          Turns a geometry filter into the postgis sql bbox statement.
 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 org.geotools.filter.SQLEncoder
encode, encode, escapeName, getCapabilities, getColnameEscape, setColnameEscape, setFIDMapper, setSqlNameEscape, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.geotools.filter.FilterVisitor
visit, visit, visit, 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)

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(java.lang.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.
Task:
REVISIT: pass in a featureType so that geometries can figure out their own default geometry?

visit

public void visit(GeometryFilter filter)
           throws java.lang.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:
java.lang.RuntimeException - for IO exception (need a better error)
See Also:
FilterVisitor.visit(org.geotools.filter.GeometryFilter)

visitLiteralGeometry

public void visitLiteralGeometry(LiteralExpression expression)
                          throws java.io.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:
java.io.IOException - for IO exception (need a better error)


Copyright © GeoTools. All Rights Reserved.