Add new platform functions for image tile and parcel
This commit is contained in:
parent
8455a67750
commit
985a2ab186
2 changed files with 79 additions and 0 deletions
38
platform/imagetile/imagetile.go
Normal file
38
platform/imagetile/imagetile.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package imagetile
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Gleipnir-Technology/arcgis-go"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/background"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
//"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func ImageAtPoint(ctx context.Context, org *models.Organization, level uint, x, y float64) ([]byte, error) {
|
||||
oauth, err := background.GetOAuthForOrg(ctx, org)
|
||||
if err != nil {
|
||||
return []byte{}, fmt.Errorf("get oauth for org: %w", err)
|
||||
}
|
||||
fssync, err := background.NewFieldSeeker(
|
||||
ctx,
|
||||
oauth,
|
||||
)
|
||||
map_service, err := aerialImageService(ctx, fssync.Arcgis)
|
||||
if err != nil {
|
||||
return []byte{}, fmt.Errorf("no map service: %w", err)
|
||||
}
|
||||
return map_service.TileGPS(ctx, fssync.Arcgis, level, x, y)
|
||||
}
|
||||
|
||||
func aerialImageService(ctx context.Context, gis *arcgis.ArcGIS) (*arcgis.MapService, error) {
|
||||
map_services, err := gis.MapServices(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("aerial image service: %w", err)
|
||||
}
|
||||
for _, ms := range map_services {
|
||||
return &ms, nil
|
||||
}
|
||||
return nil, fmt.Errorf("non found")
|
||||
}
|
||||
41
platform/parcel.go
Normal file
41
platform/parcel.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package platform
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/paulmach/orb"
|
||||
"github.com/stephenafamo/scan"
|
||||
//"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func ParcelEnvelope(ctx context.Context, parcel_id int32) (*orb.Polygon, error) {
|
||||
type _Row struct {
|
||||
Apn string
|
||||
Description string
|
||||
ID int
|
||||
Geometry string
|
||||
Envelope string
|
||||
}
|
||||
row, err := bob.One(ctx, db.PGInstance.BobDB, psql.Select(
|
||||
sm.Columns(
|
||||
psql.F("ST_AsGeoJSON", psql.F("ST_Envelope", psql.Raw("geometry")))(),
|
||||
),
|
||||
sm.From("parcel"),
|
||||
sm.Where(psql.Quote("id").EQ(psql.Arg(parcel_id))),
|
||||
), scan.StructMapper[_Row]())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query parcel: %w", err)
|
||||
}
|
||||
var polygon orb.Polygon
|
||||
err = json.Unmarshal([]byte(row.Envelope), &polygon)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unmarshal json: %w", err)
|
||||
}
|
||||
return &polygon, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue