I have trouble understanding the use of the function ReprojectingFeatureCollection. Here is my code:
try {
Double buffer = 500.0;
String attributeBuffer = "";
ReprojectingFeatureCollection clip_repojected = new ReprojectingFeatureCollection(clip, CRS.decode("EPSG:3857"));
myBufferM buffered = new myBufferM();
SimpleFeatureCollection bufferedFeatures = buffered.createBufferM(clip_repojected.collection(), buffer, attributeBuffer);
} catch (OperationNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (FactoryRegistryException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (NoSuchAuthorityCodeException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SchemaException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (FactoryException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
So my function gets a SimpleFeatureCollection as parameter and now tries to Reproject it to EPSG:3857
. I have modified the gs:BufferFeatureCollection
from the list of WPS processes of GeoServer and now call it myBufferM. I am trying to Buffer a FeatureCollection in meter instead of degrees (data's default unit). Previously I had the transformation to meter build into my Class myBufferM which worked good (transforming every feature geometry itself and then buffering it and reverse transforming it).
Now I am trying to transform the geometries beforehand using the Buffer function as it was before I modified it.
The question is: am I using the ReprojectingFeatureCollection
correctly? Because the results I get now are wrong (in degrees).
If you need more code I will update my question. I have reduced it to the important parts. The total code would be kind of huge.
Answer
The answer was very simple in the end. When I used this function I just took the first include my IDE was suggesing me to be correct. I was making use of org.geoserver.feature.ReprojectingFeatureCollection;
But somehow the code in this include is not working properly (at least not for me using GeoTools 20.0 - includes automatically loaded by maven). When using the Function as described in my question it was just changing the EPSG Code of the data but did not transform the data itself. That's why further manipulation achieved false outputs (buffering for example still took place in degrees instead of meter).
I did not imediately noticed because when I importet test data into QGis, QGis transformed the data on the fly to the CRS it said it would be. When I finally made a GeoJSON out of it to look at the geometry values itself I realised that something was not right.
Long talk short solution. I changed the import to org.geotools.data.store.ReprojectingFeatureCollection;
and that fixed the problem. Now it works like it should.
Don't know if it was my stupidity or if there is a bug in this include for real though.
No comments:
Post a Comment