本文整理了Java中org.geotools.data.Query.setHints
方法的一些代码示例,展示了Query.setHints
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setHints
方法的具体详情如下:
包路径:org.geotools.data.Query
类名称:Query
方法名:setHints
[英]Set hints to control the query execution.
Hints can control such things as:
Note: Data sources may ignore hints (depending on their values) and no mechanism currently exists to discover which hints where actually used during the query's execution.
[中]设置提示以控制查询执行。
提示可以控制以下情况:
*要使用的几何测量工厂
*要应用的泛化距离
*JDBC查询中要使用的获取大小
可以通过调用org找到支持的提示集。地理工具。数据FeatureSource#GetSupportedHits()。
注意:数据源可能会忽略提示(取决于它们的值),并且目前不存在发现查询执行期间实际使用了哪些提示的机制。
代码示例来源:origin: geoserver/geoserver
result.setHints(securityQuery.getHints());
} else if (securityQuery.getHints() == null) {
result.setHints(userQuery.getHints());
} else {
Hints mix = userQuery.getHints();
mix.putAll(securityQuery.getHints());
result.setHints(mix);
代码示例来源:origin: geoserver/geoserver
query.setMaxFeatures(maxEntries);
query.setPropertyNames(new String[] {descriptor.getStartAttribute()});
query.setHints(new Hints(StructuredCoverageViewReader.QUERY_FIRST_BAND, true));
代码示例来源:origin: geotools/geotools
private Query setupBaseQuery(Query q) {
if (q == null) {
q = new Query();
} else {
q = new Query(q);
}
if (hints != null) {
q.setHints(hints);
}
if (q.getTypeName() == null) {
q.setTypeName(typeName);
}
return q;
}
代码示例来源:origin: geotools/geotools
/**
* Merges the wrapper hints with the query ones, making sure not to overwrite the query ones
*
* @param q
* @return
*/
protected Query mergeHints(Query q) {
if (this.hints == null || this.hints.isEmpty()) {
return q;
}
Query clone = new Query(q);
Hints hints = clone.getHints();
if (hints == null || hints.isEmpty()) {
clone.setHints(this.hints);
} else {
for (Entry<Object, Object> entry : this.hints.entrySet()) {
if (!hints.containsKey(entry.getKey())) {
hints.put(entry.getKey(), entry.getValue());
}
}
}
return clone;
}
代码示例来源:origin: geotools/geotools
private Query namedQuery(Filter filter, int countLimit, boolean isJoining, Hints hints) {
Query query = isJoining ? new JoiningQuery() : new Query();
if (getName().getNamespaceURI() != null) {
try {
query.setNamespace(new URI(getName().getNamespaceURI()));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
query.setTypeName(getName().getLocalPart());
query.setFilter(filter);
query.setMaxFeatures(countLimit);
query.setHints(hints);
return query;
}
代码示例来源:origin: geotools/geotools
public void testWhereParam() throws Exception {
FeatureSource fsView = dataStore.getFeatureSource("riverParam");
// by default we get everything
assertEquals(2, fsView.getCount(Query.ALL));
// let's try filtering a bit dynamically
Query q = new Query(Query.ALL);
StringBuffer sb = new StringBuffer();
sb.append(" where ");
dialect.encodeColumnName(aname("flow"), sb);
sb.append(" > 4");
q.setHints(
new Hints(
Hints.VIRTUAL_TABLE_PARAMETERS,
Collections.singletonMap("where", sb.toString())));
assertEquals(1, fsView.getCount(q));
}
代码示例来源:origin: geotools/geotools
public void testMulParamInvalid() throws Exception {
FeatureSource fsView = dataStore.getFeatureSource("riverParam");
// let's set an invalid mul param
Query q = new Query(Query.ALL);
q.setHints(
new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, Collections.singletonMap("mul", "abc")));
try {
fsView.getFeatures(q).features();
fail("Should have thrown an exception!");
} catch (Exception e) {
// fine
}
}
代码示例来源:origin: geotools/geotools
public void testMixQueryAll() {
// mixing Query.ALL equivalents with extra hints did not work
Query firstQuery = new Query(Query.ALL);
Query secondQuery = new Query(Query.ALL);
firstQuery.setHints(new Hints(Hints.USE_PROVIDED_FID, Boolean.TRUE));
secondQuery.setHints(new Hints(Hints.FEATURE_2D, Boolean.TRUE));
Query mixed = DataUtilities.mixQueries(firstQuery, secondQuery, "mixer");
assertEquals(2, mixed.getHints().size());
assertTrue((Boolean) mixed.getHints().get(Hints.USE_PROVIDED_FID));
assertTrue((Boolean) mixed.getHints().get(Hints.FEATURE_2D));
}
代码示例来源:origin: geotools/geotools
mixed.setHints(hints);
if (start != 0) {
mixed.setStartIndex(start);
代码示例来源:origin: geotools/geotools
public void testMulParamValid() throws Exception {
FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
FeatureSource fsView = dataStore.getFeatureSource("riverParam");
// let's change the mul param
Query q = new Query(Query.ALL);
q.setHints(
new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, Collections.singletonMap("mul", "10")));
q.setSortBy(new SortBy[] {ff.sort(aname("mulflow"), SortOrder.ASCENDING)});
try (FeatureIterator fi = fsView.getFeatures(q).features()) {
assertTrue(fi.hasNext());
SimpleFeature f = (SimpleFeature) fi.next();
assertEquals(30.0, ((Number) f.getAttribute(aname("mulflow"))).doubleValue(), 0.1);
assertTrue(fi.hasNext());
f = (SimpleFeature) fi.next();
assertEquals(45.0, ((Number) f.getAttribute(aname("mulflow"))).doubleValue(), 0.1);
}
}
代码示例来源:origin: geotools/geotools
public void testGeometryFactoryHintsGF() throws IOException {
SimpleFeatureSource fs = dataStore.getFeatureSource(tname("road"));
assertTrue(fs.getSupportedHints().contains(Hints.JTS_GEOMETRY_FACTORY));
Query q = new Query(tname("road"));
GeometryFactory gf = new GeometryFactory(new LiteCoordinateSequenceFactory());
Hints hints = new Hints(Hints.JTS_GEOMETRY_FACTORY, gf);
q.setHints(hints);
try (SimpleFeatureIterator it = fs.getFeatures(q).features()) {
it.hasNext();
SimpleFeature f = (SimpleFeature) it.next();
LineString ls = (LineString) f.getDefaultGeometry();
assertTrue(ls.getCoordinateSequence() instanceof LiteCoordinateSequence);
}
}
代码示例来源:origin: geotools/geotools
public void testGeometryFactoryHint() throws Exception {
FilterFactory ff = dataStore.getFilterFactory();
PropertyIsEqualTo filter =
ff.equals(ff.property(aname("stringProperty")), ff.literal("one"));
Query query = new Query();
query.setFilter(filter);
// check we're respecting the geometry factory hint
GeometryFactory gf1 = new GeometryFactory();
query.setHints(new Hints(Hints.JTS_GEOMETRY_FACTORY, gf1));
SimpleFeature f1 = DataUtilities.first(featureSource.getFeatures(query));
assertSame(gf1, ((Geometry) f1.getDefaultGeometry()).getFactory());
// check we're respecting the geometry factory when changing it
GeometryFactory gf2 = new GeometryFactory();
query.setHints(new Hints(Hints.JTS_GEOMETRY_FACTORY, gf2));
SimpleFeature f2 = DataUtilities.first(featureSource.getFeatures(query));
assertSame(gf2, ((Geometry) f2.getDefaultGeometry()).getFactory());
}
代码示例来源:origin: geotools/geotools
public void testGeometryFactoryHintsCS() throws IOException {
SimpleFeatureSource fs = dataStore.getFeatureSource(tname("road"));
assertTrue(fs.getSupportedHints().contains(Hints.JTS_COORDINATE_SEQUENCE_FACTORY));
Query q = new Query(tname("road"));
Hints hints =
new Hints(
Hints.JTS_COORDINATE_SEQUENCE_FACTORY, new LiteCoordinateSequenceFactory());
q.setHints(hints);
try (SimpleFeatureIterator it = fs.getFeatures(q).features()) {
it.hasNext();
SimpleFeature f = (SimpleFeature) it.next();
LineString ls = (LineString) f.getDefaultGeometry();
assertTrue(ls.getCoordinateSequence() instanceof LiteCoordinateSequence);
}
}
代码示例来源:origin: geotools/geotools
private Query namedQuery(Query query) {
Query namedQuery =
namedQuery(
query.getFilter(), query.getMaxFeatures(), query instanceof JoiningQuery);
namedQuery.setProperties(query.getProperties());
namedQuery.setCoordinateSystem(query.getCoordinateSystem());
namedQuery.setCoordinateSystemReproject(query.getCoordinateSystemReproject());
namedQuery.setHandle(query.getHandle());
namedQuery.setMaxFeatures(query.getMaxFeatures());
namedQuery.setStartIndex(query.getStartIndex());
namedQuery.setSortBy(query.getSortBy());
namedQuery.setHints(query.getHints());
if (query instanceof JoiningQuery) {
((JoiningQuery) namedQuery).setQueryJoins(((JoiningQuery) query).getQueryJoins());
((JoiningQuery) namedQuery).setRootMapping(((JoiningQuery) query).getRootMapping());
}
return namedQuery;
}
代码示例来源:origin: geotools/geotools
/**
* Makes sure the datastore works when the renderer uses the typical rendering hints
*
* @throws Exception
*/
public void testRendererBehaviour() throws Exception {
Query query = new Query(featureSource.getSchema().getTypeName());
query.setHints(
new Hints(
new Hints(
Hints.JTS_COORDINATE_SEQUENCE_FACTORY,
new LiteCoordinateSequenceFactory())));
SimpleFeatureCollection fc = featureSource.getFeatures(query);
try (SimpleFeatureIterator fi = fc.features()) {
while (fi.hasNext()) {
fi.next();
}
}
}
代码示例来源:origin: geotools/geotools
public void testSimplification() throws Exception {
SimpleFeatureSource fs = dataStore.getFeatureSource(tname("road"));
if (fs.getSupportedHints().contains(Hints.GEOMETRY_SIMPLIFICATION) == false) return;
SimpleFeatureCollection fColl = fs.getFeatures();
Geometry original = null;
try (SimpleFeatureIterator iterator = fColl.features()) {
if (iterator.hasNext()) {
original = (Geometry) iterator.next().getDefaultGeometry();
}
}
double width = original.getEnvelope().getEnvelopeInternal().getWidth();
Query query = new Query();
Hints hints = new Hints(Hints.GEOMETRY_SIMPLIFICATION, width / 2);
query.setHints(hints);
Geometry simplified = null;
fColl = fs.getFeatures(query);
try (SimpleFeatureIterator iterator = fColl.features()) {
if (iterator.hasNext()) simplified = (Geometry) iterator.next().getDefaultGeometry();
}
assertTrue(original.getNumPoints() >= simplified.getNumPoints());
}
代码示例来源:origin: geotools/geotools
public void testGeneralization() throws Exception {
SimpleFeatureSource fs = dataStore.getFeatureSource(tname("lake"));
if (fs.getSupportedHints().contains(Hints.GEOMETRY_GENERALIZATION) == false) return;
SimpleFeatureCollection fColl = fs.getFeatures();
Geometry original = null;
try (SimpleFeatureIterator iterator = fColl.features()) {
if (iterator.hasNext()) {
original = (Geometry) iterator.next().getDefaultGeometry();
}
}
double width = original.getEnvelope().getEnvelopeInternal().getWidth();
Query query = new Query();
Hints hints = new Hints(Hints.GEOMETRY_GENERALIZATION, width / 2);
query.setHints(hints);
Geometry generalized = null;
fColl = fs.getFeatures(query);
try (SimpleFeatureIterator iterator = fColl.features()) {
if (iterator.hasNext()) {
generalized = (Geometry) iterator.next().getDefaultGeometry();
}
}
assertTrue(original.getNumPoints() >= generalized.getNumPoints());
}
代码示例来源:origin: geotools/geotools
Filter bbox = new FastBBOX(filterFactory.property(""), bounds, filterFactory);
optimizedQuery = new Query(null, bbox);
optimizedQuery.setHints(layerQuery.getHints());
代码示例来源:origin: geotools/geotools
hints.put(Hints.JTS_COORDINATE_SEQUENCE_FACTORY, new LiteCoordinateSequenceFactory());
Query query = new Query(tname(getPoly3d()));
query.setHints(hints);
代码示例来源:origin: geotools/geotools
new Hints(
Hints.JTS_COORDINATE_SEQUENCE_FACTORY, new LiteCoordinateSequenceFactory());
q.setHints(hints);
内容来源于网络,如有侵权,请联系作者删除!