Hi everyone,
Thank you Ian for your reply.
I've tried your solution but does not work for me :/
I've removed the prefix from the type name like shown in the code below
(the type name in my case is prefixed using underscore
) :
String typeNames[] = data.getTypeNames();
String typeName = typeNames[0];
FeatureSource<SimpleFeatureType, SimpleFeature> source =
data.getFeatureSource( typeName ); // here I keep the type name as returned
by the datastore
// because if I put the substring instruction before that I get an
error saying the type name does not exist !
typeName=typeName.substring(typeName.indexOf("_")+1);
Query query = new DefaultQuery( typeName );
query.setCoordinateSystem(DefaultGeographicCRS.WGS84);
FeatureCollection<SimpleFeatureType, SimpleFeature> features =
source.getFeatures( query );
FeatureIterator<SimpleFeature> fi=features.features();
try {
while( fi.hasNext() )
{
Feature feature = (Feature) fi.next();
// ....
}
}catch (Exception e)
{
e.printStackTrace();
}
I've tried another way to do that specifying explicitly the type name
parameters in the query. I did it like that :
FeatureSource<SimpleFeatureType, SimpleFeature> source =
data.getFeatureSource( typeName );
Query query = new DefaultQuery( typeName );
query.setAlias("ms");
query.setNamespace(new URI("http://mapserver.gis.umn.edu/mapserver"));
query.setCoordinateSystem(DefaultGeographicCRS.WGS84);
FeatureCollection<SimpleFeatureType, SimpleFeature> features =
source.getFeatures( query );
FeatureIterator<SimpleFeature> fi=features.features();
Unfortunately I am still not able to get my features!!
Any further help would be appreciated :)
Thank you,
Hanane
2016-08-31 10:07 GMT+02:00 Ian Turton <[email protected]>:
> After some fiddling about I can get features if I remove the wfs: prefix
> from the typename
>
> String name = types[i].substring(types[i].indexOf(':')+1);
>
> and add a coordinate system to the query object (not sure if this is
> essential or not)
>
> query.setCoordinateSystem(DefaultGeographicCRS.WGS84);
>
> Ian
>
> On 30 August 2016 at 17:38, Hanane Eljabiri <[email protected]>
> wrote:
>
>> Hi everyone,
>>
>> I am using the wfs-ng plugin to ceate a wfs client. Until now, the
>> library works pretty fine when it comes to establish a connection with a
>> Geoserver WFS. When it comes to a Mapserver WFS, my program fails to get
>> features. In fact, the feature collection I get from the source seems to be
>> empty.
>>
>> I provide below the code I am using with an example of a WFS URL.
>>
>> String getCapabilities = "http://ws.carmencarto.fr/WFS/
>> 119/fxx_grille?service=wfs&REQUEST=GetCapabilities&version=1.1.0";
>>
>>
>>
>> *Map* connectionParameters = *new* *HashMap*();
>>
>> *connectionParameters**.put(*
>> *"WFSDataStoreFactory:GET_CAPABILITIES_URL"**, **getCapabilities** )*;
>>
>> *connectionParameters**.put(*
>> *"WFSDataStoreFactory:WFS_STRATEGY"**, **"mapserver"**)*;
>>
>> *connectionParameters**.put(*
>> *"WFSDataStoreFactory:WFSDataStoreFactory:TIMEOUT"**,10000000)*;
>>
>>
>>
>> // Step 2 - connection
>>
>> DataStore data = DataStoreFinder.*getDataStore*(
>> connectionParameters );
>>
>>
>>
>> // Step 3 - *discouvery*
>>
>> String typeNames[] = data.getTypeNames();
>>
>> String typeName = typeNames[0];
>>
>> // Step 4 - target
>>
>> FeatureSource<SimpleFeatureType, SimpleFeature> source =
>> data.getFeatureSource( typeName );
>>
>>
>>
>>
>>
>> Query query = *new* *DefaultQuery**( **typeName** )*;
>>
>> FeatureCollection<SimpleFeatureType, SimpleFeature> features
>> = source.getFeatures( query );
>>
>> FeatureIterator<SimpleFeature> fi=features.features();
>>
>>
>>
>> *try* {
>>
>> *while*( fi.hasNext() )
>>
>> { //the following code is never executed because the
>> iterator is has
>>
>> // no next element !
>>
>> Feature feature = (Feature) fi.next();
>>
>> //do some stuff using the featureā¦
>>
>> }
>>
>> }*catch* (Exception e)
>>
>> {
>>
>> e.printStackTrace();
>>
>> }
>>
>> Did I miss something in the configuration?
>>
>> I would be thankful if someone could help me to understand why I could
>> not get features from this WFS.
>>
>> Best regards
>>
>> --
>>
>> Hanane
>>
>>
>> ------------------------------------------------------------
>> ------------------
>>
>> _______________________________________________
>> GeoTools-GT2-Users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>>
>>
>
>
> --
> Ian Turton
>
------------------------------------------------------------------------------
_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users