RenderGeoOp renders SpatiaLite spatial operations Requires SpatiaLite extension to be loaded
(ctx Context, table, col string, ex *qcode.Exp)
| 488 | // RenderGeoOp renders SpatiaLite spatial operations |
| 489 | // Requires SpatiaLite extension to be loaded |
| 490 | func (d *SQLiteDialect) RenderGeoOp(ctx Context, table, col string, ex *qcode.Exp) error { |
| 491 | geo := ex.Geo |
| 492 | if geo == nil { |
| 493 | return fmt.Errorf("GIS expression missing geometry data") |
| 494 | } |
| 495 | |
| 496 | switch ex.Op { |
| 497 | case qcode.OpGeoDistance, qcode.OpGeoNear: |
| 498 | // SpatiaLite: ST_Distance with ellipsoid calculation |
| 499 | ctx.WriteString(`ST_Distance(`) |
| 500 | ctx.ColWithTable(table, col) |
| 501 | ctx.WriteString(`, `) |
| 502 | d.renderGeoGeometry(ctx, geo) |
| 503 | ctx.WriteString(`, 1) <= `) // 1 = use ellipsoid |
| 504 | d.renderGeoDistance(ctx, geo) |
| 505 | |
| 506 | case qcode.OpGeoWithin: |
| 507 | ctx.WriteString(`ST_Within(`) |
| 508 | ctx.ColWithTable(table, col) |
| 509 | ctx.WriteString(`, `) |
| 510 | d.renderGeoGeometry(ctx, geo) |
| 511 | ctx.WriteString(`)`) |
| 512 | |
| 513 | case qcode.OpGeoContains: |
| 514 | ctx.WriteString(`ST_Contains(`) |
| 515 | ctx.ColWithTable(table, col) |
| 516 | ctx.WriteString(`, `) |
| 517 | d.renderGeoGeometry(ctx, geo) |
| 518 | ctx.WriteString(`)`) |
| 519 | |
| 520 | case qcode.OpGeoIntersects: |
| 521 | ctx.WriteString(`ST_Intersects(`) |
| 522 | ctx.ColWithTable(table, col) |
| 523 | ctx.WriteString(`, `) |
| 524 | d.renderGeoGeometry(ctx, geo) |
| 525 | ctx.WriteString(`)`) |
| 526 | |
| 527 | case qcode.OpGeoCoveredBy: |
| 528 | ctx.WriteString(`ST_CoveredBy(`) |
| 529 | ctx.ColWithTable(table, col) |
| 530 | ctx.WriteString(`, `) |
| 531 | d.renderGeoGeometry(ctx, geo) |
| 532 | ctx.WriteString(`)`) |
| 533 | |
| 534 | case qcode.OpGeoCovers: |
| 535 | ctx.WriteString(`ST_Covers(`) |
| 536 | ctx.ColWithTable(table, col) |
| 537 | ctx.WriteString(`, `) |
| 538 | d.renderGeoGeometry(ctx, geo) |
| 539 | ctx.WriteString(`)`) |
| 540 | |
| 541 | case qcode.OpGeoTouches: |
| 542 | ctx.WriteString(`ST_Touches(`) |
| 543 | ctx.ColWithTable(table, col) |
| 544 | ctx.WriteString(`, `) |
| 545 | d.renderGeoGeometry(ctx, geo) |
| 546 | ctx.WriteString(`)`) |
| 547 |
nothing calls this directly
no test coverage detected