/** * 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()); }
/** * Return a boolean value that shows weather the line is a ring or not. A line is a ring if it is * closed and simple. * * @param node xml element containing gml object(s) * @return boolean value * @throws QueryException query exception */ @Deterministic public Bln isRing(final ANode node) 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"); return Bln.get(((LineString) geo).isRing()); }
/** * Returns the start point of a line. * * @param node xml element containing gml object(s) * @return start point geometry as a gml element * @throws QueryException query exception */ @Deterministic public ANode startPoint(final ANode node) 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"); return gmlWriter(((LineString) geo).getStartPoint()); }
/** * Returns the z-coordinate value for point. * * @param node xml element containing gml object(s) * @return z double value * @throws QueryException query exception */ @Deterministic public Dbl z(final ANode node) throws QueryException { final Geometry geo = geo(node, Q_GML_POINT); if (geo == null && checkGeo(node) != null) throw GeoErrors.geoType(node.qname().local(), "Line"); return Dbl.get(geo.getCoordinate().z); }
/** * Reads an element as a gml node. Returns a geometry element or {@code null} if the element does * not match one of the specified types. * * @param node xml node containing gml object(s) * @param names allowed geometry types * @return geometry, or {@code null} * @throws QueryException query exception */ private static Geometry geo(final ANode node, final QNm... names) throws QueryException { if (node.type != NodeType.ELM) throw EXPTYPE_X_X_X.get(null, NodeType.ELM, node.type, node); final QNm qname = node.qname(); for (final QNm geo : names) { if (!qname.eq(geo)) continue; // type found... create reader and geometry element try { final String input = node.serialize().toString(); final GMLReader gmlReader = new GMLReader(); final GeometryFactory geoFactory = new GeometryFactory(); return gmlReader.read(input, geoFactory); } catch (final Throwable ex) { throw GeoErrors.gmlReaderErr(ex); } } return null; }
/** * 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)); }
/** * Checks if the line is closed loop. That is, if the start Point is same with end Point. * * @param node xml element containing gml object(s) * @return boolean value * @throws QueryException query exception */ @Deterministic public Bln isClosed(final ANode node) throws QueryException { final Geometry geo = geo(node, Q_GML_LINEARRING, Q_GML_LINESTRING, Q_GML_MULTILINESTRING); if (geo == null && checkGeo(node) != null) throw GeoErrors.geoType(node.qname().local(), "Line"); return Bln.get( geo instanceof LineString ? ((LineString) geo).isClosed() : ((MultiLineString) geo).isClosed()); }
/** * 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)); }
/** * Reads an element as a gml node. Returns a geometry element or throws an exception if the * element is of the wrong type. * * @param node xml node containing gml object(s) * @return geometry * @throws QueryException query exception */ private Geometry checkGeo(final ANode node) throws QueryException { final Geometry geo = geo(node, QNAMES); if (geo == null) throw GeoErrors.unrecognizedGeo(node.qname().local()); return geo; }