Hi everyone,
I hope someone can help me out, or at least point me in the right direction.
I am trying to retrieve an envelope/bounds for multiple geometry columns for a
SQL Server 2008 table using JDBC (geotools version 2.7.1). I am either doing
something incorrect, or there is a bug in the code.
There exists two geometry columns (SP_GEOMETRY, SP_GEOMETRY2) in my SQL Server
table AUS_Data, and to retrieve the bounds I am using the code below.
Code snippet:
ds = DataStoreFinder.getDataStore(m_params);
m_featureSource = ds.getFeatureSource("AUS_Data");
SimpleFeatureType schema = m_featureSource.getSchema();
Query query = new Query( schema.getTypeName(), Filter.INCLUDE );
query.setPropertyNames(new String[]{"SP_GEOMETRY2 "});
envelope = m_featureSource.getBounds(query);
The default geometry for this table is SP_GEOMETRY (the first geometry column
found by SimpleFeatureTypeBuilder.buildFeatureType().
Code snippet:
if ( defGeom == null ) {
//none was set by name, look for first geometric type
for ( AttributeDescriptor att : attributes() ) {
if ( att instanceof GeometryDescriptor ) {
defGeom = (GeometryDescriptor) att;
break;
}
}
}
Code snippet
SimpleFeatureType built = factory.createSimpleFeatureType(
name(), attributes(), defGeom, isAbstract,
restrictions(), superType, description);
In the creation of an aggregate query in
JDBCDataStore->selectBoundsSQL->buildEnvelopeAggregates:
I notice the feature type (SP_GEOMETRY - default geometry) is being utilised to
get the geometry column names for the purpose of query creation. The only
problem is, as you can see from the resultant sql below, SP_GEOMETRY is
generated twice - this is because the for loop iterates for both columns, but
variable geometryColumn is never set to SP_GEOMETRY2.
Code snippet:
void buildEnvelopeAggregates(SimpleFeatureType featureType, StringBuffer sql) {
//walk through all geometry attributes and build the query
for (Iterator a = featureType.getAttributeDescriptors().iterator();
a.hasNext();) {
AttributeDescriptor attribute = (AttributeDescriptor) a.next();
if (attribute instanceof GeometryDescriptor) {
** String geometryColumn =
featureType.getGeometryDescriptor().getLocalName(); **
dialect.encodeGeometryEnvelope(featureType.getTypeName(),
geometryColumn, sql);
sql.append(",");
}
}
sql.setLength(sql.length() - 1);
}
Resultant SQL:
SELECT CAST("SP_GEOMETRY".STSrid as VARCHAR) + ':' +
"SP_GEOMETRY".STEnvelope().ToString(),CAST("SP_GEOMETRY".STSrid as VARCHAR) +
':' + "SP_GEOMETRY".STEnvelope().ToString()
So, the query: query.setPropertyNames(new String[]{"SP_GEOMETRY2 "}); looks
like it has no affect on the result.
I am guessing from what I have seen from the code, that the calculated bounds
should include all geometry columns in the result. Is this correct?
Is there anything I can do to include SP_GEOMETRY2 in the bounds calculation?
Thanks for any help.
Regards
David
------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Discover what all the cheering's about.
Get your free trial download today.
http://p.sf.net/sfu/quest-dev2dev2
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel