And if you submit it as a bug in jira and attach the patch there I can build a jar to be used by others.
Sorry There are someting wrong with previous attached file so I send again.
From: "Nils Krüger" <nkrueger@anonymised.com>
To: worr <n_worr@anonymised.com>
Subject: Re: Re: [Geoserver-users] WMS GetFeatureInfo
Date: Tue, 11 Jul 2006 10:44:21 +0200
Hi,
Thank you for your help. But unfortunately I didn`t get your attached file.
Could you send me the attachment again, please?
Best Regards
Nils
-------- Original-Nachricht --------
Datum: Mon, 10 Jul 2006 10:36:47 -0700 (PDT)
Von: worr <n_worr@anonymised.com>
An: geoserver-users@lists.sourceforge.net
Betreff: Re: [Geoserver-users] WMS GetFeatureInfo
>
> It was an error on the class SQLEncoderOracle.class in lib
> gt2-oracle-spatial.jar
> I already debug and It worked.You can use my attached file.
> --
> View this message in context:
> http://www.nabble.com/WMS-GetFeatureInfo-tf1907679.html#a5255773
> Sent from the GeoServer - User forum at Nabble.com.
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job
> easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Geoserver-users mailing list
> Geoserver-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/geoserver-users
--
"Feel free" – 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
!DSPAM:1003,44b370ec180167731818748!
/*
* Geotools2 - OpenSource mapping toolkit
* http://geotools.org
* (C) 2002, Geotools Project Managment Committee (PMC)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*/
package org.geotools.filter;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import org.geotools.data.oracle.sdo.SDO;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.CoordinateSequence;
import com.vividsolutions.jts.geom.CoordinateSequenceFactory;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Polygon;
/**
* Encodes Geometry filters into valid oracle SDO statements.
*
* <p>
* At this stage it only supports the GEOMETRY_BBOX types.
* </p>
*
* <p>
* Encoded filters get written to the protected Writer called <code>out</code>
* </p>
*
* @author $Author: worr $
* @version $Id: SQLEncoderOracle.java,v 1.1 2006/07/03 04:48:51 worr Exp $
*/
public class SQLEncoderOracle extends SQLEncoder {
/** The capabilities of the encoder */
private static FilterCapabilities capabilities = null;
/** Logger - for logging */
private static final Logger LOGGER = Logger.getLogger(
"org.geotools.filter.SQLEncoderOracle");
/** Contains filter type to SDO_RELATE mask type mappings */
private static final Map SDO_RELATE_MASK_MAP = new HashMap();
/** The standard SQL multicharacter wild card. */
private static final String SQL_WILD_MULTI = "%";
/** The standard SQL single character wild card. */
private static final String SQL_WILD_SINGLE = "_";
/** Default tolerance for spatial queries. */
private static final String TOLERANCE = "0.001";
static {
SDO_RELATE_MASK_MAP.put(new Short(AbstractFilter.GEOMETRY_CONTAINS),
"contains");
SDO_RELATE_MASK_MAP.put(new Short(AbstractFilter.GEOMETRY_CROSSES),
"overlapbydisjoint");
SDO_RELATE_MASK_MAP.put(new Short(AbstractFilter.GEOMETRY_EQUALS),
"equal");
SDO_RELATE_MASK_MAP.put(new Short(AbstractFilter.GEOMETRY_OVERLAPS),
"overlapbyintersect");
SDO_RELATE_MASK_MAP.put(new Short(AbstractFilter.GEOMETRY_TOUCHES),
"touch");
SDO_RELATE_MASK_MAP.put(new Short(AbstractFilter.GEOMETRY_WITHIN),
"inside");
SDO_RELATE_MASK_MAP.put(new Short(AbstractFilter.GEOMETRY_DISJOINT),
"disjoint");
//Ok, back to using these, as the not disjoint turned out to be a big
//performance hit. I would really like to see some solid testing on
//these though, as with a trivial case it really did not seem to work
//right, not disjoint was giving different answers than anyinteract.
SDO_RELATE_MASK_MAP.put(new Short(AbstractFilter.GEOMETRY_BBOX),
"anyinteract");
SDO_RELATE_MASK_MAP.put(new Short(AbstractFilter.GEOMETRY_INTERSECTS),
"anyinteract");
}
/** The escaped version of the multiple wildcard for the REGEXP pattern. */
//private String escapedWildcardMulti = "\W.\\*"; // "\\*"
/** The escaped version of the single wildcard for the REGEXP pattern. */
//private String escapedWildcardSingle = "\\.\\?";
/**
* The Spatial Reference System IDs Keyed by ColumnName, value is Integer
* SRID number
*/
private Map srids;
private String fidColumn;
private String currentGeomColumnName = null;
boolean inGeomFilter = false;
public SQLEncoderOracle(String fidColumn, int defaultSRID) {
this(new HashMap());
this.fidColumn = fidColumn;
srids.put(null, new Integer(defaultSRID));
setSqlNameEscape("\"");
}
public SQLEncoderOracle(int defaultSRID) {
this(null, new HashMap());
srids.put(null, new Integer(defaultSRID));
}
/**
* Creates a new SQLEncoderOracle with a specified SRID.
*
* @param srids DOCUMENT ME!
* @param srids The Spatial Reference ID to use when generating SDO SQL
* statements.
*/
public SQLEncoderOracle(String fidColumn, Map srids) {
currentGeomColumnName = null;
this.fidColumn = fidColumn;
this.srids = srids;
Set geomCols = srids.keySet();
if (geomCols.size() > 0) {
currentGeomColumnName = (String) geomCols.iterator().next();
}
LOGGER.fine("SQLEncoderOracle: Geometric Column is: "
+ currentGeomColumnName);
setSqlNameEscape("\"");
}
/**
* Creates a new SQLEncoderOracle with a specified SRID.
*
* @param srids The Spatial Reference ID to use when generating SDO SQL
* statements.
*/
public SQLEncoderOracle(Map srids) {
this(null, srids);
}
/**
* Sets the capabilities of this filter.
*
* @return FilterCapabilities for this Filter
*/
protected FilterCapabilities createFilterCapabilities() {
FilterCapabilities capabilities = super.createFilterCapabilities();
capabilities.addType(AbstractFilter.GEOMETRY_BBOX);
capabilities.addType(AbstractFilter.GEOMETRY_CONTAINS);
capabilities.addType(AbstractFilter.GEOMETRY_CROSSES);
capabilities.addType(AbstractFilter.GEOMETRY_DISJOINT);
capabilities.addType(AbstractFilter.GEOMETRY_EQUALS);
capabilities.addType(AbstractFilter.GEOMETRY_INTERSECTS);
capabilities.addType(AbstractFilter.GEOMETRY_OVERLAPS);
capabilities.addType(AbstractFilter.GEOMETRY_TOUCHES);
capabilities.addType(AbstractFilter.GEOMETRY_WITHIN);
capabilities.addType(AbstractFilter.GEOMETRY_DWITHIN);
capabilities.addType(AbstractFilter.GEOMETRY_BEYOND);
capabilities.addType(AbstractFilter.FID);
capabilities.addType(AbstractFilter.LIKE);
return capabilities;
}
/**
* Reverting back to just using anyinteract, as Thijs says this is a bad
* performance hit
* This is a special case for bbox and intersects filters, as the former
* using of 'anyinteract' does not seem to be exactly a not disjoint,
* which is what is needed according to ogc specs.
*
* @param geomFilter DOCUMENT ME!
*
* @throws IOException DOCUMENT ME!
*/
/* private void doNotDisjointFilter(GeometryFilter geomFilter)
throws IOException {
//String mask = (String) SDO_RELATE_MASK_MAP.get(new Short(
// geomFilter.getFilterType()));
Expression left = geomFilter.getLeftGeometry();
Expression right = geomFilter.getRightGeometry();
if (((left != null) || (currentGeomColumnName != null))
&& (right != null)) {
inGeomFilter = true;
out.write("NOT SDO_RELATE(");
if (left != null) {
left.accept(this);
} else {
out.write(currentGeomColumnName);
}
out.write(",");
right.accept(this);
out.write(",'mask=disjoint querytype=WINDOW') = 'TRUE' ");
inGeomFilter = false;
} else {
LOGGER.warning("Invalid filter. Cannot have a Geometry filter "
+ "with only one expression.");
}
}*/
private void doSdoRelate(GeometryFilter geomFilter)
throws IOException {
String mask = (String) SDO_RELATE_MASK_MAP.get(new Short(
geomFilter.getFilterType()));
Expression left = geomFilter.getLeftGeometry();
Expression right = geomFilter.getRightGeometry();
if (((left != null) || (currentGeomColumnName != null))
/*&& (right != null)*/ && (mask != null)) {
inGeomFilter = true;
out.write("SDO_RELATE(");
out.write("\"" + currentGeomColumnName + "\"");
out.write(",");
if (left != null) {
left.accept(this);
}/* else {
out.write("\"" + currentGeomColumnName + "\"");
}
*/
//out.write(",");
//right.accept(this);
out.write(",'mask=" + mask + " querytype=WINDOW') = 'TRUE' ");
inGeomFilter = false;
} else {
LOGGER.warning("Invalid filter. Cannot have a Geometry filter "
+ "with only one expression.");
}
}
/**
* Performs a geometry distance filter, must be either a dwithin or a
* a beyond filter. Uses the SDO_WITHIN_DISTANCE function, dwithin matches
* for true, beyond for false.
*
* @param geomFilter the filter to use, must be a dwithin or beyond
*/
private void doSdoDistance(GeometryDistanceFilter geomFilter)
throws IOException {
// String mask = (String) SDO_RELATE_MASK_MAP.get(new Short(
// geomFilter.getFilterType()));
Expression left = geomFilter.getLeftGeometry();
Expression right = geomFilter.getRightGeometry();
double distance = geomFilter.getDistance();
//only dwithin and beyond, dwithin matches true for sdo_within_distance
boolean isDWithin = geomFilter.getFilterType() ==
AbstractFilter.GEOMETRY_DWITHIN;
String boolValue = isDWithin ? "TRUE" : "FALSE";
if ((left != null) && (right != null)) {
inGeomFilter = true;
out.write("SDO_WITHIN_DISTANCE(");
left.accept(this);
out.write(",");
right.accept(this);
out.write(",'distance=" + distance + "') = '" + boolValue + "' ");
inGeomFilter = false;
} else {
LOGGER.warning("Invalid filter for DWithin. Cannot have a Geometry filter "
+ "with only one expression.");
}
}
/**
* Converts JTS Geometry to a String version of a SDO Geometry. This
* should move to a utility class, as we now have more than one class
* using this (which is why it changed to public static). TODO: Multi
* Geometries
*
* @param geometry The JTS Geometry to convert.
* @param srid DOCUMENT ME!
*
* @return A String representation of the SDO Geometry.
*/
public static String toSDOGeom(Geometry geometry, int srid) {
if (Point.class.isAssignableFrom(geometry.getClass())) {
return toSDOGeom((Point) geometry, srid);
} else if (LineString.class.isAssignableFrom(geometry.getClass())) {
return toSDOGeom((LineString) geometry, srid);
} else if (Polygon.class.isAssignableFrom(geometry.getClass())) {
return toSDOGeom((Polygon) geometry, srid);
} else {
LOGGER.warning("Got a literal geometry that I can't handle: "
+ geometry.getClass().getName());
return "";
}
}
/**
* Converts a LineString Geometry in an SDO SQL geometry construction
* statement.
*
* <p>
* 2D geometries is assumed. If higher dimensional geometries are used the
* query will be encoded as a 2D geometry.
* </p>
*
* @param line The line to encode.
* @param srid DOCUMENT ME!
*
* @return An SDO SQL geometry object construction statement
*/
private static String toSDOGeom(LineString line, int srid) {
if (SDO.D(line) > 2) {
LOGGER.warning("" + SDO.D(line)
+ " dimensioned geometry provided."
+ " This encoder only supports 2D geometries. The query will be constructed as"
+ " a 2D query.");
}
StringBuffer buffer = new StringBuffer("MDSYS.SDO_GEOMETRY(");
buffer.append(SDO.D(line));
buffer.append("002,");
if (srid > 0) {
LOGGER.fine("Using layer SRID: " + srid);
buffer.append(srid);
} else {
LOGGER.fine("Using NULL SRID: ");
buffer.append("NULL");
}
buffer.append(",NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1),");
buffer.append("MDSYS.SDO_ORDINATE_ARRAY(");
Coordinate coordinates = line.getCoordinates();
for (int i = 0; i < coordinates.length; i++) {
buffer.append(coordinates[i].x);
buffer.append(",");
buffer.append(coordinates[i].y);
if (i != (coordinates.length - 1)) {
buffer.append(",");
}
}
buffer.append("))");
return buffer.toString();
}
/**
* Converts a Point Geometry in an SDO SQL geometry construction statement.
*
* <p>
* 2D geometries is assumed. If higher dimensional geometries are used the
* query will be encoded as a 2D geometry.
* </p>
*
* @param point The point to encode.
* @param srid DOCUMENT ME!
*
* @return An SDO SQL geometry object construction statement
*/
private static String toSDOGeom(Point point, int srid) {
if (SDO.D(point) > 2) {
LOGGER.warning("" + SDO.D(point)
+ " dimensioned geometry provided."
+ " This encoder only supports 2D geometries. The query will be constructed as"
+ " a 2D query.");
}
StringBuffer buffer = new StringBuffer("MDSYS.SDO_GEOMETRY(");
buffer.append(SDO.D(point));
buffer.append("001,");
if (srid > 0) {
LOGGER.fine("Using layer SRID: " + srid);
buffer.append(srid);
} else {
LOGGER.fine("Using NULL SRID: ");
buffer.append("NULL");
}
buffer.append(",MDSYS.SDO_POINT_TYPE(");
buffer.append(point.getX());
buffer.append(",");
buffer.append(point.getY());
buffer.append(",NULL),NULL,NULL)");
return buffer.toString();
}
/**
* Converts a Polygon Geometry in an SDO SQL geometry construction
* statement.
*
* <p>
* 2D geometries is assumed. If higher dimensional geometries are used the
* query will be encoded as a 2D geometry.
* </p>
*
* @param polygon The polygon to encode.
* @param srid DOCUMENT ME!
*
* @return An SDO SQL geometry object construction statement
*/
private static String toSDOGeom(Polygon polygon, int srid) {
StringBuffer buffer = new StringBuffer();
if (SDO.D(polygon) > 2) {
LOGGER.warning("" + SDO.D(polygon)
+ " dimensioned geometry provided."
+ " This encoder only supports 2D geometries. The query will be constructed as"
+ " a 2D query.");
}
if (polygon.getExteriorRing() != null) {
buffer.append("MDSYS.SDO_GEOMETRY(");
buffer.append(SDO.D(polygon));
buffer.append("003,");
if (srid > 0) {
LOGGER.fine("Using layer SRID: " + srid);
buffer.append(srid);
} else {
LOGGER.fine("Using NULL SRID: ");
buffer.append("NULL");
}
buffer.append(",NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1),");
buffer.append("MDSYS.SDO_ORDINATE_ARRAY(");
CoordinateSequenceFactory fact = polygon.getFactory().getCoordinateSequenceFactory();
CoordinateSequence exterior = polygon.getExteriorRing().getCoordinateSequence();
CoordinateSequence coordSeq = SDO.counterClockWise(fact, exterior);
for (int i = 0, size = coordSeq.size(); i < size; i++) {
Coordinate cur = coordSeq.getCoordinate(i);
buffer.append(cur.x);
buffer.append(",");
buffer.append(cur.y);
if (i != (size - 1)) {
buffer.append(",");
}
}
/* This could be expensive if coordSeq implementation is not an
an array. Leaving in for now as I can't test, and this is
more likely to work right.
Coordinate coordinates = coordSeq.toCoordinateArray();
for (int i = 0; i < coordinates.length; i++) {
buffer.append(coordinates[i].x);
buffer.append(",");
buffer.append(coordinates[i].y);
if (i != (coordinates.length - 1)) {
buffer.append(",");
}
}*/
buffer.append("))");
} else {
LOGGER.warning("No Exterior ring on polygon. "
+ "This encode only supports Polygons with exterior rings.");
}
if (polygon.getNumInteriorRing() > 0) {
LOGGER.warning("Polygon contains Interior Rings. "
+ "These rings will not be included in the query.");
}
return buffer.toString();
}
/**
* Handles Geometry Filter encoding. Currently only supports the encoding
* of GEOMETRY_BBOX filters. If a GEOMETRY_BBOX filter is encounter it
* will be converted into an SDO_RELATE() function. If another filter is
* found, nothing will happen.
*
* @param geomFilter The geometry filter to encode.
*
* @see org.geotools.filter.FilterVisitor#visit(org.geotools.filter.GeometryFilter)
*/
public void visit(GeometryFilter geomFilter) {
LOGGER.finer("Visiting a Geometry filter");
try {
short filterType = geomFilter.getFilterType();
if ((filterType == AbstractFilter.GEOMETRY_DWITHIN)
|| (filterType == AbstractFilter.GEOMETRY_BEYOND)){
//doSdoDistance((GeometryDistanceFilter)geomFilter);
//} else if (filterType == AbstractFilter.GEOMETRY_INTERSECTS
//|| filterType == AbstractFilter.GEOMETRY_BBOX) {
//doNotDisjointFilter(geomFilter);
} else
if (SDO_RELATE_MASK_MAP.get(new Short(geomFilter.getFilterType())) != null) {
doSdoRelate(geomFilter);
} else {
LOGGER.warning("Unknown filter type: "
+ geomFilter.getFilterType());
}
} catch (IOException e) {
LOGGER.warning("IO Error exporting geometry filter");
}
}
/**
* 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.
*
* @param filter the Like Filter to be visited.
*
* @task TODO: LikeFilter doesn't work right...revisit this when it does.
* Need to think through the escape char, so it works right when
* Java uses one, and escapes correctly with an '_'.
*/
public void visit(LikeFilter filter) {
try {
String pattern = filter.getPattern();
String multi = "\\Q"+filter.getWildcardMulti()+"\\E";
pattern = pattern.replaceAll( multi, SQL_WILD_MULTI);
String single = "\\Q"+filter.getWildcardSingle()+"\\E";
pattern = pattern.replaceAll( single, SQL_WILD_SINGLE);
//pattern = pattern.replace('\\', ''); //get rid of java escapes.
out.write("UPPER(");
((Expression) filter.getValue()).accept(this);
out.write(") LIKE ");
out.write("UPPER('" + pattern + "')");
String esc = filter.getEscape();
if (pattern.indexOf(esc) != -1) { //if it uses the escape char
out.write(" ESCAPE " + "'" + esc + "'"); //this needs testing
}
//TODO figure out when to add ESCAPE clause, probably just for the
// '_' char.
} catch (java.io.IOException ioe) {
LOGGER.warning("Unable to export filter" + ioe);
}
}
/**
* Converts a literal expression into a valid SDO object. Only handles
* Literal Geometries, all other literals are passed up to the parent.
*
* @param literal The Literal expression to encode.
*
* @see org.geotools.filter.FilterVisitor#visit(org.geotools.filter.LiteralExpression)
*/
public void visit(LiteralExpression literal) {
if (literal.getType() == DefaultExpression.LITERAL_GEOMETRY) {
Geometry geometry = (Geometry) literal.getLiteral();
try {
int srid = -1;
Integer sridO = (Integer) srids.get(currentGeomColumnName);
if (sridO == null) {
// try for default
sridO = (Integer) srids.get(null);
}
if (sridO != null) {
srid = sridO.intValue();
}
out.write(toSDOGeom(geometry, srid));
} catch (IOException e) {
LOGGER.warning("IO Error exporting Literal Geometry");
}
} else {
// can't do it, send it off to the parent
super.visit(literal);
}
}
/**
* DOCUMENT ME!
*
* @param filter
*
* @see org.geotools.filter.SQLEncoder#visit(org.geotools.filter.FidFilter)
*/
public void visit(FidFilter filter) {
if (fidColumn != null) {
String fids = filter.getFids();
LOGGER.finer("Exporting FID=" + Arrays.asList(fids));
for (int i = 0; i < fids.length; i++) {
try {
out.write(fidColumn);
out.write(" = '");
int pos;
if ((pos = fids[i].indexOf('.')) != -1) {
out.write(fids[i].substring(pos + 1));
} else {
out.write(fids[i]);
}
out.write("'");
if (i < (fids.length - 1)) {
out.write(" OR ");
}
} catch (IOException e) {
LOGGER.warning("IO Error exporting FID Filter.");
}
}
} else {
super.visit(filter);
}
}
/*
* (non-Javadoc)
*
* @see org.geotools.filter.SQLEncoder#visit(org.geotools.filter.AttributeExpression)
*/
public void visit(AttributeExpression ae) throws RuntimeException {
super.visit(ae);
if (inGeomFilter) {
currentGeomColumnName = ae.getAttributePath();
}
}
}
------------------------------------------------------------------------
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
!DSPAM:1003,44b370ec180167731818748!
------------------------------------------------------------------------
_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users
!DSPAM:1003,44b370ec180167731818748!