Thanks Andrea !
I found what I did wrong. I used two Strings instead of a String and a
Double. Your example helped me to find this rather trivial mistake.
Here is the working code, for those who are interested.

OK for the text symbolizer, I have replaced the code as you said.
Regarding the evaluate method, I have evaluated the two parameters
against the object as you said (see below).
I have built the formatter from the string result.
But then, I don't know what to return. I have tried (T)
formatter.format(propertyString), but it doesn't seem to work.
propertyName is equal to "depth", and my propertyString is null... If
I don't know I have a feature as an object, how do I retrieve the
"depth" attribute value ?
I guess I missed something :-D
public final <T> T evaluate(final Object object, final Class<T>
context) {
Expression propertyName = parameters.get(0);
Expression format = parameters.get(1);
String propertyString = propertyName.evaluate(object, String.class);
String formatString = format.evaluate(object, String.class);
return (T) formatter.format(propertyString);
}
Le 3 mars 09 à 17:08, Andrea Aime a écrit :
> You're not supposed to know. You have expressions as parameters,
> evaluate the first against the object and ask for a String.class
> result
> type, evaluate the second and do the same.
> Then use the two results to perform the formatting, and return the
> resulting value.

Benoît Thiébault wrote:
> Hi everyone,
>
> As Andrea suggested, I'm trying to implement a formatting filter
> function that could be used in SLD files (or programmatically) to
> display text in a given format, like this :
>
> <Function name="numberFormat">
> <PropertyName>myAtt</PropertyName>
> <Literal>##.##</Literal>
> </Function>
>
> I have looked at existing functions and coded the function attached.
>
> However, I still have some questions to finish it.
>
> 1) I don't really know how to implement the evaluate(final Object
> object, final Class<T> context) method.
> What is the object parameter supposed to be ? A feature ? What should I
> return ?
You're not supposed to know. You have expressions as parameters,
evaluate the first against the object and ask for a String.class result
type, evaluate the second and do the same.
Then use the two results to perform the formatting, and return the
resulting value.
> 2) I dont' really know how to use the function in my programmatically
> built style. I have created a text symbolizer and successfully retrieved
> the function. But I don't know how to make the text symbolizer depend on
> my function result. Here is the code I have for now.
>
> StyleBuilder sb = new StyleBuilder();
> FilterFactory ff =
> CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
>
> Function format = null;
> try {
> format = ff.function("NumberFormat", ff
> .property("depth"), sb.literalExpression(".##"));
> } catch (Exception e) {
> logger.error(e);
> }
>
> org.geotools.styling.Font[] fontArray = { sb.createFont(new Font(
> "sansserif", Font.PLAIN, 12)) };
>
> TextSymbolizer text = sb.createTextSymbolizer(null, fontArray, null, sb
> .attributeExpression("depth"), sb.createPointPlacement(0.5,
> 0.0, 0.0), "");
The symbolizer must use the function as the source of the label, so you
should pass "format" instead of "sb.attributeExpression("depth")"
Cheers
Andrea

Hello,
I am new to GeoTools and I have a question about the use of the gml:Envelope tag. I have a project where I am going to have to take in xml documents that will include OGC Filter statements. I downloaded a source copy of GeoTools version 2.5.1 and started to look at the code. I wanted to see how the xml version of the filter was handled in GeoTools, after some looking I found the test class modules/library/xml/src/test/java/org/geotools/xml/ogc/XMLEncoderTest.java. This test class apparently takes in filter statements in xml and tries to parse them into an org.opengis.filter.Filter object. I ran the JUnit test and of course everything passed. I then decided that I wanted to try some filter statements other than the ones used in the test. So I went to the file modules/library/xml/src/test/resources/org/geotools/xml/ogc/test-data/test3b.xml. This is one of the xml files that gets read in and parsed from xml to the Filter object, I decided to change it into a different filter statement to see how the filter object would look when using a gml:Envelope tag. I changed this xml file to the following:
<Filter xmlns:gml="http://www.opengis.net/gml"&gt;
<BBOX>
<PropertyName>Geometry</PropertyName>
<gml:Envelope>
<gml:lowerCorner>0 0</gml:lowerCorner>
<gml:upperCorner>10 10</gml:upperCorner>
</gml:Envelope>
</BBOX>
</Filter>
I then ran the JUnit test again. The test that uses the file test3b.xml does not make any assertion statements to check and see what the outcome of the Filter is, so I thought that my test would still pass. Instead I got the following error while parsing the xml into the Filter object:
java.lang.NullPointerException
at org.geotools.filter.FilterFactoryImpl.bbox(FilterFactoryImpl.java:261)
at org.geotools.filter.FilterDOMParser.parseFilter(FilterDOMParser.java:453)
at org.geotools.xml.ogc.XMLEncoderTest.parseDocument(XMLEncoderTest.java:238)
at org.geotools.xml.ogc.XMLEncoderTest.test3b(XMLEncoderTest.java:139)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
I tried to debug the error and found that in the method org.geotools.filterFilterDOMParser.parseFilter the code cannot parse the gml:Envelope tag to determine what the values for the bounding box are.
Does GeoTools not support all of the gml language such as gml:Envelope tags, or is my filter statement written incorrectly for using the gml:Envelope tag, or is it that the class modules/library/xml/src/test/java/org/geotools/xml/ogc/XMLEncoderTest.java is not the correct JUnit class to handle parsing xml messages with gml:Envelope tags to Filter objects, or is there something else I am missing? Thank you.
Brett

