Loading src/adql/query/operand/function/geometry/CentroidFunction.java +4 −4 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package adql.query.operand.function.geometry; * You should have received a copy of the GNU Lesser General Public License * along with ADQLLibrary. If not, see <http://www.gnu.org/licenses/>. * * Copyright 2012-2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Copyright 2012-2017 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Astronomisches Rechen Institut (ARI) */ Loading @@ -36,7 +36,7 @@ import adql.query.operand.ADQLOperand; * </i></p> * * @author Grégory Mantelet (CDS;ARI) * @version 1.4 (06/2015) * @version 1.4 (02/2017) */ public class CentroidFunction extends GeometryFunction { Loading Loading @@ -80,7 +80,7 @@ public class CentroidFunction extends GeometryFunction { @Override public boolean isNumeric(){ return true; return false; } @Override Loading @@ -90,7 +90,7 @@ public class CentroidFunction extends GeometryFunction { @Override public boolean isGeometry(){ return false; return true; } @Override Loading src/adql/translator/PgSphereTranslator.java +17 −8 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package adql.translator; * You should have received a copy of the GNU Lesser General Public License * along with ADQLLibrary. If not, see <http://www.gnu.org/licenses/>. * * Copyright 2012-2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Copyright 2012-2017 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Astronomisches Rechen Institut (ARI) */ Loading @@ -34,6 +34,7 @@ import adql.query.constraint.Comparison; import adql.query.constraint.ComparisonOperator; import adql.query.operand.function.geometry.AreaFunction; import adql.query.operand.function.geometry.BoxFunction; import adql.query.operand.function.geometry.CentroidFunction; import adql.query.operand.function.geometry.CircleFunction; import adql.query.operand.function.geometry.ContainsFunction; import adql.query.operand.function.geometry.DistanceFunction; Loading @@ -48,7 +49,7 @@ import adql.query.operand.function.geometry.PolygonFunction; * The other functions are managed by {@link PostgreSQLTranslator}.</p> * * @author Grégory Mantelet (CDS;ARI) * @version 1.4 (07/2015) * @version 1.4 (07/2017) */ public class PgSphereTranslator extends PostgreSQLTranslator { Loading Loading @@ -174,6 +175,13 @@ public class PgSphereTranslator extends PostgreSQLTranslator { return str.toString(); } @Override public String translate(CentroidFunction centroidFunction) throws TranslationException{ StringBuffer str = new StringBuffer("center("); str.append(translate(centroidFunction.getParameter(0))).append(")"); return str.toString(); } @Override public String translate(ContainsFunction fct) throws TranslationException{ StringBuffer str = new StringBuffer("("); Loading Loading @@ -624,7 +632,8 @@ public class PgSphereTranslator extends PostgreSQLTranslator { end(); // Build the STC Box region: double width = Math.abs(northeast[0] - southwest[0]), height = Math.abs(northeast[1] - southwest[1]); double width = Math.abs(northeast[0] - southwest[0]), height = Math.abs(northeast[1] - southwest[1]); double[] center = new double[]{northeast[0] - width / 2,northeast[1] - height / 2}; return new Region(null, center, width, height); } Loading test/adql/query/operand/function/geometry/TestCentroidFunction.java 0 → 100644 +28 −0 Original line number Diff line number Diff line package adql.query.operand.function.geometry; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.junit.Test; import adql.query.operand.NumericConstant; import adql.query.operand.StringConstant; import adql.query.operand.function.geometry.GeometryFunction.GeometryValue; public class TestCentroidFunction { @Test public void testIsGeometry(){ try{ CentroidFunction centfc = new CentroidFunction(new GeometryValue<GeometryFunction>(new CircleFunction(new StringConstant("ICRS"), new NumericConstant(128.23), new NumericConstant(0.53), new NumericConstant(2)))); assertTrue(centfc.isGeometry()); assertFalse(centfc.isNumeric()); assertFalse(centfc.isString()); }catch(Throwable t){ t.printStackTrace(System.err); fail("An error occured while building a simple CentroidFunction! (see the console for more details)"); } } } test/adql/translator/TestPgSphereTranslator.java +18 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,12 @@ import adql.db.DBType; import adql.db.DBType.DBDatatype; import adql.db.STCS.Region; import adql.parser.ParseException; import adql.query.operand.NumericConstant; import adql.query.operand.StringConstant; import adql.query.operand.function.geometry.CentroidFunction; import adql.query.operand.function.geometry.CircleFunction; import adql.query.operand.function.geometry.GeometryFunction; import adql.query.operand.function.geometry.GeometryFunction.GeometryValue; public class TestPgSphereTranslator { Loading @@ -34,6 +40,18 @@ public class TestPgSphereTranslator { @After public void tearDown() throws Exception{} @Test public void testTranslateCentroidFunction(){ try{ PgSphereTranslator translator = new PgSphereTranslator(); CentroidFunction centfc = new CentroidFunction(new GeometryValue<GeometryFunction>(new CircleFunction(new StringConstant("ICRS"), new NumericConstant(128.23), new NumericConstant(0.53), new NumericConstant(2)))); assertEquals("center(scircle(spoint(radians(128.23),radians(0.53)),radians(2)))", translator.translate(centfc)); }catch(Throwable t){ t.printStackTrace(System.err); fail("An error occured while building a simple CentroidFunction! (see the console for more details)"); } } @Test public void testConvertTypeFromDB(){ PgSphereTranslator translator = new PgSphereTranslator(); Loading Loading
src/adql/query/operand/function/geometry/CentroidFunction.java +4 −4 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package adql.query.operand.function.geometry; * You should have received a copy of the GNU Lesser General Public License * along with ADQLLibrary. If not, see <http://www.gnu.org/licenses/>. * * Copyright 2012-2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Copyright 2012-2017 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Astronomisches Rechen Institut (ARI) */ Loading @@ -36,7 +36,7 @@ import adql.query.operand.ADQLOperand; * </i></p> * * @author Grégory Mantelet (CDS;ARI) * @version 1.4 (06/2015) * @version 1.4 (02/2017) */ public class CentroidFunction extends GeometryFunction { Loading Loading @@ -80,7 +80,7 @@ public class CentroidFunction extends GeometryFunction { @Override public boolean isNumeric(){ return true; return false; } @Override Loading @@ -90,7 +90,7 @@ public class CentroidFunction extends GeometryFunction { @Override public boolean isGeometry(){ return false; return true; } @Override Loading
src/adql/translator/PgSphereTranslator.java +17 −8 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package adql.translator; * You should have received a copy of the GNU Lesser General Public License * along with ADQLLibrary. If not, see <http://www.gnu.org/licenses/>. * * Copyright 2012-2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Copyright 2012-2017 - UDS/Centre de Données astronomiques de Strasbourg (CDS), * Astronomisches Rechen Institut (ARI) */ Loading @@ -34,6 +34,7 @@ import adql.query.constraint.Comparison; import adql.query.constraint.ComparisonOperator; import adql.query.operand.function.geometry.AreaFunction; import adql.query.operand.function.geometry.BoxFunction; import adql.query.operand.function.geometry.CentroidFunction; import adql.query.operand.function.geometry.CircleFunction; import adql.query.operand.function.geometry.ContainsFunction; import adql.query.operand.function.geometry.DistanceFunction; Loading @@ -48,7 +49,7 @@ import adql.query.operand.function.geometry.PolygonFunction; * The other functions are managed by {@link PostgreSQLTranslator}.</p> * * @author Grégory Mantelet (CDS;ARI) * @version 1.4 (07/2015) * @version 1.4 (07/2017) */ public class PgSphereTranslator extends PostgreSQLTranslator { Loading Loading @@ -174,6 +175,13 @@ public class PgSphereTranslator extends PostgreSQLTranslator { return str.toString(); } @Override public String translate(CentroidFunction centroidFunction) throws TranslationException{ StringBuffer str = new StringBuffer("center("); str.append(translate(centroidFunction.getParameter(0))).append(")"); return str.toString(); } @Override public String translate(ContainsFunction fct) throws TranslationException{ StringBuffer str = new StringBuffer("("); Loading Loading @@ -624,7 +632,8 @@ public class PgSphereTranslator extends PostgreSQLTranslator { end(); // Build the STC Box region: double width = Math.abs(northeast[0] - southwest[0]), height = Math.abs(northeast[1] - southwest[1]); double width = Math.abs(northeast[0] - southwest[0]), height = Math.abs(northeast[1] - southwest[1]); double[] center = new double[]{northeast[0] - width / 2,northeast[1] - height / 2}; return new Region(null, center, width, height); } Loading
test/adql/query/operand/function/geometry/TestCentroidFunction.java 0 → 100644 +28 −0 Original line number Diff line number Diff line package adql.query.operand.function.geometry; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.junit.Test; import adql.query.operand.NumericConstant; import adql.query.operand.StringConstant; import adql.query.operand.function.geometry.GeometryFunction.GeometryValue; public class TestCentroidFunction { @Test public void testIsGeometry(){ try{ CentroidFunction centfc = new CentroidFunction(new GeometryValue<GeometryFunction>(new CircleFunction(new StringConstant("ICRS"), new NumericConstant(128.23), new NumericConstant(0.53), new NumericConstant(2)))); assertTrue(centfc.isGeometry()); assertFalse(centfc.isNumeric()); assertFalse(centfc.isString()); }catch(Throwable t){ t.printStackTrace(System.err); fail("An error occured while building a simple CentroidFunction! (see the console for more details)"); } } }
test/adql/translator/TestPgSphereTranslator.java +18 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,12 @@ import adql.db.DBType; import adql.db.DBType.DBDatatype; import adql.db.STCS.Region; import adql.parser.ParseException; import adql.query.operand.NumericConstant; import adql.query.operand.StringConstant; import adql.query.operand.function.geometry.CentroidFunction; import adql.query.operand.function.geometry.CircleFunction; import adql.query.operand.function.geometry.GeometryFunction; import adql.query.operand.function.geometry.GeometryFunction.GeometryValue; public class TestPgSphereTranslator { Loading @@ -34,6 +40,18 @@ public class TestPgSphereTranslator { @After public void tearDown() throws Exception{} @Test public void testTranslateCentroidFunction(){ try{ PgSphereTranslator translator = new PgSphereTranslator(); CentroidFunction centfc = new CentroidFunction(new GeometryValue<GeometryFunction>(new CircleFunction(new StringConstant("ICRS"), new NumericConstant(128.23), new NumericConstant(0.53), new NumericConstant(2)))); assertEquals("center(scircle(spoint(radians(128.23),radians(0.53)),radians(2)))", translator.translate(centfc)); }catch(Throwable t){ t.printStackTrace(System.err); fail("An error occured while building a simple CentroidFunction! (see the console for more details)"); } } @Test public void testConvertTypeFromDB(){ PgSphereTranslator translator = new PgSphereTranslator(); Loading