After I changed the test code(remove the attributes filter from the cql):

Filter filter = CQL.toFilter("BBOX(" +
sfs.getSchema().getGeometryDescriptor().getLocalName() + ",
20,30,21,31)");

Then I got the output:

POLYGON ((20 20, 21 30, .....))
Filter.INCLUDE
null

So I think the point is that: OGRFilterTranslator can not extract the
geometry filter from an And filter.

And this is part of OGRFilterTranslator code:

class OGRFilterTranslator {
    static final FilterCapabilities GEOMETRY_FILTER_CAPABILITIES;

    static {
        // attribute filters, these we can encode fully
        ATTRIBUTE_FILTER_CAPABILITIES = new FilterCapabilities();
        ATTRIBUTE_FILTER_CAPABILITIES.addType(PropertyIsBetween.class);
        .....
        ATTRIBUTE_FILTER_CAPABILITIES.addType(Or.class);
        ATTRIBUTE_FILTER_CAPABILITIES.addType(And.class);
.....
}

As shown, And.class is marked as an attribute filter, but obviously it’s
not. It can contain both geometry and attribute filters at the same time.
So does the Or filter.

So any idea to fix that?

On Tue, Oct 13, 2020 at 5:06 PM maven apache <apachemav...@gmail.com> wrote:

> But the `org.gdal.ogr.Layer` provides the spatial method
> `SetSpatialFilter`, if the bbox filter is translated, then we can
> benefit the underlay datastore if it support filter natively like the
> database.
>
> On Tue, Oct 13, 2020 at 4:45 PM Andrea Aime <andrea.a...@geo-solutions.it>
> wrote:
>
>> Of course, the OGR datastore passes bbox filters directly in the data
>> access API,
>> not as part of the SQL, so there is no need to translate them. If the OGR
>> SQL has a
>> way to express spatial filters, feel free to extend
>> the OGRFilterTranslator as you see fit.
>>
>> Cheers
>> Andrea
>>
>> On Tue, Oct 13, 2020 at 10:06 AM maven apache <apachemav...@gmail.com>
>> wrote:
>>
>>> public class FilterTest {
>>>     static {
>>>         ogr.RegisterAll();
>>>     }
>>>
>>>     public static void main(String[] args) throws CQLException, IOException 
>>> {
>>>         Map<String, Object> params = new HashMap<>();
>>>         params.put("DriverName", "xxx");
>>>         params.put("DatasourceName", xxx);
>>>
>>>         DataStore dataStore = DataStoreFinder.getDataStore(params);
>>>         SimpleFeatureSource sfs = dataStore.getFeatureSource("water");
>>>         Filter filter = CQL.toFilter("BBOX(" + 
>>> sfs.getSchema().getGeometryDescriptor().getLocalName() + ", 20,30,21,31) 
>>> and num <= 10");
>>>         OGRFilterTranslator ogrFilterTranslator = new 
>>> OGRFilterTranslator(sfs.getSchema(), filter);
>>>         System.out.println(ogrFilterTranslator.getSpatialFilter());
>>>         System.out.println(ogrFilterTranslator.getPostFilter());
>>>         System.out.println(ogrFilterTranslator.getAttributeFilter());
>>>     }
>>> }
>>>
>>> Output:
>>>
>>> null
>>> [ the_geom bbox ReferencedEnvelope[20:21,30:31] ]
>>> num <= 10
>>>
>>> Seems like that the bbox filter is not recognized by OGRFilterTranslator
>>> _______________________________________________
>>> GeoTools-GT2-Users mailing list
>>> GeoTools-GT2-Users@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>>>
>>
>>
>> --
>>
>> Regards, Andrea Aime
>>
>> == GeoServer Professional Services from the experts! Visit
>> http://goo.gl/it488V for more information. == Ing. Andrea Aime @geowolf
>> Technical Lead GeoSolutions S.A.S. Via di Montramito 3/A 55054 Massarosa
>> (LU) phone: +39 0584 962313 fax: +39 0584 1660272 mob: +39 339 8844549
>> http://www.geo-solutions.it http://twitter.com/geosolutions_it
>> ------------------------------------------------------- *Con riferimento
>> alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 -
>> Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni
>> circostanza inerente alla presente email (il suo contenuto, gli eventuali
>> allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i
>> destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per
>> errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le
>> sarei comunque grato se potesse darmene notizia. This email is intended
>> only for the person or entity to which it is addressed and may contain
>> information that is privileged, confidential or otherwise protected from
>> disclosure. We remind that - as provided by European Regulation 2016/679
>> “GDPR” - copying, dissemination or use of this e-mail or the information
>> herein by anyone other than the intended recipient is prohibited. If you
>> have received this email by mistake, please notify us immediately by
>> telephone or e-mail.*
>>
>
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to