本文整理了Java中org.geotools.data.Query.getJoins
方法的一些代码示例,展示了Query.getJoins
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getJoins
方法的具体详情如下:
包路径:org.geotools.data.Query
类名称:Query
方法名:getJoins
[英]The list of joins for this query.
Each Join object specifies a feature type to join to. The join may only reference a feature type from within the same datastore.
[中]此查询的联接列表。
每个连接对象都指定要连接到的要素类型。联接只能引用同一数据存储中的要素类型。
代码示例来源:origin: geoserver/geoserver
&& !query.getJoins().isEmpty()) {
continue;
代码示例来源:origin: geoserver/geoserver
modified.setTypeName(typeMap.getOriginalName());
modified.setFilter(retypeFilter(q.getFilter(), typeMap));
List<Join> joins = q.getJoins();
if (!joins.isEmpty()) {
modified.getJoins().clear();
for (Join join : joins) {
FeatureTypeMap map = (FeatureTypeMap) backwardsMap.get(join.getTypeName());
if (map == null) {
modified.getJoins().add(join);
} else {
final FeatureTypeMap joinTypeMap =
mj.setProperties(join.getProperties());
mj.setFilter(join.getFilter());
modified.getJoins().add(mj);
代码示例来源:origin: geoserver/geoserver
/**
* * Takes into account eventual joins
*
* @param query
* @return
*/
public SimpleFeatureType getFeatureType(Query query) {
SimpleFeatureType result;
if (query.getPropertyNames() != Query.ALL_NAMES) {
result = SimpleFeatureTypeBuilder.retype(featureType, query.getPropertyNames());
} else {
result = featureType;
}
// add back the joined features in case of join
if (!query.getJoins().isEmpty()) {
SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
tb.init(result);
for (Join join : query.getJoins()) {
String joinedFeatureAttribute = join.getAlias();
if (joinedFeatureAttribute == null) {
joinedFeatureAttribute = join.getTypeName();
}
tb.add(joinedFeatureAttribute, SimpleFeature.class);
}
result = tb.buildFeatureType();
}
return result;
}
代码示例来源:origin: geotools/geotools
/**
* Copy contructor.
*
* @param query the query to copy
*/
public Query(Query query) {
this(
query.getTypeName(),
query.getNamespace(),
query.getFilter(),
query.getMaxFeatures(),
query.getProperties(),
query.getHandle());
this.sortBy = query.getSortBy();
this.coordinateSystem = query.getCoordinateSystem();
this.coordinateSystemReproject = query.getCoordinateSystemReproject();
this.version = query.getVersion();
this.hints = query.getHints();
this.startIndex = query.getStartIndex();
this.alias = query.getAlias();
this.joins = new ArrayList();
for (Join j : query.getJoins()) {
this.joins.add(new Join(j));
}
}
代码示例来源:origin: geotools/geotools
/**
* Copy contructor, clones the state of a generic Query into a DefaultQuery
*
* @param query
*/
public DefaultQuery(Query query) {
this(
query.getTypeName(),
query.getNamespace(),
query.getFilter(),
query.getMaxFeatures(),
query.getProperties(),
query.getHandle());
this.sortBy = query.getSortBy();
this.coordinateSystem = query.getCoordinateSystem();
this.coordinateSystemReproject = query.getCoordinateSystemReproject();
this.version = query.getVersion();
this.hints = query.getHints();
this.startIndex = query.getStartIndex();
this.alias = query.getAlias();
this.joins = query.getJoins();
}
}
代码示例来源:origin: geotools/geotools
public void testJoinViewsWithPlaceHolder() {
Query joinQuery = new Query("riverFullPlaceHolder");
FilterFactory ff = dataStore.getFilterFactory();
Join join =
new Join(
"riverFullPlaceHolder",
ff.equal(
ff.property("a." + aname("river")),
ff.property(aname("river")),
false));
join.setAlias("a");
joinQuery.getJoins().add(join);
try {
dataStore.getFeatureSource("riverFullPlaceHolder").getCount(joinQuery);
} catch (Exception exception) {
assertTrue(
exception
.getMessage()
.contains(
"Joins between virtual tables that provide a "
+ ":where_placeholder: are not supported"));
return;
}
fail("count query should have fail with an exception");
}
代码示例来源:origin: geotools/geotools
public void testTemporalJoin() throws Exception {
FilterFactory ff = dataStore.getFilterFactory();
After after = ff.after(ff.property(aname("dt")), ff.property("other." + aname("dt")));
Query q = new Query(tname("dates"));
q.getJoins().add(new Join(tname("dates"), after).alias("other"));
q.setSortBy(new SortBy[] {ff.sort(aname("dt"), SortOrder.ASCENDING)});
assertDatesMatch(q, "2009-06-28 15:12:41", "2009-09-29 17:54:23", "2009-09-29 17:54:23");
}
代码示例来源:origin: geotools/geotools
public void testJoinViews() throws Exception {
Query joinQuery = new Query("riverFull");
FilterFactory ff = dataStore.getFilterFactory();
Join join =
new Join(
"riverReduced",
ff.equal(
ff.property("a." + aname("river")),
ff.property(aname("river")),
false));
join.setAlias("a");
joinQuery.getJoins().add(join);
// get the two feature sources
ContentFeatureSource fsFull = dataStore.getFeatureSource("riverFull");
ContentFeatureSource fsReduced = dataStore.getFeatureSource("riverReduced");
// check count
int expectedCount = fsReduced.getCount(Query.ALL);
int count = fsFull.getCount(joinQuery);
assertEquals(expectedCount, count);
}
代码示例来源:origin: geotools/geotools
public void testJoinSchema() throws Exception {
FilterFactory ff = dataStore.getFilterFactory();
Query q = new Query(tname("ft1"));
Join join =
new Join(
tname("ftjoin"),
ff.equal(
ff.property(aname("stringProperty")),
ff.property(aname("name")),
true));
join.setAlias("b");
q.getJoins().add(join);
SimpleFeatureCollection features = dataStore.getFeatureSource(tname("ft1")).getFeatures(q);
SimpleFeatureType schema = features.getSchema();
AttributeDescriptor ad = schema.getDescriptor("b");
assertNotNull(ad);
assertEquals(SimpleFeature.class, ad.getType().getBinding());
SimpleFeatureType joinedSchema =
(SimpleFeatureType) ad.getUserData().get(ContentDataStore.JOINED_FEATURE_TYPE);
assertEquals(dataStore.getSchema(tname("ftjoin")), joinedSchema);
}
代码示例来源:origin: geotools/geotools
void doTestSimpleJoinWithPostFilter(boolean exposePrimaryKeys) throws Exception {
dataStore.setExposePrimaryKeyColumns(exposePrimaryKeys);
FilterFactory ff = dataStore.getFilterFactory();
Filter j = ff.equal(ff.property(aname("stringProperty")), ff.property(aname("name")), true);
Query q = new Query(tname("ft1"));
q.getJoins().add(new Join(tname("ftjoin"), j));
q.setFilter(
ff.equal(
ff.function(
"__equals",
ff.property(aname("stringProperty")),
ff.literal("one")),
ff.literal(true),
true));
SimpleFeatureCollection features = dataStore.getFeatureSource(tname("ft1")).getFeatures(q);
assertEquals(1, features.size());
// test with post filter on table being joined
q = new Query(tname("ft1"));
Join join = new Join(tname("ftjoin"), j);
join.filter(
ff.equal(
ff.function("__equals", ff.property(aname("name")), ff.literal("one")),
ff.literal(true),
true));
q.getJoins().add(join);
features = dataStore.getFeatureSource(tname("ft1")).getFeatures(q);
assertEquals(1, features.size());
}
代码示例来源:origin: geotools/geotools
void doTestSimpleJoinWithFilterCount(boolean exposePrimaryKeys) throws Exception {
dataStore.setExposePrimaryKeyColumns(exposePrimaryKeys);
FilterFactory ff = dataStore.getFilterFactory();
Query q = new Query(tname("ft1"));
Join j =
new Join(
tname("ftjoin"),
ff.equal(
ff.property(aname("stringProperty")),
ff.property(aname("name")),
true));
j.filter(ff.greater(ff.property(aname("join1intProperty")), ff.literal(1)));
q.getJoins().add(j);
q.setFilter(ff.less(ff.property(aname("intProperty")), ff.literal(3)));
assertEquals(1, dataStore.getFeatureSource(tname("ft1")).getCount(q));
}
代码示例来源:origin: geotools/geotools
FilterFactory ff = dataStore.getFilterFactory();
Query q = new Query(tname("ftjoin"));
q.getJoins()
.add(
new Join(
true)));
q.getJoins()
.add(
new Join(
代码示例来源:origin: geotools/geotools
Join join = new Join(tname("ftjoin"), j);
join.setProperties(Query.NO_PROPERTIES);
q.getJoins().add(join);
q.setFilter(
ff.equal(
ff.literal(true),
true));
q.getJoins().add(join);
代码示例来源:origin: geotools/geotools
void doTestOuterJoin(boolean exposePrimaryKeys) throws Exception {
dataStore.setExposePrimaryKeyColumns(exposePrimaryKeys);
FilterFactory ff = dataStore.getFilterFactory();
Query q = new Query(tname("ftjoin"));
q.getJoins()
.add(
new Join(
tname("ft1"),
ff.equal(
ff.property(aname("name")),
ff.property(aname("stringProperty")),
true))
.type(Type.OUTER));
SimpleFeatureCollection features =
dataStore.getFeatureSource(tname("ftjoin")).getFeatures(q);
assertEquals(
dataStore.getFeatureSource(tname("ftjoin")).getFeatures(q).size(), features.size());
try (SimpleFeatureIterator it = features.features()) {
while (it.hasNext()) {
SimpleFeature f = it.next();
assertEquals(4 + (exposePrimaryKeys ? 1 : 0), f.getAttributeCount());
SimpleFeature g = (SimpleFeature) f.getAttribute(tname("ft1"));
if ("three".equals(f.getAttribute(aname("name")))) {
assertNull(g);
} else {
assertNotNull(g);
}
}
}
}
代码示例来源:origin: geotools/geotools
void doTestSimpleJoinWithFilter(boolean exposePrimaryKeys) throws Exception {
dataStore.setExposePrimaryKeyColumns(exposePrimaryKeys);
FilterFactory ff = dataStore.getFilterFactory();
Query q = new Query(tname("ft1"));
q.getJoins()
.add(
new Join(
tname("ftjoin"),
ff.equal(
ff.property(aname("stringProperty")),
ff.property(aname("name")),
true)));
q.setFilter(ff.equal(ff.property(aname("stringProperty")), ff.literal("two"), true));
SimpleFeatureCollection features = dataStore.getFeatureSource(tname("ft1")).getFeatures(q);
assertEquals(1, features.size());
try (SimpleFeatureIterator it = features.features()) {
SimpleFeature f = it.next();
assertEquals(5 + (exposePrimaryKeys ? 1 : 0), f.getAttributeCount());
assertEquals(2, ((Number) f.getAttribute(aname("intProperty"))).intValue());
assertEquals("two", f.getAttribute(aname("stringProperty")));
SimpleFeature g = (SimpleFeature) f.getAttribute(aname("ftjoin"));
assertEquals(3 + (exposePrimaryKeys ? 1 : 0), g.getAttributeCount());
if (exposePrimaryKeys) {
assertEquals(2, ((Number) g.getAttribute(aname("id"))).intValue());
}
assertEquals("two", g.getAttribute(aname("name")));
}
}
代码示例来源:origin: geotools/geotools
public void doTestSelfJoin(boolean exposePrimaryKeys) throws Exception {
dataStore.setExposePrimaryKeyColumns(exposePrimaryKeys);
FilterFactory ff = dataStore.getFilterFactory();
Query q = new Query(tname("ft1"));
q.getJoins()
.add(
new Join(
tname("ft1"),
ff.equal(
ff.property(aname("intProperty")),
ff.property(aname("foo.intProperty")),
true))
.alias(aname("foo")));
q.setFilter(ff.equal(ff.property(aname("stringProperty")), ff.literal("two"), true));
SimpleFeatureCollection features = dataStore.getFeatureSource(tname("ft1")).getFeatures(q);
assertEquals(1, features.size());
try (SimpleFeatureIterator it = features.features()) {
assertTrue(it.hasNext());
SimpleFeature f = it.next();
assertEquals(5 + (exposePrimaryKeys ? 1 : 0), f.getAttributeCount());
assertEquals(2, ((Number) f.getAttribute(aname("intProperty"))).intValue());
assertEquals("two", f.getAttribute(aname("stringProperty")));
SimpleFeature g = (SimpleFeature) f.getAttribute(aname("foo"));
assertEquals(4 + (exposePrimaryKeys ? 1 : 0), g.getAttributeCount());
assertEquals(2, ((Number) g.getAttribute(aname("intProperty"))).intValue());
assertEquals("two", g.getAttribute(aname("stringProperty")));
}
}
代码示例来源:origin: geotools/geotools
void doTestSimpleJoinWithFilterNoProperties(boolean exposePrimaryKeys) throws Exception {
dataStore.setExposePrimaryKeyColumns(exposePrimaryKeys);
FilterFactory ff = dataStore.getFilterFactory();
Query q = new Query(tname("ft1"));
Join j =
new Join(
tname("ftjoin"),
ff.equal(
ff.property(aname("stringProperty")),
ff.property(aname("name")),
true));
j.setProperties(Query.NO_PROPERTIES);
q.getJoins().add(j);
q.setFilter(ff.equal(ff.property(aname("stringProperty")), ff.literal("two"), true));
SimpleFeatureCollection features = dataStore.getFeatureSource(tname("ft1")).getFeatures(q);
assertEquals(1, features.size());
try (SimpleFeatureIterator it = features.features()) {
SimpleFeature f = it.next();
assertEquals(5 + (exposePrimaryKeys ? 1 : 0), f.getAttributeCount());
assertEquals(2, ((Number) f.getAttribute(aname("intProperty"))).intValue());
assertEquals("two", f.getAttribute(aname("stringProperty")));
SimpleFeature g = (SimpleFeature) f.getAttribute(aname("ftjoin"));
assertEquals(0, g.getAttributeCount());
}
}
代码示例来源:origin: geotools/geotools
void doTestSimpleJoinWithSort(boolean exposePrimaryKeys) throws Exception {
dataStore.setExposePrimaryKeyColumns(exposePrimaryKeys);
FilterFactory ff = dataStore.getFilterFactory();
Filter j = ff.equal(ff.property(aname("stringProperty")), ff.property(aname("name")), true);
Query q = new Query(tname("ft1"));
q.getJoins().add(new Join(tname("ftjoin"), j));
q.setSortBy(new SortBy[] {ff.sort(aname("intProperty"), SortOrder.DESCENDING)});
SimpleFeatureCollection features = dataStore.getFeatureSource(tname("ft1")).getFeatures(q);
try (SimpleFeatureIterator it = features.features()) {
assertTrue(it.hasNext());
assertEquals("two", it.next().getAttribute(aname("stringProperty")));
assertTrue(it.hasNext());
assertEquals("one", it.next().getAttribute(aname("stringProperty")));
assertTrue(it.hasNext());
assertEquals("zero", it.next().getAttribute(aname("stringProperty")));
}
}
代码示例来源:origin: geotools/geotools
void doTestSimpleJoinWithLimitOffset(boolean exposePrimaryKeys) throws Exception {
dataStore.setExposePrimaryKeyColumns(exposePrimaryKeys);
FilterFactory ff = dataStore.getFilterFactory();
Filter j = ff.equal(ff.property(aname("stringProperty")), ff.property(aname("name")), true);
Query q = new Query(tname("ft1"));
q.getJoins().add(new Join(tname("ftjoin"), j));
q.setFilter(ff.greater(ff.property(aname("intProperty")), ff.literal(0)));
q.setStartIndex(1);
q.setSortBy(new SortBy[] {ff.sort(aname("intProperty"), SortOrder.ASCENDING)});
SimpleFeatureCollection features = dataStore.getFeatureSource(tname("ft1")).getFeatures(q);
assertEquals(1, features.size());
try (SimpleFeatureIterator it = features.features()) {
assertTrue(it.hasNext());
SimpleFeature f = it.next();
assertEquals("two", f.getAttribute(aname("stringProperty")));
SimpleFeature g = (SimpleFeature) f.getAttribute(aname("ftjoin"));
assertEquals("two", g.getAttribute(aname("name")));
}
}
代码示例来源:origin: geotools/geotools
q.getJoins()
.add(
new Join(
内容来源于网络,如有侵权,请联系作者删除!