/** * Returns the nth geometry of a geometry collection, or the geometry if the input is not a * collection. * * @param node xml element containing gml object(s) * @param number integer number as the index of nth geometry * @return geometry as a gml element * @throws QueryException query exception */ @Deterministic public ANode geometryN(final ANode node, final Int number) throws QueryException { final Geometry geo = checkGeo(node); final long n = number.itr(); if (n < 1 || n > geo.getNumGeometries()) throw GeoErrors.outOfRangeIdx(number); return gmlWriter(geo.getGeometryN((int) n - 1)); }
/** * Runs a query with an external variable declaration. * * @throws IOException I/O exception */ @Test public void queryBindSequence() throws IOException { Query query = session.query("declare variable $a external; $a"); query.bind("a", "1\u00012", "xs:integer"); assertEqual("1", query.next()); assertEqual("2", query.next()); query.close(); query = session.query("declare variable $a external; $a"); query.bind("a", "09\u0002xs:hexBinary\u00012", "xs:integer"); assertEqual("09", query.next()); assertEqual("2", query.next()); query.close(); query = session.query("declare variable $a external; $a"); query.bind("a", Seq.get(new Item[] {Int.get(1), Str.get("X")}, 2)); assertEqual("1", query.next()); assertEqual("X", query.next()); query.close(); query = session.query("declare variable $a external; $a"); query.bind("a", IntSeq.get(new long[] {1, 2}, AtomType.INT)); assertEqual("1", query.next()); assertEqual("2", query.next()); query.close(); query = session.query("declare variable $a external; $a"); query.bind("a", IntSeq.get(new long[] {1, 2}, AtomType.INT), "xs:integer"); assertEqual("1", query.next()); assertEqual("2", query.next()); query.close(); }
/** * Returns the number of interior rings in a polygon. * * @param node xml element containing gml object(s) * @return integer number of interior rings * @throws QueryException query exception */ @Deterministic public Int numInteriorRing(final ANode node) throws QueryException { final Geometry geo = geo(node, Q_GML_POLYGON); if (geo == null && checkGeo(node) != null) throw GeoErrors.geoType(node.qname().local(), "Polygon"); return Int.get(((Polygon) geo).getNumInteriorRing()); }
/** * Returns the nth geometry of a geometry collection. * * @param node xml element containing gml object(s) * @param number index of i-th interior ring * @return n-th interior ring geometry (LineString) as a gml element * @throws QueryException query exception */ @Deterministic public ANode interiorRingN(final ANode node, final Int number) throws QueryException { final Geometry geo = geo(node, Q_GML_POLYGON); if (geo == null && checkGeo(node) != null) throw GeoErrors.geoType(node.qname().local(), "Polygon"); final long n = number.itr(); final int max = ((Polygon) geo).getNumInteriorRing(); if (n < 1 || n > max) throw GeoErrors.outOfRangeIdx(number); return gmlWriter(((Polygon) geo).getInteriorRingN((int) n - 1)); }
/** * Returns the nth point of a line. * * @param node xml element containing gml object(s) * @param number index of i-th point * @return n-th point as a gml element * @throws QueryException query exception */ @Deterministic public ANode pointN(final ANode node, final Int number) throws QueryException { final Geometry geo = geo(node, Q_GML_LINEARRING, Q_GML_LINESTRING); if (geo == null && checkGeo(node) != null) throw GeoErrors.geoType(node.qname().local(), "Line"); final int max = geo.getNumPoints(); final long n = number.itr(); if (n < 1 || n > max) throw GeoErrors.outOfRangeIdx(number); return gmlWriter(((LineString) geo).getPointN((int) n - 1)); }
/** * Runs a query with an external variable declaration. * * @throws IOException I/O exception */ @Test public void queryBindInt() throws IOException { Query query = session.query("declare variable $a as xs:integer external; $a"); query.bind("a", "5", "xs:integer"); assertEqual("5", query.next()); query.close(); query = session.query("declare variable $a external; $a"); query.bind("a", Int.get(1), "xs:integer"); assertEqual("1", query.next()); query.close(); }
/** * Returns the dimension of an item. * * @param node xml element containing gml object(s) * @return dimension * @throws QueryException query exception */ @Deterministic public Int dimension(final ANode node) throws QueryException { return Int.get(checkGeo(node).getDimension()); }
/** * Returns the number of points in a geometry. * * @param node xml element containing gml object(s) * @return number of points int value * @throws QueryException query exception */ @Deterministic public Int numPoints(final ANode node) throws QueryException { return Int.get(checkGeo(node).getNumPoints()); }
/** * Returns a database function for the first node in a node set. * * @param n node set * @param i offset * @return function string */ static String openPre(final Nodes n, final int i) { return Function._DB_OPEN_PRE.get(Str.get(n.data.meta.name), Int.get(n.pres[i])).toString(); }
@Override Item key(final QueryContext ctx, final int i) { return Int.get(i); }