private ArrayList<org.apache.olingo.commons.api.edm.geo.Point> convertLineStringToPoints( Coordinate[] lineString) { ArrayList<org.apache.olingo.commons.api.edm.geo.Point> points = new ArrayList<>(lineString.length); for (Coordinate c : lineString) { org.apache.olingo.commons.api.edm.geo.Point p = new org.apache.olingo.commons.api.edm.geo.Point(dimension, srid); p.setX(c.x); p.setY(c.y); } return points; }
private String point(final Point point, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { return new StringBuilder(). append(EdmDouble.getInstance().valueToString(point.getX(), isNullable, maxLength, precision, scale, isUnicode)). append(' '). append(EdmDouble.getInstance().valueToString(point.getY(), isNullable, maxLength, precision, scale, isUnicode)). toString(); }
private Point readGeoPointValue(final String name, final Geospatial.Dimension dimension, JsonNode node) throws DeserializerException, EdmPrimitiveTypeException { if (node.isArray() && (node.size() ==2 || node.size() == 3) && node.get(0).isNumber() && node.get(1).isNumber() && (node.get(2) == null || node.get(2).isNumber())) { Point point = new Point(dimension, null); point.setX(getDoubleValue(node.get(0).asText())); point.setY(getDoubleValue(node.get(1).asText())); if (node.get(2) != null) { point.setZ(getDoubleValue(node.get(2).asText())); } return point; } throw new DeserializerException("Invalid point value '" + node + "' in property: " + name, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name); }
@Test public void testPolygon() throws EdmPrimitiveTypeException { ODataWKTWriter writer = new ODataWKTWriter(); GeometryFactory factory = new GeometryFactory(); Polygon polygon = factory .createPolygon( factory.createLinearRing(new Coordinate[] { new Coordinate(0, 0), new Coordinate(3, 0), new Coordinate(3, 3), new Coordinate(0, 3), new Coordinate(0, 0) }), new LinearRing[] { factory.createLinearRing( new Coordinate[] { new Coordinate(1, 1), new Coordinate(2, 1), new Coordinate(2, 2), new Coordinate(1, 2), new Coordinate(1, 1) }) }); //hole first, no space between rings assertEquals("Polygon((1.0 1.0,2.0 1.0,2.0 2.0,1.0 2.0,1.0 1.0)," + "(0.0 0.0,3.0 0.0,3.0 3.0,0.0 3.0,0.0 0.0))", writer.write(polygon)); String uriValue = ODataTypeManager.geometryToODataValueString(polygon, true); org.apache.olingo.commons.api.edm.geo.Polygon olingoPolygon = (org.apache.olingo.commons.api.edm.geo.Polygon) EdmGeometryPolygon.getInstance().valueOfString(uriValue, null, null, null, null, null, EdmGeometryPolygon.getInstance().getDefaultType()); assertEquals(0, olingoPolygon.getExterior().iterator().next().getX(), 0); assertEquals(1, olingoPolygon.getInterior().iterator().next().getX(), 0); }
private String point(final Point point, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { return new StringBuilder(). append(EdmDouble.getInstance().valueToString(point.getX(), isNullable, maxLength, precision, scale, isUnicode)). append(' '). append(EdmDouble.getInstance().valueToString(point.getY(), isNullable, maxLength, precision, scale, isUnicode)). toString(); }
private Point readGeoPointValue(final String name, final Geospatial.Dimension dimension, JsonNode node, SRID srid) throws DeserializerException, EdmPrimitiveTypeException { if (node.isArray() && (node.size() ==2 || node.size() == 3) && node.get(0).isNumber() && node.get(1).isNumber() && (node.get(2) == null || node.get(2).isNumber())) { Point point = new Point(dimension, srid); point.setX(getDoubleValue(node.get(0).asText())); point.setY(getDoubleValue(node.get(1).asText())); if (node.get(2) != null) { point.setZ(getDoubleValue(node.get(2).asText())); } return point; } throw new DeserializerException("Invalid point value '" + node + "' in property: " + name, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name); }
private ArrayList<org.apache.olingo.commons.api.edm.geo.Point> convertLineStringToPoints( Coordinate[] lineString) { ArrayList<org.apache.olingo.commons.api.edm.geo.Point> points = new ArrayList<>(lineString.length); for (Coordinate c : lineString) { org.apache.olingo.commons.api.edm.geo.Point p = new org.apache.olingo.commons.api.edm.geo.Point(dimension, srid); p.setX(c.x); p.setY(c.y); } return points; }
private void point(final JsonGenerator jgen, final Point point) throws IOException { try { jgen.writeNumber(EdmDouble.getInstance().valueToString(point.getX(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)); jgen.writeNumber(EdmDouble.getInstance().valueToString(point.getY(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)); } catch (EdmPrimitiveTypeException e) { throw new IllegalArgumentException("While serializing point coordinates as double", e); } }
private Point point(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type, final SRID srid) { Point point = null; if (itor.hasNext()) { point = new Point(GeoUtils.getDimension(type), srid); try { point.setX(EdmDouble.getInstance().valueOfString(itor.next().asText(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, Double.class)); point.setY(EdmDouble.getInstance().valueOfString(itor.next().asText(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, Double.class)); } catch (EdmPrimitiveTypeException e) { throw new IllegalArgumentException("While deserializing point coordinates as double", e); } } return point; }
private void point(final JsonGenerator jgen, final Point point) throws IOException { try { jgen.writeNumber(EdmDouble.getInstance().valueToString(point.getX(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)); jgen.writeNumber(EdmDouble.getInstance().valueToString(point.getY(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)); } catch (EdmPrimitiveTypeException e) { throw new IllegalArgumentException("While serializing point coordinates as double", e); } }
private Point point(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type, final SRID srid) { Point point = null; if (itor.hasNext()) { point = new Point(GeoUtils.getDimension(type), srid); try { point.setX(EdmDouble.getInstance().valueOfString(itor.next().asText(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, Double.class)); point.setY(EdmDouble.getInstance().valueOfString(itor.next().asText(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null, Double.class)); } catch (EdmPrimitiveTypeException e) { throw new IllegalArgumentException("While deserializing point coordinates as double", e); } } return point; }
private void points(final XMLStreamWriter writer, final Iterator<Point> itor, final boolean wrap) throws XMLStreamException { while (itor.hasNext()) { final Point point = itor.next(); if (wrap) { writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POINT, Constants.NS_GML); } writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POS, Constants.NS_GML); try { writer.writeCharacters(EdmDouble.getInstance().valueToString(point.getX(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null) + " " + EdmDouble.getInstance().valueToString(point.getY(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)); } catch (EdmPrimitiveTypeException e) { throw new XMLStreamException("While serializing point coordinates as double", e); } writer.writeEndElement(); if (wrap) { writer.writeEndElement(); } } }
private Point newPoint(final SRID srid, final String point, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { final List<String> pointCoo = split(point, ' '); if (pointCoo == null || pointCoo.size() != 2) { throw new EdmPrimitiveTypeException("The literal '" + point + "' has illegal content."); } final Point result = new Point(this.dimension, srid); result.setX(EdmDouble.getInstance().valueOfString(pointCoo.get(0), isNullable, maxLength, precision, scale, isUnicode, Double.class)); result.setY(EdmDouble.getInstance().valueOfString(pointCoo.get(1), isNullable, maxLength, precision, scale, isUnicode, Double.class)); return result; }
private void points(final XMLStreamWriter writer, final Iterator<Point> itor, final boolean wrap) throws XMLStreamException { while (itor.hasNext()) { final Point point = itor.next(); if (wrap) { writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POINT, Constants.NS_GML); } writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POS, Constants.NS_GML); try { writer.writeCharacters(EdmDouble.getInstance().valueToString(point.getX(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null) + " " + EdmDouble.getInstance().valueToString(point.getY(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null)); } catch (EdmPrimitiveTypeException e) { throw new XMLStreamException("While serializing point coordinates as double", e); } writer.writeEndElement(); if (wrap) { writer.writeEndElement(); } } }
private Point newPoint(final SRID srid, final String point, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { final List<String> pointCoo = split(point, ' '); if (pointCoo == null || pointCoo.size() != 2) { throw new EdmPrimitiveTypeException("The literal '" + point + "' has illegal content."); } final Point result = new Point(this.dimension, srid); result.setX(EdmDouble.getInstance().valueOfString(pointCoo.get(0), isNullable, maxLength, precision, scale, isUnicode, Double.class)); result.setY(EdmDouble.getInstance().valueOfString(pointCoo.get(1), isNullable, maxLength, precision, scale, isUnicode, Double.class)); return result; }