private void writeGeoPolygon(JsonGenerator json, final Polygon polygon) throws IOException { json.writeStartArray(); writeGeoPoints(json, polygon.getExterior()); json.writeEndArray(); if (!polygon.getInterior().isEmpty()) { json.writeStartArray(); writeGeoPoints(json, polygon.getInterior()); json.writeEndArray(); } }
private Polygon readGeoPolygon(final String name, final Geospatial.Dimension dimension, JsonNode node) throws DeserializerException, EdmPrimitiveTypeException { // GeoJSON would allow for more than one interior polygon (hole). // But there is no place in the data object to store this information so for now we throw an error. // There could be a more strict verification that the lines describe boundaries and have the correct winding order. if (node.isArray() && (node.size() == 1 || node.size() == 2)) { return new Polygon(dimension, null, node.size() > 1 ? readGeoPointValues(name, dimension, 4, true, node.get(1)) : null, readGeoPointValues(name, dimension, 4, true, node.get(0))); } throw new DeserializerException("Invalid polygon values '" + node + "' in property: " + name, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name); }
private void writeGeoPolygon(JsonGenerator json, final Polygon polygon) throws IOException { json.writeStartArray(); writeGeoPoints(json, polygon.getExterior()); json.writeEndArray(); for (int i = 0; i < polygon.getNumberOfInteriorRings(); i++) { json.writeStartArray(); writeGeoPoints(json, polygon.getInterior(i)); json.writeEndArray(); } }
protected String toString(final Polygon polygon, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (dimension != polygon.getDimension()) { throw new EdmPrimitiveTypeException("The value '" + polygon + "' is not valid."); } return toStringBuilder(polygon.getSrid()). append(reference.getSimpleName()). append('('). append(polygon(polygon, isNullable, maxLength, precision, scale, isUnicode)). append(")'").toString(); }
/** * Gets interior points. * * @return interior points. * @deprecated * @see #getInterior(int) */ public ComposedGeospatial<Point> getInterior() { if (interiorRings == null || interiorRings.geospatials.isEmpty()) { return null; } return getInterior(0); }
protected String toString(final Polygon polygon, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { if (dimension != polygon.getDimension()) { throw new EdmPrimitiveTypeException("The value '" + polygon + "' is not valid."); } return toStringBuilder(polygon.getSrid()). append(reference.getSimpleName()). append('('). append(polygon(polygon, isNullable, maxLength, precision, scale, isUnicode)). append(")'").toString(); }
private void polygon(final JsonGenerator jgen, final Polygon polygon) throws IOException { if (!polygon.getExterior().isEmpty()) { jgen.writeStartArray(); lineString(jgen, polygon.getExterior()); jgen.writeEndArray(); } if (!polygon.getInterior().isEmpty()) { jgen.writeStartArray(); lineString(jgen, polygon.getInterior()); jgen.writeEndArray(); } }
private void polygon(final JsonGenerator jgen, final Polygon polygon) throws IOException { jgen.writeStartArray(); lineString(jgen, polygon.getExterior()); jgen.writeEndArray(); for (int i = 0; i < polygon.getNumberOfInteriorRings(); i++) { jgen.writeStartArray(); lineString(jgen, polygon.getInterior(i)); jgen.writeEndArray(); } }
private Polygon readGeoPolygon(final String name, final Geospatial.Dimension dimension, JsonNode node, SRID srid) throws DeserializerException, EdmPrimitiveTypeException { // GeoJSON would allow for more than one interior polygon (hole). // But there is no place in the data object to store this information so for now we throw an error. // There could be a more strict verification that the lines describe boundaries and have the correct winding order. if (node.isArray() && (node.size() == 1 || node.size() == 2)) { return new Polygon(dimension, srid, node.size() > 1 ? readGeoPointValues(name, dimension, 4, true, node.get(1)) : null, readGeoPointValues(name, dimension, 4, true, node.get(0))); } throw new DeserializerException("Invalid polygon values '" + node + "' in property: " + name, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name); }
static private com.vividsolutions.jts.geom.Polygon convertPolygon( Polygon polygon) throws AssertionError { Coordinate[] coords = convertLineStringToPoints(polygon.getExterior()); LinearRing shell = GeometryUtils.GEOMETRY_FACTORY.createLinearRing(coords); LinearRing[] holes = null; if (polygon.getInterior() != null && polygon.getInterior().isEmpty()) { holes = new LinearRing[1]; holes[0] = GeometryUtils.GEOMETRY_FACTORY.createLinearRing(convertLineStringToPoints(polygon.getExterior())); } return GeometryUtils.GEOMETRY_FACTORY.createPolygon(shell, holes); }
private String polygon(final Polygon polygon, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { final StringBuilder result = new StringBuilder(); for (int i = 0; i < polygon.getNumberOfInteriorRings(); i++) { result.append('('); appendPoints(polygon.getInterior(i), isNullable, maxLength, precision, scale, isUnicode, result); result.append("),"); } result.append('('); appendPoints(polygon.getExterior(), isNullable, maxLength, precision, scale, isUnicode, result); return result.append(')').toString(); }
private Polygon newPolygon(final SRID srid, final String polygon, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { final String[] first = polygon.split("\\),\\("); final List<Point> interior = new ArrayList<Point>(); for (final String pointCoo : split(first[0].substring(1, first[0].length()), ',')) { interior.add(newPoint(null, pointCoo, isNullable, maxLength, precision, scale, isUnicode)); } final List<Point> exterior = new ArrayList<Point>(); for (final String pointCoo : split(first[1].substring(0, first[1].length() - 1), ',')) { exterior.add(newPoint(null, pointCoo, isNullable, maxLength, precision, scale, isUnicode)); } return new Polygon(dimension, srid, interior, exterior); }
static private com.vividsolutions.jts.geom.Polygon convertPolygon( Polygon polygon) throws AssertionError { Coordinate[] coords = convertLineStringToPoints(polygon.getExterior()); LinearRing shell = GeometryUtils.GEOMETRY_FACTORY.createLinearRing(coords); LinearRing[] holes = null; if (polygon.getInterior() != null && polygon.getInterior().isEmpty()) { holes = new LinearRing[1]; holes[0] = GeometryUtils.GEOMETRY_FACTORY.createLinearRing(convertLineStringToPoints(polygon.getExterior())); } return GeometryUtils.GEOMETRY_FACTORY.createPolygon(shell, holes); }
private void polygons(final XMLStreamWriter writer, final Iterator<Polygon> itor, final boolean wrap) throws XMLStreamException { while (itor.hasNext()) { final Polygon polygon = itor.next(); if (wrap) { writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON, Constants.NS_GML); } if (!polygon.getExterior().isEmpty()) { writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON_EXTERIOR, Constants.NS_GML); writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON_LINEARRING, Constants.NS_GML); points(writer, polygon.getExterior().iterator(), false); writer.writeEndElement(); writer.writeEndElement(); } for (int i = 0; i < polygon.getNumberOfInteriorRings(); i++) { writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON_INTERIOR, Constants.NS_GML); writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON_LINEARRING, Constants.NS_GML); points(writer, polygon.getInterior(i).iterator(), false); writer.writeEndElement(); writer.writeEndElement(); } if (wrap) { writer.writeEndElement(); } } }
private Polygon polygon(final XMLEventReader reader, final StartElement start, final EdmPrimitiveTypeKind type, final SRID srid) throws XMLStreamException { List<Point> extPoints = null; List<Point> intPoints = null; boolean foundEndProperty = false; while (reader.hasNext() && !foundEndProperty) { final XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { if (event.asStartElement().getName().equals(Constants.QNAME_POLYGON_EXTERIOR)) { extPoints = points(reader, event.asStartElement(), type, null); } if (event.asStartElement().getName().equals(Constants.QNAME_POLYGON_INTERIOR)) { intPoints = points(reader, event.asStartElement(), type, null); } } if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) { foundEndProperty = true; } } return new Polygon(GeoUtils.getDimension(type), srid, intPoints, extPoints); }
private String polygon(final Polygon polygon, final Boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException { final StringBuilder result = new StringBuilder(); result.append('('); for (final Iterator<Point> itor = polygon.getInterior().iterator(); itor.hasNext();) { result.append(point(itor.next(), isNullable, maxLength, precision, scale, isUnicode)); if (itor.hasNext()) { result.append(','); } } result.append("),("); for (final Iterator<Point> itor = polygon.getExterior().iterator(); itor.hasNext();) { result.append(point(itor.next(), isNullable, maxLength, precision, scale, isUnicode)); if (itor.hasNext()) { result.append(','); } } return result.append(')').toString(); }
private Polygon polygon(final Iterator<JsonNode> itor, final EdmPrimitiveTypeKind type, final SRID srid) { List<Point> extPoints = null; if (itor.hasNext()) { final Iterator<JsonNode> extItor = itor.next().elements(); if (extItor.hasNext()) { extPoints = new ArrayList<Point>(); while (extItor.hasNext()) { final Iterator<JsonNode> mpItor = extItor.next().elements(); extPoints.add(point(mpItor, type, srid)); } } } List<Point> intPoints = null; if (itor.hasNext()) { final Iterator<JsonNode> intItor = itor.next().elements(); if (intItor.hasNext()) { intPoints = new ArrayList<Point>(); while (intItor.hasNext()) { final Iterator<JsonNode> mpItor = intItor.next().elements(); intPoints.add(point(mpItor, type, srid)); } } } return new Polygon(GeoUtils.getDimension(type), srid, intPoints, extPoints); }
private void polygons(final XMLStreamWriter writer, final Iterator<Polygon> itor, final boolean wrap) throws XMLStreamException { while (itor.hasNext()) { final Polygon polygon = itor.next(); if (wrap) { writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON, Constants.NS_GML); } if (!polygon.getExterior().isEmpty()) { writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON_EXTERIOR, Constants.NS_GML); writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON_LINEARRING, Constants.NS_GML); points(writer, polygon.getExterior().iterator(), false); writer.writeEndElement(); writer.writeEndElement(); } if (!polygon.getInterior().isEmpty()) { writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON_INTERIOR, Constants.NS_GML); writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POLYGON_LINEARRING, Constants.NS_GML); points(writer, polygon.getInterior().iterator(), false); writer.writeEndElement(); writer.writeEndElement(); } if (wrap) { writer.writeEndElement(); } } }
private Polygon polygon(final XMLEventReader reader, final StartElement start, final EdmPrimitiveTypeKind type, final SRID srid) throws XMLStreamException { LineString extPoints = null; List<LineString> intRings = new ArrayList<LineString>(); boolean foundEndProperty = false; while (reader.hasNext() && !foundEndProperty) { final XMLEvent event = reader.nextEvent(); if (event.isStartElement()) { if (event.asStartElement().getName().equals(Constants.QNAME_POLYGON_EXTERIOR)) { List<Point> points = points(reader, event.asStartElement(), type, null); extPoints = new LineString(GeoUtils.getDimension(type), srid, points); } if (event.asStartElement().getName().equals(Constants.QNAME_POLYGON_INTERIOR)) { List<Point> points = points(reader, event.asStartElement(), type, null); intRings.add(new LineString(GeoUtils.getDimension(type), srid, points)); } } if (event.isEndElement() && start.getName().equals(event.asEndElement().getName())) { foundEndProperty = true; } } return new Polygon(GeoUtils.getDimension(type), srid, intRings, extPoints); }
@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); }