Remove now-extraneous latitude/longitude generated columns
Now that we can pull out the geometry directly into a go object we don't need these and they complicate our insertions
This commit is contained in:
parent
34a136eba5
commit
7a361a330d
40 changed files with 426 additions and 464 deletions
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/model"
|
||||
//"github.com/rs/zerolog/log"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/stephenafamo/scan"
|
||||
)
|
||||
|
||||
|
|
@ -33,15 +33,16 @@ func (a Address) String() string {
|
|||
}
|
||||
func AddressFromModel(m model.Address) Address {
|
||||
//log.Debug().Int32("id", m.ID).Float64("lat", m.LocationLatitude.GetOr(0.0)).Float64("lng", m.LocationLongitude.GetOr(0.0)).Msg("converting address")
|
||||
l, err := LocationFromGeom(m.Location)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Int32("id", m.ID).Msg("getting location for address")
|
||||
}
|
||||
return Address{
|
||||
Country: m.Country,
|
||||
GID: m.Gid,
|
||||
ID: &m.ID,
|
||||
Locality: m.Locality,
|
||||
Location: &Location{
|
||||
Latitude: *m.LocationLatitude,
|
||||
Longitude: *m.LocationLongitude,
|
||||
},
|
||||
Country: m.Country,
|
||||
GID: m.Gid,
|
||||
ID: &m.ID,
|
||||
Locality: m.Locality,
|
||||
Location: &l,
|
||||
Number: m.Number,
|
||||
PostalCode: m.PostalCode,
|
||||
Raw: addressToRaw(m),
|
||||
|
|
|
|||
|
|
@ -42,6 +42,16 @@ func (l Location) ToGeom() geom.T {
|
|||
func LocationFromFS(pl *models.FieldseekerPointlocation) Location {
|
||||
return Location{}
|
||||
}
|
||||
func LocationFromGeom(g geom.T) (Location, error) {
|
||||
p, err := geomutil.AsPoint(g)
|
||||
if err != nil {
|
||||
return Location{}, fmt.Errorf("as point: %w", err)
|
||||
}
|
||||
return Location{
|
||||
Latitude: p.Y(),
|
||||
Longitude: p.X(),
|
||||
}, nil
|
||||
}
|
||||
func LocationDistance(l1 Location, l2 Location) float64 {
|
||||
lat_delta := l1.Latitude - l2.Latitude
|
||||
lng_delta := l1.Longitude - l2.Longitude
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue