本文整理了Java中org.geotools.data.Query.setPropertyNames
方法的一些代码示例,展示了Query.setPropertyNames
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setPropertyNames
方法的具体详情如下:
包路径:org.geotools.data.Query
类名称: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
/** Returns a GeoTools query build with the provided attributes and filters */
private Query buildQuery(List<PropertyName> attributes, Filter filter) {
if (attributes == null && (filter == null || filter == Filter.INCLUDE)) {
return Query.ALL;
} else {
Query q = new Query();
q.setFilter(filter);
// TODO: switch this to property names when possible
q.setPropertyNames(flattenNames(attributes));
return q;
}
}
代码示例来源:origin: geotools/geotools
/**
* Constructor.
*
* @param typeName the name of the featureType to retrieve.
* @param namespace Namespace for provided typeName, or null if unspecified
* @param filter the OGC filter to constrain the request.
* @param maxFeatures the maximum number of features to be returned.
* @param propNames an array of the properties to fetch.
* @param handle the name to associate with the query.
*/
public Query(
String typeName,
URI namespace,
Filter filter,
int maxFeatures,
String[] propNames,
String handle) {
this.typeName = typeName;
this.filter = filter;
this.namespace = namespace;
this.maxFeatures = maxFeatures;
this.handle = handle;
setPropertyNames(propNames);
}
代码示例来源:origin: geoserver/geoserver
defQuery.setPropertyNames(propNames);
代码示例来源:origin: geoserver/geoserver
query.setFilter(rangeFilter);
query.setMaxFeatures(maxEntries);
query.setPropertyNames(new String[] {descriptor.getStartAttribute()});
query.setHints(new Hints(StructuredCoverageViewReader.QUERY_FIRST_BAND, true));
代码示例来源:origin: geotools/geotools
@Override
public int getCount(Query query) throws IOException {
// transforming does not change count, but we have to transform the filter
Query txQuery = transformer.transformQuery(query);
txQuery.setPropertyNames(Query.ALL_NAMES);
// let the world know
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(
Level.FINE,
"The original query for count computation{0} has been transformed to {1}",
new Object[] {query, txQuery});
}
return source.getCount(txQuery);
}
代码示例来源:origin: geotools/geotools
/**
* @param metadataName
* @param attributeName
* @return
* @throws IOException
*/
FeatureCalc createExtremaQuery(String metadataName, String attributeName) throws IOException {
final Query query = new Query(typeName);
query.setPropertyNames(Arrays.asList(attributeName));
final FeatureCalc visitor =
metadataName.toLowerCase().endsWith("maximum")
? new MaxVisitor(attributeName)
: new MinVisitor(attributeName);
granuleCatalog.computeAggregateFunction(query, visitor);
return visitor;
}
代码示例来源:origin: geotools/geotools
/**
* Extract the domain of a dimension as a set of unique values.
*
* <p>It retrieves a comma separated list of values as a Set of {@link String}.
*
* @return a comma separated list of values as a {@link String}.
* @throws IOException
*/
Set extractDomain(final String attribute) throws IOException {
Query query = new Query(typeName);
query.setPropertyNames(Arrays.asList(attribute));
final UniqueVisitor visitor = new UniqueVisitor(attribute);
granuleCatalog.computeAggregateFunction(query, visitor);
return visitor.getUnique();
}
代码示例来源:origin: geotools/geotools
public boolean isEmpty() {
// build a minimal query
Query notEmptyQuery = new Query(query);
notEmptyQuery.setMaxFeatures(1);
AttributeDescriptor smallAttribute = getSmallAttributeInSchema();
if (smallAttribute != null) {
notEmptyQuery.setPropertyNames(
Collections.singletonList(smallAttribute.getLocalName()));
}
try {
FeatureReader<?, ?> fr = featureSource.getReader(notEmptyQuery);
try {
return !fr.hasNext();
} finally {
fr.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: geotools/geotools
private List<String> collectFilesFromTable(DataStore sourceStore, String table)
throws IOException {
final SimpleFeatureSource featureSource = sourceStore.getFeatureSource(table);
final Properties properties = getCoverageConfiguration(table);
String locationAttribute =
getProperty(
properties,
Utils.Prop.LOCATION_ATTRIBUTE,
Utils.DEFAULT_LOCATION_ATTRIBUTE);
PathType pathType =
PathType.RELATIVE.valueOf(
getProperty(properties, Utils.Prop.PATH_TYPE, PathType.ABSOLUTE.name()));
// query the location attribute
Query q = new Query(table);
q.setPropertyNames(new String[] {locationAttribute});
// extract unique values
UniqueVisitor uniqueLocations = new UniqueVisitor(locationAttribute);
featureSource.getFeatures(q).accepts(uniqueLocations, null);
Set<String> locations = uniqueLocations.getUnique();
// map via pathtype and return
return locations
.stream()
.map(l -> pathType.resolvePath(configuration.getMosaicDirectory().getPath(), l))
.map(url -> URLs.urlToFile(url).getAbsolutePath())
.collect(Collectors.toList());
}
代码示例来源:origin: geotools/geotools
@Test
public void testRetypeCannotSortFullyCovered() throws Exception {
Query q = new Query();
q.setPropertyNames(
new String[] {
"name",
});
q.setSortBy(new SortBy[] {ff.sort("z", SortOrder.ASCENDING)});
Query expected = new Query(q);
expected.setPropertyNames(new String[] {"name", "z"});
checkRetypeCannotSort(q, expected);
}
代码示例来源:origin: geotools/geotools
@Test
public void testRetypeCannotSortPartiallyCovered() throws Exception {
Query q = new Query();
q.setPropertyNames(
new String[] {
"name",
});
q.setSortBy(
new SortBy[] {
ff.sort("name", SortOrder.ASCENDING), ff.sort("z", SortOrder.ASCENDING)
});
Query expected = new Query(q);
expected.setPropertyNames(new String[] {"name", "z"});
checkRetypeCannotSort(q, expected);
}
代码示例来源:origin: geotools/geotools
@Test
public void testRetypeCannotSortCovered() throws Exception {
Query q = new Query();
q.setPropertyNames(new String[] {"name", "z"});
q.setSortBy(new SortBy[] {ff.sort("z", SortOrder.ASCENDING)});
checkRetypeCannotSort(q, q);
}
代码示例来源:origin: geotools/geotools
/** Test of retrieveAllProperties method, of class org.geotools.data.Query. */
public void testRetrieveAllProperties() {
// System.out.println("testRetrieveAllProperties");
Query query = new Query();
assertTrue(query.retrieveAllProperties());
query.setPropertyNames(new String[] {"foo", "bar"});
assertFalse(query.retrieveAllProperties());
query.setPropertyNames(Query.ALL_NAMES);
assertTrue(query.retrieveAllProperties());
query.setProperties(Query.ALL_PROPERTIES);
assertTrue(query.retrieveAllProperties());
query.setPropertyNames(new String[] {"foo", "bar"});
query.setProperties(Query.ALL_PROPERTIES);
assertTrue(query.retrieveAllProperties());
}
代码示例来源:origin: geotools/geotools
/** Test of getPropertyNames method, of class org.geotools.data.Query. */
public void testPropertyNames() {
// System.out.println("testPropertyNames");
Query query = new Query();
assertNull(query.getPropertyNames());
query.setPropertyNames(new String[] {"foo", "bar"});
String names[] = query.getPropertyNames();
assertNotNull(names);
assertEquals("foo", names[0]);
List list = Arrays.asList(names);
query.setPropertyNames(list);
names = query.getPropertyNames();
assertEquals("bar", names[1]);
// test compatibility with getProperties method
List<PropertyName> properties2 = query.getProperties();
assertNotNull(properties2);
assertEquals("foo", properties2.get(0).getPropertyName());
assertEquals("bar", properties2.get(1).getPropertyName());
query.setPropertyNames(Query.ALL_NAMES);
assertNull(query.getPropertyNames());
query = new Query("Test", Filter.INCLUDE, new String[] {"foo", "wibble"});
assertNotNull(query.getPropertyNames());
}
代码示例来源:origin: geotools/geotools
public void testGetFeatureInvalidFilter() throws Exception {
FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
PropertyIsEqualTo f = ff.equals(ff.property("invalidAttribute"), ff.literal(5));
Query q = new Query(tname("river"));
q.setPropertyNames(new String[] {aname("geom")});
q.setFilter(f);
// make sure a complaint related to the invalid filter is thrown here
try (FeatureReader<SimpleFeatureType, SimpleFeature> reader =
dataStore.getFeatureReader(q, Transaction.AUTO_COMMIT)) {
fail("This query should have failed, it contains an invalid filter");
} catch (Exception e) {
// good, it's supposed to fail
}
}
代码示例来源:origin: geotools/geotools
/** Test of toString method, of class org.geotools.data.Query. */
public void testToString() {
// System.out.println("testToString");
Query query = new Query();
assertNotNull(query.toString());
query.setHandle("myquery");
assertNotNull(query.toString());
query.setFilter(Filter.EXCLUDE);
assertNotNull(query.toString());
query.setPropertyNames(new String[] {"foo", "bar"});
assertNotNull(query.toString());
query = new Query();
query.setSortBy(new SortBy[] {SortBy.NATURAL_ORDER});
assertTrue(query.toString().contains("[sort by: NATURAL]"));
query.setSortBy(new SortBy[] {SortBy.REVERSE_ORDER});
assertTrue(query.toString().contains("[sort by: REVERSE]"));
}
}
代码示例来源:origin: geotools/geotools
public void testGetFeatureReaderFilterPrePostWithNoGeometry()
throws IOException, IllegalFilterException {
// GEOT-1069, make sure the post filter is run even if the geom property is not requested
try (Transaction t = new DefaultTransaction()) {
FilterFactory factory = CommonFactoryFinder.getFilterFactory(null);
FilterFunction_geometryType geomTypeExpr = new FilterFunction_geometryType();
geomTypeExpr.setParameters(
(List) Collections.singletonList(factory.property(aname("geom"))));
PropertyIsEqualTo filter = factory.equals(geomTypeExpr, factory.literal("Polygon"));
Query query = new Query(tname("road"), filter);
query.setPropertyNames((List) Collections.singletonList(aname("id")));
try (FeatureReader<SimpleFeatureType, SimpleFeature> reader =
dataStore.getFeatureReader(query, t)) {
// if the above statement didn't throw an exception, we're content
assertNotNull(reader);
}
filter = factory.equals(geomTypeExpr, factory.literal("LineString"));
query.setFilter(filter);
try (FeatureReader<SimpleFeatureType, SimpleFeature> reader =
dataStore.getFeatureReader(query, t)) {
assertTrue(reader.hasNext());
}
}
}
代码示例来源:origin: geotools/geotools
public void testGetFeatureReaderFilterWithAttributesNotRequested2() throws Exception {
SimpleFeatureType type = dataStore.getSchema(tname("river"));
FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
FilterFunction_ceil ceil = new FilterFunction_ceil();
ceil.setParameters((List) Collections.singletonList(ff.property(aname("flow"))));
PropertyIsEqualTo f = ff.equals(ceil, ff.literal(5));
Query q = new Query(tname("river"));
q.setPropertyNames(new String[] {aname("geom")});
q.setFilter(f);
// with GEOT-1069 an exception is thrown here
try (Transaction t = new DefaultTransaction();
FeatureReader<SimpleFeatureType, SimpleFeature> reader =
dataStore.getFeatureReader(q, t)) {
assertTrue(reader.hasNext());
assertEquals(1, reader.getFeatureType().getAttributeCount());
reader.next();
assertFalse(reader.hasNext());
}
}
代码示例来源:origin: geotools/geotools
public void testGetFeaturesWithQuery() throws Exception {
FilterFactory ff = dataStore.getFilterFactory();
PropertyIsEqualTo filter =
ff.equals(ff.property(aname("stringProperty")), ff.literal("one"));
Query query = new Query();
query.setPropertyNames(new String[] {aname("doubleProperty"), aname("intProperty")});
query.setFilter(filter);
SimpleFeatureCollection features = featureSource.getFeatures(query);
assertEquals(1, features.size());
try (SimpleFeatureIterator iterator = features.features()) {
assertTrue(iterator.hasNext());
SimpleFeature feature = (SimpleFeature) iterator.next();
assertEquals(2, feature.getAttributeCount());
assertEquals(new Double(1.1), feature.getAttribute(aname("doubleProperty")));
assertNotNull(feature.getAttribute(aname("intProperty")));
}
}
代码示例来源:origin: geotools/geotools
public void testGetFeatureReaderFilterWithAttributesNotRequested() throws Exception {
// this is here to avoid http://jira.codehaus.org/browse/GEOT-1069
// to come up again
SimpleFeatureType type = dataStore.getSchema(tname("river"));
FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
PropertyIsEqualTo f = ff.equals(ff.property(aname("flow")), ff.literal(4.5));
Query q = new Query(tname("river"));
q.setPropertyNames(new String[] {aname("geom")});
q.setFilter(f);
// with GEOT-1069 an exception is thrown here
try (Transaction t = new DefaultTransaction();
FeatureReader<SimpleFeatureType, SimpleFeature> reader =
dataStore.getFeatureReader(q, t)) {
assertTrue(reader.hasNext());
assertEquals(1, reader.getFeatureType().getAttributeCount());
reader.next();
assertFalse(reader.hasNext());
}
}
内容来源于网络,如有侵权,请联系作者删除!