Package com.google.common.geometry
Class S2TextFormat
java.lang.Object
com.google.common.geometry.S2TextFormat
S2TextFormat contains a collection of functions for converting geometry to and from a human-
readable format. It is mainly intended for testing and debugging. Be aware that the human-
readable format is *not* designed to preserve the full precision of the original object, so it
should not be used for data storage.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
appendVertex
(S2LatLng ll, StringBuilder out) private static void
appendVertex
(S2Point p, StringBuilder out) private static void
appendVertices
(Iterable<S2Point> points, StringBuilder out) private static List
<S2TextFormat.ParseEntry> dictionaryParse
(String str) Modeled on the DictionaryParse method of strings/serialize.ccprivate static S2Polygon
internalMakePolygon
(String str, boolean normalizeLoops) static S2CellId
makeCellId
(String str) As above, but does not CHECK-fail on invalid input.static S2CellId
makeCellIdOrDie
(String str) Parses an S2CellId in the format "f/dd..d" where "f" is a digit in the range [0-5] representing the S2CellId face, and "dd..d" is a string of digits in the range [0-3] representing each child's position with respect to its parent.static S2CellUnion
makeCellUnion
(String str) As above, but does not CHECK-fail on invalid input.static S2CellUnion
makeCellUnionOrDie
(String str) Parses a comma-separated list of S2CellIds in the format above, and returns the corresponding S2CellUnion.static S2ShapeIndex
As above, but does not CHECK-fail on invalid input.static S2ShapeIndex
makeIndexOrDie
(String str) Returns a S2ShapeIndex containing the points, polylines, and loops (in the form of a single polygon) described by the following format:static S2LatLng
makeLatLng
(String str) As above, but does not CHECK-fail on invalid input.static S2LatLng
makeLatLngOrDie
(String str) Given a string in the same format as ParseLatLngs, returns a single S2LatLng.static S2LatLngRect
makeLatLngRect
(String str) As above, but does not CHECK-fail on invalid input.(package private) S2LatLngRect
Given a string in the same format as ParseLatLngs, returns the minimal bounding S2LatLngRect that contains the coordinates.static S2LaxPolygonShape
makeLaxPolygon
(String str) As above, but does not CHECK-fail on invalid input.static S2LaxPolygonShape
Parses a string in the same format as MakePolygon, except that loops must be oriented so that the interior of the loop is always on the left, and polygons with degeneracies are supported.static S2LaxPolylineShape
makeLaxPolyline
(String str) As above, but does not CHECK-fail on invalid input.static S2LaxPolylineShape
Like makePolyline, but returns an S2LaxPolylineShape instead.static S2Loop
As above, but does not CHECK-fail on invalid input.static S2Loop
makeLoopOrDie
(String str) Given a string of latitude-longitude coordinates in degrees, returns a newly allocated loop.static S2Point
As above, but do not CHECK-fail on invalid input.static S2Point
makePointOrDie
(String str) Returns an S2Point corresponding to the given a latitude-longitude coordinate in degrees.static S2Polygon
makePolygon
(String str) As above, but does not CHECK-fail on invalid input.static S2Polygon
makePolygonOrDie
(String str) Given a sequence of loops separated by semicolons, returns a newly allocated polygon.static S2Polyline
makePolyline
(String str) As above, but does not CHECK-fail on invalid input.static S2Polyline
makePolylineOrDie
(String str) Similar to makeLoop(), but returns an S2Polyline rather than an S2Loop.static S2Polygon
As above, but does not CHECK-fail on invalid input.static S2Polygon
Like MakePolygon(), except that it does not normalize loops (i.e., it gives you exactly what you asked for).parseLatLngs
(String str) As above, but does not CHECK-fail on invalid input.parseLatLngsOrDie
(String str) Parses a string of one or more latitude-longitude coordinates in degrees, and return the corresponding List of S2LatLng points.parsePoints
(String str) As above, but does not CHECK-fail on invalid input.parsePointsOrDie
(String str) Parses a string in the same format as parseLatLngs, and return the corresponding List of S2Point values.static String
s2LatLngsToString
(List<S2LatLng> latlngs) Convert a list of S2LatLngs to the S2TextFormat string representation documented above.static String
s2PointsToString
(List<S2Point> points) Convert a list of S2Points to the S2TextFormat string representation documented above.splitString
(String str, String regexp) static String
Convert an S2CellId to the S2TextFormat string representation documented above.static String
toString
(S2CellUnion cellUnion) Convert an S2CellUnion to the S2TextFormat string representation documented above.static String
Convert an S2LatLng to the S2TextFormat string representation documented above.static String
toString
(S2LatLngRect rect) Convert an S2LatLngRect to the S2TextFormat string representation documented above.static String
toString
(S2LaxPolygonShape polygon) Convert an S2LaxPolygonShape to the S2TextFormat string representation documented above.static String
toString
(S2LaxPolygonShape polygon, String loopSeparator) Convert an S2LaxPolygonShape to the S2TextFormat string representation documented above, using the given loopSeparator.static String
toString
(S2LaxPolylineShape polyline) Convert an S2LaxPolylineShape to the S2TextFormat string representation documented above.static String
Convert an S2Loop to the S2TextFormat string representation documented above.static String
Convert an S2Point to the S2TextFormat string representation documented above.static String
Convert an S2Polygon to the S2TextFormat string representation documented above.static String
Convert an S2 polygon to the S2TextFormat string representation documented above, using the given loopSeparator between each loop.static String
toString
(S2Polyline polyline) Convert an S2Polyline to the S2TextFormat string representation documented above.static String
toString
(S2ShapeIndex index) Convert an S2CellUnion to the S2TextFormat string representation documented above.
-
Constructor Details
-
S2TextFormat
public S2TextFormat()
-
-
Method Details
-
makePointOrDie
Returns an S2Point corresponding to the given a latitude-longitude coordinate in degrees. Example of the input format: "-20:150" -
makePoint
As above, but do not CHECK-fail on invalid input. Returns null if conversion is unsuccessful. -
parseLatLngsOrDie
Parses a string of one or more latitude-longitude coordinates in degrees, and return the corresponding List of S2LatLng points.Examples of the input format:
"" // no points "-20:150" // one point "-20:150, -20:151, -19:150" // three points
-
parseLatLngs
As above, but does not CHECK-fail on invalid input. Returns null if conversion is unsuccessful. -
parsePointsOrDie
Parses a string in the same format as parseLatLngs, and return the corresponding List of S2Point values. -
parsePoints
As above, but does not CHECK-fail on invalid input. Returns null if conversion is unsuccessful. -
makeLatLngOrDie
Given a string in the same format as ParseLatLngs, returns a single S2LatLng. -
makeLatLng
As above, but does not CHECK-fail on invalid input. Returns null if conversion is unsuccessful. -
makeLatLngRectOrDie
Given a string in the same format as ParseLatLngs, returns the minimal bounding S2LatLngRect that contains the coordinates. -
makeLatLngRect
As above, but does not CHECK-fail on invalid input. Returns null if conversion is unsuccessful. -
makeCellIdOrDie
Parses an S2CellId in the format "f/dd..d" where "f" is a digit in the range [0-5] representing the S2CellId face, and "dd..d" is a string of digits in the range [0-3] representing each child's position with respect to its parent. (Note that the latter string may be empty.)For example "4/" represents S2CellId.fromFace(4), and "3/02" represents S2CellId.fromFace(3).child(0).child(2).
This function is a wrapper for S2CellId.fromDebugString().
-
makeCellId
As above, but does not CHECK-fail on invalid input. Returns null if conversion is unsuccessful. -
makeCellUnionOrDie
Parses a comma-separated list of S2CellIds in the format above, and returns the corresponding S2CellUnion. (Note that S2CellUnions are automatically normalized by sorting, removing duplicates, and replacing groups of 4 child cells by their parent cell.) -
makeCellUnion
As above, but does not CHECK-fail on invalid input. Returns null if conversion is unsuccessful. -
makeLoopOrDie
Given a string of latitude-longitude coordinates in degrees, returns a newly allocated loop. Example of the input format:"-20:150, 10:-120, 0.123:-170.652"
The strings "empty" or "full" create an empty or full loop respectively.
-
makeLoop
As above, but does not CHECK-fail on invalid input. Returns null if conversion is unsuccessful. -
makePolylineOrDie
Similar to makeLoop(), but returns an S2Polyline rather than an S2Loop. -
makePolyline
As above, but does not CHECK-fail on invalid input. Returns null if conversion is unsuccessful. -
makeLaxPolylineOrDie
@GwtIncompatible("S2LaxPolylineShape") public static S2LaxPolylineShape makeLaxPolylineOrDie(String str) Like makePolyline, but returns an S2LaxPolylineShape instead. -
makeLaxPolyline
@Nullable @GwtIncompatible("S2LaxPolylineShape") public static S2LaxPolylineShape makeLaxPolyline(String str) As above, but does not CHECK-fail on invalid input. Returns null if conversion is unsuccessful. -
makePolygonOrDie
Given a sequence of loops separated by semicolons, returns a newly allocated polygon. Loops are automatically normalized by inverting them if necessary so that they enclose at most half of the unit sphere. (Historically this was once a requirement of polygon loops. It also hides the problem that if the user thinks of the coordinates as X:Y rather than LAT:LNG, it yields a loop with the opposite orientation.)Examples of the input format:
"10:20, 90:0, 20:30" // one loop "10:20, 90:0, 20:30; 5.5:6.5, -90:-180, -15.2:20.3" // two loops "" // the empty polygon (consisting of no loops) "empty" // the empty polygon (consisting of no loops) "full" // the full polygon (consisting of one full loop).
-
makePolygon
As above, but does not CHECK-fail on invalid input. Returns null if conversion is unsuccessful. -
makeVerbatimPolygonOrDie
Like MakePolygon(), except that it does not normalize loops (i.e., it gives you exactly what you asked for). -
makeVerbatimPolygon
As above, but does not CHECK-fail on invalid input. Returns null if conversion is unsuccessful. -
makeLaxPolygonOrDie
@GwtIncompatible("S2LaxPolygonShape") public static S2LaxPolygonShape makeLaxPolygonOrDie(String str) Parses a string in the same format as MakePolygon, except that loops must be oriented so that the interior of the loop is always on the left, and polygons with degeneracies are supported. As with MakePolygon, "full" denotes the full polygon, and "" or "empty" denote the empty polygon. -
makeLaxPolygon
@Nullable @GwtIncompatible("S2LaxPolygonShape") public static S2LaxPolygonShape makeLaxPolygon(String str) As above, but does not CHECK-fail on invalid input. Returns null if conversion is unsuccessful. -
makeIndexOrDie
@GwtIncompatible("S2LaxPolylineShape, S2LaxPolygonShape") public static S2ShapeIndex makeIndexOrDie(String str) Returns a S2ShapeIndex containing the points, polylines, and loops (in the form of a single polygon) described by the following format:point1|point2|... # line1|line2|... # polygon1|polygon2|...
Examples:
1:2 | 2:3 # # // Two points # 0:0, 1:1, 2:2 | 3:3, 4:4 # // Two polylines # # 0:0, 0:3, 3:0; 1:1, 2:1, 1:2 // Two nested loops (one polygon) 5:5 # 6:6, 7:7 # 0:0, 0:1, 1:0 // One of each # # empty // One empty polygon # # empty | full // One empty polygon, one full polygon
Loops should be directed so that the region's interior is on the left. Loops can be degenerate (they do not need to meet S2Loop requirements).
CAVEAT: Because whitespace is ignored, empty polygons must be specified as the string "empty" rather than as the empty string ("").
-
makeIndex
@Nullable @GwtIncompatible("S2LaxPolylineShape, S2LaxPolygonShape") public static S2ShapeIndex makeIndex(String str) As above, but does not CHECK-fail on invalid input. Returns null if conversion is unsuccessful. -
toString
Convert an S2Point to the S2TextFormat string representation documented above. -
toString
Convert an S2LatLng to the S2TextFormat string representation documented above. -
toString
Convert an S2LatLngRect to the S2TextFormat string representation documented above. -
toString
Convert an S2CellId to the S2TextFormat string representation documented above. -
toString
Convert an S2CellUnion to the S2TextFormat string representation documented above. -
toString
Convert an S2Loop to the S2TextFormat string representation documented above. -
toString
Convert an S2Polyline to the S2TextFormat string representation documented above. -
toString
Convert an S2Polygon to the S2TextFormat string representation documented above. -
toString
Convert an S2 polygon to the S2TextFormat string representation documented above, using the given loopSeparator between each loop. Empty and Full polygons are represented as "empty" and "full" respectively. -
s2PointsToString
Convert a list of S2Points to the S2TextFormat string representation documented above. -
s2LatLngsToString
Convert a list of S2LatLngs to the S2TextFormat string representation documented above. -
toString
@GwtIncompatible("S2LaxPolylineShape, S2LaxPolygonShape") public static String toString(S2LaxPolylineShape polyline) Convert an S2LaxPolylineShape to the S2TextFormat string representation documented above. -
toString
@GwtIncompatible("S2LaxPolylineShape, S2LaxPolygonShape") public static String toString(S2LaxPolygonShape polygon) Convert an S2LaxPolygonShape to the S2TextFormat string representation documented above. -
toString
@GwtIncompatible("S2LaxPolylineShape, S2LaxPolygonShape") public static String toString(S2LaxPolygonShape polygon, String loopSeparator) Convert an S2LaxPolygonShape to the S2TextFormat string representation documented above, using the given loopSeparator. -
toString
Convert an S2CellUnion to the S2TextFormat string representation documented above. The index may contain S2Shapes of any type. Shapes are reordered if necessary so that all point geometry (shapes of dimension 0) are first, followed by all polyline geometry, followed by all polygon geometry. -
splitString
-
dictionaryParse
Modeled on the DictionaryParse method of strings/serialize.cc -
internalMakePolygon
-
appendVertex
-
appendVertex
-
appendVertices
-