From: Ron L. <rli...@ya...> - 2013-12-21 16:05:21
|
Hi all, I want to do a thematic presentation using an attribute of a related(joined) table. Sometime ago I didn't get the Join working but in the newer Geotools version (10.0) the join works. But the problem now is that the theme attribute is not filled in getFeatures(). Maybe this is a know limitation? This is my code: 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 attributepath = m_filterFactory.property("THEME_ATTRIBUTE"); featureCollection.accepts( new FeatureVisitor(){ public void visit(Feature feature) { Geometry geom = (Geometry) ((SimpleFeature) feature).getDefaultGeometry(); featureBuilder.add(geom); String attribute = attributepath.evaluate(feature, String.class); // attribute is always NULL! featureBuilder.add(attribute); features.add(featureBuilder.buildFeature(feature.getIdentifier().getID())); } }, null); // featureCollection.size() gives size > 0 ! layer = new FeatureLayer(features, styleGeometry); // styleGeometry contains rules for THEME_ATTRIBUTE and an ELSE rule, it alwyas hits the ELSE rule because THEME_ATTRIBUTE is NULL This is the logging: [2013-12-21 16:48:57:260] org.geotools.jdbc FINE: SELECT A.ID as A_ID,A.GEOMETRIE as GEOMETRIE,A.OPP_VLAK,B.ID as B_ID,B.THEME_ATTRIBUTE FROM GEO_TABLE A INNER JOIN ADMIN_TABLE B ON a."ID" = b."GEO_ID" WHERE SDO_FILTER(a.GEOMETRIE, ?, 'mask=anyinteract querytype=WINDOW') = 'TRUE' [2013-12-21 16:48:57:351] org.geotools.jdbc FINE: Setting parameter 1 as MDSYS.SDO_GEOMETRY(2003,90112,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,3),MDSYS.SDO_ORDINATE_ARRAY(255811.28767032965,471097.4052967033,256223.82832967033,471264.5987032967)) [2013-12-21 16:48:57:354] org.geotools.jdbc FINE: 1 = POLYGON ((255811.28767032965 471097.4052967033, 255811.28767032965 471264.5987032967, 256223.82832967033 471264.5987032967, 256223.82832967033 471097.4052967033, 255811.28767032965 471097.4052967033)) [2013-12-21 16:48:57:468] org.geotools.jdbc FINE: CLOSE CONNECTION [2013-12-21 16:48:57:470] org.geotools.jdbc FINE: CREATE CONNECTION [2013-12-21 16:48:57:476] org.geotools.jdbc FINE: SELECT count(*) FROM GEO_TABLE A INNER JOIN ADMIN_TABLE B ON a."ID" = b."GEO_ID" WHERE SDO_FILTER(a.GEOMETRIE, ?, 'mask=anyinteract querytype=WINDOW') = 'TRUE' [2013-12-21 16:48:57:479] org.geotools.jdbc FINE: Setting parameter 1 as MDSYS.SDO_GEOMETRY(2003,90112,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,3),MDSYS.SDO_ORDINATE_ARRAY(255811.28767032965,471097.4052967033,256223.82832967033,471264.5987032967)) [2013-12-21 16:48:57:481] org.geotools.jdbc FINE: 1 = POLYGON ((255811.28767032965 471097.4052967033, 255811.28767032965 471264.5987032967, 256223.82832967033 471264.5987032967, 256223.82832967033 471097.4052967033, 255811.28767032965 471097.4052967033)) [2013-12-21 16:48:57:500] org.geotools.jdbc FINE: CLOSE CONNECTION [2013-12-21 16:48:57:539] org.geotools.rendering FINE: Computed scale denominator: 996.8602825746194 [2013-12-21 16:48:57:545] org.geotools.rendering FINE: Processing 1 stylers for http://www.opengis.net/gml:GIE_GEO_KADASTRAAL_PERCEEL [2013-12-21 16:48:57:546] org.geotools.rendering FINE: creating rules for scale denominator - 996,86 [2013-12-21 16:48:57:568] org.geotools.rendering FINE: Expanding rendering area by 2 pixels to consider stroke width [2013-12-21 16:48:57:573] org.geotools.rendering FINE: Querying layer http://www.opengis.net/gml:GEO_TABLE with bbox: ReferencedEnvelope[255810.72942857142 : 256224.38657142856, 471096.847054945 : 471265.15694505494] [2013-12-21 16:48:57:650] org.geotools.rendering FINE: Style cache hit ratio: 0.9743589743589743 , hits 76, requests 78 The logging shows that the join query is correct and it also returns features but attribute THEME_ATTRIBUTE is always NULL. So it seems that featureSource.getFeatures(query) does not fill the values of the attributes of the joined table. Thanks for any help. Ron |