public static GeographyType getGeographyType(Geometry geom, CommandContext ctx) throws FunctionExecutionException { if (geom.getSRID() == GeometryType.UNKNOWN_SRID) { geom.setSRID(GeographyType.DEFAULT_SRID); } if (!GeometryTransformUtils.isLatLong(ctx, geom.getSRID())) { throw new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31290, geom.getSRID())); } geom.apply(new CoordinateFilter() { @Override public void filter(Coordinate coord) { if (coord.x > 180) { ctx.addWarning(new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31291))); coord.x = ((coord.x+180)%360) - 180; } else if (coord.x < -180) { ctx.addWarning(new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31291))); coord.x = ((coord.x+180)%360) + 180; } if (coord.y > 90) { ctx.addWarning(new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31291))); coord.y = (((coord.y/90)%2>=1?90:0)-(coord.y%90))*((((coord.y-90)/180)%2>=1)?-1:1); } else if (coord.y < -90) { ctx.addWarning(new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31291))); coord.y = (((coord.y/90)%2<=-1?-90:0)-(coord.y%90))*((((coord.y+90)/180)%2<=-1)?-1:1); } } }); GeographyType result = getGeographyType(geom); return result; }
public static GeographyType getGeographyType(Geometry geom, CommandContext ctx) throws FunctionExecutionException { if (geom.getSRID() == GeometryType.UNKNOWN_SRID) { geom.setSRID(GeographyType.DEFAULT_SRID); } if (!GeometryTransformUtils.isLatLong(ctx, geom.getSRID())) { throw new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31290, geom.getSRID())); } geom.apply(new CoordinateFilter() { @Override public void filter(Coordinate coord) { if (coord.x > 180) { ctx.addWarning(new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31291))); coord.x = ((coord.x+180)%360) - 180; } else if (coord.x < -180) { ctx.addWarning(new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31291))); coord.x = ((coord.x+180)%360) + 180; } if (coord.y > 90) { ctx.addWarning(new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31291))); coord.y = (((coord.y/90)%2>=1?90:0)-(coord.y%90))*((((coord.y-90)/180)%2>=1)?-1:1); } else if (coord.y < -90) { ctx.addWarning(new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31291))); coord.y = (((coord.y/90)%2<=-1?-90:0)-(coord.y%90))*((((coord.y+90)/180)%2<=-1)?-1:1); } } }); GeographyType result = getGeographyType(geom); return result; }