[Geoserver-users] WFS + Mysql: Problems getting features by FID

Hi,

Look at this method, please. Do you know if are there any bugs related
to Geoserver 1.7.5, WFS 1.0.0 and MySQL Data Store? Although identifiers
exist in the DB, this kind of request always return an empty feature
collection. I haven't found open issues about fid filters.

    public static FeatureCollection getFeaturesByFID(String id, String
layer)
    {
        FeatureCollection feats = null;
        FilterFactory2 filterFactory = null;
        DefaultQuery query = null;
        String nameSpace = null;
        FeatureSource featSource = null;
        Set<FeatureId> fids = null;
        FeatureId fid = null;
        Filter filter = null;
       
        nameSpace = geoServerConfig.getNameSpace();
        query = new DefaultQuery(nameSpace + layer);
       
        try {
            featSource = getFeatureSource(layer);
            filterFactory =
CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
            fids = new HashSet<FeatureId>();*
            fid = filterFactory.featureId(id);
            fids.add(fid);
            filter = filterFactory.id(fids);
            feats = featSource.getFeatures(filter);*
        }
        catch (Exception e) {
            logger.error(":frowning: Error!",e);
        }
       
        return feats;
    }

Thanks,
Antonio

You mentioned the table has identifiers, does it have a primary key defined on it. Also it is possible for you to turn up logging in geoserver (change it to GEOTOOLS_DEVELOPER_LOGGING) to see what query being sent to the database.

Thanks,

-Justin

Antonio Redondo Lora wrote:

Hi,

Look at this method, please. Do you know if are there any bugs related
to Geoserver 1.7.5, WFS 1.0.0 and MySQL Data Store? Although identifiers
exist in the DB, this kind of request always return an empty feature
collection. I haven't found open issues about fid filters.

    public static FeatureCollection getFeaturesByFID(String id, String
layer)
    {
        FeatureCollection feats = null;
        FilterFactory2 filterFactory = null;
        DefaultQuery query = null;
        String nameSpace = null;
        FeatureSource featSource = null;
        Set<FeatureId> fids = null;
        FeatureId fid = null;
        Filter filter = null;
               nameSpace = geoServerConfig.getNameSpace(); query = new DefaultQuery(nameSpace + layer);
               try { featSource = getFeatureSource(layer); filterFactory =
CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
            fids = new HashSet<FeatureId>();* fid = filterFactory.featureId(id);
            fids.add(fid); filter = filterFactory.id(fids);
            feats = featSource.getFeatures(filter);* }
        catch (Exception e) {
            logger.error(":frowning: Error!",e); }
               return feats;
    }

Thanks,
Antonio

------------------------------------------------------------------------------
_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

The table has FID like identifier and primary key:

CREATE TABLE PG_RECURSOS
(
    FID NUMERIC(11) NOT NULL,
    GEOM GEOMETRY NOT NULL,
    TX_NAME TEXT NOT NULL,
    PRIMARY KEY (FID),
    SPATIAL INDEX(GEOM)
);

I think the query you mean (for fid=30) is the next one ....

01 jul 09:57:31 INFO [geoserver.wfs] -
Request: getFeature
        handle = null
        service = WFS
        version = 1.0.0
        baseUrl = http://10.239.216.169:8080/geoserver/
        providedVersion = 1.0.0
        query = [net.opengis.wfs.impl.QueryTypeImpl@anonymised.com (group:
null, propertyName: null, function: null, filter: [ 30 ], sortBy: null,
featureVersion: null, handle: null, srsName: null, typeName: [PG_RECURSOS])]
        maxFeatures = null
        outputFormat = GML2
        resultType = results
        traverseXlinkDepth = null
        traverseXlinkExpiry = null
        formatOptions = {}

