<commit_before>package pip

import (
	"github.com/dhconnelly/rtreego"
	"github.com/whosonfirst/go-whosonfirst-geojson"
)

type WOFPointInPolygon struct {
	Rtree *rtreego.Rtree
}

func PointInPolygon() *WOFPointInPolygon {

	rt := rtreego.NewTree(2, 25, 50)

	return &WOFPointInPolygon{
		Rtree: rt,
	}
}

func (p WOFPointInPolygon) IndexGeoJSONFile(source string) error {

	feature, parse_err := geojson.UnmarshalFile(source)

	if parse_err != nil {
		return parse_err
	}

	return p.IndexGeoJSONFeature(*feature)
}

func (p WOFPointInPolygon) IndexGeoJSONFeature(feature geojson.WOFFeature) error {

	bounds, bounds_err := feature.Bounds()

	if bounds_err != nil {
		return bounds_err
	}

	p.Rtree.Insert(bounds)
	return nil
}

func (p WOFPointInPolygon) GetByLatLon(lat float64, lon float64) []rtreego.Spatial{

	pt := rtreego.Point{lon, lat}
	bbox, _ := rtreego.NewRect(pt, []float64{0.0001, 0.0001})	// how small can I make this?

	results := p.Rtree.SearchIntersect(bbox)
	return results
}

func (p WOFPointInPolygon) InflateResults(results []rtreego.Spatial) []*geojson.WOFRTree {

     inflated := make([]*geojson.WOFRTree, 0)

	for _, r := range results {

	        // https://golang.org/doc/effective_go.html#interface_conversions
		wof := r.(*geojson.WOFRTree)<commit_msg>update to reflect EnSpatialize changes in go-whosonfirst-geojson<commit_after>package pip

import (
	"github.com/dhconnelly/rtreego"
	"github.com/whosonfirst/go-whosonfirst-geojson"
)

type WOFPointInPolygon struct {
	Rtree *rtreego.Rtree
}

func PointInPolygon() *WOFPointInPolygon {

	rt := rtreego.NewTree(2, 25, 50)

	return &WOFPointInPolygon{
		Rtree: rt,
	}
}

func (p WOFPointInPolygon) IndexGeoJSONFile(source string) error {

	feature, parse_err := geojson.UnmarshalFile(source)

	if parse_err != nil {
		return parse_err
	}

	return p.IndexGeoJSONFeature(*feature)
}

func (p WOFPointInPolygon) IndexGeoJSONFeature(feature geojson.WOFFeature) error {

	spatial, spatial_err := feature.EnSpatialize()

	if spatial_err != nil {
		return spatial_err
	}

	p.Rtree.Insert(spatial)
	return nil
}

func (p WOFPointInPolygon) GetByLatLon(lat float64, lon float64) []rtreego.Spatial{

	pt := rtreego.Point{lon, lat}
	bbox, _ := rtreego.NewRect(pt, []float64{0.0001, 0.0001})	// how small can I make this?

	results := p.Rtree.SearchIntersect(bbox)
	return results
}

func (p WOFPointInPolygon) InflateResults(results []rtreego.Spatial) []*geojson.WOFSpatial {

     inflated := make([]*geojson.WOFSpatial, 0)

	for _, r := range results {

	        // https://golang.org/doc/effective_go.html#interface_conversions
		wof := r.(*geojson.WOFSpatial)
{'fraction_non_alphanumeric': 0.12243346007604562, 'fraction_numerical': 0.016730038022813688, 'mean_word_length': 4.682505399568035, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2660917', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1001, 'n_words': 195}