David Blasby wrote:
Jody,

I looked more into the featurewriting stuff that we talked about last night -- here's what I found. I think there's a problem in how "Feature" implements "equals". Here's where it came up.
I wrote a tiny program that updates a table in my database:

/**
*   similiar to:
* update <table name> set <destination geometry> = generalize(<source geometry name>,<tolerance>);
*
* but the generalize() function in here is much "smarter" than the one in postgis
...
*/

Here's my main loop (taken from the documentation page "http://docs.codehaus.org/display/GEOTOOLS/Data+Writing";):
So we need the standard safety performance checks here ;-)

private void process() throws Exception
{
Transaction t = new DefaultTransaction("HACK");
     FeatureWriter aWriter = ds.getFeatureWriter(table_name, t );
try{
             while (aWriter.hasNext())
       {
           Feature f = aWriter.next();  // get a feature
           Geometry g = (Geometry) f.getAttribute(source_column);
Geometry g_gen = generalize(g,tolerance); // less point!!
           f.setAttribute(dest_colum,g_gen);  // modify it
           aWriter.write();  // write it to DB
       }
t.commit();
} finally {
       aWriter.close();
}
}

Here's my problems.

1. This isnt happening in a transaction - it put my database into an invalid state :(
See above! Make a test cases for Transcation.AUTO_COMMIT putting you database into an invalid sate. Justin is the module maintainer
and his boss should be able to aerange for him to help you on this one :-)
2. DOCUMENTATION: its really weird seeing your writer acting as a reader. Might want to emphasis that in the documentation. I put a note at the top so others wouldnt be confused. You should also include a brief summary of FeatureStore/FeatureSource/FeatureXYZ since that is also confusing (ie. you ask for a FeatureSource, but you really get a FeatureStore!).
This is covered in my document, however it has been shunted off to one side in the user docs wiki space. I am not cleaning up the documentation until the FM is done. I would be happy to clean up the javadocs, perhaps with your example.

In general I would like to avoid FeatureReader and FeatureWriter. I do understand that the situation you working from kind of needs it. You should also be able to use an iterator() and the iterator will return you clones, and if the clone is different from the original when next is called the result will be written out.

I hope to do a better job of this for OracleDataStore, and would love to see the changes picked up by postgis.
3. Unfortunately, my program doesnt work! As I mentioned, this has to do with Feature.equals(). When the "aWriter.write();" occurs it gets passed off to the JDBCFeatureWriter class which quickly does a:
       live.equals(current)   on line 193 (2.2.x)
       in DefaultFeature (line 480) we see this:
NOTE: THIS CODE IS DUPLICATED IN DataUtilities#attributesEqual()

                       if (!((Geometry) attributes[i]).equals(
                                   (Geometry) otherAtt)) {
                           return false;
                       }
      I dont think this is the correct behavior.

     a) this takes a *long time* to compute
b) if your geometries are invalid, it will likely throw an exception and you're screwed (thats what happened to me) c) Geometry.equals(Geometry) probably doesnt do what you think/want it to do.
         For example, these 3 geometries are all equal:
         LINESTRING(0 0, 10 10)
LINESTRING(0 0, 5 5, 10 10) // extra point that coincident with the segment
         LINESTRING(10 10,0 0) // backwards
NOTE: this means you cannot "flip" the direction of lines in Geotools -- it'll never get written out.

The alternative is to use Geometry.equalsExact(Geometry). This is a "relatively" quick method that checks to see if 2 geometries are the same type, have the same number of points, and all the points are equal and in the same order. Basically, what most people mean when they say two geometries are equal.
If you want to make the change - cool. I would much rather see a "isDirty" flag on the feature - and that is what I will do for oracle Datastore. The thinking is if the attribute can remember it has been changed then we can know the feature needs to be written without doing any equals check.
So, how about changing all occurances of Geometry.equals(Geometry) with Geometry.equalsExact(Geometry)? Is this going to cause problems?
I found these two places where it happens, but I'm sure there are others.
Dave if you make the change, and the test case passes please commit it as a performance improvement. Since you are the first person to use this seriously I would also love to have you around to do a review of my oracle Datastore work. Even if that review is grabbing the design for postgis.

Jody



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Geotools-devel mailing list
Geotools-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to