Howevwe, it finds features if we use queries and generic filters like
"TX_NAME='r1'" (but TX_NAME isn't an unique field)

Thanks, again

Justin Deoliveira escribió:

You mentioned the table has identifiers, does it have a primary key
defined on it. Also it is possible for you to turn up logging in
geoserver (change it to GEOTOOLS_DEVELOPER_LOGGING) to see what query
being sent to the database.

Thanks,

-Justin

Antonio Redondo Lora wrote:

Hi,

Look at this method, please. Do you know if are there any bugs related
to Geoserver 1.7.5, WFS 1.0.0 and MySQL Data Store? Although identifiers
exist in the DB, this kind of request always return an empty feature
collection. I haven't found open issues about fid filters.

    public static FeatureCollection getFeaturesByFID(String id, String
layer)
    {
        FeatureCollection feats = null;
        FilterFactory2 filterFactory = null;
        DefaultQuery query = null;
        String nameSpace = null;
        FeatureSource featSource = null;
        Set<FeatureId> fids = null;
        FeatureId fid = null;
        Filter filter = null;
               nameSpace = geoServerConfig.getNameSpace();
        query = new DefaultQuery(nameSpace + layer);
               try { featSource =
getFeatureSource(layer); filterFactory =
CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints());
            fids = new HashSet<FeatureId>();* fid =
filterFactory.featureId(id);
            fids.add(fid); filter =
filterFactory.id(fids);
            feats = featSource.getFeatures(filter);* }
        catch (Exception e) {
            logger.error(":frowning: Error!",e); }
               return feats;
    }

Thanks,
Antonio

------------------------------------------------------------------------------

_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

Antonio Redondo Lora ha scritto:

The table has FID like identifier and primary key:

CREATE TABLE PG_RECURSOS
(
    FID NUMERIC(11) NOT NULL,
    GEOM GEOMETRY NOT NULL,
    TX_NAME TEXT NOT NULL, PRIMARY KEY (FID),
    SPATIAL INDEX(GEOM)
);

I think the query you mean (for fid=30) is the next one ....

01 jul 09:57:31 INFO [geoserver.wfs] -
Request: getFeature
        handle = null
        service = WFS
        version = 1.0.0
        baseUrl = http://10.239.216.169:8080/geoserver/
        providedVersion = 1.0.0
        query = [net.opengis.wfs.impl.QueryTypeImpl@anonymised.com (group:
null, propertyName: null, function: null, filter: [ 30 ], sortBy: null,
featureVersion: null, handle: null, srsName: null, typeName: [PG_RECURSOS])]
        maxFeatures = null
        outputFormat = GML2
        resultType = results
        traverseXlinkDepth = null
        traverseXlinkExpiry = null
        formatOptions = {}

fid = 30? That's not the format GeoServer generates fid with.
It should look something like "pg_recursos.30" instead.
Run a GetFeature against your table and see how GeoServer generates
the fids, then mimick it. Usually the structure is "typeName.pk"

Cheers
Andrea

--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.

Thanks Andrea, you're right, it's works in this way.

Of course, we know Geoserver uses this kind of features identifiers.
However, we were confused because, in the DB table, we have "30" stored
as identifier instead of "pg_recursos.30". It works with composed fids
(layer name + integer identifier) before making wfs addFeatures, for
example, but inserts simple identifiers on DB. We have thought it would
compose the primary key before doing selects too.

Andrea Aime escribió:

Antonio Redondo Lora ha scritto:

The table has FID like identifier and primary key:

CREATE TABLE PG_RECURSOS
(
    FID NUMERIC(11) NOT NULL,
    GEOM GEOMETRY NOT NULL,
    TX_NAME TEXT NOT NULL, PRIMARY KEY (FID),
    SPATIAL INDEX(GEOM)
);

I think the query you mean (for fid=30) is the next one ....

01 jul 09:57:31 INFO [geoserver.wfs] -
Request: getFeature
        handle = null
        service = WFS
        version = 1.0.0
        baseUrl = http://10.239.216.169:8080/geoserver/
        providedVersion = 1.0.0
        query = [net.opengis.wfs.impl.QueryTypeImpl@anonymised.com (group:
null, propertyName: null, function: null, filter: [ 30 ], sortBy: null,
featureVersion: null, handle: null, srsName: null, typeName:
[PG_RECURSOS])]
        maxFeatures = null
        outputFormat = GML2
        resultType = results
        traverseXlinkDepth = null
        traverseXlinkExpiry = null
        formatOptions = {}

fid = 30? That's not the format GeoServer generates fid with.
It should look something like "pg_recursos.30" instead.
Run a GetFeature against your table and see how GeoServer generates
the fids, then mimick it. Usually the structure is "typeName.pk"

Cheers
Andrea