[postgis-users] getPrefix() lies me?

marcos boullón magán marcosboullon at gmail.com
Wed Mar 22 02:28:24 PST 2006


Hello everyone,

Trying to make OrbisCAD work against a PostGIS database (postgresql
7.4, postgis 1.1.1), I found a bizarre behaviour in jdbc extensions:
file src/org/postgis/PGboxbase.java, PGboxbase class, setValue()
method. Finally a hack in the code did the job, so TO ME it's a bug in
PostGIS.

In PGboxbase.java, exists the following code...

public void setValue(String value) throws SQLException {
int srid = -1;
value = value.trim();
if (value.startsWith("SRID=")) {
  String[] temp = PGgeometry.splitSRID(value);
  value = temp[1].trim();
  srid = Integer.parseInt(temp[0].substring(5));
}
String myPrefix = getPrefix();
if (value.startsWith(myPrefix)) {
  value = value.substring(myPrefix.length()).trim();
}
PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ',');
llb = new Point(t.getToken(0));
urt = new Point(t.getToken(1));
if (srid != -1) {
  llb.setSrid(srid);
  urt.setSrid(srid);
}
}

... to remove the first component, then get the coordinates. But when
OrbisCAD makes a "select extent() ..." and calls PGboxbase with a
string value "BOX(coord1 coord2, coord3 coord4)", the method
getPrefix(value) returns a BOX3D prefix not a "BOX" prefix, and I get
a cascade of errors: if the code cannot remove here the prefix, when
code arrives at PGtokenizer a crash happens.

The error (when OrbisCAD) appears this way (pointing to gdbms, not postgis!):
[...]
Caused by: com.hardcode.gdbms.engine.data.driver.DriverException:
java.sql.SQLException: postgis.Pointjava.lang.NumberFormatException:
For input string: "BOX(-0.137837842106819
-0.0815315321087837,0.0423423424363136 0.0792792811989784"
[...]


My hack was adding a new check, removing all characteres until first
'(' if the pattern "xxx(data)" is found before PGtokenizer().

[...]
String myPrefix = getPrefix();
if (value.startsWith(myPrefix)) {
  value = value.substring(myPrefix.length()).trim();
}
>else {
>  // my hack
>  System.out.println("** my hack got activated!!");
>  System.out.println("value=\""+value+"\"");
>  System.out.println("myPrefix=\""+myPrefix+"\"");
>  // if value is like xxx(data), remove the xxx
>  if(value.indexOf('(')>0 && value.lastIndexOf(')')==(value.length()-1)) {
>    // remove characteres until first '('
>    value = value.substring(value.indexOf('('));
>    System.out.println("extrated \""+value+"\"");
>  }
>  System.out.println("now value=\""+value+"\"");
>}
PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ',');
[...]

Hope this helps someone else.

M.

--
-- marcos boullón magán



More information about the postgis-users mailing list