CoordinateReferenceSystem sourceCRS = DefaultGeographicCRS.WGS84;
String gml = Xml.getString(geom);
try {
if (srs != null && !(srs.equals(""))) sourceCRS = CRS.decode(srs);
MultiPolygon jts = parseGml(parser, gml);
// if we have an srs and its not WGS84 then transform to WGS84
if (!CRS.equalsIgnoreMetadata(sourceCRS, DefaultGeographicCRS.WGS84)) {
MathTransform tform = CRS.findMathTransform(sourceCRS, DefaultGeographicCRS.WGS84);
jts = (MultiPolygon)JTS.transform(jts, tform);
}
for (int i = 0; i < jts.getNumGeometries(); i++) {
allPolygons.add((Polygon) jts.getGeometryN(i));
}
} catch (Exception e) {
errorMessage.put("PARSE", gml + ". Error is:" + e.getMessage());
Log.error(Geonet.INDEX_ENGINE, "Failed to convert gml to jts object: "+gml+"\n\t"+e.getMessage());
e.printStackTrace();