Thanks Jody for your answers,
I will have a look at the updated code. It seems to be a very useful
example.
Ben
Le 3 mars 09 à 14:23, Jody Garnett a écrit :
> Hi Mr Thiébault:
>
> I am jumping in with a couple answers where I can.
>> Do you have any example of code using this listenerManager ?
>>
> You can find the updated source code in our svn repository:
> - http://svn.osgeo.org/geotools/trunk/modules/plugin/property
>
> I hope that can serve as an example.
>> In the old API, to fire a remove event for instance, you just
>> needed to pass the removed feature as an argument. To fire a
>> change event, you had to pass the old and the new feature. That
>> was straightforward and easy to understand.
>>
> First of all thanks for the list of questions; the above example
> should help you and there are some utility methods that take care of
> firing the event. With that in mind I will try and answer quickly...
>> Now, I need to pass the feature type,
> This is the feature type of the feature being added, updated or
> removed (feature.getFeatureType() should return the right value)
>> the transaction (what is it ? I don't use transactions in my
>> feature writer...)
> Transactions allow multiple threads to work on the same file at once
> (only writing to the file when transaction.commit() is called). This
> is handled for you by the superclass; it only actually calls your
> writer during that commit() call. You can go over the user guide for
> some examples of using a transaction.
>> , the referenced envelope (is this the envelope containing the
>> feature or does it correspond to the bounds of the whole
>> datastore ?)
> This is focused on saying where the change is that took place; the
> area of a map that should be redrawn based on this change. It is
> literally used to update the screen in a desktop application such as
> udig
> So for delete it will be the area of the feature removed; for add it
> will be the area where the feature was created; and for update it
> will be a combination of the area before and after the change..
>> and a commitboolean (the javadoc says: true for commit, false to
>> rolback... what is this ?).
>
>> Where is my feature?
> Your feature is what you are building in a FeatureReader; or writing
> in a FeatureWriter.
>> Is it embedded in the transaction?
>>
> No this is the responsibility of the datastore provider; the example
> shows how to implement a FeatureReader and goes on to show how to
> implement a FeatureWriter. These classes are like iterators but they
> throw exceptions.
>> How do I build one ?
>>
> The user guide has some examples of building a feature by hand.
>

Hi everyone,
As Andrea suggested, I'm trying to implement a formatting filter
function that could be used in SLD files (or programmatically) to
display text in a given format, like this :
<Function name="numberFormat">
<PropertyName>myAtt</PropertyName>
<Literal>##.##</Literal>
</Function>
I have looked at existing functions and coded the function attached.
However, I still have some questions to finish it.
1) I don't really know how to implement the evaluate(final Object
object, final Class<T> context) method.
What is the object parameter supposed to be ? A feature ? What should
I return ?
For now, my filter function takes two arguments: the feature attribute
name and the format pattern (##.## for instance).
I don't know however how the function interacts with the style...
which leads to my second question
2) I dont' really know how to use the function in my programmatically
built style. I have created a text symbolizer and successfully
retrieved the function. But I don't know how to make the text
symbolizer depend on my function result. Here is the code I have for
now.
StyleBuilder sb = new StyleBuilder();
FilterFactory ff =
CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
Function format = null;
try {
format = ff.function("NumberFormat", ff
.property("depth"), sb.literalExpression(".##"));
} catch (Exception e) {
logger.error(e);
}
org.geotools.styling.Font[] fontArray = { sb.createFont(new Font(
"sansserif", Font.PLAIN, 12)) };
TextSymbolizer text = sb.createTextSymbolizer(null, fontArray, null, sb
.attributeExpression("depth"), sb.createPointPlacement(0.5,
0.0, 0.0), "");

