I got it working now.
The trick was to extract/evaluate the feature using the join alias as attribute.
It is encrypted in the documentation probably but for experienced geotools 
users/developers but without an example it is difficult for simple developers 
like me.

This is a working example:



query = new Query("GEO_TABLE");

query.setAlias("a");
Join join = new Join("ADMIN_TABLE", 
m_filterFactory.equals(m_filterFactory.property("a.\"ID\""), 
m_filterFactory.property("b.\"GEO_ID\"")));
join.setAlias("b");

List<PropertyName> properties = new ArrayList<PropertyName>();
properties.add(m_filterFactory.property("THEME_ATTRIBUTE"));
join.setProperties(properties);

query.getJoins().add(join);
query.setPropertyNames(new String[] {"GEOMETRIE"});

FeatureSource featureSource = m_datastore.getAbsoluteFeatureSource("GEO_TABLE");

SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
typeBuilder.setName("TEST");
typeBuilder.add("GEOMETRIE", Geometry.class, crs);

SimpleFeatureType simpleFeatureType = typeBuilder.buildFeatureType();

final SimpleFeatureBuilder featureBuilder = new 
SimpleFeatureBuilder(simpleFeatureType);
final ListFeatureCollection features = new 
ListFeatureCollection(simpleFeatureType);

FeatureCollection featureCollection = featureSource.getFeatures(query);
final Expression geometriepath = m_filterFactory.property("GEOMETRIE");
final Expression joinedfeaturepath = m_filterFactory.property("b");
final Expression attributepath = m_filterFactory.property("THEME_ATTRIBUTE");

featureCollection.accepts( new FeatureVisitor(){
    public void visit(Feature feature)
    {
    Geometry geom = (Geometry) ((SimpleFeature) feature).getDefaultGeometry();
    featureBuilder.add(geom);

    Feature joinedfeature = joinedfeaturepath.evaluate(feature, Feature.class); 
// First extract the joined feature

    String attribute = attributepath.evaluate(joinedfeaturepath, String.class); 
// Take the attribute of the joined feature
    featureBuilder.add(attribute);            
    features.add(featureBuilder.buildFeature(feature.getIdentifier().getID()));
    }
}, null);

layer = new FeatureLayer(features, styleGeometry); // styleGeometry contains 
rules for THEME_ATTRIBUTE 







On Monday, December 23, 2013 4:10 PM, Andrea Aime 
<[email protected]> wrote:
 
On Mon, Dec 23, 2013 at 2:28 PM, Ron Lindhoudt <[email protected]> wrote:

Hi Andrea,
>
>
>I sent this mail to the geotools user list but I did not see it distributed 
>yet.

It has been distributed, see these public archives:
http://osgeo-org.1560.x6.nabble.com/geotools-gt2-users-f4317834.html


It's just that the person that did develop join support is unlikely to answer 
because he's in
vacation, and normally does not answer anyways, unless, I guess, you have a 
support contract
with Boundless.

I don't know the answer off the top of my head, I'd need to do some research 
myself,
but as far as I remember, jonining in GeoTools does not work like in databases, 
giving
you a flat representation of the output, but returns tuples, sets of full 
features,
with a main feature and some associated features, each one in its own 
attribute, see
here:
http://docs.codehaus.org/display/GEOTOOLS/Join+Support


Cheers
Andrea
-- 

== GeoSolutions will be closed for seasonal holidays from 23/12/2013 to 
06/01/2014 ==


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 1660272
mob: +39  339 8844549

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

-------------------------------------------------------
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to