Skip to content

Conversation

@Mandukhai-Alimaa
Copy link
Contributor

Rationale for this change

There is no support for geoarrow in go

What changes are included in this PR?

Add support for geoarrow.point and register it as extension type and add tests for the geoarrow.point

Are these changes tested?

Yes, the newly added test and all the other tests are passing.

Are there any user-facing changes?

Users will be able to use geoarrow.point as an extension type.

@Mandukhai-Alimaa
Copy link
Contributor Author

This is part of solving #504. On the last PR to add support for the final geoarrow data type will add the closes tag and close the issue

Comment on lines +63 to +65
func (p Point) IsEmpty() bool {
return math.IsNaN(p.X) && math.IsNaN(p.Y) && math.IsNaN(p.Z) && math.IsNaN(p.M)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment says "NaN or zero" but you're only checking for NaN here

Comment on lines +66 to +71
// GeometryEncoding represents the encoding method for geometry data
type GeometryEncoding int

const (
EncodingGeoArrow GeometryEncoding = iota
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would be the alternate to this that would be the other constants?

Comment on lines +111 to +112
// Encoding specifies the geometry encoding format
Encoding GeometryEncoding `json:"encoding,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this in the spec, where is this member coming from?

Comment on lines +114 to +115
// CRS contains PROJJSON coordinate reference system information
CRS json.RawMessage `json:"crs,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it should be PROJJSON it could also be other formats

}

// GeometryMetadata contains metadata for GeoArrow geometry types
type GeometryMetadata struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're missing the optional crs_type member which should be one of

  • "projjson"
  • "wkt2:2019"
  • "authority_code"
  • "srid"

// Value returns the Point at the given index
func (p *PointArray) Value(i int) Point {
pointType := p.ExtensionType().(*PointType)
structArray := p.Storage().(*array.Struct)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to determine whether it is interleaved or separate before you assume it's a struct

point := Point{Dimension: pointType.dimension}

if p.IsNull(i) {
return point
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use NewEmptyPoint?

Comment on lines +295 to +307
switch point.Dimension {
case DimensionXY:
return []float64{point.X, point.Y}
case DimensionXYZ:
return []float64{point.X, point.Y, point.Z}
case DimensionXYM:
return []float64{point.X, point.Y, point.M}
case DimensionXYZM:
return []float64{point.X, point.Y, point.Z, point.M}
default:
// Should never happen but defensive programming
panic(fmt.Sprintf("unknown coordinate dimension: %v", point.Dimension))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implement MarshalJSON on the Point type and then just use that

Comment on lines +334 to +335
structBuilder := b.Builder.(*array.StructBuilder)
structBuilder.Append(true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above needs to handle the interleaved OR separate cases


// AppendNull appends a null value to the array
func (b *PointBuilder) AppendNull() {
b.ExtensionBuilder.Builder.(*array.StructBuilder).AppendNull()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above, need to handle the FixedSizeList case

Copy link
Member

@paleolimbot paleolimbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool!

I will take a closer look over the weekend, but I did want to quickly point out up front that geoarrow.wkb is the only one required for GeoParquet/Parquet Geometry/Geography support (because in Parquet land everything is WKB binary). Functionally that just means there's a tiny bit of CRS translation that has to happen on read/write (and a bit of WKB parsing if you would like to support writing statistics).

Implementing the other extension types is also very cool but fairly difficult (the matrix expansion of point/linestring/polygon/multipoint/multilinestring/multipolygon by xy/xyz/xym/xyzm by interleaved/separated is sort of insane to deal with and is not widely used).

@Mandukhai-Alimaa
Copy link
Contributor Author

@paleolimbot, before you spend time looking at this, I will address @zeroshade's feedback and fix some stuff first.

But for the bigger picture, do you think I should punt on geoarrow.point and start with geoarrow.wkb ? It sounds like it would provide more value. What do you think?

@paleolimbot
Copy link
Member

But for the bigger picture, do you think I should punt on geoarrow.point and start with geoarrow.wkb ?

If you are aiming for Parquet Geometry/Geography support, yes, because geoarrow.point isn't used in any part of that. The metadata for geoarrow.wkb is the same as for geoarrow.point (e.g., CRS, edges), and so I think most of this PR is equally relevant to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants