NaN values in PostGIS DataStore
-------------------------------
Key: GEOT-2416
URL: http://jira.codehaus.org/browse/GEOT-2416
Project: GeoTools
Issue Type: Bug
Components: data jdbc
Affects Versions: 2.5.3
Environment: Windows Vista Home Premium, JDK1.5.0_17
Reporter: Tobia Di Pisa
Priority: Minor
Fix For: 2.5.5
Attachments: jdbc.diff, PGDataStoreTest.java
I am using the GeoTools 2.5.X library to insert the data
in a table whose attributes are of type "double precision".
The database to which the table belongs is of type PostGIS.
...
DataStore pgDataStore = DataStoreFinder.getDataStore(params);
FeatureWriter aWriter = pgDataStore.getFeatureWriter("measurements",
Transaction.AUTO_COMMIT);
for(int y=0; y<measurements; y++){
Feature aNewFeature = aWriter.next();
aNewFeature.setAttribute("dist", dist[y].doubleValue());
aNewFeature.setAttribute("cond", cond[y].doubleValue());
...
aWriter.write();
}
aWriter.close();
...
The problem concerns the case in which dist[y] and/or cond[y] contain NaN.
In this case the application finishes abruptly showing the following error in
console:
25-mar-2009 17.56.00 org.geotools.data.jdbc.JDBCTextFeatureWriter doInsert
GRAVE: SQL Exception writing geometry columnERROR: column "nan" does not exist
org.postgresql.util.PSQLException: ERROR: column "nan" does not exist
at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1525)
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1309)
at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:340)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:286)
at
org.apache.commons.dbcp.DelegatingStatement.executeUpdate(DelegatingStatement.java:228)
at
org.geotools.data.jdbc.JDBCTextFeatureWriter.doInsert(JDBCTextFeatureWriter.java:117)
at
org.geotools.data.jdbc.JDBCFeatureWriter.write(JDBCFeatureWriter.java:216)
at
org.geotools.data.InProcessLockingManager$1.write(InProcessLockingManager.java:330)
at test.NETcdfPGDataStore.main(NETcdfPGDataStore.java:261)
17:56:00,680 ERROR NETcdfPGDataStore:267 -
org.geotools.data.DataSourceException: SQL Exception writing geometry
columnERROR: column "nan" does not exist
I have modified the JDBCTextFeatureWriter.addQuotes() method to fix this
problem:
...
protected String addQuotes(Object value) {
String retString;
if (value != null) {
if(value instanceof Number)
if(Double.isNaN(((Number)value).doubleValue()))
retString ="'" + value.toString() + "'";
else
retString = value.toString();
else
retString = "'" + doubleQuote(value) + "'";
} else {
retString = "null";
}
return retString;
}
...
I have also inserted the particular TestCase with JUnit in postgis plugin in
order to verify
the change (the TestCase is PGDataStoreTest).Inside the PGDataStoreTest class
I have
tested a will both the insertion of float that of double values.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
------------------------------------------------------------------------------
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel