org.geotools.data.Query.setPropertyNames()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(12.6k)|赞(0)|评价(0)|浏览(251)

本文整理了Java中org.geotools.data.Query.setPropertyNames方法的一些代码示例,展示了Query.setPropertyNames的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setPropertyNames方法的具体详情如下:
包路径:org.geotools.data.Query
类名称:Query
方法名:setPropertyNames

Query.setPropertyNames介绍

[英]Set the names of the properties that this Query should retrieve as part of the returned org.geotools.feature.FeatureCollection.

The available properties can be determined with FeatureSource#getSchema(). If properties that are not part of the source's schema are requested an exception will be thrown.
[中]设置此查询应作为返回组织的一部分检索的属性的名称。地理工具。特色特色系列。
可用属性可通过FeatureSource#getSchema()确定。如果请求不属于源架构的属性,则会引发异常。

代码示例

代码示例来源:origin: geoserver/geoserver

  1. /** Returns a GeoTools query build with the provided attributes and filters */
  2. private Query buildQuery(List<PropertyName> attributes, Filter filter) {
  3. if (attributes == null && (filter == null || filter == Filter.INCLUDE)) {
  4. return Query.ALL;
  5. } else {
  6. Query q = new Query();
  7. q.setFilter(filter);
  8. // TODO: switch this to property names when possible
  9. q.setPropertyNames(flattenNames(attributes));
  10. return q;
  11. }
  12. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Constructor.
  3. *
  4. * @param typeName the name of the featureType to retrieve.
  5. * @param namespace Namespace for provided typeName, or null if unspecified
  6. * @param filter the OGC filter to constrain the request.
  7. * @param maxFeatures the maximum number of features to be returned.
  8. * @param propNames an array of the properties to fetch.
  9. * @param handle the name to associate with the query.
  10. */
  11. public Query(
  12. String typeName,
  13. URI namespace,
  14. Filter filter,
  15. int maxFeatures,
  16. String[] propNames,
  17. String handle) {
  18. this.typeName = typeName;
  19. this.filter = filter;
  20. this.namespace = namespace;
  21. this.maxFeatures = maxFeatures;
  22. this.handle = handle;
  23. setPropertyNames(propNames);
  24. }

代码示例来源:origin: geoserver/geoserver

  1. defQuery.setPropertyNames(propNames);

代码示例来源:origin: geoserver/geoserver

  1. query.setFilter(rangeFilter);
  2. query.setMaxFeatures(maxEntries);
  3. query.setPropertyNames(new String[] {descriptor.getStartAttribute()});
  4. query.setHints(new Hints(StructuredCoverageViewReader.QUERY_FIRST_BAND, true));

代码示例来源:origin: geotools/geotools

  1. @Override
  2. public int getCount(Query query) throws IOException {
  3. // transforming does not change count, but we have to transform the filter
  4. Query txQuery = transformer.transformQuery(query);
  5. txQuery.setPropertyNames(Query.ALL_NAMES);
  6. // let the world know
  7. if (LOGGER.isLoggable(Level.FINE)) {
  8. LOGGER.log(
  9. Level.FINE,
  10. "The original query for count computation{0} has been transformed to {1}",
  11. new Object[] {query, txQuery});
  12. }
  13. return source.getCount(txQuery);
  14. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * @param metadataName
  3. * @param attributeName
  4. * @return
  5. * @throws IOException
  6. */
  7. FeatureCalc createExtremaQuery(String metadataName, String attributeName) throws IOException {
  8. final Query query = new Query(typeName);
  9. query.setPropertyNames(Arrays.asList(attributeName));
  10. final FeatureCalc visitor =
  11. metadataName.toLowerCase().endsWith("maximum")
  12. ? new MaxVisitor(attributeName)
  13. : new MinVisitor(attributeName);
  14. granuleCatalog.computeAggregateFunction(query, visitor);
  15. return visitor;
  16. }

代码示例来源:origin: geotools/geotools

  1. /**
  2. * Extract the domain of a dimension as a set of unique values.
  3. *
  4. * <p>It retrieves a comma separated list of values as a Set of {@link String}.
  5. *
  6. * @return a comma separated list of values as a {@link String}.
  7. * @throws IOException
  8. */
  9. Set extractDomain(final String attribute) throws IOException {
  10. Query query = new Query(typeName);
  11. query.setPropertyNames(Arrays.asList(attribute));
  12. final UniqueVisitor visitor = new UniqueVisitor(attribute);
  13. granuleCatalog.computeAggregateFunction(query, visitor);
  14. return visitor.getUnique();
  15. }

代码示例来源:origin: geotools/geotools

  1. public boolean isEmpty() {
  2. // build a minimal query
  3. Query notEmptyQuery = new Query(query);
  4. notEmptyQuery.setMaxFeatures(1);
  5. AttributeDescriptor smallAttribute = getSmallAttributeInSchema();
  6. if (smallAttribute != null) {
  7. notEmptyQuery.setPropertyNames(
  8. Collections.singletonList(smallAttribute.getLocalName()));
  9. }
  10. try {
  11. FeatureReader<?, ?> fr = featureSource.getReader(notEmptyQuery);
  12. try {
  13. return !fr.hasNext();
  14. } finally {
  15. fr.close();
  16. }
  17. } catch (IOException e) {
  18. throw new RuntimeException(e);
  19. }
  20. }

代码示例来源:origin: geotools/geotools

  1. private List<String> collectFilesFromTable(DataStore sourceStore, String table)
  2. throws IOException {
  3. final SimpleFeatureSource featureSource = sourceStore.getFeatureSource(table);
  4. final Properties properties = getCoverageConfiguration(table);
  5. String locationAttribute =
  6. getProperty(
  7. properties,
  8. Utils.Prop.LOCATION_ATTRIBUTE,
  9. Utils.DEFAULT_LOCATION_ATTRIBUTE);
  10. PathType pathType =
  11. PathType.RELATIVE.valueOf(
  12. getProperty(properties, Utils.Prop.PATH_TYPE, PathType.ABSOLUTE.name()));
  13. // query the location attribute
  14. Query q = new Query(table);
  15. q.setPropertyNames(new String[] {locationAttribute});
  16. // extract unique values
  17. UniqueVisitor uniqueLocations = new UniqueVisitor(locationAttribute);
  18. featureSource.getFeatures(q).accepts(uniqueLocations, null);
  19. Set<String> locations = uniqueLocations.getUnique();
  20. // map via pathtype and return
  21. return locations
  22. .stream()
  23. .map(l -> pathType.resolvePath(configuration.getMosaicDirectory().getPath(), l))
  24. .map(url -> URLs.urlToFile(url).getAbsolutePath())
  25. .collect(Collectors.toList());
  26. }

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void testRetypeCannotSortFullyCovered() throws Exception {
  3. Query q = new Query();
  4. q.setPropertyNames(
  5. new String[] {
  6. "name",
  7. });
  8. q.setSortBy(new SortBy[] {ff.sort("z", SortOrder.ASCENDING)});
  9. Query expected = new Query(q);
  10. expected.setPropertyNames(new String[] {"name", "z"});
  11. checkRetypeCannotSort(q, expected);
  12. }

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void testRetypeCannotSortPartiallyCovered() throws Exception {
  3. Query q = new Query();
  4. q.setPropertyNames(
  5. new String[] {
  6. "name",
  7. });
  8. q.setSortBy(
  9. new SortBy[] {
  10. ff.sort("name", SortOrder.ASCENDING), ff.sort("z", SortOrder.ASCENDING)
  11. });
  12. Query expected = new Query(q);
  13. expected.setPropertyNames(new String[] {"name", "z"});
  14. checkRetypeCannotSort(q, expected);
  15. }

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void testRetypeCannotSortCovered() throws Exception {
  3. Query q = new Query();
  4. q.setPropertyNames(new String[] {"name", "z"});
  5. q.setSortBy(new SortBy[] {ff.sort("z", SortOrder.ASCENDING)});
  6. checkRetypeCannotSort(q, q);
  7. }

代码示例来源:origin: geotools/geotools

  1. /** Test of retrieveAllProperties method, of class org.geotools.data.Query. */
  2. public void testRetrieveAllProperties() {
  3. // System.out.println("testRetrieveAllProperties");
  4. Query query = new Query();
  5. assertTrue(query.retrieveAllProperties());
  6. query.setPropertyNames(new String[] {"foo", "bar"});
  7. assertFalse(query.retrieveAllProperties());
  8. query.setPropertyNames(Query.ALL_NAMES);
  9. assertTrue(query.retrieveAllProperties());
  10. query.setProperties(Query.ALL_PROPERTIES);
  11. assertTrue(query.retrieveAllProperties());
  12. query.setPropertyNames(new String[] {"foo", "bar"});
  13. query.setProperties(Query.ALL_PROPERTIES);
  14. assertTrue(query.retrieveAllProperties());
  15. }

代码示例来源:origin: geotools/geotools

  1. /** Test of getPropertyNames method, of class org.geotools.data.Query. */
  2. public void testPropertyNames() {
  3. // System.out.println("testPropertyNames");
  4. Query query = new Query();
  5. assertNull(query.getPropertyNames());
  6. query.setPropertyNames(new String[] {"foo", "bar"});
  7. String names[] = query.getPropertyNames();
  8. assertNotNull(names);
  9. assertEquals("foo", names[0]);
  10. List list = Arrays.asList(names);
  11. query.setPropertyNames(list);
  12. names = query.getPropertyNames();
  13. assertEquals("bar", names[1]);
  14. // test compatibility with getProperties method
  15. List<PropertyName> properties2 = query.getProperties();
  16. assertNotNull(properties2);
  17. assertEquals("foo", properties2.get(0).getPropertyName());
  18. assertEquals("bar", properties2.get(1).getPropertyName());
  19. query.setPropertyNames(Query.ALL_NAMES);
  20. assertNull(query.getPropertyNames());
  21. query = new Query("Test", Filter.INCLUDE, new String[] {"foo", "wibble"});
  22. assertNotNull(query.getPropertyNames());
  23. }

代码示例来源:origin: geotools/geotools

  1. public void testGetFeatureInvalidFilter() throws Exception {
  2. FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
  3. PropertyIsEqualTo f = ff.equals(ff.property("invalidAttribute"), ff.literal(5));
  4. Query q = new Query(tname("river"));
  5. q.setPropertyNames(new String[] {aname("geom")});
  6. q.setFilter(f);
  7. // make sure a complaint related to the invalid filter is thrown here
  8. try (FeatureReader<SimpleFeatureType, SimpleFeature> reader =
  9. dataStore.getFeatureReader(q, Transaction.AUTO_COMMIT)) {
  10. fail("This query should have failed, it contains an invalid filter");
  11. } catch (Exception e) {
  12. // good, it's supposed to fail
  13. }
  14. }

代码示例来源:origin: geotools/geotools

  1. /** Test of toString method, of class org.geotools.data.Query. */
  2. public void testToString() {
  3. // System.out.println("testToString");
  4. Query query = new Query();
  5. assertNotNull(query.toString());
  6. query.setHandle("myquery");
  7. assertNotNull(query.toString());
  8. query.setFilter(Filter.EXCLUDE);
  9. assertNotNull(query.toString());
  10. query.setPropertyNames(new String[] {"foo", "bar"});
  11. assertNotNull(query.toString());
  12. query = new Query();
  13. query.setSortBy(new SortBy[] {SortBy.NATURAL_ORDER});
  14. assertTrue(query.toString().contains("[sort by: NATURAL]"));
  15. query.setSortBy(new SortBy[] {SortBy.REVERSE_ORDER});
  16. assertTrue(query.toString().contains("[sort by: REVERSE]"));
  17. }
  18. }

代码示例来源:origin: geotools/geotools

  1. public void testGetFeatureReaderFilterPrePostWithNoGeometry()
  2. throws IOException, IllegalFilterException {
  3. // GEOT-1069, make sure the post filter is run even if the geom property is not requested
  4. try (Transaction t = new DefaultTransaction()) {
  5. FilterFactory factory = CommonFactoryFinder.getFilterFactory(null);
  6. FilterFunction_geometryType geomTypeExpr = new FilterFunction_geometryType();
  7. geomTypeExpr.setParameters(
  8. (List) Collections.singletonList(factory.property(aname("geom"))));
  9. PropertyIsEqualTo filter = factory.equals(geomTypeExpr, factory.literal("Polygon"));
  10. Query query = new Query(tname("road"), filter);
  11. query.setPropertyNames((List) Collections.singletonList(aname("id")));
  12. try (FeatureReader<SimpleFeatureType, SimpleFeature> reader =
  13. dataStore.getFeatureReader(query, t)) {
  14. // if the above statement didn't throw an exception, we're content
  15. assertNotNull(reader);
  16. }
  17. filter = factory.equals(geomTypeExpr, factory.literal("LineString"));
  18. query.setFilter(filter);
  19. try (FeatureReader<SimpleFeatureType, SimpleFeature> reader =
  20. dataStore.getFeatureReader(query, t)) {
  21. assertTrue(reader.hasNext());
  22. }
  23. }
  24. }

代码示例来源:origin: geotools/geotools

  1. public void testGetFeatureReaderFilterWithAttributesNotRequested2() throws Exception {
  2. SimpleFeatureType type = dataStore.getSchema(tname("river"));
  3. FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
  4. FilterFunction_ceil ceil = new FilterFunction_ceil();
  5. ceil.setParameters((List) Collections.singletonList(ff.property(aname("flow"))));
  6. PropertyIsEqualTo f = ff.equals(ceil, ff.literal(5));
  7. Query q = new Query(tname("river"));
  8. q.setPropertyNames(new String[] {aname("geom")});
  9. q.setFilter(f);
  10. // with GEOT-1069 an exception is thrown here
  11. try (Transaction t = new DefaultTransaction();
  12. FeatureReader<SimpleFeatureType, SimpleFeature> reader =
  13. dataStore.getFeatureReader(q, t)) {
  14. assertTrue(reader.hasNext());
  15. assertEquals(1, reader.getFeatureType().getAttributeCount());
  16. reader.next();
  17. assertFalse(reader.hasNext());
  18. }
  19. }

代码示例来源:origin: geotools/geotools

  1. public void testGetFeaturesWithQuery() throws Exception {
  2. FilterFactory ff = dataStore.getFilterFactory();
  3. PropertyIsEqualTo filter =
  4. ff.equals(ff.property(aname("stringProperty")), ff.literal("one"));
  5. Query query = new Query();
  6. query.setPropertyNames(new String[] {aname("doubleProperty"), aname("intProperty")});
  7. query.setFilter(filter);
  8. SimpleFeatureCollection features = featureSource.getFeatures(query);
  9. assertEquals(1, features.size());
  10. try (SimpleFeatureIterator iterator = features.features()) {
  11. assertTrue(iterator.hasNext());
  12. SimpleFeature feature = (SimpleFeature) iterator.next();
  13. assertEquals(2, feature.getAttributeCount());
  14. assertEquals(new Double(1.1), feature.getAttribute(aname("doubleProperty")));
  15. assertNotNull(feature.getAttribute(aname("intProperty")));
  16. }
  17. }

代码示例来源:origin: geotools/geotools

  1. public void testGetFeatureReaderFilterWithAttributesNotRequested() throws Exception {
  2. // this is here to avoid http://jira.codehaus.org/browse/GEOT-1069
  3. // to come up again
  4. SimpleFeatureType type = dataStore.getSchema(tname("river"));
  5. FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
  6. PropertyIsEqualTo f = ff.equals(ff.property(aname("flow")), ff.literal(4.5));
  7. Query q = new Query(tname("river"));
  8. q.setPropertyNames(new String[] {aname("geom")});
  9. q.setFilter(f);
  10. // with GEOT-1069 an exception is thrown here
  11. try (Transaction t = new DefaultTransaction();
  12. FeatureReader<SimpleFeatureType, SimpleFeature> reader =
  13. dataStore.getFeatureReader(q, t)) {
  14. assertTrue(reader.hasNext());
  15. assertEquals(1, reader.getFeatureType().getAttributeCount());
  16. reader.next();
  17. assertFalse(reader.hasNext());
  18. }
  19. }

相关文章