AI2 Component  (Version nb184)
GeometryUtil.java
Go to the documentation of this file.
1 // -*- mode: java; c-basic-offset: 2; -*-
2 // Copyright © 2017 Massachusetts Institute of Technology, All rights reserved.
3 // Released under the Apache License, Version 2.0
4 // http://www.apache.org/licenses/LICENSE-2.0
5 
6 package com.google.appinventor.components.runtime.util;
7 
10 import org.json.JSONArray;
11 import org.json.JSONException;
12 import org.locationtech.jts.geom.Coordinate;
13 import org.locationtech.jts.geom.Geometry;
14 import org.locationtech.jts.geom.GeometryFactory;
15 import org.locationtech.jts.geom.LineString;
16 import org.locationtech.jts.geom.LinearRing;
17 import org.locationtech.jts.geom.Point;
18 import org.locationtech.jts.geom.Polygon;
19 import org.locationtech.jts.geom.PrecisionModel;
20 import org.osmdroid.api.IGeoPoint;
21 
27 import org.osmdroid.util.GeoPoint;
28 
29 import java.util.ArrayList;
30 import java.util.Iterator;
31 import java.util.LinkedList;
32 import java.util.List;
33 
40 @SuppressWarnings("WeakerAccess")
41 public final class GeometryUtil {
42 
43  public static final double EARTH_RADIUS = 6378137.0;
44  public static final double ONE_DEG_IN_METERS = EARTH_RADIUS * Math.PI / 180.0;
45  public static final int WEB_MERCATOR_SRID = 4326;
46  private static final GeometryFactory FACTORY =
47  new GeometryFactory(new PrecisionModel(), WEB_MERCATOR_SRID);
48 
49  private GeometryUtil() {
50  }
51 
52  public static double coerceToDouble(Object o) {
53  if (o instanceof Number) {
54  return ((Number) o).doubleValue();
55  } else {
56  try {
57  return Double.parseDouble(o.toString());
58  } catch(NumberFormatException e) {
59  return Double.NaN;
60  }
61  }
62  }
63 
64  public static GeoPoint coerceToPoint(Object lat, Object lng) {
65  double latitude = coerceToDouble(lat);
66  double longitude = coerceToDouble(lng);
67  if (Double.isNaN(latitude)) {
68  throw new IllegalArgumentException("Latitude must be a numeric.");
69  } else if (Double.isNaN(longitude)) {
70  throw new IllegalArgumentException("Longitude must be a numeric.");
71  } else if (latitude < -90.0 || latitude > 90.0) {
72  throw new IllegalArgumentException("Latitude must be between -90 and 90.");
73  } else if (longitude < -180.0 || longitude > 180.0) {
74  throw new IllegalArgumentException("Longitude must be between -180 and 180.");
75  } else {
76  return new GeoPoint(latitude, longitude);
77  }
78  }
79 
80  public static YailList asYailList(IGeoPoint point) {
81  return YailList.makeList(new Object[] { point.getLatitude(), point.getLongitude() });
82  }
83 
84  public static YailList pointsListToYailList(List<? extends IGeoPoint> points) {
85  List<YailList> entries = new ArrayList<YailList>();
86  for (IGeoPoint point : points) {
87  entries.add(asYailList(point));
88  }
89  return YailList.makeList(entries);
90  }
91 
92  public static GeoPoint pointFromYailList(YailList point) {
93  if (point.length() < 3) {
95  2, point.length() - 1);
96  }
97  try {
98  return GeometryUtil.coerceToPoint(point.get(1), point.get(2));
99  } catch(IllegalArgumentException e) {
100  throw new DispatchableError(ErrorMessages.ERROR_INVALID_POINT, point.get(1), point.get(2));
101  }
102  }
103 
104  public static List<GeoPoint> pointsFromYailList(YailList points) {
105  List<GeoPoint> newPoints = new ArrayList<GeoPoint>();
106  Iterator<?> it = points.iterator();
107  int i = 1;
108  it.next(); // skip *list* at index 0
109  while (it.hasNext()) {
110  try {
111  newPoints.add(pointFromYailList(TypeUtil.castNotNull(it.next(), YailList.class, "list")));
112  i++;
113  } catch(DispatchableError e) {
114  throw IterationError.fromError(i, e);
115  }
116  }
117  return newPoints;
118  }
119 
120  public static Geometry createGeometry(GeoPoint point) {
121  return FACTORY.createPoint(geoPointToCoordinate(point));
122  }
123 
124  public static Geometry createGeometry(List<GeoPoint> line) {
125  return FACTORY.createLineString(pointsToCoordinates(line));
126  }
127 
128  public static Geometry createGeometry(double north, double east, double south, double west) {
129  return FACTORY.createPolygon(new Coordinate[]{
130  new Coordinate(east, north),
131  new Coordinate(east, south),
132  new Coordinate(west, south),
133  new Coordinate(west, north),
134  new Coordinate(east, north)
135  });
136  }
137 
138  public static Geometry createGeometry(List<List<GeoPoint>> points, List<List<List<GeoPoint>>> holes) {
139  if (points == null) {
140  throw new IllegalArgumentException("points must not be null.");
141  }
142  if (holes != null && !holes.isEmpty() && holes.size() != points.size()) {
143  throw new IllegalArgumentException("holes must either be null or the same length as points.");
144  }
145  Polygon[] polygons = new Polygon[points.size()];
146  int i = 0;
147  if (holes == null || holes.isEmpty()) {
148  for (List<GeoPoint> ring : points) {
149  polygons[i++] = ringToPolygon(ring);
150  }
151  } else {
152  Iterator<List<GeoPoint>> ip = points.iterator();
153  Iterator<List<List<GeoPoint>>> jp = holes.iterator();
154  while (ip.hasNext()) {
155  polygons[i++] = ringToPolygon(ip.next(), jp.next());
156  }
157  }
158  return polygons.length == 1 ? polygons[0] : FACTORY.createMultiPolygon(polygons);
159  }
160 
161  public static GeoPoint getMidpoint(List<GeoPoint> points) {
162  if (points.isEmpty()) {
163  // no points?
164  return new GeoPoint(0.0, 0.0);
165  } else if (points.size() == 1) {
166  return new GeoPoint(points.get(0));
167  }
168  LineString ls = FACTORY.createLineString(pointsToCoordinates(points));
169  return jtsPointToGeoPoint(ls.getCentroid());
170  }
171 
186  public static GeoPoint getCentroid(List<List<GeoPoint>> points, List<List<List<GeoPoint>>> holes) {
187  return jtsPointToGeoPoint(createGeometry(points, holes).getCentroid());
188  }
189 
190  public static Polygon ringToPolygon(List<GeoPoint> ring) {
191  return FACTORY.createPolygon(geoPointsToLinearRing(ring));
192  }
193 
194  public static Coordinate[] pointsToCoordinates(List<GeoPoint> points) {
195  boolean closed = points.get(0).equals(points.get(points.size() - 1));
196  Coordinate[] coordinates = new Coordinate[points.size() + (closed ? 0 : 1)];
197  int i = 0;
198  for (GeoPoint p : points) {
199  coordinates[i++] = geoPointToCoordinate(p);
200  }
201  if (!closed) {
202  coordinates[i] = coordinates[0];
203  }
204  return coordinates;
205  }
206 
207  public static LinearRing geoPointsToLinearRing(List<GeoPoint> points) {
208  return FACTORY.createLinearRing(pointsToCoordinates(points));
209  }
210 
211  public static Polygon ringToPolygon(List<GeoPoint> ring, List<List<GeoPoint>> holes) {
212  LinearRing shell = geoPointsToLinearRing(ring);
213  LinearRing[] holeRings = new LinearRing[holes.size()];
214  int i = 0;
215  for (List<GeoPoint> h : holes) {
216  holeRings[i++] = geoPointsToLinearRing(h);
217  }
218  return FACTORY.createPolygon(shell, holeRings);
219  }
220 
221  public static GeoPoint jtsPointToGeoPoint(Point p) {
222  return new GeoPoint(p.getY(), p.getX());
223  }
224 
225  public static Coordinate geoPointToCoordinate(GeoPoint p) {
226  return new Coordinate(p.getLongitude(), p.getLatitude());
227  }
228 
229  public static double distanceBetween(IGeoPoint a, IGeoPoint b) {
230  double lat1 = Math.toRadians(a.getLatitude());
231  double lng1 = Math.toRadians(a.getLongitude());
232  double lat2 = Math.toRadians(b.getLatitude());
233  double lng2 = Math.toRadians(b.getLongitude());
234  double dLat = lat2 - lat1;
235  double dLng = lng2 - lng1;
236  double cordlen = Math.pow(Math.sin(dLat / 2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dLng / 2), 2);
237  double angle = 2 * Math.atan2(Math.sqrt(cordlen), Math.sqrt(1 - cordlen));
238  return EARTH_RADIUS * angle;
239  }
240 
241  public static double distanceBetween(MapMarker marker, GeoPoint point) {
242  return distanceBetween(marker.getLocation(), point);
243  }
244 
245  public static double distanceBetween(MapMarker marker1, MapMarker marker2) {
246  return distanceBetween(marker1.getLocation(), marker2.getLocation());
247  }
248 
249  public static double distanceBetweenEdges(MapMarker marker, MapLineString lineString) {
250  return ONE_DEG_IN_METERS * marker.getGeometry().distance(lineString.getGeometry());
251  }
252 
253  public static double distanceBetweenEdges(MapMarker marker, MapPolygon polygon) {
254  return ONE_DEG_IN_METERS * marker.getGeometry().distance(polygon.getGeometry());
255  }
256 
257  public static double distanceBetweenEdges(MapMarker marker, MapCircle circle) {
258  double d = marker.getCentroid().distanceTo(circle.getCentroid()) - circle.Radius();
259  return d < 0 ? 0 : d;
260  }
261 
262  public static double distanceBetweenEdges(MapMarker marker, MapRectangle rectangle) {
263  return ONE_DEG_IN_METERS * marker.getGeometry().distance(rectangle.getGeometry());
264  }
265 
266  public static double distanceBetweenEdges(MapLineString lineString, GeoPoint point) {
267  return ONE_DEG_IN_METERS * lineString.getGeometry().distance(createGeometry(point));
268  }
269 
270  public static double distanceBetweenEdges(MapLineString lineString1, MapLineString lineString2) {
271  return ONE_DEG_IN_METERS * lineString1.getGeometry().distance(lineString2.getGeometry());
272  }
273 
274  public static double distanceBetweenEdges(MapLineString lineString, MapPolygon polygon) {
275  return ONE_DEG_IN_METERS * lineString.getGeometry().distance(polygon.getGeometry());
276  }
277 
278  public static double distanceBetweenEdges(MapLineString lineString, MapCircle circle) {
279  double d = (ONE_DEG_IN_METERS * lineString.getGeometry().distance(createGeometry(circle.getCentroid()))) - circle.Radius();
280  return d < 0 ? 0 : d;
281  }
282 
283  public static double distanceBetweenEdges(MapLineString lineString, MapRectangle rectangle) {
284  return ONE_DEG_IN_METERS * lineString.getGeometry().distance(rectangle.getGeometry());
285  }
286 
287  public static double distanceBetweenEdges(MapPolygon polygon, GeoPoint point) {
288  return ONE_DEG_IN_METERS * polygon.getGeometry().distance(createGeometry(point));
289  }
290 
291  public static double distanceBetweenEdges(MapPolygon polygon1, MapPolygon polygon2) {
292  return ONE_DEG_IN_METERS * polygon1.getGeometry().distance(polygon2.getGeometry());
293  }
294 
295  public static double distanceBetweenEdges(MapPolygon polygon, MapCircle circle) {
296  double d = (ONE_DEG_IN_METERS * polygon.getGeometry().distance(createGeometry(circle.getCentroid()))) - circle.Radius();
297  return d < 0 ? 0 : d;
298  }
299 
300  public static double distanceBetweenEdges(MapPolygon polygon, MapRectangle rectangle) {
301  return ONE_DEG_IN_METERS * polygon.getGeometry().distance(rectangle.getGeometry());
302  }
303 
304  public static double distanceBetweenEdges(MapCircle circle, GeoPoint point) {
305  double d = distanceBetween(circle.getCentroid(), point) - circle.Radius();
306  return d < 0 ? 0 : d;
307  }
308 
309  public static double distanceBetweenEdges(MapCircle circle1, MapCircle circle2) {
310  double d = distanceBetween(circle1.getCentroid(), circle2.getCentroid()) - circle1.Radius() - circle2.Radius();
311  return d < 0 ? 0 : d;
312  }
313 
314  public static double distanceBetweenEdges(MapCircle circle, MapRectangle rectangle) {
315  double d = (ONE_DEG_IN_METERS * rectangle.getGeometry().distance(createGeometry(circle.getCentroid()))) - circle.Radius();
316  return d < 0 ? 0 : d;
317  }
318 
319  public static double distanceBetweenEdges(MapRectangle rectangle, GeoPoint point) {
320  return ONE_DEG_IN_METERS * rectangle.getGeometry().distance(createGeometry(point));
321  }
322 
323  public static double distanceBetweenEdges(MapRectangle rectangle1, MapRectangle rectangle2) {
324  return ONE_DEG_IN_METERS * rectangle1.getGeometry().distance(rectangle2.getGeometry());
325  }
326 
327  public static double distanceBetweenCentroids(MapMarker marker, MapLineString lineString) {
328  return distanceBetween(marker.getCentroid(), lineString.getCentroid());
329  }
330 
331  public static double distanceBetweenCentroids(MapMarker marker, MapPolygon polygon) {
332  return distanceBetween(marker.getCentroid(), polygon.getCentroid());
333  }
334 
335  public static double distanceBetweenCentroids(MapMarker marker, MapCircle circle) {
336  return distanceBetween(marker.getCentroid(), circle.getCentroid());
337  }
338 
339  public static double distanceBetweenCentroids(MapMarker marker, MapRectangle rectangle) {
340  return distanceBetween(marker.getCentroid(), rectangle.getCentroid());
341  }
342 
343  public static double distanceBetweenCentroids(MapLineString lineString, GeoPoint point) {
344  return distanceBetween(lineString.getCentroid(), point);
345  }
346 
347  public static double distanceBetweenCentroids(MapLineString lineString1, MapLineString lineString2) {
348  return distanceBetween(lineString1.getCentroid(), lineString2.getCentroid());
349  }
350 
351  public static double distanceBetweenCentroids(MapLineString lineString, MapPolygon polygon) {
352  return distanceBetween(lineString.getCentroid(), polygon.getCentroid());
353  }
354 
355  public static double distanceBetweenCentroids(MapLineString lineString, MapCircle circle) {
356  return distanceBetween(lineString.getCentroid(), circle.getCentroid());
357  }
358 
359  public static double distanceBetweenCentroids(MapLineString lineString, MapRectangle rectangle) {
360  return distanceBetween(lineString.getCentroid(), rectangle.getCentroid());
361  }
362 
363  public static double distanceBetweenCentroids(MapPolygon polygon, GeoPoint point) {
364  return distanceBetween(polygon.getCentroid(), point);
365  }
366 
367  public static double distanceBetweenCentroids(MapPolygon polygon1, MapPolygon polygon2) {
368  return distanceBetween(polygon1.getCentroid(), polygon2.getCentroid());
369  }
370 
371  public static double distanceBetweenCentroids(MapPolygon polygon, MapCircle circle) {
372  return distanceBetween(polygon.getCentroid(), circle.getCentroid());
373  }
374 
375  public static double distanceBetweenCentroids(MapPolygon polygon, MapRectangle rectangle) {
376  return distanceBetween(polygon.getCentroid(), rectangle.getCentroid());
377  }
378 
379  public static double distanceBetweenCentroids(MapCircle circle, GeoPoint point) {
380  return distanceBetween(circle.getCentroid(), point);
381  }
382 
383  public static double distanceBetweenCentroids(MapCircle circle1, MapCircle circle2) {
384  return distanceBetween(circle1.getCentroid(), circle2.getCentroid());
385  }
386 
387  public static double distanceBetweenCentroids(MapCircle circle, MapRectangle rectangle) {
388  return distanceBetween(circle.getCentroid(), rectangle.getCentroid());
389  }
390 
391  public static double distanceBetweenCentroids(MapRectangle rectangle, GeoPoint point) {
392  return distanceBetween(rectangle.getCentroid(), point);
393  }
394 
395  public static double distanceBetweenCentroids(MapRectangle rectangle1, MapRectangle rectangle2) {
396  return distanceBetween(rectangle1.getCentroid(), rectangle2.getCentroid());
397  }
398 
399  public static double bearingTo(MapMarker from, MapMarker to) {
400  return from.getCentroid().bearingTo(to.getCentroid());
401  }
402 
403  public static double bearingToEdge(MapMarker from, MapLineString to) {
404  // TODO(ewpatton): Switch to using distance to nearest edge from centroid
405  return from.getCentroid().bearingTo(to.getCentroid());
406  }
407 
408  public static double bearingToEdge(MapMarker from, MapPolygon to) {
409  // TODO(ewpatton): Switch to using distance to nearest edge from centroid
410  return from.getCentroid().bearingTo(to.getCentroid());
411  }
412 
413  public static double bearingToEdge(MapMarker from, MapRectangle to) {
414  // TODO(ewpatton): Switch to using distance to nearest edge from centroid
415  return from.getCentroid().bearingTo(to.getCentroid());
416  }
417 
418  public static double bearingToEdge(MapMarker from, MapCircle to) {
419  return from.getCentroid().bearingTo(to.getCentroid());
420  }
421 
422  public static double bearingToCentroid(MapMarker from, MapLineString to) {
423  return from.getCentroid().bearingTo(to.getCentroid());
424  }
425 
426  public static double bearingToCentroid(MapMarker from, MapPolygon to) {
427  return from.getCentroid().bearingTo(to.getCentroid());
428  }
429 
430  public static double bearingToCentroid(MapMarker from, MapRectangle to) {
431  return from.getCentroid().bearingTo(to.getCentroid());
432  }
433 
434  public static double bearingToCentroid(MapMarker from, MapCircle to) {
435  return from.getCentroid().bearingTo(to.getCentroid());
436  }
437 
444  public static boolean isValidLatitude(double latitude) {
445  return -90.0 <= latitude && latitude <= 90.0;
446  }
447 
454  public static boolean isValidLongitude(double longitude) {
455  return -180.0 <= longitude && longitude <= 180.0;
456  }
457 
458  public static List<GeoPoint> polygonToList(JSONArray array) throws JSONException {
459  List<GeoPoint> points = new ArrayList<GeoPoint>(array.length());
460  if (array.length() < 3) {
462  "Too few points in Polygon, expected 3.");
463  }
464  for (int i = 0; i < array.length(); i++) {
465  JSONArray point = array.getJSONArray(i);
466  if (point.length() < 2) {
467  throw new JSONException("Invalid number of dimensions in polygon, expected 2.");
468  }
469  if (point.length() == 2) {
470  points.add(new GeoPoint(point.getDouble(0), point.getDouble(1)));
471  } else {
472  points.add(new GeoPoint(point.getDouble(0), point.getDouble(1), point.getDouble(2)));
473  }
474  }
475  return points;
476  }
477 
478  public static List<List<GeoPoint>> multiPolygonToList(JSONArray array) throws JSONException {
479  List<List<GeoPoint>> result = new ArrayList<List<GeoPoint>>();
480  if (array.length() == 0) {
481  return result;
482  } else if (array.getJSONArray(0).optJSONArray(0) == null) {
483  result.add(polygonToList(array));
484  } else {
485  for (int i = 0; i < array.length(); i++) {
486  result.add(polygonToList(array.getJSONArray(i)));
487  }
488  }
489  return result;
490  }
491 
492  public static YailList multiPolygonToYailList(List<List<GeoPoint>> multipolygon) {
493  List<YailList> result = new LinkedList<YailList>();
494  for (List<GeoPoint> polygon : multipolygon) {
495  result.add(pointsListToYailList(polygon));
496  }
497  return YailList.makeList(result);
498  }
499 
500  public static List<List<GeoPoint>> multiPolygonFromYailList(YailList list) {
501  List<List<GeoPoint>> multipolygon = new ArrayList<List<GeoPoint>>();
502  Iterator<?> it = list.listIterator(1);
503  while(it.hasNext()) {
504  multipolygon.add(pointsFromYailList(TypeUtil.castNotNull(it.next(), YailList.class, "list")));
505  }
506  return multipolygon;
507  }
508 
509  public static List<List<List<GeoPoint>>> multiPolygonHolesFromYailList(YailList points) {
510  List<List<List<GeoPoint>>> holes = new ArrayList<List<List<GeoPoint>>>();
511  Iterator<?> it = points.listIterator(1); // skip *list* symbol
512  int i = 1;
513  try {
514  while (it.hasNext()) {
515  YailList yailHoles = TypeUtil.castNotNull(it.next(), YailList.class, "list");
516  holes.add(multiPolygonFromYailList(yailHoles)); // holes are just negative multipolygon
517  i++;
518  }
519  } catch (DispatchableError e) {
520  throw IterationError.fromError(i, e);
521  }
522  return holes;
523  }
524 
525  public static List<List<List<GeoPoint>>> multiPolygonHolesToList(JSONArray array) throws JSONException {
526  List<List<List<GeoPoint>>> result = new ArrayList<List<List<GeoPoint>>>();
527  if (array.getJSONArray(0).getJSONArray(0).optJSONArray(0) == null) {
528  result.add(multiPolygonToList(array));
529  } else {
530  for (int i = 0; i < array.length(); i++) {
531  result.add(multiPolygonToList(array.getJSONArray(i)));
532  }
533  }
534  return result;
535  }
536 
545  public static boolean isPolygon(YailList points) {
546  if (points.size() < 3) {
547  return false;
548  }
549  try {
550  pointFromYailList(TypeUtil.castNotNull(points.get(1), YailList.class, "list"));
551  return true;
552  } catch(DispatchableError e) {
553  return false;
554  }
555  }
556 
566  public static boolean isMultiPolygon(YailList points) {
567  return points.size() > 0 &&
568  isPolygon(TypeUtil.castNotNull(points.get(1), YailList.class, "list"));
569  }
570 }
com.google.appinventor.components.runtime.util.GeometryUtil.bearingToCentroid
static double bearingToCentroid(MapMarker from, MapCircle to)
Definition: GeometryUtil.java:434
com.google.appinventor.components.runtime.util.ErrorMessages.ERROR_POLYGON_PARSE_ERROR
static final int ERROR_POLYGON_PARSE_ERROR
Definition: ErrorMessages.java:233
com.google.appinventor.components.runtime.util.YailList
Definition: YailList.java:26
com.google.appinventor.components.runtime.util.MapFactory.MapCircle
Definition: MapFactory.java:1028
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapCircle circle1, MapCircle circle2)
Definition: GeometryUtil.java:309
com.google.appinventor.components.runtime.util.GeometryUtil.asYailList
static YailList asYailList(IGeoPoint point)
Definition: GeometryUtil.java:80
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapPolygon polygon, MapCircle circle)
Definition: GeometryUtil.java:295
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapLineString lineString, MapPolygon polygon)
Definition: GeometryUtil.java:351
com.google.appinventor.components.runtime.errors.DispatchableError
Definition: DispatchableError.java:12
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapLineString lineString, MapRectangle rectangle)
Definition: GeometryUtil.java:359
com.google.appinventor.components.runtime.util.ErrorMessages
Definition: ErrorMessages.java:17
com.google.appinventor.components.runtime.util
-*- mode: java; c-basic-offset: 2; -*-
Definition: AccountChooser.java:7
com.google.appinventor.components.runtime.util.MapFactory
Definition: MapFactory.java:30
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapRectangle rectangle, GeoPoint point)
Definition: GeometryUtil.java:319
com.google.appinventor.components.runtime.util.GeometryUtil.bearingToEdge
static double bearingToEdge(MapMarker from, MapCircle to)
Definition: GeometryUtil.java:418
com.google.appinventor.components.runtime.util.TypeUtil
Definition: TypeUtil.java:10
com.google.appinventor.components.runtime.util.GeometryUtil.bearingToCentroid
static double bearingToCentroid(MapMarker from, MapPolygon to)
Definition: GeometryUtil.java:426
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetween
static double distanceBetween(IGeoPoint a, IGeoPoint b)
Definition: GeometryUtil.java:229
com.google.appinventor.components.runtime.util.GeometryUtil.pointsToCoordinates
static Coordinate[] pointsToCoordinates(List< GeoPoint > points)
Definition: GeometryUtil.java:194
com.google.appinventor.components.runtime.util.GeometryUtil.bearingTo
static double bearingTo(MapMarker from, MapMarker to)
Definition: GeometryUtil.java:399
com.google.appinventor.components.runtime.util.GeometryUtil.multiPolygonFromYailList
static List< List< GeoPoint > > multiPolygonFromYailList(YailList list)
Definition: GeometryUtil.java:500
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapCircle circle, MapRectangle rectangle)
Definition: GeometryUtil.java:387
com.google.appinventor.components
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapPolygon polygon, MapRectangle rectangle)
Definition: GeometryUtil.java:300
com.google.appinventor.components.runtime.util.YailList.makeList
static YailList makeList(Object[] objects)
Definition: YailList.java:59
com.google.appinventor.components.runtime.util.GeometryUtil.multiPolygonHolesFromYailList
static List< List< List< GeoPoint > > > multiPolygonHolesFromYailList(YailList points)
Definition: GeometryUtil.java:509
com.google.appinventor.components.runtime.util.GeometryUtil.coerceToDouble
static double coerceToDouble(Object o)
Definition: GeometryUtil.java:52
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapRectangle rectangle, GeoPoint point)
Definition: GeometryUtil.java:391
com.google.appinventor.components.runtime.util.MapFactory.MapLineString
Definition: MapFactory.java:1373
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapRectangle rectangle1, MapRectangle rectangle2)
Definition: GeometryUtil.java:395
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapLineString lineString1, MapLineString lineString2)
Definition: GeometryUtil.java:347
com.google.appinventor.components.runtime.util.MapFactory.MapPolygon
Definition: MapFactory.java:1410
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapMarker marker, MapCircle circle)
Definition: GeometryUtil.java:257
com.google.appinventor.components.runtime.util.GeometryUtil.pointsListToYailList
static YailList pointsListToYailList(List<? extends IGeoPoint > points)
Definition: GeometryUtil.java:84
com.google.appinventor.components.runtime.util.GeometryUtil.pointsFromYailList
static List< GeoPoint > pointsFromYailList(YailList points)
Definition: GeometryUtil.java:104
com.google.appinventor.components.runtime.util.GeometryUtil.createGeometry
static Geometry createGeometry(List< List< GeoPoint >> points, List< List< List< GeoPoint >>> holes)
Definition: GeometryUtil.java:138
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapMarker marker, MapLineString lineString)
Definition: GeometryUtil.java:249
com.google.appinventor.components.runtime.util.GeometryUtil.ringToPolygon
static Polygon ringToPolygon(List< GeoPoint > ring)
Definition: GeometryUtil.java:190
com.google.appinventor.components.runtime.util.MapFactory.MapRectangle
Definition: MapFactory.java:1099
com.google.appinventor.components.runtime.util.ErrorMessages.ERROR_INVALID_NUMBER_OF_VALUES_IN_POINT
static final int ERROR_INVALID_NUMBER_OF_VALUES_IN_POINT
Definition: ErrorMessages.java:238
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapMarker marker, MapLineString lineString)
Definition: GeometryUtil.java:327
com.google.appinventor.components.runtime.util.GeometryUtil.polygonToList
static List< GeoPoint > polygonToList(JSONArray array)
Definition: GeometryUtil.java:458
com.google.appinventor.components.runtime.util.GeometryUtil.getMidpoint
static GeoPoint getMidpoint(List< GeoPoint > points)
Definition: GeometryUtil.java:161
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapLineString lineString, MapCircle circle)
Definition: GeometryUtil.java:355
com.google.appinventor.components.runtime.errors.IterationError
Definition: IterationError.java:10
com.google.appinventor.components.runtime.Polygon
Definition: Polygon.java:55
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapPolygon polygon, MapCircle circle)
Definition: GeometryUtil.java:371
com.google.appinventor.components.runtime.MapFeatureBase.getCentroid
final synchronized GeoPoint getCentroid()
Definition: MapFeatureBase.java:414
com.google.appinventor.components.runtime.util.MapFactory.MapMarker
Definition: MapFactory.java:1205
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapLineString lineString, MapPolygon polygon)
Definition: GeometryUtil.java:274
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapCircle circle, GeoPoint point)
Definition: GeometryUtil.java:379
com.google.appinventor.components.runtime.errors.IterationError.fromError
static DispatchableError fromError(int index, DispatchableError e)
Definition: IterationError.java:28
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetween
static double distanceBetween(MapMarker marker, GeoPoint point)
Definition: GeometryUtil.java:241
com.google.appinventor.components.runtime.util.GeometryUtil.isValidLongitude
static boolean isValidLongitude(double longitude)
Definition: GeometryUtil.java:454
com.google.appinventor.components.runtime.util.GeometryUtil.pointFromYailList
static GeoPoint pointFromYailList(YailList point)
Definition: GeometryUtil.java:92
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapMarker marker, MapRectangle rectangle)
Definition: GeometryUtil.java:339
com.google.appinventor.components.runtime.util.GeometryUtil.getCentroid
static GeoPoint getCentroid(List< List< GeoPoint >> points, List< List< List< GeoPoint >>> holes)
Definition: GeometryUtil.java:186
com.google.appinventor.components.runtime.util.GeometryUtil.multiPolygonHolesToList
static List< List< List< GeoPoint > > > multiPolygonHolesToList(JSONArray array)
Definition: GeometryUtil.java:525
com.google.appinventor.components.runtime.util.YailObject.iterator
Iterator< T > iterator()
com.google.appinventor.components.runtime.util.GeometryUtil.ringToPolygon
static Polygon ringToPolygon(List< GeoPoint > ring, List< List< GeoPoint >> holes)
Definition: GeometryUtil.java:211
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapLineString lineString1, MapLineString lineString2)
Definition: GeometryUtil.java:270
com.google.appinventor.components.runtime.util.GeometryUtil
Definition: GeometryUtil.java:41
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapMarker marker, MapPolygon polygon)
Definition: GeometryUtil.java:253
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapPolygon polygon, MapRectangle rectangle)
Definition: GeometryUtil.java:375
com.google.appinventor.components.runtime.util.GeometryUtil.geoPointToCoordinate
static Coordinate geoPointToCoordinate(GeoPoint p)
Definition: GeometryUtil.java:225
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetween
static double distanceBetween(MapMarker marker1, MapMarker marker2)
Definition: GeometryUtil.java:245
com.google.appinventor.components.runtime.util.GeometryUtil.jtsPointToGeoPoint
static GeoPoint jtsPointToGeoPoint(Point p)
Definition: GeometryUtil.java:221
com.google.appinventor.components.runtime.util.GeometryUtil.createGeometry
static Geometry createGeometry(GeoPoint point)
Definition: GeometryUtil.java:120
com.google.appinventor.components.runtime
Copyright 2009-2011 Google, All Rights reserved.
Definition: AccelerometerSensor.java:8
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapLineString lineString, GeoPoint point)
Definition: GeometryUtil.java:343
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapLineString lineString, GeoPoint point)
Definition: GeometryUtil.java:266
com.google.appinventor.components.runtime.util.GeometryUtil.isPolygon
static boolean isPolygon(YailList points)
Definition: GeometryUtil.java:545
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapMarker marker, MapRectangle rectangle)
Definition: GeometryUtil.java:262
com.google.appinventor.components.runtime.util.GeometryUtil.coerceToPoint
static GeoPoint coerceToPoint(Object lat, Object lng)
Definition: GeometryUtil.java:64
com.google.appinventor.components.runtime.util.GeometryUtil.bearingToEdge
static double bearingToEdge(MapMarker from, MapPolygon to)
Definition: GeometryUtil.java:408
com.google.appinventor.components.runtime.util.MapFactory.MapFeature.getCentroid
GeoPoint getCentroid()
com.google
com
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapCircle circle, GeoPoint point)
Definition: GeometryUtil.java:304
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapMarker marker, MapCircle circle)
Definition: GeometryUtil.java:335
com.google.appinventor.components.runtime.util.GeometryUtil.bearingToCentroid
static double bearingToCentroid(MapMarker from, MapLineString to)
Definition: GeometryUtil.java:422
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapCircle circle1, MapCircle circle2)
Definition: GeometryUtil.java:383
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapLineString lineString, MapCircle circle)
Definition: GeometryUtil.java:278
com.google.appinventor.components.runtime.errors
Definition: ArrayIndexOutOfBoundsError.java:7
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapPolygon polygon1, MapPolygon polygon2)
Definition: GeometryUtil.java:367
com.google.appinventor.components.runtime.util.GeometryUtil.bearingToEdge
static double bearingToEdge(MapMarker from, MapRectangle to)
Definition: GeometryUtil.java:413
com.google.appinventor.components.runtime.util.ErrorMessages.ERROR_INVALID_POINT
static final int ERROR_INVALID_POINT
Definition: ErrorMessages.java:234
com.google.appinventor.components.runtime.LineString
Definition: LineString.java:49
com.google.appinventor.components.runtime.util.GeometryUtil.multiPolygonToList
static List< List< GeoPoint > > multiPolygonToList(JSONArray array)
Definition: GeometryUtil.java:478
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapMarker marker, MapPolygon polygon)
Definition: GeometryUtil.java:331
com.google.appinventor.components.runtime.util.GeometryUtil.createGeometry
static Geometry createGeometry(double north, double east, double south, double west)
Definition: GeometryUtil.java:128
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapPolygon polygon1, MapPolygon polygon2)
Definition: GeometryUtil.java:291
com.google.appinventor.components.runtime.util.GeometryUtil.bearingToEdge
static double bearingToEdge(MapMarker from, MapLineString to)
Definition: GeometryUtil.java:403
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapCircle circle, MapRectangle rectangle)
Definition: GeometryUtil.java:314
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapPolygon polygon, GeoPoint point)
Definition: GeometryUtil.java:287
com.google.appinventor.components.runtime.util.GeometryUtil.multiPolygonToYailList
static YailList multiPolygonToYailList(List< List< GeoPoint >> multipolygon)
Definition: GeometryUtil.java:492
com.google.appinventor.components.runtime.util.GeometryUtil.isValidLatitude
static boolean isValidLatitude(double latitude)
Definition: GeometryUtil.java:444
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapRectangle rectangle1, MapRectangle rectangle2)
Definition: GeometryUtil.java:323
com.google.appinventor.components.runtime.util.MapFactory.MapFeature.getGeometry
Geometry getGeometry()
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenEdges
static double distanceBetweenEdges(MapLineString lineString, MapRectangle rectangle)
Definition: GeometryUtil.java:283
com.google.appinventor.components.runtime.util.GeometryUtil.bearingToCentroid
static double bearingToCentroid(MapMarker from, MapRectangle to)
Definition: GeometryUtil.java:430
com.google.appinventor.components.runtime.util.TypeUtil.castNotNull
static< T > T castNotNull(Object o, Class< T > tClass, String expected)
Definition: TypeUtil.java:24
com.google.appinventor.components.runtime.util.GeometryUtil.createGeometry
static Geometry createGeometry(List< GeoPoint > line)
Definition: GeometryUtil.java:124
com.google.appinventor.components.runtime.util.GeometryUtil.geoPointsToLinearRing
static LinearRing geoPointsToLinearRing(List< GeoPoint > points)
Definition: GeometryUtil.java:207
com.google.appinventor.components.runtime.util.YailList.size
int size()
Definition: YailList.java:172
com.google.appinventor.components.runtime.util.GeometryUtil.isMultiPolygon
static boolean isMultiPolygon(YailList points)
Definition: GeometryUtil.java:566
com.google.appinventor
com.google.appinventor.components.runtime.util.MapFactory.MapCircle.Radius
void Radius(double radius)
com.google.appinventor.components.runtime.util.MapFactory.MapMarker.getLocation
IGeoPoint getLocation()
com.google.appinventor.components.runtime.util.GeometryUtil.distanceBetweenCentroids
static double distanceBetweenCentroids(MapPolygon polygon, GeoPoint point)
Definition: GeometryUtil.java:363