本文整理汇总了Java中org.geotools.data.Query类的典型用法代码示例。如果您正苦于以下问题:Java Query类的具体用法?Java Query怎么用?Java Query使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Query类属于org.geotools.data包,在下文中一共展示了Query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: basicQuery
import org.geotools.data.Query; //导入依赖的package包/类
/**
* Executes a basic bounding box query without any projections.
*
* @param simpleFeatureTypeName
* @param featureSource
*
* @throws IOException
* @throws CQLException
*/
static void basicQuery(String simpleFeatureTypeName, FeatureSource featureSource)
throws IOException, CQLException {
System.out.println("Submitting basic query with no projections\n");
// start with our basic filter to narrow the results
Filter cqlFilter = createBaseFilter();
// use the 2-arg constructor for the query - this will not restrict the attributes returned
Query query = new Query(simpleFeatureTypeName, cqlFilter);
// execute the query
FeatureCollection results = featureSource.getFeatures(query);
// loop through all results
FeatureIterator iterator = results.features();
try {
printResults(iterator);
} finally {
iterator.close();
}
}
示例2: testFidFilterQuery
import org.geotools.data.Query; //导入依赖的package包/类
@Test
public void testFidFilterQuery() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
final String fidsString = fids.stream().collect(Collectors.joining("','", "'", "'"));
final Filter filter = ECQL.toFilter("IN (" + fidsString + ")");
final Query query = new Query(
"GeoWaveFeatureReaderTest",
filter,
new String[] {
"geometry",
"pid"
});
final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
int count = 0;
while (reader.hasNext()) {
final SimpleFeature feature = reader.next();
assertTrue(fids.contains(feature.getID()));
count++;
}
assertTrue(count == fids.size());
}
示例3: testPidFilterQuery
import org.geotools.data.Query; //导入依赖的package包/类
@Test
public void testPidFilterQuery() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
// Filter it so that it only queries for everything but the first pid.
// There's only 2 pids total so it should just return the second one.
final String pidsString = pids.subList(1, pids.size()).stream().collect(Collectors.joining("','", "'", "'"));
final Filter filter = ECQL.toFilter("pid IN (" + pidsString + ")");
final Query query = new Query(
"GeoWaveFeatureReaderTest",
filter,
new String[] {
"geometry",
"pid"
});
final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
int count = 0;
while (reader.hasNext()) {
final SimpleFeature feature = reader.next();
assertTrue(fids.contains(feature.getID()));
count++;
}
assertTrue(count == pids.size() - 1);
}
示例4: testLike
import org.geotools.data.Query; //导入依赖的package包/类
@Test
public void testLike() throws IllegalArgumentException, NoSuchElementException, IOException, CQLException {
final Query query = new Query(
"GeoWaveFeatureReaderTest",
ECQL.toFilter("pid like '" + pids.get(
0).substring(
0,
1) + "%'"),
new String[] {
"geometry",
"pid"
});
final FeatureReader<SimpleFeatureType, SimpleFeature> reader =
dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
int count = 0;
while (reader.hasNext()) {
final SimpleFeature feature = reader.next();
assertTrue(fids.contains(feature.getID()));
count++;
}
assertEquals(1, count);
}
示例5: testEncodedNativeTermQuery
import org.geotools.data.Query; //导入依赖的package包/类
@Test
public void testEncodedNativeTermQuery() throws Exception {
init("not-active");
Map<String, String> vparams = new HashMap<String, String>();
Map<String,Object> query = ImmutableMap.of("term", ImmutableMap.of("security_ss", "WPA"));
vparams.put("q", URLEncoder.encode(mapper.writeValueAsString(query), "UTF-8"));
Hints hints = new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, vparams);
Query q = new Query(featureSource.getSchema().getTypeName());
q.setHints(hints);
FilterFactory ff = dataStore.getFilterFactory();
PropertyIsEqualTo filter = ff.equals(ff.property("speed_is"), ff.literal("300"));
q.setFilter(filter);
ContentFeatureCollection features = featureSource.getFeatures(q);
assertEquals(1, features.size());
SimpleFeatureIterator fsi = features.features();
assertTrue(fsi.hasNext());
assertEquals(fsi.next().getID(), "active.12");
}
示例6: testNativeAggregation
import org.geotools.data.Query; //导入依赖的package包/类
@Test
public void testNativeAggregation() throws Exception {
init();
Map<String, String> vparams = new HashMap<String, String>();
Map<String,Object> query = ImmutableMap.of("agg", ImmutableMap.of("geohash_grid",
ImmutableMap.of("field", "geo", "precision", 3)));
vparams.put("a", mapper.writeValueAsString(query));
Hints hints = new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, vparams);
Query q = new Query(featureSource.getSchema().getTypeName());
q.setHints(hints);
ContentFeatureCollection features = featureSource.getFeatures(q);
assertFalse(features.isEmpty());
SimpleFeatureIterator fsi = features.features();
assertTrue(fsi.hasNext());
assertNotNull(fsi.next().getAttribute("_aggregation"));
}
示例7: testGetFeaturesWithQuery
import org.geotools.data.Query; //导入依赖的package包/类
@Test
public void testGetFeaturesWithQuery() throws Exception {
init();
FilterFactory ff = dataStore.getFilterFactory();
PropertyIsEqualTo filter = ff.equals(ff.property("modem_b"), ff.literal(true));
Query query = new Query();
query.setPropertyNames(new String[] { "standard_ss", "security_ss" });
query.setFilter(filter);
SimpleFeatureCollection features = featureSource.getFeatures(query);
assertEquals(8, features.size());
SimpleFeatureIterator iterator = features.features();
try {
assertTrue(iterator.hasNext());
SimpleFeature feature = iterator.next();
assertEquals(2, feature.getAttributeCount());
String st = (String) feature.getAttribute("standard_ss");
// changed from "IEEE 802.11b" in SolrFeatureSourceTest
assertTrue(st.contains("IEEE 802.11b"));
} finally {
iterator.close();
}
}
示例8: testOnlySourceFieldsWithSourceFiltering
import org.geotools.data.Query; //导入依赖的package包/类
@Test
public void testOnlySourceFieldsWithSourceFiltering() throws Exception {
init();
dataStore.setSourceFilteringEnabled(true);
Name name = new NameImpl("active");
for (final ElasticAttribute attribute : dataStore.getElasticAttributes(name) ){
if (attribute.isStored()) {
attribute.setUse(false);
}
}
featureSource = (ElasticFeatureSource) dataStore.getFeatureSource(TYPE_NAME);
assertEquals(11, featureSource.getCount(Query.ALL));
SimpleFeatureIterator features = featureSource.getFeatures().features();
for (int i=0; i<11; i++) {
assertTrue(features.hasNext());
features.next();
}
}
示例9: getReaderInternal
import org.geotools.data.Query; //导入依赖的package包/类
@Override
protected FeatureReader<SimpleFeatureType, SimpleFeature> getReaderInternal(Query query) throws IOException {
// build the actual SQL query for selecting features
String sql = buildSqlQuery(query);
System.out.println("QUERY: " + sql);
// get connection
Connection conn = getDataStore().getConnection();
// create the reader
FeatureReader<SimpleFeatureType, SimpleFeature> reader;
try {
reader = new SimpleMonetDBFeatureReader(sql, conn, this, getSchema(), query.getHints(), this.srid);
} catch (Throwable e) {
if (e instanceof Error) {
throw (Error) e;
} else {
throw (IOException) new IOException().initCause(e);
}
}
return reader;
}
示例10: selectColumns
import org.geotools.data.Query; //导入依赖的package包/类
void selectColumns(SimpleFeatureType featureType, String prefix, Query query, StringBuilder sql)
throws IOException {
//other columns
for (AttributeDescriptor att : featureType.getAttributeDescriptors()) {
String columnName = att.getLocalName();
if (att instanceof GeometryDescriptor) {
sql.append(columnName + "_x,");
sql.append(columnName + "_y");
} else {
sql.append(columnName);
}
sql.append(",");
}
}
示例11: getFeatures
import org.geotools.data.Query; //导入依赖的package包/类
private List<Object[]> getFeatures() throws Exception {
String layername = meta.getLayername();
Query q = new Query(layername);
FeatureSource<SimpleFeatureType, SimpleFeature> fs = ds
.getFeatureSource(layername);
SimpleFeatureType sft = fs.getSchema();
Filter f = buildFilter(sft);
if (f != null)
q.setFilter(f);
String maxFeatures = meta.getMaxFeatures();
if (!Const.isEmpty(maxFeatures))
q.setMaxFeatures(Integer.parseInt(maxFeatures));
String srs = meta.getSrs();
if (!Const.isEmpty(srs))
q.setCoordinateSystem(CRS.decode(srs));
return getRow(fs.getFeatures(q));
}
示例12: example3
import org.geotools.data.Query; //导入依赖的package包/类
private static void example3() throws IOException {
System.out.println("example3 start\n");
// example3 start
Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put("directory", directory);
DataStore datastore = DataStoreFinder.getDataStore(params);
Query query = new Query("example");
FeatureReader<SimpleFeatureType, SimpleFeature> reader = datastore
.getFeatureReader(query, Transaction.AUTO_COMMIT);
try {
int count = 0;
while (reader.hasNext()) {
SimpleFeature feature = reader.next();
System.out.println("feature " + count + ": " + feature.getID());
count++;
}
System.out.println("read in " + count + " features");
} finally {
reader.close();
}
// example3 end
System.out.println("\nexample3 end\n");
}
示例13: getBoundsInternal
import org.geotools.data.Query; //导入依赖的package包/类
/**
* Implementation that generates the total bounds
* (many file formats record this information in the header)
*/
protected ReferencedEnvelope getBoundsInternal(Query query) throws IOException {
ReferencedEnvelope bounds = new ReferencedEnvelope( getSchema().getCoordinateReferenceSystem() );
FeatureReader<SimpleFeatureType, SimpleFeature> featureReader = getReaderInternal(query);
try {
while( featureReader.hasNext() ){
SimpleFeature feature = featureReader.next();
bounds.include( feature.getBounds() );
}
}
finally {
featureReader.close();
}
return bounds;
}
示例14: getCountInternal
import org.geotools.data.Query; //导入依赖的package包/类
protected int getCountInternal(Query query) throws IOException {
CsvReader reader = getDataStore().read();
try {
boolean connect = reader.readHeaders();
if( connect == false ){
throw new IOException("Unable to connect");
}
int count = 0;
while( reader.readRecord() ){
count += 1;
}
return count;
}
finally {
reader.close();
}
}
示例15: getBBox
import org.geotools.data.Query; //导入依赖的package包/类
private Geometry getBBox(
final Query query,
final ReferencedEnvelope envelope ) {
if (envelope != null) {
return new GeometryFactory().toGeometry(envelope);
}
String geomAtrributeName = reader
.getComponents()
.getAdapter()
.getFeatureType()
.getGeometryDescriptor()
.getLocalName();
ExtractGeometryFilterVisitorResult geoAndCompareOp = ExtractGeometryFilterVisitor.getConstraints(
query.getFilter(),
GeometryUtils.DEFAULT_CRS,
geomAtrributeName);
if (geoAndCompareOp == null) {
return reader.clipIndexedBBOXConstraints(null);
}
else {
return reader.clipIndexedBBOXConstraints(geoAndCompareOp.getGeometry());
}
}