本文整理汇总了Java中org.geotools.factory.CommonFactoryFinder.getFilterFactory2方法的典型用法代码示例。如果您正苦于以下问题:Java CommonFactoryFinder.getFilterFactory2方法的具体用法?Java CommonFactoryFinder.getFilterFactory2怎么用?Java CommonFactoryFinder.getFilterFactory2使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.geotools.factory.CommonFactoryFinder
的用法示例。
在下文中一共展示了CommonFactoryFinder.getFilterFactory2方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addDeleteNewFeature
import org.geotools.factory.CommonFactoryFinder; //导入方法依赖的package包/类
public static void addDeleteNewFeature(SimpleFeatureType sft, FeatureStore producerFS)
throws InterruptedException, IOException {
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(sft);
DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
final Random random = new Random();
String id = "1000";
builder.add("Antoninus"); // name
builder.add((int) Math.round(random.nextDouble()*110)); // age
builder.add(new Date()); // dtg
builder.add(WKTUtils$.MODULE$.read("POINT(-1 -1)")); // geom
SimpleFeature feature = builder.buildFeature(id);
featureCollection.add(feature);
producerFS.addFeatures(featureCollection);
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
Filter idFilter = ff.id(ff.featureId(id));
producerFS.removeFeatures(idFilter);
}
示例2: temporal
import org.geotools.factory.CommonFactoryFinder; //导入方法依赖的package包/类
void temporal() throws Exception {
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
// temporal start
// use the default implementations from gt-main
DateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Date date1 = FORMAT.parse("2001-07-05T12:08:56.235-0700");
Instant temporalInstant = new DefaultInstant(new DefaultPosition(date1));
// Simple check if property is after provided temporal instant
Filter after = ff.after(ff.property("date"), ff.literal(temporalInstant));
// can also check of property is within a certain period
Date date2 = FORMAT.parse("2001-07-04T12:08:56.235-0700");
Instant temporalInstant2 = new DefaultInstant(new DefaultPosition(date2));
Period period = new DefaultPeriod(temporalInstant, temporalInstant2);
Filter within = ff.toverlaps(ff.property("constructed_date"),
ff.literal(period));
// temporal end
}
示例3: caseSensitive
import org.geotools.factory.CommonFactoryFinder; //导入方法依赖的package包/类
void caseSensitive() throws Exception {
// caseSensitive start
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
// default is matchCase = true
Filter filter = ff.equal(ff.property("state"), ff.literal("queensland"));
// You can override this default with matchCase = false
filter = ff.equal(ff.property("state"), ff.literal("new south wales"),
false);
// All property comparisons allow you to control case sensitivity
Filter welcome = ff.greater(ff.property("zone"), ff.literal("danger"),
false);
// caseSensitive end
}
示例4: classiferExample
import org.geotools.factory.CommonFactoryFinder; //导入方法依赖的package包/类
public void classiferExample() {
SimpleFeatureCollection collection = null;
SimpleFeature feature = null;
// classiferExample start
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
Function classify = ff.function("Quantile", ff.property("name"), ff.literal(2));
Classifier groups = (Classifier) classify.evaluate(collection);
// classiferExample end
// classiferExample2 start
groups.setTitle(0, "Group A");
groups.setTitle(1, "Group B");
// classiferExample2 end
// classiferExample3 start
// groups is a classifier with "Group A" and "Group B"
Function sort = ff.function("classify", ff.property("name"), ff.literal(groups));
int slot = (Integer) sort.evaluate(feature);
System.out.println(groups.getTitle(slot)); // ie. "Group A"
// classiferExample3 end
}
示例5: grabFeaturesInBoundingBox
import org.geotools.factory.CommonFactoryFinder; //导入方法依赖的package包/类
/**
* What features on in this bounding Box?
*
* You can make a bounding box query as shown below:
*
* @param x1
* @param y1
* @param x2
* @param y2
* @return
* @throws Exception
*/
// grabFeaturesInBoundingBox start
SimpleFeatureCollection grabFeaturesInBoundingBox(double x1, double y1, double x2, double y2)
throws Exception {
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
FeatureType schema = featureSource.getSchema();
// usually "THE_GEOM" for shapefiles
String geometryPropertyName = schema.getGeometryDescriptor().getLocalName();
CoordinateReferenceSystem targetCRS = schema.getGeometryDescriptor()
.getCoordinateReferenceSystem();
ReferencedEnvelope bbox = new ReferencedEnvelope(x1, y1, x2, y2, targetCRS);
Filter filter = ff.bbox(ff.property(geometryPropertyName), bbox);
return featureSource.getFeatures(filter);
}
示例6: click1
import org.geotools.factory.CommonFactoryFinder; //导入方法依赖的package包/类
SimpleFeatureCollection click1(MapMouseEvent ev) throws Exception {
// Construct a 3x3 pixel rectangle centred on the mouse click position
java.awt.Point screenPos = ev.getPoint();
Rectangle screenRect = new Rectangle(screenPos.x - 1, screenPos.y - 1, 3, 3);
CoordinateReferenceSystem worldCRS = mapFrame.getMapContent().getCoordinateReferenceSystem();
// Transform the screen rectangle into a bounding box in the
// coordinate reference system of our map content.
AffineTransform screenToWorld = mapFrame.getMapPane().getScreenToWorldTransform();
Rectangle2D worldRect = screenToWorld.createTransformedShape(screenRect).getBounds2D();
ReferencedEnvelope worldBBox = new ReferencedEnvelope(worldRect, worldCRS);
// transform from world to target CRS
SimpleFeatureType schema = featureSource.getSchema();
CoordinateReferenceSystem targetCRS = schema.getCoordinateReferenceSystem();
String geometryAttributeName = schema.getGeometryDescriptor().getLocalName();
ReferencedEnvelope bbox = worldBBox.transform(targetCRS, true, 10);
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
// Option 1 BBOX
Filter filter = ff.bbox(ff.property(geometryAttributeName), bbox);
// Option 2 Intersects
// Filter filter = ff.intersects(ff.property(geometryAttributeName), ff.literal(bbox));
return featureSource.getFeatures(filter);
}
示例7: setup
import org.geotools.factory.CommonFactoryFinder; //导入方法依赖的package包/类
@Override
public void setup(
final Configuration configuration,
final List<ColumnInterface> columnList) throws IOException
{
final URL url = getUrl(configuration);
final ShapefileDataStoreFactory fac = new ShapefileDataStoreFactory();
final Map params = new HashMap();
params.put(ShapefileDataStoreFactory.URLP.key, url);
params.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key, Boolean.TRUE);
params.put(ShapefileDataStoreFactory.ENABLE_SPATIAL_INDEX, Boolean.TRUE);
params.put(ShapefileDataStoreFactory.MEMORY_MAPPED, Boolean.TRUE);
m_dataStore = fac.createDataStore(params);
final String[] typeNames = m_dataStore.getTypeNames();
m_featureSource = m_dataStore.getFeatureSource(typeNames[0]);
m_geometryName = m_featureSource.getSchema().getGeometryDescriptor().getLocalName();
m_filterFactory = CommonFactoryFinder.getFilterFactory2(null);
m_progressListener = new NullProgressListener();
m_buffer = configuration.getFloat(GeoEnrichmentJob.KEY_BUFFER, 0.000001F);
}
示例8: openInputShapefile
import org.geotools.factory.CommonFactoryFinder; //导入方法依赖的package包/类
/**
* Open the input shape file and load it into memory.
*/
public void openInputShapefile(String inputShapefile) throws IOException {
File file = new File(inputShapefile);
ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();
Map<String, Serializable> params = new HashMap<>();
params.put(ShapefileDataStoreFactory.URLP.key, file.toURI().toURL());
params.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key, Boolean.TRUE);
params.put(ShapefileDataStoreFactory.ENABLE_SPATIAL_INDEX.key, Boolean.TRUE);
params.put(ShapefileDataStoreFactory.MEMORY_MAPPED.key, Boolean.TRUE);
params.put(ShapefileDataStoreFactory.CACHE_MEMORY_MAPS.key, Boolean.TRUE);
ShapefileDataStore store = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
featureSource = store.getFeatureSource();
// determine the correct case of the tz attribute because its case has been
// changed from efele to evansiroky
SimpleFeatureType schema = featureSource.getSchema();
List<AttributeDescriptor> attributeDescriptorList = schema.getAttributeDescriptors();
for (AttributeDescriptor attributeDescriptor : attributeDescriptorList) {
if ("tzid".equalsIgnoreCase(attributeDescriptor.getLocalName())) {
tzidAttr = attributeDescriptor.getLocalName();
}
}
filterFactory = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
geometryFactory = JTSFactoryFinder.getGeometryFactory();
}
示例9: joinFeaures
import org.geotools.factory.CommonFactoryFinder; //导入方法依赖的package包/类
/**
*
* @param shapes
* @param shapes2
* @throws Exception
*/
private static SimpleFeatureCollection joinFeaures(SimpleFeatureSource shapes, SimpleFeatureSource shapes2) throws Exception {
SimpleFeatureCollection join =null;
SimpleFeatureType schema = shapes.getSchema();
String typeName = schema.getTypeName();
String geomName = schema.getGeometryDescriptor().getLocalName();
SimpleFeatureType schema2 = shapes2.getSchema();
String typeName2 = schema2.getTypeName();
String geomName2 = schema2.getGeometryDescriptor().getLocalName();
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
Query outerGeometry = new Query(typeName, Filter.INCLUDE, new String[] { geomName });
SimpleFeatureCollection outerFeatures = shapes.getFeatures(outerGeometry);
SimpleFeatureIterator iterator = outerFeatures.features();
int max = 0;
try {
while (iterator.hasNext()) {
SimpleFeature feature = iterator.next();
try {
Geometry geometry = (Geometry) feature.getDefaultGeometry();
if (!geometry.isValid()) {
// skip bad data
continue;
}
Filter innerFilter = ff.intersects(ff.property(geomName2), ff.literal(geometry));
Query innerQuery = new Query(typeName2, innerFilter, Query.NO_NAMES);
join = shapes2.getFeatures(innerQuery);
int size = join.size();
max = Math.max(max, size);
} catch (Exception skipBadData) {
}
}
} finally {
iterator.close();
}
return join;
}
示例10: secondaryIndexExample
import org.geotools.factory.CommonFactoryFinder; //导入方法依赖的package包/类
static void secondaryIndexExample(String simpleFeatureTypeName,
DataStore dataStore,
String[] attributeFields,
String attributesQuery,
int maxFeatures,
String sortByField)
throws CQLException, IOException {
// construct a (E)CQL filter from the search parameters,
// and use that as the basis for the query
Filter cqlFilter = CQL.toFilter(attributesQuery);
Query query = new Query(simpleFeatureTypeName, cqlFilter);
query.setPropertyNames(attributeFields);
query.setMaxFeatures(maxFeatures);
if (!sortByField.equals("")) {
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
SortBy[] sort = new SortBy[]{ff.sort(sortByField, SortOrder.DESCENDING)};
query.setSortBy(sort);
}
// submit the query, and get back an iterator over matching features
FeatureSource featureSource = dataStore.getFeatureSource(simpleFeatureTypeName);
FeatureIterator featureItr = featureSource.getFeatures(query).features();
// loop through all results
int n = 0;
while (featureItr.hasNext()) {
Feature feature = featureItr.next();
StringBuilder sb = new StringBuilder();
sb.append("Feature ID ").append(feature.getIdentifier());
for (String field : attributeFields) {
sb.append(" | ").append(field).append(": ").append(feature.getProperty(field).getValue());
}
System.out.println(sb.toString());
}
featureItr.close();
}
示例11: createBaseFilter
import org.geotools.factory.CommonFactoryFinder; //导入方法依赖的package包/类
/**
* Creates a base filter that will return a small subset of our results. This can be tweaked to
* return different results if desired. Currently it should return 16 results.
*
* @return
*
* @throws org.geotools.filter.text.cql2.CQLException
* @throws java.io.IOException
*/
static Filter createBaseFilter()
throws CQLException, IOException {
// Get a FilterFactory2 to build up our query
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
// We are going to query for events in Ukraine during the
// civil unrest.
// We'll start by looking at a particular time frame
Filter timeFilter =
ff.between(ff.property(Attributes.SQLDATE.getName()),
ff.literal("2013-01-01T05:00:00.000Z"),
ff.literal("2014-04-30T23:00:00.000Z"));
// We'll bound our query spatially to Ukraine
Filter spatialFilter =
ff.bbox(Attributes.geom.getName(),
31.6, 44, 37.4, 47.75,
"EPSG:4326");
// we'll also restrict our query to only articles about the US, UK or UN
Filter attributeFilter = ff.like(ff.property(Attributes.Actor1Name.getName()), "UNITED%");
// Now we can combine our filters using a boolean AND operator
Filter conjunction = ff.and(Arrays.asList(timeFilter, spatialFilter, attributeFilter));
return conjunction;
}
示例12: secondaryIndexExample
import org.geotools.factory.CommonFactoryFinder; //导入方法依赖的package包/类
static void secondaryIndexExample(String simpleFeatureTypeName,
DataStore dataStore,
String[] attributeFields,
String attributesQuery,
int maxFeatures,
String sortByField)
throws CQLException, IOException {
// construct a (E)CQL filter from the search parameters,
// and use that as the basis for the query
Filter cqlFilter = CQL.toFilter(attributesQuery);
Query query = new Query(simpleFeatureTypeName, cqlFilter);
query.setPropertyNames(attributeFields);
query.setMaxFeatures(maxFeatures);
if (!sortByField.equals("")) {
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
SortBy[] sort = new SortBy[]{ff.sort(sortByField, SortOrder.DESCENDING)};
query.setSortBy(sort);
}
// submit the query, and get back an iterator over matching features
FeatureSource featureSource = dataStore.getFeatureSource(simpleFeatureTypeName);
FeatureIterator featureItr = featureSource.getFeatures(query).features();
// loop through all results
while (featureItr.hasNext()) {
Feature feature = featureItr.next();
StringBuilder sb = new StringBuilder();
sb.append("Feature ID ").append(feature.getIdentifier());
for (String field : attributeFields) {
sb.append(" | ").append(field).append(": ").append(feature.getProperty(field).getValue());
}
System.out.println(sb.toString());
}
featureItr.close();
}
示例13: ffExample
import org.geotools.factory.CommonFactoryFinder; //导入方法依赖的package包/类
public void ffExample() {
// start ff example
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
Filter filter;
// the most common selection criteria is a simple equal test
ff.equal(ff.property("land_use"), ff.literal("URBAN"));
// You can also quickly test if a property has a value
filter = ff.isNull(ff.property("approved"));
// The usual array of property comparisons is supported
// the comparison is based on the kind of data so both
// numeric, date and string comparisons are supported.
filter = ff.less(ff.property("depth"), ff.literal(300));
filter = ff.lessOrEqual(ff.property("risk"), ff.literal(3.7));
filter = ff.greater(ff.property("name"), ff.literal("Smith"));
filter = ff.greaterOrEqual(ff.property("schedule"), ff.literal(new Date()));
// PropertyIsBetween is a short inclusive test between two values
filter = ff.between(ff.property("age"), ff.literal(20), ff.literal("29"));
filter = ff.between(ff.property("group"), ff.literal("A"), ff.literal("D"));
// In a similar fashion there is a short cut for notEqual
filter = ff.notEqual(ff.property("type"), ff.literal("draft"));
// pattern based "like" filter
filter = ff.like(ff.property("code"), "2300%");
// you can customise the wildcard characters used
filter = ff.like(ff.property("code"), "2300?", "*", "?", "\\");
// end ff example
}
示例14: example3
import org.geotools.factory.CommonFactoryFinder; //导入方法依赖的package包/类
public static void example3() {
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
tb.setName("featureType");
tb.add("geometry", Point.class);
tb.add("integer", Integer.class);
GeometryFactory gf = new GeometryFactory();
SimpleFeatureBuilder b = new SimpleFeatureBuilder(tb.buildFeatureType());
DefaultFeatureCollection features = new DefaultFeatureCollection(null, b.getFeatureType());
for (int i = 0; i < 2; i++) {
b.add(gf.createPoint(new Coordinate(i, i)));
b.add(i);
features.add(b.buildFeature(i + ""));
}
Map<String, Object> input = new HashMap();
input.put(BufferFeatureCollectionFactory.FEATURES.key, features);
input.put(BufferFeatureCollectionFactory.BUFFER.key, 10d);
BufferFeatureCollectionFactory factory = new BufferFeatureCollectionFactory();
BufferFeatureCollectionProcess process = factory.create();
Map<String, Object> output = process.execute(input, null);
FeatureCollection buffered = (FeatureCollection) output
.get(BufferFeatureCollectionFactory.RESULT.key);
assertEquals(2, buffered.size());
for (int i = 0; i < 2; i++) {
Geometry expected = gf.createPoint(new Coordinate(i, i)).buffer(10d);
FeatureCollection sub = buffered.subCollection(ff.equals(ff.property("integer"),
ff.literal(i)));
assertEquals(1, sub.size());
FeatureIterator iterator = sub.features();
SimpleFeature sf = (SimpleFeature) iterator.next();
assertTrue(expected.equals((Geometry) sf.getDefaultGeometry()));
iterator.close();
}
}
示例15: id
import org.geotools.factory.CommonFactoryFinder; //导入方法依赖的package包/类
public void id(){
// id start
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
Filter filter;
filter = ff.id(ff.featureId("CITY.98734597823459687235"),
ff.featureId("CITY.98734592345235823474"));
// id end
}