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: [email protected] [mailto:[email protected]] On Behalf Of
Andrea Aime
Sent: Thursday, August 29, 2013 11:07 AM
To: Bessette-Halsema, Dominique E
Cc: [email protected]
Subject: Re: [Geoserver-users] getFeature within geoserver
On Thu, Aug 29, 2013 at 7:27 PM, Bessette-Halsema, Dominique E
<[email protected]> 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
<https://localhost:8443/geoserver/gis/ows?service=WFS&version=1.0.0&request=
GetFeature&typeName=gis:simpleafeature&featureId=43601>
&version=1.0.0&request=GetFeature&typeName=gis:simpleafeature&featureId=4360
1 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(<theLayerName>);
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
-------------------------------------------------------
smime.p7s
Description: S/MIME cryptographic signature
------------------------------------------------------------------------------ Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! Discover the easy way to master current and previous Microsoft technologies and advance your career. Get an incredible 1,500+ hours of step-by-step tutorial videos with LearnDevNow. Subscribe today and save! http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________ Geoserver-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geoserver-users
