That worked thanks!
public static SimpleFeature GetFeature(String featurename, String namespace, String fid){
SimpleFeature feature = null;
GeoServer geoServer = GeoServerExtensions.bean(GeoServer.class);
DefaultWebFeatureService20 wfs = new DefaultWebFeatureService20(geoServer);
Catalog catalog = wfs.getCatalog();
FeatureTypeInfo info = catalog.getFeatureTypeByName(namespace, featurename);
try{
SimpleFeatureSource fs = (SimpleFeatureSource) info.getFeatureSource(null, null);
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
Id id = ff.id(Collections.singleton(ff.featureId(fid)));
SimpleFeatureCollection coll = fs.getFeatures(id);
SimpleFeatureIterator fi = null;
try {
fi = coll.features();
feature = fi.next();
} finally {
fi.close();
}
}
catch(Exception e){
LOGGER.info(e.getMessage());
}
return feature;
}
Dominique Bessette
Engineer, Software
General Dynamics Information Technology
Supporting Fleet Numerical Meteorology and Oceanography Center (FNMOC)
Office: 619-881-2748
From: andrea.aime@anonymised.com [mailto:andrea.aime@anonymised.com] On Behalf Of Andrea Aime
Sent: Thursday, August 29, 2013 11:07 AM
To: Bessette-Halsema, Dominique E
Cc: geoserver-users@anonymised.coms.sourceforge.net
Subject: Re: [Geoserver-users] getFeature within geoserver
On Thu, Aug 29, 2013 at 7:27 PM, Bessette-Halsema, Dominique E <Dominique.Bessette@anonymised.com> wrote:
I’m creating a wps and I was wondering how I get a feature by a featureid within geoserver…
I would like https://localhost:8443/geoserver/gis/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=gis:simpleafeature&featureId=43601 but using the geoserver classes.
public static void GetFeature(String name, String namespace, String fid){
GeoServer geoServer = GeoServerExtensions.bean(GeoServer.class);
DefaultWebFeatureService20 wfs = new DefaultWebFeatureService20(geoServer);
WFSInfo wfsinfo = wfs.getServiceInfo();
Catalog catalog = wfs.getCatalog();
FeatureTypeInfo featuretype = catalog.getFeatureTypeByName(namespace, name);
//now what
}
You’re going too much the long way. Get the Catalog bean, then do something like
(almost pseudo code, totally untested):
FeatureTypeInfo info = catalog.getFeatureTypeByName();
SimpleFeatureSource fs = info.getFeatureSource();
FilterFactory ff = CommonFActoryFinder.getFilterFactory();
SimpleFeatureCollect coll = fs.getFeatures(ff.id(ff.featureId(<yourId));
SimpleFeatureIterator fi = null;
SimpleFeature theFeature = null;
try {
fi = coll.features();
theFeature = fi.next();
} finally {
fi.close();
}
Hope this helps
Cheers
Andrea
–
==
Our support, Your Success! Visit http://opensdi.geo-solutions.it for more information.
==
Ing. Andrea Aime
@geowolf
Technical Lead
GeoSolutions S.A.S.
Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy
phone: +39 0584 962313
fax: +39 0584 1660272
mob: +39 339 8844549
http://www.geo-solutions.it
http://twitter.com/geosolutions_it