Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Code Block
// 1. Configure:
String getCapabilitiesURL = "http://servicesnvclwebservices.auscopevm.orgcsiro.au/geodesygeoserverBH/wfs?REQUEST=GetCapabilities";
Map<String, Serializable> connectionParameters = new HashMap<String, Serializable>();
connectionParameters.put("WFSDataStoreFactory:WFS_GET_CAPABILITIES_URL", getCapabilitiesURL);
connectionParameters.put("WFSDataStoreFactory:TIMEOUT", 0);
connectionParameters.put("WFSDataStoreFactory:PROTOCOL", false);
// Prefer GET over POST.
/** #A: Require a Factory with this level of compliance. **/
connectionParameters.put("WFSDataStoreFactory:GML_COMPLIANCE_LEVEL", 2);
connectionParameters.put("WFSDataStoreFactory:MAXFEATURES", 2);
/** #B: Specify the location of the folder to be used by app-schema-resolver. **/
connectionParameters.put("WFSDataStoreFactory:SCHEMA_CACHE_LOCATION", "C:/Adam'sAdams/GitHub_GeoTools_Branch-wfs_ngGeoTools/schema_cache");

// 2. Find suitable DataAccess:
/** #C: Notice that these classes are the non-Simple forms. **/
DataAccess<FeatureType, Feature> dataAccess = DataAccessFinder.getDataStore(connectionParameters);

// 3. Declare the typeNametype you're interested in (this could be done by iterating through the typeNames in dataAccessdataStore.getNamesgetTypeNames()):.
Name typeNamenameToRetrieve = new NameImpl("urn:cgi:xmlns:GGICCGI:EarthResourceGeoSciML:1.12.0", ":", "MineBorehole");

// 4. Get the FeatureSource (WFSContentComplexFeatureSource):
FeatureSource<FeatureType, Feature> featureSource = dataAccess.getFeatureSource(typeNamenameToRetrieve);

// 5. Get the FeatureType (AKA schema):
FeatureType schema = dataAccess.getSchema(typeNamenameToRetrieve);

// 6. Create a Query Stringusing geomNamethe = schema.getGeometryDescriptor().getLocalName();
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
Object polygon = JTS.toGeometry(new Envelope(-30, -32, 115, 116)); 
Intersects filter = ff.intersects(ff.property(geomName), ff.literal(polygon));
// MineName could have been extracted from schema.getDescriptors(), see note on 3, above.
Query query = new Query(typeName.toString(), filter, new String[] { "MineName", geomName }"gsml:Borehole");
query.setCoordinateSystem(schema.getGeometryDescriptor().getCoordinateReferenceSystem());

// 7. Get the features and their corresponding types:
FeatureCollection<FeatureType, Feature> features = featureSource.getFeatures(query);

// 8. Iterate over andthe interactfeatures withand thedisplay itemsthem:
FeatureIterator<Feature> iterator = features.features();

try {
    while (iterator.hasNext()) {
        Feature feature = (Feature) iterator.next();
        
        for (Property property : feature.getProperties()) {
            System.out.println(property);
        }
    }
} finally {
    iterator.close();
}

...