|
|
|
svn_geotools
|
Author: aaime
Date: 2009-10-26 21:29:34 -0400 (Mon, 26 Oct 2009) New Revision: 34256 Modified: branches/2.6.x/modules/plugin/shapefile/ branches/2.6.x/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/indexed/IndexedShapefileDataStore.java branches/2.6.x/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/indexed/IndexedShapefileDataStoreTest.java Log: GEOT-2799 Shapefile Query for FeatureIds fails Property changes on: branches/2.6.x/modules/plugin/shapefile ___________________________________________________________________ Modified: svn:mergeinfo - /branches/2.5.x/modules/plugin/shapefile:33331,33337-33338,33349,33351,33354,33601,33614,33682,33788 + /branches/2.5.x/modules/plugin/shapefile:33331,33337-33338,33349,33351,33354,33601,33614,33682,33788 /trunk/modules/plugin/shapefile:34241,34255 Modified: branches/2.6.x/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/indexed/IndexedShapefileDataStore.java =================================================================== --- branches/2.6.x/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/indexed/IndexedShapefileDataStore.java 2009-10-27 01:08:51 UTC (rev 34255) +++ branches/2.6.x/modules/plugin/shapefile/src/main/java/org/geotools/data/shapefile/indexed/IndexedShapefileDataStore.java 2009-10-27 01:29:34 UTC (rev 34256) @@ -288,7 +288,8 @@ String defaultGeomName = schema.getGeometryDescriptor().getLocalName(); - if(propertyNames.length > 0) { + // add the attributes we need to read to keep the filtering going + if(propertyNames.length > 0) { FilterAttributeExtractor fae = new FilterAttributeExtractor(); query.getFilter().accept(fae, null); @@ -299,26 +300,25 @@ .size()]); } + // check what we actually have to read SimpleFeatureType newSchema = schema; boolean readDbf = true; boolean readGeometry = true; try { - if (((query.getPropertyNames() != null) + if (((query.getPropertyNames() != Query.NO_NAMES) && (propertyNames.length == 1) && propertyNames[0] .equals(defaultGeomName))) { readDbf = false; newSchema = createSubType( propertyNames); - } else if ((query.getPropertyNames() != null) + } else if ((query.getPropertyNames() == Query.NO_NAMES) && (propertyNames.length == 0)) { readDbf = false; readGeometry = false; newSchema = createSubType( propertyNames); - } - else if( propertyNames.length > 0 && !propertyNames[0].equals(defaultGeomName) ){ + } else if( propertyNames.length > 0 && !propertyNames[0].equals(defaultGeomName) ){ readGeometry = false; newSchema = createSubType(propertyNames); - } - else if(propertyNames.length > 0) { + } else if(propertyNames.length > 0) { newSchema = createSubType(propertyNames); } Modified: branches/2.6.x/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/indexed/IndexedShapefileDataStoreTest.java =================================================================== --- branches/2.6.x/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/indexed/IndexedShapefileDataStoreTest.java 2009-10-27 01:08:51 UTC (rev 34255) +++ branches/2.6.x/modules/plugin/shapefile/src/test/java/org/geotools/data/shapefile/indexed/IndexedShapefileDataStoreTest.java 2009-10-27 01:29:34 UTC (rev 34256) @@ -29,6 +29,7 @@ import java.util.Collections; import java.util.Date; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -56,6 +57,8 @@ import org.geotools.feature.simple.SimpleFeatureTypeBuilder; import org.geotools.filter.IllegalFilterException; import org.geotools.geometry.jts.ReferencedEnvelope; +import org.opengis.feature.Feature; +import org.opengis.feature.FeatureVisitor; import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; import org.opengis.feature.type.AttributeDescriptor; @@ -320,6 +323,40 @@ ds2.dispose(); } + public void testSelectionQuery() throws Exception { + File shpFile = copyShapefiles(STATE_POP); + URL url = shpFile.toURI().toURL(); + IndexedShapefileDataStore ds = new IndexedShapefileDataStore(url, null, true, true, + IndexType.NONE); + FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = ds.getFeatureSource(); + SimpleFeatureType schema = featureSource.getSchema(); + DefaultQuery query = new DefaultQuery( schema.getTypeName() ); + query.setPropertyNames(new String[0]); + FeatureCollection<SimpleFeatureType, SimpleFeature> features = featureSource.getFeatures( query ); + + assertNotNull( "selection query worked", features ); + assertTrue( "selection non empty", features.size() > 0 ); + ReferencedEnvelope bounds = features.getBounds(); + + final Set<FeatureId> selection = new LinkedHashSet<FeatureId>(); + features.accepts( new FeatureVisitor() { + public void visit(Feature feature) { + selection.add( feature.getIdentifier() ); + } + }, null ); + assertFalse( selection.isEmpty() ); + + // try with filter and no attributes + FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); + String geomName = schema.getGeometryDescriptor().getName().getLocalPart(); + + query.setFilter( ff.bbox( ff.property(geomName), bounds) ); + features = featureSource.getFeatures( query ); + + assertNotNull( "selection query worked", features ); + assertTrue( "selection non empty", features.size() > 0 ); + } + public void testFidFilter() throws Exception { File shpFile = copyShapefiles(STATE_POP); URL url = shpFile.toURI().toURL(); ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ GeoTools-commits mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-commits |
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |