diff --git a/pkg/geo/bbox.go b/pkg/geo/bbox.go index c6304b3086bb..ed796de5829f 100644 --- a/pkg/geo/bbox.go +++ b/pkg/geo/bbox.go @@ -145,7 +145,7 @@ func boundingBoxFromGeomTGeographyType(g geom.T) (s2.Rect, error) { if g.Empty() { return s2.EmptyRect(), nil } - regions, err := S2RegionsFromGeom(g, EmptyBehaviorOmit) + regions, err := S2RegionsFromGeomT(g, EmptyBehaviorOmit) if err != nil { return s2.EmptyRect(), err } diff --git a/pkg/geo/geo.go b/pkg/geo/geo.go index 1fad6c23a165..121acb6d910d 100644 --- a/pkg/geo/geo.go +++ b/pkg/geo/geo.go @@ -111,8 +111,8 @@ func NewGeometryFromPointCoords(x, y float64) (*Geometry, error) { return NewGeometry(s) } -// NewGeometryFromGeom creates a new Geometry object from a geom.T object. -func NewGeometryFromGeom(g geom.T) (*Geometry, error) { +// NewGeometryFromGeomT creates a new Geometry object from a geom.T object. +func NewGeometryFromGeomT(g geom.T) (*Geometry, error) { spatialObject, err := spatialObjectFromGeomT(g, geopb.SpatialObjectType_GeometryType) if err != nil { return nil, err @@ -309,8 +309,8 @@ func NewGeographyUnsafe(spatialObject geopb.SpatialObject) *Geography { return &Geography{spatialObject: spatialObject} } -// NewGeographyFromGeom creates a new Geography from a geom.T object. -func NewGeographyFromGeom(g geom.T) (*Geography, error) { +// NewGeographyFromGeomT creates a new Geography from a geom.T object. +func NewGeographyFromGeomT(g geom.T) (*Geography, error) { spatialObject, err := spatialObjectFromGeomT(g, geopb.SpatialObjectType_GeographyType) if err != nil { return nil, err @@ -318,9 +318,9 @@ func NewGeographyFromGeom(g geom.T) (*Geography, error) { return NewGeography(spatialObject) } -// MustNewGeographyFromGeom enforces no error from NewGeographyFromGeom. -func MustNewGeographyFromGeom(g geom.T) *Geography { - ret, err := NewGeographyFromGeom(g) +// MustNewGeographyFromGeomT enforces no error from NewGeographyFromGeomT. +func MustNewGeographyFromGeomT(g geom.T) *Geography { + ret, err := NewGeographyFromGeomT(g) if err != nil { panic(err) } @@ -469,7 +469,7 @@ func (g *Geography) AsS2(emptyBehavior EmptyBehavior) ([]s2.Region, error) { return nil, err } // TODO(otan): convert by reading from EWKB to S2 directly. - return S2RegionsFromGeom(geomRepr, emptyBehavior) + return S2RegionsFromGeomT(geomRepr, emptyBehavior) } // BoundingRect returns the bounding s2.Rect of the given Geography. @@ -531,11 +531,11 @@ func IsLinearRingCCW(linearRing *geom.LinearRing) bool { return areaSign > 0 } -// S2RegionsFromGeom converts an geom representation of an object +// S2RegionsFromGeomT converts an geom representation of an object // to s2 regions. // As S2 does not really handle empty geometries well, we need to ingest emptyBehavior and // react appropriately. -func S2RegionsFromGeom(geomRepr geom.T, emptyBehavior EmptyBehavior) ([]s2.Region, error) { +func S2RegionsFromGeomT(geomRepr geom.T, emptyBehavior EmptyBehavior) ([]s2.Region, error) { var regions []s2.Region if geomRepr.Empty() { switch emptyBehavior { @@ -584,7 +584,7 @@ func S2RegionsFromGeom(geomRepr geom.T, emptyBehavior EmptyBehavior) ([]s2.Regio } case *geom.GeometryCollection: for _, geom := range repr.Geoms() { - subRegions, err := S2RegionsFromGeom(geom, emptyBehavior) + subRegions, err := S2RegionsFromGeomT(geom, emptyBehavior) if err != nil { return nil, err } @@ -592,7 +592,7 @@ func S2RegionsFromGeom(geomRepr geom.T, emptyBehavior EmptyBehavior) ([]s2.Regio } case *geom.MultiPoint: for i := 0; i < repr.NumPoints(); i++ { - subRegions, err := S2RegionsFromGeom(repr.Point(i), emptyBehavior) + subRegions, err := S2RegionsFromGeomT(repr.Point(i), emptyBehavior) if err != nil { return nil, err } @@ -600,7 +600,7 @@ func S2RegionsFromGeom(geomRepr geom.T, emptyBehavior EmptyBehavior) ([]s2.Regio } case *geom.MultiLineString: for i := 0; i < repr.NumLineStrings(); i++ { - subRegions, err := S2RegionsFromGeom(repr.LineString(i), emptyBehavior) + subRegions, err := S2RegionsFromGeomT(repr.LineString(i), emptyBehavior) if err != nil { return nil, err } @@ -608,7 +608,7 @@ func S2RegionsFromGeom(geomRepr geom.T, emptyBehavior EmptyBehavior) ([]s2.Regio } case *geom.MultiPolygon: for i := 0; i < repr.NumPolygons(); i++ { - subRegions, err := S2RegionsFromGeom(repr.Polygon(i), emptyBehavior) + subRegions, err := S2RegionsFromGeomT(repr.Polygon(i), emptyBehavior) if err != nil { return nil, err } diff --git a/pkg/geo/geogfn/segmentize.go b/pkg/geo/geogfn/segmentize.go index 572f264f962d..e80d4ca1cd23 100644 --- a/pkg/geo/geogfn/segmentize.go +++ b/pkg/geo/geogfn/segmentize.go @@ -47,7 +47,7 @@ func Segmentize(geography *geo.Geography, segmentMaxLength float64) (*geo.Geogra if err != nil { return nil, err } - return geo.NewGeographyFromGeom(segGeometry) + return geo.NewGeographyFromGeomT(segGeometry) } } diff --git a/pkg/geo/geogfn/topology_operations.go b/pkg/geo/geogfn/topology_operations.go index 37ef340aa062..053c93bae170 100644 --- a/pkg/geo/geogfn/topology_operations.go +++ b/pkg/geo/geogfn/topology_operations.go @@ -41,7 +41,7 @@ func Centroid(g *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid) (*geo.G return nil, err } if geomRepr.Empty() { - return geo.NewGeographyFromGeom(geom.NewGeometryCollection().SetSRID(geomRepr.SRID())) + return geo.NewGeographyFromGeomT(geom.NewGeometryCollection().SetSRID(geomRepr.SRID())) } switch geomRepr.(type) { case *geom.Point, *geom.LineString, *geom.Polygon, *geom.MultiPoint, *geom.MultiLineString, *geom.MultiPolygon: @@ -49,7 +49,7 @@ func Centroid(g *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid) (*geo.G return nil, errors.Newf("unhandled geography type %s", g.ShapeType().String()) } - regions, err := geo.S2RegionsFromGeom(geomRepr, geo.EmptyBehaviorOmit) + regions, err := geo.S2RegionsFromGeomT(geomRepr, geo.EmptyBehaviorOmit) if err != nil { return nil, err } @@ -118,5 +118,5 @@ func Centroid(g *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid) (*geo.G } latLng := s2.LatLngFromPoint(s2.Point{Vector: centroidVector.Normalize()}) centroid := geom.NewPointFlat(geom.XY, []float64{latLng.Lng.Degrees(), latLng.Lat.Degrees()}).SetSRID(int(g.SRID())) - return geo.NewGeographyFromGeom(centroid) + return geo.NewGeographyFromGeomT(centroid) } diff --git a/pkg/geo/geogfn/unary_operators.go b/pkg/geo/geogfn/unary_operators.go index 443255b69a5d..9b7fefa6c5a5 100644 --- a/pkg/geo/geogfn/unary_operators.go +++ b/pkg/geo/geogfn/unary_operators.go @@ -69,7 +69,7 @@ func Perimeter(g *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid) (float default: return 0, nil } - regions, err := geo.S2RegionsFromGeom(gt, geo.EmptyBehaviorOmit) + regions, err := geo.S2RegionsFromGeomT(gt, geo.EmptyBehaviorOmit) if err != nil { return 0, err } @@ -93,7 +93,7 @@ func Length(g *geo.Geography, useSphereOrSpheroid UseSphereOrSpheroid) (float64, default: return 0, nil } - regions, err := geo.S2RegionsFromGeom(gt, geo.EmptyBehaviorOmit) + regions, err := geo.S2RegionsFromGeomT(gt, geo.EmptyBehaviorOmit) if err != nil { return 0, err } @@ -152,7 +152,7 @@ func Project(g *geo.Geography, distance float64, azimuth s1.Angle) (*geo.Geograp geo.NormalizeLatitudeDegrees(projected.Lat.Degrees()), }, ).SetSRID(point.SRID()) - return geo.NewGeographyFromGeom(ret) + return geo.NewGeographyFromGeomT(ret) } // length returns the sum of the lengtsh and perimeters in the shapes of the Geography. diff --git a/pkg/geo/geogfn/unary_operators_test.go b/pkg/geo/geogfn/unary_operators_test.go index 24abca0d3815..a981f8ce21c5 100644 --- a/pkg/geo/geogfn/unary_operators_test.go +++ b/pkg/geo/geogfn/unary_operators_test.go @@ -252,17 +252,17 @@ func TestProject(t *testing.T) { }{ { "POINT(0 0), 100000, radians(45)", - geo.MustNewGeographyFromGeom(geom.NewPointFlat(geom.XY, []float64{0, 0}).SetSRID(4326)), + geo.MustNewGeographyFromGeomT(geom.NewPointFlat(geom.XY, []float64{0, 0}).SetSRID(4326)), 100000, 45 * math.Pi / 180.0, - geo.MustNewGeographyFromGeom(geom.NewPointFlat(geom.XY, []float64{0.6352310291255374, 0.6394723347291977}).SetSRID(4326)), + geo.MustNewGeographyFromGeomT(geom.NewPointFlat(geom.XY, []float64{0.6352310291255374, 0.6394723347291977}).SetSRID(4326)), }, { "SRID=4004;POINT(0 0), 100000, radians(45)", - geo.MustNewGeographyFromGeom(geom.NewPointFlat(geom.XY, []float64{0, 0}).SetSRID(4004)), + geo.MustNewGeographyFromGeomT(geom.NewPointFlat(geom.XY, []float64{0, 0}).SetSRID(4004)), 100000, 45 * math.Pi / 180.0, - geo.MustNewGeographyFromGeom(geom.NewPointFlat(geom.XY, []float64{0.6353047281438549, 0.6395336363116583}).SetSRID(4004)), + geo.MustNewGeographyFromGeomT(geom.NewPointFlat(geom.XY, []float64{0.6353047281438549, 0.6395336363116583}).SetSRID(4004)), }, } diff --git a/pkg/geo/geoindex/s2_geometry_index.go b/pkg/geo/geoindex/s2_geometry_index.go index 8cfd86a64ca4..f1a92643d5bf 100644 --- a/pkg/geo/geoindex/s2_geometry_index.go +++ b/pkg/geo/geoindex/s2_geometry_index.go @@ -91,7 +91,7 @@ func (s *s2GeometryIndex) InvertedIndexKeys(c context.Context, g *geo.Geometry) } var keys []Key if gt != nil { - r := s.s2RegionsFromPlanarGeom(gt) + r := s.s2RegionsFromPlanarGeomT(gt) keys = invertedIndexKeys(c, s.rc, r) } if clipped { @@ -115,7 +115,7 @@ func (s *s2GeometryIndex) CoveredBy(c context.Context, g *geo.Geometry) (RPKeyEx } var expr RPKeyExpr if gt != nil { - r := s.s2RegionsFromPlanarGeom(gt) + r := s.s2RegionsFromPlanarGeomT(gt) expr = coveredBy(c, s.rc, r) } if clipped { @@ -138,7 +138,7 @@ func (s *s2GeometryIndex) Intersects(c context.Context, g *geo.Geometry) (UnionK } var spans UnionKeySpans if gt != nil { - r := s.s2RegionsFromPlanarGeom(gt) + r := s.s2RegionsFromPlanarGeomT(gt) spans = intersects(c, s.rc, r) } if clipped { @@ -290,10 +290,10 @@ func (s *s2GeometryIndex) planarPointToS2Point(x float64, y float64) s2.Point { return face0UVToXYZPoint(u, v) } -// TODO(sumeer): this is similar to s2RegionsFromGeom() but needs to do +// TODO(sumeer): this is similar to s2RegionsFromGeomT() but needs to do // a different point conversion. If these functions do not diverge further, // and turn out not to be performance critical, merge the two implementations. -func (s *s2GeometryIndex) s2RegionsFromPlanarGeom(geomRepr geom.T) []s2.Region { +func (s *s2GeometryIndex) s2RegionsFromPlanarGeomT(geomRepr geom.T) []s2.Region { var regions []s2.Region switch repr := geomRepr.(type) { case *geom.Point: @@ -332,19 +332,19 @@ func (s *s2GeometryIndex) s2RegionsFromPlanarGeom(geomRepr geom.T) []s2.Region { } case *geom.GeometryCollection: for _, geom := range repr.Geoms() { - regions = append(regions, s.s2RegionsFromPlanarGeom(geom)...) + regions = append(regions, s.s2RegionsFromPlanarGeomT(geom)...) } case *geom.MultiPoint: for i := 0; i < repr.NumPoints(); i++ { - regions = append(regions, s.s2RegionsFromPlanarGeom(repr.Point(i))...) + regions = append(regions, s.s2RegionsFromPlanarGeomT(repr.Point(i))...) } case *geom.MultiLineString: for i := 0; i < repr.NumLineStrings(); i++ { - regions = append(regions, s.s2RegionsFromPlanarGeom(repr.LineString(i))...) + regions = append(regions, s.s2RegionsFromPlanarGeomT(repr.LineString(i))...) } case *geom.MultiPolygon: for i := 0; i < repr.NumPolygons(); i++ { - regions = append(regions, s.s2RegionsFromPlanarGeom(repr.Polygon(i))...) + regions = append(regions, s.s2RegionsFromPlanarGeomT(repr.Polygon(i))...) } } return regions @@ -355,6 +355,6 @@ func (s *s2GeometryIndex) TestingInnerCovering(g *geo.Geometry) s2.CellUnion { if err != nil || gt == nil { return nil } - r := s.s2RegionsFromPlanarGeom(gt) + r := s.s2RegionsFromPlanarGeomT(gt) return innerCovering(s.rc, r) } diff --git a/pkg/geo/geomfn/distance.go b/pkg/geo/geomfn/distance.go index 8963329a0846..7cadf1bc9667 100644 --- a/pkg/geo/geomfn/distance.go +++ b/pkg/geo/geomfn/distance.go @@ -141,7 +141,7 @@ func distanceLineStringInternal( return nil, errors.Newf("programmer error: unknown behavior") } lineString := geom.NewLineStringFlat(geom.XY, append(coordA, coordB...)).SetSRID(int(a.SRID())) - return geo.NewGeometryFromGeom(lineString) + return geo.NewGeometryFromGeomT(lineString) } // maxDistanceInternal finds the maximum distance between two geometries. diff --git a/pkg/geo/geomfn/linear_reference.go b/pkg/geo/geomfn/linear_reference.go index 6e927b34cc10..e54c75c659bb 100644 --- a/pkg/geo/geomfn/linear_reference.go +++ b/pkg/geo/geomfn/linear_reference.go @@ -52,7 +52,7 @@ func LineInterpolatePoints(g *geo.Geometry, fraction float64, repeat bool) (*geo return nil, err } } - return geo.NewGeometryFromGeom(interpolatedPoints) + return geo.NewGeometryFromGeomT(interpolatedPoints) } interpolatedPointEWKB, err := geos.InterpolateLine(g.EWKB(), fraction*lengthOfLineString) if err != nil { diff --git a/pkg/geo/geomfn/segmentize.go b/pkg/geo/geomfn/segmentize.go index 12b8186cc829..3090bd135b0c 100644 --- a/pkg/geo/geomfn/segmentize.go +++ b/pkg/geo/geomfn/segmentize.go @@ -41,7 +41,7 @@ func Segmentize(g *geo.Geometry, segmentMaxLength float64) (*geo.Geometry, error if err != nil { return nil, err } - return geo.NewGeometryFromGeom(segGeometry) + return geo.NewGeometryFromGeomT(segGeometry) } } diff --git a/pkg/geo/geotransform/geotransform.go b/pkg/geo/geotransform/geotransform.go index e81cf79473f3..2ee76cc1d43e 100644 --- a/pkg/geo/geotransform/geotransform.go +++ b/pkg/geo/geotransform/geotransform.go @@ -36,7 +36,7 @@ func Transform( if err != nil { return nil, err } - return geo.NewGeometryFromGeom(newT) + return geo.NewGeometryFromGeomT(newT) } // transform performs the projection operation on a geom.T object. diff --git a/pkg/sql/sem/builtins/geo_builtins.go b/pkg/sql/sem/builtins/geo_builtins.go index a5421480f474..2d54450b040c 100644 --- a/pkg/sql/sem/builtins/geo_builtins.go +++ b/pkg/sql/sem/builtins/geo_builtins.go @@ -1180,7 +1180,7 @@ Negative azimuth values and values greater than 2π (360 degrees) are supported. return tree.DNull, nil } coord := t.Coord(0) - retG, err := geo.NewGeometryFromGeom( + retG, err := geo.NewGeometryFromGeomT( geom.NewPointFlat(geom.XY, []float64{coord.X(), coord.Y()}).SetSRID(t.SRID()), ) if err != nil { @@ -1270,7 +1270,7 @@ Flags shown square brackets after the geometry type have the following meaning: return tree.DNull, nil } coord := t.Coord(t.NumCoords() - 1) - retG, err := geo.NewGeometryFromGeom( + retG, err := geo.NewGeometryFromGeomT( geom.NewPointFlat(geom.XY, []float64{coord.X(), coord.Y()}).SetSRID(t.SRID()), ) if err != nil { @@ -1352,7 +1352,7 @@ Flags shown square brackets after the geometry type have the following meaning: ring := t.LinearRing(0) lineString = geom.NewLineStringFlat(t.Layout(), ring.FlatCoords()) } - ret, err := geo.NewGeometryFromGeom(lineString.SetSRID(t.SRID())) + ret, err := geo.NewGeometryFromGeomT(lineString.SetSRID(t.SRID())) if err != nil { return nil, err } @@ -1387,7 +1387,7 @@ Flags shown square brackets after the geometry type have the following meaning: } ring := t.LinearRing(n) lineString := geom.NewLineStringFlat(t.Layout(), ring.FlatCoords()).SetSRID(t.SRID()) - ret, err := geo.NewGeometryFromGeom(lineString) + ret, err := geo.NewGeometryFromGeomT(lineString) if err != nil { return nil, err } @@ -1421,7 +1421,7 @@ Flags shown square brackets after the geometry type have the following meaning: if n >= t.NumCoords() { return tree.DNull, nil } - g, err := geo.NewGeometryFromGeom(geom.NewPointFlat(t.Layout(), t.Coord(n)).SetSRID(t.SRID())) + g, err := geo.NewGeometryFromGeomT(geom.NewPointFlat(t.Layout(), t.Coord(n)).SetSRID(t.SRID())) if err != nil { return nil, err } @@ -1460,7 +1460,7 @@ Flags shown square brackets after the geometry type have the following meaning: if n >= t.NumPoints() { return tree.DNull, nil } - g, err := geo.NewGeometryFromGeom(t.Point(n).SetSRID(t.SRID())) + g, err := geo.NewGeometryFromGeomT(t.Point(n).SetSRID(t.SRID())) if err != nil { return nil, err } @@ -1469,7 +1469,7 @@ Flags shown square brackets after the geometry type have the following meaning: if n >= t.NumLineStrings() { return tree.DNull, nil } - g, err := geo.NewGeometryFromGeom(t.LineString(n).SetSRID(t.SRID())) + g, err := geo.NewGeometryFromGeomT(t.LineString(n).SetSRID(t.SRID())) if err != nil { return nil, err } @@ -1478,7 +1478,7 @@ Flags shown square brackets after the geometry type have the following meaning: if n >= t.NumPolygons() { return tree.DNull, nil } - g, err := geo.NewGeometryFromGeom(t.Polygon(n).SetSRID(t.SRID())) + g, err := geo.NewGeometryFromGeomT(t.Polygon(n).SetSRID(t.SRID())) if err != nil { return nil, err } @@ -1487,7 +1487,7 @@ Flags shown square brackets after the geometry type have the following meaning: if n >= t.NumGeoms() { return tree.DNull, nil } - g, err := geo.NewGeometryFromGeom(t.Geom(n)) + g, err := geo.NewGeometryFromGeomT(t.Geom(n)) if err != nil { return nil, err }