Add centroid information when geocoding

I would use the boundary rect, but I'm getting a 500-level error from
stadia maps
This commit is contained in:
Eli Ribble 2026-02-25 16:08:32 +00:00
parent 8feabbc489
commit 2bb4a134b2
No known key found for this signature in database
10 changed files with 272 additions and 56 deletions

View file

@ -258,6 +258,24 @@ var Organizations = Table[
Generated: true,
AutoIncr: false,
},
ServiceAreaCentroidX: column{
Name: "service_area_centroid_x",
DBType: "double precision",
Default: "GENERATED",
Comment: "",
Nullable: true,
Generated: true,
AutoIncr: false,
},
ServiceAreaCentroidY: column{
Name: "service_area_centroid_y",
DBType: "double precision",
Default: "GENERATED",
Comment: "",
Nullable: true,
Generated: true,
AutoIncr: false,
},
},
Indexes: organizationIndexes{
OrganizationPkey: index{
@ -372,11 +390,13 @@ type organizationColumns struct {
ServiceAreaXmax column
ServiceAreaYmax column
ServiceAreaCentroidGeojson column
ServiceAreaCentroidX column
ServiceAreaCentroidY column
}
func (c organizationColumns) AsSlice() []column {
return []column{
c.ID, c.Name, c.ArcgisID, c.ArcgisName, c.FieldseekerURL, c.ImportDistrictGid, c.Website, c.LogoUUID, c.Slug, c.GeneralManagerName, c.MailingAddressCity, c.MailingAddressPostalCode, c.MailingAddressStreet, c.OfficeAddressCity, c.OfficeAddressPostalCode, c.OfficeAddressStreet, c.ServiceAreaGeometry, c.ServiceAreaSquareMeters, c.ServiceAreaCentroid, c.ServiceAreaExtent, c.OfficeFax, c.OfficePhone, c.ServiceAreaXmin, c.ServiceAreaYmin, c.ServiceAreaXmax, c.ServiceAreaYmax, c.ServiceAreaCentroidGeojson,
c.ID, c.Name, c.ArcgisID, c.ArcgisName, c.FieldseekerURL, c.ImportDistrictGid, c.Website, c.LogoUUID, c.Slug, c.GeneralManagerName, c.MailingAddressCity, c.MailingAddressPostalCode, c.MailingAddressStreet, c.OfficeAddressCity, c.OfficeAddressPostalCode, c.OfficeAddressStreet, c.ServiceAreaGeometry, c.ServiceAreaSquareMeters, c.ServiceAreaCentroid, c.ServiceAreaExtent, c.OfficeFax, c.OfficePhone, c.ServiceAreaXmin, c.ServiceAreaYmin, c.ServiceAreaXmax, c.ServiceAreaYmax, c.ServiceAreaCentroidGeojson, c.ServiceAreaCentroidX, c.ServiceAreaCentroidY,
}
}

View file

@ -2929,6 +2929,8 @@ func (f *Factory) FromExistingOrganization(m *models.Organization) *Organization
o.ServiceAreaXmax = func() null.Val[float64] { return m.ServiceAreaXmax }
o.ServiceAreaYmax = func() null.Val[float64] { return m.ServiceAreaYmax }
o.ServiceAreaCentroidGeojson = func() null.Val[string] { return m.ServiceAreaCentroidGeojson }
o.ServiceAreaCentroidX = func() null.Val[float64] { return m.ServiceAreaCentroidX }
o.ServiceAreaCentroidY = func() null.Val[float64] { return m.ServiceAreaCentroidY }
ctx := context.Background()
if len(m.R.EmailContacts) > 0 {

View file

@ -65,6 +65,8 @@ type OrganizationTemplate struct {
ServiceAreaXmax func() null.Val[float64]
ServiceAreaYmax func() null.Val[float64]
ServiceAreaCentroidGeojson func() null.Val[string]
ServiceAreaCentroidX func() null.Val[float64]
ServiceAreaCentroidY func() null.Val[float64]
r organizationR
f *Factory
@ -971,6 +973,12 @@ func (o OrganizationTemplate) Build() *models.Organization {
if o.ServiceAreaCentroidGeojson != nil {
m.ServiceAreaCentroidGeojson = o.ServiceAreaCentroidGeojson()
}
if o.ServiceAreaCentroidX != nil {
m.ServiceAreaCentroidX = o.ServiceAreaCentroidX()
}
if o.ServiceAreaCentroidY != nil {
m.ServiceAreaCentroidY = o.ServiceAreaCentroidY()
}
o.setModelRels(m)
@ -1902,6 +1910,8 @@ func (m organizationMods) RandomizeAllColumns(f *faker.Faker) OrganizationMod {
OrganizationMods.RandomServiceAreaXmax(f),
OrganizationMods.RandomServiceAreaYmax(f),
OrganizationMods.RandomServiceAreaCentroidGeojson(f),
OrganizationMods.RandomServiceAreaCentroidX(f),
OrganizationMods.RandomServiceAreaCentroidY(f),
}
}
@ -3292,6 +3302,112 @@ func (m organizationMods) RandomServiceAreaCentroidGeojsonNotNull(f *faker.Faker
})
}
// Set the model columns to this value
func (m organizationMods) ServiceAreaCentroidX(val null.Val[float64]) OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.ServiceAreaCentroidX = func() null.Val[float64] { return val }
})
}
// Set the Column from the function
func (m organizationMods) ServiceAreaCentroidXFunc(f func() null.Val[float64]) OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.ServiceAreaCentroidX = f
})
}
// Clear any values for the column
func (m organizationMods) UnsetServiceAreaCentroidX() OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.ServiceAreaCentroidX = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m organizationMods) RandomServiceAreaCentroidX(f *faker.Faker) OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.ServiceAreaCentroidX = func() null.Val[float64] {
if f == nil {
f = &defaultFaker
}
val := random_float64(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m organizationMods) RandomServiceAreaCentroidXNotNull(f *faker.Faker) OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.ServiceAreaCentroidX = func() null.Val[float64] {
if f == nil {
f = &defaultFaker
}
val := random_float64(f)
return null.From(val)
}
})
}
// Set the model columns to this value
func (m organizationMods) ServiceAreaCentroidY(val null.Val[float64]) OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.ServiceAreaCentroidY = func() null.Val[float64] { return val }
})
}
// Set the Column from the function
func (m organizationMods) ServiceAreaCentroidYFunc(f func() null.Val[float64]) OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.ServiceAreaCentroidY = f
})
}
// Clear any values for the column
func (m organizationMods) UnsetServiceAreaCentroidY() OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.ServiceAreaCentroidY = nil
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is sometimes null
func (m organizationMods) RandomServiceAreaCentroidY(f *faker.Faker) OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.ServiceAreaCentroidY = func() null.Val[float64] {
if f == nil {
f = &defaultFaker
}
val := random_float64(f)
return null.From(val)
}
})
}
// Generates a random value for the column using the given faker
// if faker is nil, a default faker is used
// The generated value is never null
func (m organizationMods) RandomServiceAreaCentroidYNotNull(f *faker.Faker) OrganizationMod {
return OrganizationModFunc(func(_ context.Context, o *OrganizationTemplate) {
o.ServiceAreaCentroidY = func() null.Val[float64] {
if f == nil {
f = &defaultFaker
}
val := random_float64(f)
return null.From(val)
}
})
}
func (m organizationMods) WithParentsCascading() OrganizationMod {
return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) {
if isDone, _ := organizationWithParentsCascadingCtx.Value(ctx); isDone {

View file

@ -0,0 +1,3 @@
-- +goose Up
ALTER TABLE organization ADD COLUMN service_area_centroid_x DOUBLE PRECISION GENERATED ALWAYS AS (ST_X(ST_Centroid(service_area_geometry))) STORED;
ALTER TABLE organization ADD COLUMN service_area_centroid_y DOUBLE PRECISION GENERATED ALWAYS AS (ST_Y(ST_Centroid(service_area_geometry))) STORED;

View file

@ -56,6 +56,8 @@ type Organization struct {
ServiceAreaXmax null.Val[float64] `db:"service_area_xmax,generated" `
ServiceAreaYmax null.Val[float64] `db:"service_area_ymax,generated" `
ServiceAreaCentroidGeojson null.Val[string] `db:"service_area_centroid_geojson,generated" `
ServiceAreaCentroidX null.Val[float64] `db:"service_area_centroid_x,generated" `
ServiceAreaCentroidY null.Val[float64] `db:"service_area_centroid_y,generated" `
R organizationR `db:"-" `
@ -118,7 +120,7 @@ type organizationR struct {
func buildOrganizationColumns(alias string) organizationColumns {
return organizationColumns{
ColumnsExpr: expr.NewColumnsExpr(
"id", "name", "arcgis_id", "arcgis_name", "fieldseeker_url", "import_district_gid", "website", "logo_uuid", "slug", "general_manager_name", "mailing_address_city", "mailing_address_postal_code", "mailing_address_street", "office_address_city", "office_address_postal_code", "office_address_street", "service_area_geometry", "service_area_square_meters", "service_area_centroid", "service_area_extent", "office_fax", "office_phone", "service_area_xmin", "service_area_ymin", "service_area_xmax", "service_area_ymax", "service_area_centroid_geojson",
"id", "name", "arcgis_id", "arcgis_name", "fieldseeker_url", "import_district_gid", "website", "logo_uuid", "slug", "general_manager_name", "mailing_address_city", "mailing_address_postal_code", "mailing_address_street", "office_address_city", "office_address_postal_code", "office_address_street", "service_area_geometry", "service_area_square_meters", "service_area_centroid", "service_area_extent", "office_fax", "office_phone", "service_area_xmin", "service_area_ymin", "service_area_xmax", "service_area_ymax", "service_area_centroid_geojson", "service_area_centroid_x", "service_area_centroid_y",
).WithParent("organization"),
tableAlias: alias,
ID: psql.Quote(alias, "id"),
@ -148,6 +150,8 @@ func buildOrganizationColumns(alias string) organizationColumns {
ServiceAreaXmax: psql.Quote(alias, "service_area_xmax"),
ServiceAreaYmax: psql.Quote(alias, "service_area_ymax"),
ServiceAreaCentroidGeojson: psql.Quote(alias, "service_area_centroid_geojson"),
ServiceAreaCentroidX: psql.Quote(alias, "service_area_centroid_x"),
ServiceAreaCentroidY: psql.Quote(alias, "service_area_centroid_y"),
}
}
@ -181,6 +185,8 @@ type organizationColumns struct {
ServiceAreaXmax psql.Expression
ServiceAreaYmax psql.Expression
ServiceAreaCentroidGeojson psql.Expression
ServiceAreaCentroidX psql.Expression
ServiceAreaCentroidY psql.Expression
}
func (c organizationColumns) Alias() string {
@ -4449,6 +4455,8 @@ type organizationWhere[Q psql.Filterable] struct {
ServiceAreaXmax psql.WhereNullMod[Q, float64]
ServiceAreaYmax psql.WhereNullMod[Q, float64]
ServiceAreaCentroidGeojson psql.WhereNullMod[Q, string]
ServiceAreaCentroidX psql.WhereNullMod[Q, float64]
ServiceAreaCentroidY psql.WhereNullMod[Q, float64]
}
func (organizationWhere[Q]) AliasedAs(alias string) organizationWhere[Q] {
@ -4484,6 +4492,8 @@ func buildOrganizationWhere[Q psql.Filterable](cols organizationColumns) organiz
ServiceAreaXmax: psql.WhereNull[Q, float64](cols.ServiceAreaXmax),
ServiceAreaYmax: psql.WhereNull[Q, float64](cols.ServiceAreaYmax),
ServiceAreaCentroidGeojson: psql.WhereNull[Q, string](cols.ServiceAreaCentroidGeojson),
ServiceAreaCentroidX: psql.WhereNull[Q, float64](cols.ServiceAreaCentroidX),
ServiceAreaCentroidY: psql.WhereNull[Q, float64](cols.ServiceAreaCentroidY),
}
}