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 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); }
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); }
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 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 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<LineString> interiorRings = new ArrayList<LineString>(); for (int i = 0; i < first.length -1; i++) { List<Point> interior = new ArrayList<Point>(); for (final String pointCoo : split(first[i].substring(i==0?1:0, first[i].length()), ',')) { interior.add(newPoint(null, pointCoo, isNullable, maxLength, precision, scale, isUnicode)); } interiorRings.add(new LineString(dimension, srid, interior)); } final List<Point> exterior = new ArrayList<Point>(); for (final String pointCoo : split(first[first.length -1].substring(0, first[first.length -1].length() - 1), ',')) { exterior.add(newPoint(null, pointCoo, isNullable, maxLength, precision, scale, isUnicode)); } return new Polygon(dimension, srid, interiorRings, new LineString(dimension, srid, exterior)); }
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); }
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<LineString> intRings = new ArrayList<LineString>(); while (itor.hasNext()) { final Iterator<JsonNode> intItor = itor.next().elements(); if (intItor.hasNext()) { List<Point> intPoints = new ArrayList<Point>(); while (intItor.hasNext()) { final Iterator<JsonNode> mpItor = intItor.next().elements(); intPoints.add(point(mpItor, type, srid)); } intRings.add(new LineString(GeoUtils.getDimension(type), srid, intPoints)); } } LineString exterior = new LineString(GeoUtils.getDimension(type), srid, extPoints); return new Polygon(GeoUtils.getDimension(type), srid, intRings, exterior); }
private org.apache.olingo.commons.api.edm.geo.Polygon convertPolygon( Polygon polygon) throws AssertionError { if (polygon.getNumInteriorRing() > 1) { throw new AssertionError("Polygons with more than 1 interior rings are not supported by olingo"); //$NON-NLS-1$ } List<org.apache.olingo.commons.api.edm.geo.Point> interior = Collections.emptyList(); if (polygon.getNumInteriorRing() == 1) { interior = convertLineStringToPoints(polygon.getInteriorRingN(1).getCoordinates()); } List<org.apache.olingo.commons.api.edm.geo.Point> exterior = convertLineStringToPoints(polygon.getExteriorRing().getCoordinates()); return new org.apache.olingo.commons.api.edm.geo.Polygon(dimension, srid, interior, exterior); }
private org.apache.olingo.commons.api.edm.geo.Polygon convertPolygon( Polygon polygon) throws AssertionError { if (polygon.getNumInteriorRing() > 1) { throw new AssertionError("Polygons with more than 1 interior rings are not supported by olingo"); //$NON-NLS-1$ } List<org.apache.olingo.commons.api.edm.geo.Point> interior = Collections.emptyList(); if (polygon.getNumInteriorRing() == 1) { interior = convertLineStringToPoints(polygon.getInteriorRingN(1).getCoordinates()); } List<org.apache.olingo.commons.api.edm.geo.Point> exterior = convertLineStringToPoints(polygon.getExteriorRing().getCoordinates()); return new org.apache.olingo.commons.api.edm.geo.Polygon(dimension, srid, interior, exterior); }