Hi Mr Thiébault:
I am jumping in with a couple answers where I can.
> Do you have any example of code using this listenerManager ?
>
You can find the updated source code in our svn repository:
- http://svn.osgeo.org/geotools/trunk/modules/plugin/property
I hope that can serve as an example.
> In the old API, to fire a remove event for instance, you just needed
> to pass the removed feature as an argument. To fire a change event,
> you had to pass the old and the new feature. That was straightforward
> and easy to understand.
>
First of all thanks for the list of questions; the above example should
help you and there are some utility methods that take care of firing the
event. With that in mind I will try and answer quickly...
> Now, I need to pass the feature type,
This is the feature type of the feature being added, updated or removed
(feature.getFeatureType() should return the right value)
> the transaction (what is it ? I don't use transactions in my feature writer...)
Transactions allow multiple threads to work on the same file at once
(only writing to the file when transaction.commit() is called). This is
handled for you by the superclass; it only actually calls your writer
during that commit() call. You can go over the user guide for some
examples of using a transaction.
> , the referenced envelope (is this the envelope containing the feature or does it
> correspond to the bounds of the whole datastore ?)
This is focused on saying where the change is that took place; the area
of a map that should be redrawn based on this change. It is literally
used to update the screen in a desktop application such as udig
So for delete it will be the area of the feature removed; for add it
will be the area where the feature was created; and for update it will
be a combination of the area before and after the change..
> and a commitboolean (the javadoc says: true for commit, false to rolback... what
> is this ?).
> Where is my feature?
Your feature is what you are building in a FeatureReader; or writing in
a FeatureWriter.
> Is it embedded in the transaction?
>
No this is the responsibility of the datastore provider; the example
shows how to implement a FeatureReader and goes on to show how to
implement a FeatureWriter. These classes are like iterators but they
throw exceptions.
> How do I build one ?
>
The user guide has some examples of building a feature by hand.

Ok thanks for the explanation and the work done so far.
Sylvain
Martin Desruisseaux a écrit :
> Hello Sylvain
>
> Sylvain GRELLET a écrit :
>> One last question, do you know when the last port of Proj.4 C/C++
>> code to Java occured ?
>
> Hard to give a clear answer on this one since it is spread over
> time... We do not have a complete port of the full Proj.4 library. We
> usually port parts of it on a projection-by-projection basis (usually
> from volunter work) as the need appear. The last projection ported
> that way was Cassini in 2008.
>
>
>> Working in France, maybe you know Martin, that IGN France recently
>> contributed to Proj.4 in order to update projection & transformations
>> related to RGF93/Lambert93 (it's in proj.4 version 4-6-1).
>> It's in this context that I plan to use GeoTools 2.5 via SDI.
>> Using RGF93/Lambert93 when publishing datasets will be a legal
>> obligation in France starting on Monday March 9th.
>>
>> In the mean time I have contacted the person in charge of RGF93/L93
>> project at IGN France in order to know whether they had validated
>> GeoTools for this use or no. We'll see what his answer would be.
>
> We are in contact with IGN as well and they gave us material to help
> us implementing the RGF93 projection. We are planning to implement it.
> My schedule is to get EPSG factory to work on geotidy (I mostly
> finished to port and clean the GeoTools 2.x code. I'm now porting the
> tests and testing), test the integration of that code in geotools and
> after that I will implement RGF93.
>
>
> Martin
>
>

Hello Sylvain
Sylvain GRELLET a écrit :
> One last question, do you know when the last port of Proj.4 C/C++ code
> to Java occured ?
Hard to give a clear answer on this one since it is spread over time... We do
not have a complete port of the full Proj.4 library. We usually port parts of it
on a projection-by-projection basis (usually from volunter work) as the need
appear. The last projection ported that way was Cassini in 2008.
> Working in France, maybe you know Martin, that IGN France recently
> contributed to Proj.4 in order to update projection & transformations
> related to RGF93/Lambert93 (it's in proj.4 version 4-6-1).
> It's in this context that I plan to use GeoTools 2.5 via SDI.
> Using RGF93/Lambert93 when publishing datasets will be a legal
> obligation in France starting on Monday March 9th.
>
> In the mean time I have contacted the person in charge of RGF93/L93
> project at IGN France in order to know whether they had validated
> GeoTools for this use or no. We'll see what his answer would be.
We are in contact with IGN as well and they gave us material to help us
implementing the RGF93 projection. We are planning to implement it. My schedule
is to get EPSG factory to work on geotidy (I mostly finished to port and clean
the GeoTools 2.x code. I'm now porting the tests and testing), test the
integration of that code in geotools and after that I will implement RGF93.
Martin

Hello,
Thanks for your answers.
One last question, do you know when the last port of Proj.4 C/C++ code
to Java occured ?
Working in France, maybe you know Martin, that IGN France recently
contributed to Proj.4 in order to update projection & transformations
related to RGF93/Lambert93 (it's in proj.4 version 4-6-1).
It's in this context that I plan to use GeoTools 2.5 via SDI.
Using RGF93/Lambert93 when publishing datasets will be a legal
obligation in France starting on Monday March 9th.
In the mean time I have contacted the person in charge of RGF93/L93
project at IGN France in order to know whether they had validated
GeoTools for this use or no. We'll see what his answer would be.
Regards.
Sylvain
Frank Warmerdam a écrit :
> Martin Desruisseaux wrote:
>> Hello Sylvain
>>
>> Sylvain GRELLET a écrit :
>>> My question is the following :
>>> - to which extent is GeoTools2 using Proj.4 librairie ? Proj.4 web
>>> site (http://trac.osgeo.org/proj/) is citing GeoTools as a Related
>>> Ressource.
>>
>> Proj.4 is not used at all in the sense that GeoTools has no
>> dependency toward the Proj.4 library. However most projection
>> formulas are port of Proj.4 C/C++ code to Java, licenced under LGPL
>> with Frank Wamardam permission. Note however that the Java code has
>> been refactored in various way with time, so when comparing the C/C++
>> and Java codes their relationship may not be obvious.
>
> Sylvain,
>
> I would add that GeoTools is listed as a related resource because the
> coordinate transformation part of GeoTools performs a similar role to
> PROJ.4, not because there was any implication of derivation from, or
> use of PROJ.4.
>
> Best regards,

Thanks Justin,
Do you have any example of code using this listenerManager ?
In the old API, to fire a remove event for instance, you just needed
to pass the removed feature as an argument. To fire a change event,
you had to pass the old and the new feature. That was straightforward
and easy to understand.
Now, I need to pass the feature type, the transaction (what is it ? I
don't use transactions in my feature writer...), the referenced
envelope (is this the envelope containing the feature or does it
correspond to the bounds of the whole datastore ?) and a commit
boolean (the javadoc says: true for commit, false to rolback... what
is this ?). Where is my feature ? Is it embedded in the transaction ?
How do I build one ?
Thanks
Le 3 mars 09 à 04:38, Justin Deoliveira a écrit :
> Hi Benoît,
>
> Yes, that tutorial seems quite out of date. Looking at the code it
> seems like what you want to do (if your datastore extends from
> AbstractDataStore) is to use the listenerManager member of
> AbstractDataStore to add/remove listeners, and to fire events.
>
> -Justin
>
> Benoît Thiébault wrote:
>> Hi everyone,
>> I'm currently creating a writeable datastore following this
>> tutorial : http://docs.codehaus.org/display/GEOTDOC/3+Making+PropertyDataStore+Writable
>> It seems however a little outdated.
>> When the feature has changed, in the feature writer, I am supposed
>> to call a datastore method :
>> datastore.fireChanged( original, live );
>> But this method does not exist in the AbstractDataStore class. How
>> should I do to notify the featureSource created from the datastore
>> that my data has changed ?
>> Thanks
>> Benoît
>> ------------------------------------------------------------------------------
>> Open Source Business Conference (OSBC), March 24-25, 2009, San
>> Francisco, CA
>> -OSBC tackles the biggest issue in open source: Open Sourcing the
>> Enterprise
>> -Strategies to boost innovation and cut costs with open source
>> participation
>> -Receive a $600 discount off the registration fee with the source
>> code: SFAD
>> http://p.sf.net/sfu/XcvMzF8H
>> _______________________________________________
>> Geotools-gt2-users mailing list
>> Geotools-gt2-users@...
>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
>
> --
> Justin Deoliveira
> OpenGeo - http://opengeo.org
> Enterprise support for open source geospatial.
>

That is good it sounds like we have a couple of projects that could benifit
from OWSContext reading and writing.
How about it Carsten are you willing to start up an unsupported module? I
would be willing to fold the functionality into the renderer module once it
meets everyones needs.
Jody
On Mon, Mar 2, 2009 at 4:14 PM, Justin Deoliveira <jdeolive@...>wrote:
> You may also want to poll the openlayers community (if you are interested
> in web stuff), since I believe there may be some support for ows context
> documents in the library.
>
> On a related note one thing that has popped up in geoserver recently is the
> ability to output a wms get map request as an ows context document.
> Basically make a normal getMap request, but instead of getting an image
> back, you get a context document back.
>
> -Justin
>
>
> Jody Garnett wrote:
>
>> I would be happy to join you in working on an OWSContext parser; in
>> particular some of the standards@... email has revised the
>> OWSContext schema to allow for Extensions in the ResourceList (so we can use
>> these files to document local and remote files).
>>
>> Cheers,
>> Jody
>>
>> Carsten Ehbrecht wrote:
>>
>>> Hi,
>>>
>>> i'm building a mapviewer based on geotools (StreamMap) and i would like
>>> to save my "project" settings as a OWSContext xml document. This xml
>>> document stores the settings of the MapContext (layer, visible, url). Is
>>> there already some code available in geotools to handle OWSContext
>>> documents? Or could you give me some hints where to find an
>>> implementation?
>>>
>>> I've already found some code in uDig (seams to be outdated) and
>>> MapBuilder for OWSContext.
>>>
>>> Cheers,
>>> Carsten
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco,
>>> CA
>>> -OSBC tackles the biggest issue in open source: Open Sourcing the
>>> Enterprise
>>> -Strategies to boost innovation and cut costs with open source
>>> participation
>>> -Receive a $600 discount off the registration fee with the source code:
>>> SFAD
>>> http://p.sf.net/sfu/XcvMzF8H
>>> _______________________________________________
>>> Geotools-gt2-users mailing list
>>> Geotools-gt2-users@...
>>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>>>
>>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco,
>> CA
>> -OSBC tackles the biggest issue in open source: Open Sourcing the
>> Enterprise
>> -Strategies to boost innovation and cut costs with open source
>> participation
>> -Receive a $600 discount off the registration fee with the source code:
>> SFAD
>> http://p.sf.net/sfu/XcvMzF8H
>> _______________________________________________
>> Geotools-gt2-users mailing list
>> Geotools-gt2-users@...
>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>>
>
>
> --
> Justin Deoliveira
> OpenGeo - http://opengeo.org
> Enterprise support for open source geospatial.
>

Hi Benoît,
Yes, that tutorial seems quite out of date. Looking at the code it seems
like what you want to do (if your datastore extends from
AbstractDataStore) is to use the listenerManager member of
AbstractDataStore to add/remove listeners, and to fire events.
-Justin
Benoît Thiébault wrote:
> Hi everyone,
>
> I'm currently creating a writeable datastore following this tutorial : http://docs.codehaus.org/display/GEOTDOC/3+Making+PropertyDataStore+Writable
>
> It seems however a little outdated.
>
> When the feature has changed, in the feature writer, I am supposed to
> call a datastore method :
> datastore.fireChanged( original, live );
> But this method does not exist in the AbstractDataStore class. How
> should I do to notify the featureSource created from the datastore
> that my data has changed ?
> Thanks
> Benoît
> ------------------------------------------------------------------------------
> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
> -Strategies to boost innovation and cut costs with open source participation
> -Receive a $600 discount off the registration fee with the source code: SFAD
> http://p.sf.net/sfu/XcvMzF8H
> _______________________________________________
> Geotools-gt2-users mailing list
> Geotools-gt2-users@...
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
--
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

Martin Desruisseaux wrote:
> Hello Sylvain
>
> Sylvain GRELLET a écrit :
>> My question is the following :
>> - to which extent is GeoTools2 using Proj.4 librairie ? Proj.4 web site
>> (http://trac.osgeo.org/proj/) is citing GeoTools as a Related Ressource.
>
> Proj.4 is not used at all in the sense that GeoTools has no dependency toward
> the Proj.4 library. However most projection formulas are port of Proj.4 C/C++
> code to Java, licenced under LGPL with Frank Wamardam permission. Note however
> that the Java code has been refactored in various way with time, so when
> comparing the C/C++ and Java codes their relationship may not be obvious.
Sylvain,
I would add that GeoTools is listed as a related resource because the
coordinate transformation part of GeoTools performs a similar role to
PROJ.4, not because there was any implication of derivation from, or
use of PROJ.4.
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam@...
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | Geospatial Programmer for Rent