Please keep in mind that GeoTools is not implementing SQL (as we use the
same query language for shape files and other spatial content).
That said there is a transform process, and transform datastore that can be
configured to provide attributes derived from an expression. Andrea has
already mentioned the SQL view approach.
Jody Garnett
On Thu, Aug 21, 2014 at 5:27 AM, Alireza Shamakhy <
alireza.shama...@gmail.com> wrote:
> So I can only sort based on the existing fields not alias fields.
> The problem is in Geotools when you connect to postgis database you can
> not have alias field as well. look at following:
>
> final Map<String, Object> params = new HashMap<String, Object>();
>
> params.put("dbtype", "postgis");
> params.put("host", "localhost");
> params.put("port", 5432);
> params.put("schema", "xx");
> params.put("database", "xxx");
> params.put("user", "xxx");
> params.put("passwd", "");
>
> final DataStore dataStore = DataStoreFinder.getDataStore(params);
>
> final String typeName = "mytable";
> final SimpleFeatureSource source =
> dataStore.getFeatureSource(typeName);
>
> final FeatureType schema = source.getSchema();
> final String name = schema.getGeometryDescriptor().getLocalName()
>
> final ArrayList<String> values = new ArrayList<String>();
>
>
> * values.add("field1"); // values.add("field2 - 10");*
>
> final String[] properties = values.toArray(new String[values.size()]);
>
> Filter filter = null;
> filter = CQL.toFilter("field1 >0");
>
> final Query query = new Query(typeName, filter, properties);
>
> final SimpleFeatureCollection features = source.getFeatures(query);
>
> final SimpleFeatureIterator iterator1 = features.features();
>
> final int count = features.size();
> logger.info("size file: " + count);
>
> you can not fetch fields like "*field2 - 10" *although field2 is exist
> in the table.
>
> This is frustrating that you neither can have alias fields nor you can
> sort based on the alias field.
>
> Please correct me if I am wrong. I think it is essential if we can have
> fields on the fly while working on Postgis.
>
> Thanks
>
>
> ------------------------------------------------------------------------------
> Slashdot TV.
> Video for Nerds. Stuff that matters.
> http://tv.slashdot.org/
> _______________________________________________
> GeoTools-GT2-Users mailing list
> GeoTools-GT2-Users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
>
------------------------------------------------------------------------------
Slashdot TV.
Video for Nerds. Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users