Hi all,
during the last few weekends I've been working on a reshaping
SimpleFeatureSource/SimpleFeatureStore wrapper:
https://github.com/aaime/geotools/tree/reshape/modules/unsupported/reshape/src/main/java/org/geotools/data/reshape
https://github.com/aaime/geotools/tree/reshape/modules/unsupported/reshape/src/test/java/org/geotools/data/reshape

The work is inspired and based on Jody's reshape process, but working
at the FeatureSource/FeatureStore level
is more feature rich. Short feature summary:
* wrap any source/store and rename, type cast or hide any existing
attribute, plus the ability to add new
  attributes computed via expressions
* the above works also around stores, and preserves their writability
within some limitations (more on this later)
* full support for paging and sorting, either on native properties or
computed ones
* fully streaming in both directions (read and write)
* around 70% code coverage
* better heuristics to compute/guess the type of each attribute given
only the start schema and the expressions
  (though it's possible to force a specific target type by hand)

The set of classes is relatively large, but only one is visible, a
factory that builds the wrapper given the
source, the target type name and the list of Definitions (which
contain the definition of each new attribute).
Here is an example of how it can be used:

        List<Definition> definitions = new ArrayList<Definition>();
        definitions.add(new Definition("geom",
ECQL.toExpression("buffer(the_geom, 1)")));
        definitions.add(new Definition("name",
ECQL.toExpression("strToLowercase(state_name)")));
        definitions.add(new Definition("total",
ECQL.toExpression("male + female")));
        definitions.add(new Definition("logp",
ECQL.toExpression("log(persons)")));

        SimpleFeatureSource reshaped = ReshapeFactory.reshape(STATES,
"bstates", definitions);

The set of use cases I see for this tool:
* rename ugly attribute names coming from the database (shapefile or
Oracle are two common sources
  of butt ugly names) without losing the ability to perform
transactions --> this would allow to run WFS CITE
  tests against Oracle for example
* add new attributes that were not available in the source
* cast the type of an attribute to something else (for example, a
String with WKT could be turned into a Geometry
  via converters, which would allow to run WFS 1.1 CITE tests against
shapefiles too)
* replace the geometryless store, this would require a new function
point(x, y) and a way to invert that function
  within filters so that we can turn, say, bbox into a set of
predicates against x and y, which is something that
  could be done within the simplifying filter visitor
* replace the retyping data store in GeoServer with something at the
same time more general and more
  efficient (since it wraps directly a feature source, not a store)

Keeping writability is an interesting subject. So far I've been a bit
sloppy, things can definitely be improved.
What I have so far is a notion of Definition inversion:

    public List<Definition> inverse();

The current code is simple and can only invert renaming, so only
attributes that are not really computed
can be inverted and thus be written on.
This could be improved upon in some ways, for example:
* have a general concept of invertible function
* have a pluggable way to create "definition inverters" that can be
added at runtime
* for some limited cases, try to invert algebraic expressions of a
single variable (e.g. a = b + 10)

So far I've kept it simple, the above method can be overridden, so an
implementor can decide to roll
her own inversion logic.

Writability control is also particularly loose right now, basically if
we can invert at least one definition
we come up with a writable wrapper, otherwise we return a read only one.
I guess at the very least one should check if all the mandatory fields
can be inverted... which brings
an interesting riddle, what if one is not available, but I still want
the wrapper to be writable?
I guess the API could provide default values for the fields that get
hidden and/or cannot be inverted.

Feedback/opinions welcomed

Ah, one more thing: on the branch I've linked above I've been pretty
loose about commits, before
merging into trunk I intend to squash them, so please don't fork it off

Cheers
Andrea

-- 
==
Our support, Your Success! Visit http://opensdi.geo-solutions.it for
more information.
==

Ing. Andrea Aime
@geowolf
Technical Lead

GeoSolutions S.A.S.
Via Poggio alle Viti 1187
55054  Massarosa (LU)
Italy
phone: +39 0584 962313
fax:   +39 0584 962313
mob:   +39  339 8844549

http://www.geo-solutions.it
http://twitter.com/geosolutions_it

-------------------------------------------------------

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
GeoTools-Devel mailing list
GeoTools-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to