private Polygon parsePolygon(List<Object> coordinates) throws ParseException { List<Polygon> holes = new ArrayList<>(); Object o = coordinates.get(0); if (o instanceof List == false) { throw newParseException("first element of polygon array must be an array [[lat, lon], [lat, lon] ...] but got: " + o); } double[][] polyPoints = parsePoints((List<Object>) o); for(int i=1;i<coordinates.size();i++) { o = coordinates.get(i); if (o instanceof List == false) { throw newParseException("elements of coordinates array must be an array [[lat, lon], [lat, lon] ...] but got: " + o); } double[][] holePoints = parsePoints((List<Object>) o); holes.add(new Polygon(holePoints[0], holePoints[1])); } return new Polygon(polyPoints[0], polyPoints[1], holes.toArray(new Polygon[holes.size()])); }
/** Builds a Polygon2D from multipolygon */ public static Polygon2D create(Polygon... polygons) { Polygon2D components[] = new Polygon2D[polygons.length]; for (int i = 0; i < components.length; i++) { Polygon gon = polygons[i]; Polygon gonHoles[] = gon.getHoles(); Polygon2D holes = null; if (gonHoles.length > 0) { holes = create(gonHoles); } components[i] = new Polygon2D(gon, holes); } return (Polygon2D)createTree(components, 0, components.length - 1, false); }
private Polygon2D(Polygon polygon, Polygon2D holes) { super(polygon.minLat, polygon.maxLat, polygon.minLon, polygon.maxLon, polygon.getPolyLats(), polygon.getPolyLons()); this.holes = holes; }
/** * Convert a list of polygons to a list of polygon descriptions. * @param polygons is the list of polygons to convert. * @return the list of polygon descriptions. */ private static List<GeoPolygonFactory.PolygonDescription> convertToDescription(final Polygon... polygons) { final List<GeoPolygonFactory.PolygonDescription> descriptions = new ArrayList<>(polygons.length); for (final Polygon polygon : polygons) { final Polygon[] theHoles = polygon.getHoles(); final List<GeoPolygonFactory.PolygonDescription> holes = convertToDescription(theHoles); // Now do the polygon itself final double[] polyLats = polygon.getPolyLats(); final double[] polyLons = polygon.getPolyLons(); // I presume the arguments have already been checked final List<GeoPoint> points = new ArrayList<>(polyLats.length-1); // We skip the last point anyway because the API requires it to be repeated, and geo3d doesn't repeat it. for (int i = 0; i < polyLats.length - 1; i++) { final int index = polyLats.length - 2 - i; points.add(new GeoPoint(PlanetModel.WGS84, fromDegrees(polyLats[index]), fromDegrees(polyLons[index]))); } descriptions.add(new GeoPolygonFactory.PolygonDescription(points, holes)); } return descriptions; }
protected Node(final Polygon polygon, final int index, final int vertexIndex) { this.idx = index; this.vrtxIdx = vertexIndex; this.polygon = polygon; this.y = encodeLatitude(polygon.getPolyLat(vrtxIdx)); this.x = encodeLongitude(polygon.getPolyLon(vrtxIdx)); this.morton = BitUtil.interleave(x ^ 0x80000000, y ^ 0x80000000); this.previous = null; this.next = null; this.previousZ = null; this.nextZ = null; }
/** prints polygons as geojson */ public String toGeoJSON() { StringBuilder sb = new StringBuilder(); sb.append("["); sb.append(verticesToGeoJSON(polyLats, polyLons)); for (Polygon hole : holes) { sb.append(","); sb.append(verticesToGeoJSON(hole.polyLats, hole.polyLons)); } sb.append("]"); return sb.toString(); }
/** get the latitude value */ public final double getLat() { return polygon.getPolyLat(vrtxIdx); }
final Polygon[] theHoles = polygon.getHoles(); final List<GeoPolygon> holeList = new ArrayList<>(theHoles.length); for (final Polygon hole : theHoles) { final double[] polyLats = polygon.getPolyLats(); final double[] polyLons = polygon.getPolyLons();
protected Node(final Polygon polygon, final int index, final int vertexIndex) { this.idx = index; this.vrtxIdx = vertexIndex; this.polygon = polygon; this.y = encodeLatitude(polygon.getPolyLat(vrtxIdx)); this.x = encodeLongitude(polygon.getPolyLon(vrtxIdx)); this.morton = BitUtil.interleave(x ^ 0x80000000, y ^ 0x80000000); this.previous = null; this.next = null; this.previousZ = null; this.nextZ = null; }
/** prints polygons as geojson */ public String toGeoJSON() { StringBuilder sb = new StringBuilder(); sb.append("["); sb.append(verticesToGeoJSON(polyLats, polyLons)); for (Polygon hole : holes) { sb.append(","); sb.append(verticesToGeoJSON(hole.polyLats, hole.polyLons)); } sb.append("]"); return sb.toString(); }
/** get the y value */ public final double getY() { return polygon.getPolyLat(vrtxIdx); }
public Object toPolygonLucene() { final org.apache.lucene.geo.Polygon[] holes = new org.apache.lucene.geo.Polygon[this.holes.size()]; for (int i = 0; i < holes.length; ++i) { holes[i] = linearRing(this.holes.get(i).coordinates); } return new org.apache.lucene.geo.Polygon(this.shell.coordinates.stream().mapToDouble(i -> normalizeLat(i.y)).toArray(), this.shell.coordinates.stream().mapToDouble(i -> normalizeLon(i.x)).toArray(), holes); }
private Polygon2D(Polygon polygon, Polygon2D holes) { super(polygon.minLat, polygon.maxLat, polygon.minLon, polygon.maxLon, polygon.getPolyLats(), polygon.getPolyLons()); this.holes = holes; }
/** Builds a Polygon2D from multipolygon */ public static Polygon2D create(Polygon... polygons) { Polygon2D components[] = new Polygon2D[polygons.length]; for (int i = 0; i < components.length; i++) { Polygon gon = polygons[i]; Polygon gonHoles[] = gon.getHoles(); Polygon2D holes = null; if (gonHoles.length > 0) { holes = create(gonHoles); } components[i] = new Polygon2D(gon, holes); } return (Polygon2D)createTree(components, 0, components.length - 1, false); }
/** prints polygons as geojson */ public String toGeoJSON() { StringBuilder sb = new StringBuilder(); sb.append("["); sb.append(Polygon.verticesToGeoJSON(lats, lons)); sb.append("]"); return sb.toString(); } }
/** get the latitude value */ public final double getLat() { return polygon.getPolyLat(vrtxIdx); }