Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use geometry type in postgis #522

Open
boojongmin opened this issue Apr 23, 2022 · 10 comments
Open

how to use geometry type in postgis #522

boojongmin opened this issue Apr 23, 2022 · 10 comments
Labels
question Further information is requested stale

Comments

@boojongmin
Copy link

hi, I have a question when using postgis.

how to model mapping geometry type?

thanks you :)

@imraan-go
Copy link

+1

@vmihailenco
Copy link
Member

pgtype support some geometric types, e.g. https://pkg.go.dev/github.com/jackc/pgtype#Point

@vmihailenco vmihailenco added the question Further information is requested label Apr 23, 2022
@boojongmin-gm
Copy link

thank you for your answer :)

@boojongmin-gm
Copy link

@vmihailenco

Point       pgtype.Point

I use point type but that is not working without cast(geometry::point)

how to use pgtype.Point type on gemetry type when insert sql?

thantk you

@vmihailenco
Copy link
Member

@boojongmin can you try

Point       pgtype.Point `bun:"type:geometry::point"`

If that does not work, please provide a program that reproduces the problem.

@max107
Copy link
Contributor

max107 commented May 4, 2022

@boojongmin-gm

how to use pgtype.Point type on gemetry type when insert sql?

you can use paulmach/orb package.

package geotype

import (
	"database/sql/driver"
	"github.com/paulmach/orb"
	"github.com/paulmach/orb/encoding/wkt"
)

type OrbGeometry struct {
	orb.Geometry
}

var _ driver.Valuer = (*OrbGeometry)(nil)

func (tm *OrbGeometry) Value() (driver.Value, error) {
	if tm.Geometry == nil {
		return nil, nil
	}
	return wkt.MarshalString(tm.Geometry), nil
}

func NewPoint(lng, lat float64) OrbGeometry {
	return OrbGeometry{
		Geometry: orb.Point{lng, lat},
	}
}

@max107
Copy link
Contributor

max107 commented May 4, 2022

@vmihailenco

Schema creation (db.NewCreateTable().Model(m).Exec(ctx)) is not work with ::point.

Example

`bun:"geom,notnull,type:geometry(Point, 4326)::point" json:"-"`

Error

ERROR: syntax error at or near "::" (SQLSTATE=42601)

@boojongmin-gm
Copy link

boojongmin-gm commented May 19, 2022

@vmihailenco

it is not working for me my code and error message is below.

type Building struct {
	bun.BaseModel `bun:"table:tt,alias:t"`
	Id            int64 `bun:",pk"`
	Point         pgtype.Point `bun:"type:geometry::point"`
}
err := Db.NewSelect().
		Column("*").
		Model(r).
		Where("id = ?", id).
		Scan(ctx)
SELECT * FROM "tt" AS "p" WHERE (id = 1) 	  *fmt.wrapError: sql: Scan error on column index 6, name "point": invalid format for point 

error: sql: Scan error on column index 6, name "point": invalid format for point

would you check this?

thank you.

@tingold
Copy link

tingold commented Aug 23, 2022

I've been using PostGIS+Bun+Orb for a while and just broke it into a separate project --> https://github.com/tingold/bunpostgis let me know if this helps

Copy link

github-actions bot commented Nov 7, 2024

This issue has been automatically marked as stale because it has not had activity in the last 30 days. If there is no update within the next 7 days, this issue will be closed.

@github-actions github-actions bot added the stale label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested stale
Projects
None yet
Development

No branches or pull requests

6 participants