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 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.
I have also created a new issue in jira.codehaus.org.

Thanks Andrea for the help.


best regards,

      Tobia Di Pisa




2009/3/30 Tobia Di Pisa <[email protected]>

> Hi all,
>
> I have already sent you a mail to explain the problem I have found
> inserting some data in a table,
> whose attributes are of type "double precision". The database to which the
> table belongs is of type PostGIS.
> As I have sad in the previous mail I have initially used the library
> geotools 2.4-RC0. Andrea Aime has
> answered me saying that this kind of library is too old and he suggested me
> to replace it with the trunk.
>
> For my project I have to use the stable version 2.5.3 with whom there is
> the same error.
>
> The code I am using now is the following:
>
>
> ...
>
> Map params = new HashMap();
> params.put("dbtype", "postgis");        //must be postgis
> params.put("host", "localhost");        //the name or ip address of the
> machine running PostGIS
> params.put("port", new Integer(5432));  //the port that PostGIS is running
> on (generally 5432)
> params.put("database", "testdb");       //the name of the database to
> connect to.
> params.put("user", "postgres");         //the user to connect with
> params.put("passwd", "tobaro");         //the password of the user.
>
> DataStore pgDataStore = DataStoreFinder.getDataStore(params);
>
> FeatureWriter aWriter = pgDataStore.getFeatureWriter("measurements",
> Transaction.AUTO_COMMIT);
>
>
> for(int y=0; y<measurements; y++){
>     SimpleFeature aNewFeature = (SimpleFeature)aWriter.next();
>
>
>     aNewFeature.setAttribute("dist", dist[y].doubleValue());
>     aNewFeature.setAttribute("cond", cond[y].doubleValue());
>
>     ...
>
>     aWriter.write();
> }
>
> aWriter.close();
>
> ...
>
>
> The problem always concerns the case in which dist[y] 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
>
>
> In all the other cases the records are correctly inserted in the table.
> Could you give me any indications to resolve this problem?
>
>
> Best regards,
>     Tobia Di Pisa
>
------------------------------------------------------------------------------
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to