当前位置: 首页>>代码示例>>Java>>正文


Java Query类代码示例

本文整理汇总了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();
    }
}
 
开发者ID:geomesa,项目名称:geomesa-tutorials,代码行数:32,代码来源:QueryTutorial.java

示例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());
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:22,代码来源:GeoWaveFeatureReaderTest.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:24,代码来源:GeoWaveFeatureReaderTest.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:23,代码来源:GeoWaveFeatureReaderTest.java

示例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");
}
 
开发者ID:ngageoint,项目名称:elasticgeo,代码行数:19,代码来源:ElasticViewParametersFilterIT.java

示例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"));
}
 
开发者ID:ngageoint,项目名称:elasticgeo,代码行数:17,代码来源:ElasticViewParametersFilterIT.java

示例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();
    }
}
 
开发者ID:ngageoint,项目名称:elasticgeo,代码行数:26,代码来源:ElasticFeatureFilterIT.java

示例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();
    }
}
 
开发者ID:ngageoint,项目名称:elasticgeo,代码行数:21,代码来源:ElasticFeatureFilterIT.java

示例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;        
}
 
开发者ID:DennisPallett,项目名称:gt-jdbc-monetdb-simple,代码行数:25,代码来源:SimpleMonetDBFeatureSource.java

示例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(",");
    }
}
 
开发者ID:DennisPallett,项目名称:gt-jdbc-monetdb-simple,代码行数:18,代码来源:SimpleMonetDBFeatureSource.java

示例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));
}
 
开发者ID:icholy,项目名称:geokettle-2.0,代码行数:25,代码来源:WFSInput.java

示例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");
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:25,代码来源:PropertyExamples.java

示例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;
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:20,代码来源:CSVFeatureSource.java

示例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();
    }
}
 
开发者ID:ianturton,项目名称:geotools-cookbook,代码行数:18,代码来源:CSVFeatureSource.java

示例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());
	}
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:24,代码来源:GeoWaveFeatureCollection.java


注:本文中的org.geotools.data.Query类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。