Skip to content

Commit

Permalink
[bug fix] NewExtentFromGeometry incorrect ext (#39)
Browse files Browse the repository at this point in the history
The extentent was always initilizing the extent with [0,0,0,0]
instead of the first point in the geomentry and then calculating
the actual extent.
  • Loading branch information
gdey authored Jul 6, 2019
1 parent c03a62f commit 2760310
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions bbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,18 @@ func NewExtent(points ...[2]float64) *Extent {

// NewExtentFromGeometry tries to create an extent based on the geometry
func NewExtentFromGeometry(g Geometry) (*Extent, error) {
e := Extent{}
err := getExtent(g, &e)
if err != nil {
var pts []Point
if err := getCoordinates(g, &pts); err != nil {
return nil, err
}
if len(pts) == 0 {
return nil, nil
}
e := Extent{pts[0][0], pts[0][1], pts[0][0], pts[0][1]}
for _, pt := range pts {
e.AddPoints([2]float64(pt))
}

return &e, nil
}

Expand Down

0 comments on commit 2760310

Please sign in to comment.