package foo.bar;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.geotools.data.DataStore;
import org.geotools.data.DefaultQuery;
import org.geotools.data.FeatureSource;
import org.geotools.data.Query;
import org.geotools.data.wfs.WFSDataStoreFactory;
import org.geotools.data.wfs.protocol.wfs.Version;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.factory.GeoTools;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.opengis.feature.Feature;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.filter.Filter;
import org.opengis.filter.FilterFactory;
public class WFSClient
{
private DataStore wfs;
public WFSClient( URL endPointUrl )
{
final WFSDataStoreFactory wfsDataStoreFactory = new WFSDataStoreFactory();
final Map params = new HashMap();
params.put( WFSDataStoreFactory.URL.key,
WFSDataStoreFactory.createGetCapabilitiesRequest( endPointUrl, Version.v1_1_0 ) );
try
{
this.wfs = wfsDataStoreFactory.createDataStore( params );
}
catch ( IOException e )
{
e.printStackTrace();
}
}
public void getFoo( String propertyId ) throws IOException
{
final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory( GeoTools.getDefaultHints() );
final Filter filter = filterFactory.equal( filterFactory.property( "ktjkiiwfs:kiinteistotunnus" ),
filterFactory.literal( propertyId ), true );
final Query query = new DefaultQuery( "ktjkiiwfs:RekisteriyksikonTietoja", filter );
final FeatureSource<SimpleFeatureType, SimpleFeature> source = wfs.getFeatureSource( "ktjkiiwfs:RekisteriyksikonTietoja" );
final FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = source.getFeatures( query );
final FeatureIterator<SimpleFeature> iterator = featureCollection.features();
try
{
while ( iterator.hasNext() )
{
Feature feature = iterator.next();
System.out.println( feature );
}
}
finally
{
iterator.close();
}
}
}
...
WFSClient client = new WFSClient(new URL("http:));
client.getFoo("21442500160044");