[geotk] DefaultPortrayalService BufferedImage Flipped/Rotated

Alexis Manin alexis.manin at geomatys.com
Sun Jul 16 23:58:08 PDT 2017


Hi Cullen,

I think the problem comes from the usage of EPSG:4326. In Geotoolkit, we
strictly follow EPSG database definition, which states EPSG:4326 is a
latitude first coordinate system. So, when drawing an image with this CRS,
the horizontal axis of the image will be the latitude.

To overcome this problem, you should rather use "CRS:84" coordinate system,
which is the equivalent of EPSG:4326, but with longitude as x-axis. You can
acquire it by using one of these two methods :
 - CRS.forCode("CRS:84"),
<http://sis.apache.org/apidocs/org/apache/sis/referencing/CRS.html#forCode-java.lang.String->
 - CommonCRS.defaultGeographic().
<http://sis.apache.org/apidocs/org/apache/sis/referencing/CommonCRS.html#defaultGeographic-->

Regards,

2017-07-12 17:56 GMT+02:00 Cullen Rombach <cullenr at imagemattersllc.com>:

> Hello all,
>
> I am using DefaultPortrayalService to render a MapContext to a
> BufferedImage. My (heavily simplified) code looks something like this:
>
> MapContext context = ... (created earlier)
> Envelope envelope = ... (created earlier)
> OutputStream outputStream = ... (created earlier)
> Dimension dimension = ... (created earlier)
>
> BufferedImage img = DefaultPortrayalService.portray(context, envelope,
> dimension, false);
>
> ImageIO.write(img, "PNG", outputStream);
>
> As far as I can tell, this is the proper way to render a MapContext.
> However, the image I get back in the output stream is incorrect. In order
> to get the image oriented properly, I need to flip it upside down and
> rotate it -90 degrees. Additionally, if the supplied dimensions are not
> square, the original image is missing content because it is drawn in the
> wrong orientation (that is, it gets cropped). I've attached a few example
> files.
>
> I'm trying to work around the issue by performing AffineTransforms on the
> rendered image to get it oriented properly, but I would obviously prefer if
> the image were correct on the first try. Is this an issue with the way I am
> using DefaultPortrayalService, or is it a bug?
>
> In case it is relevant, I am getting the FeatureCollection in my
> MapContext from WGS 1984 shape files. I have tried a few different shape
> files, so I don't think it's an issue caused only by certain data sets.
> Also of note is that my source CRS and target CRS are the same (EPSG:4326,
> AKA WGS 1984).
>
> Regards
> Cullen Rombach
>
> --
> Cullen Rombach
> Image Matters LLC
> www.imagemattersllc.com
>
> _______________________________________________
> Geotoolkit mailing list
> Geotoolkit at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/geotoolkit
>



-- 
Alexis Manin,
Développeur JAVA/JEE.
Geomatys.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/geotoolkit/attachments/20170717/05bdc614/attachment.html>


More information about the Geotoolkit mailing list