Exemple #1
0
func main() {

	flag.Parse()
	args := flag.Args()

	for _, path := range args {

		f, parse_err := geojson.UnmarshalFile(path)

		if parse_err != nil {
			panic(parse_err)
		}

		polygons := f.GeomToPolygons()

		fmt.Printf("%s has this many polygons: %d\n", path, len(polygons))

		pt := geo.NewPoint(40.681, -73.986)

		for _, poly := range polygons {

			c := poly.Contains(pt)
			fmt.Printf("contained: %v\n", c)
		}
	}

}
func main() {

	flag.Parse()
	args := flag.Args()

	for _, path := range args {

		f, parse_err := geojson.UnmarshalFile(path)

		if parse_err != nil {
			panic(parse_err)
		}

		fmt.Println("Enspatialize bounding box")

		sp, _ := f.EnSpatialize()
		fmt.Printf("%v\n", sp)
		fmt.Printf("%d\n", sp.Id)

		fmt.Println("Enspatialize geom")

		spg, _ := f.EnSpatializeGeom()
		fmt.Printf("%v\n", len(spg))

		for _, s := range spg {
			fmt.Printf("%v\n", s)
		}
	}

}
func (idx *WOFIndex) LoadGeoJSON(path string) (*geojson.WOFFeature, error) {

	feature, err := geojson.UnmarshalFile(path)

	if err != nil {
		idx.Logger.Error("failed to unmarshal %s, because %s", path, err)
		return nil, err
	}

	return feature, err
}
func main() {

	var source = flag.String("source", "", "Where to look for files")
	var procs = flag.Int("processes", runtime.NumCPU()*2, "Number of concurrent processes to use")

	flag.Parse()

	runtime.GOMAXPROCS(*procs)

	// TO DO: ensure *source exists and is a directory

	t1 := time.Now()
	count := 0

	wg := new(sync.WaitGroup)

	callback := func(source string, info os.FileInfo) error {

		wg.Add(1)
		defer wg.Done()

		if info.IsDir() {
			return nil
		}

		count += 1

		_, err := geojson.UnmarshalFile(source)

		if err != nil {
			fmt.Println(source, err)
		}

		return nil
	}

	c := crawl.NewCrawler(*source)
	_ = c.Crawl(callback)

	wg.Wait()

	t2 := time.Since(t1)

	fmt.Printf("time to validate %d files: %v\n", count, t2)
}
func main() {

	flag.Parse()
	args := flag.Args()

	for _, path := range args {

		f, parse_err := geojson.UnmarshalFile(path)

		if parse_err != nil {
			panic(parse_err)
		}

		sp, _ := f.EnSpatialize()
		fmt.Printf("%v\n", sp)
		fmt.Printf("%d\n", sp.Id)
	}

}
func main() {

	flag.Parse()
	args := flag.Args()

	for _, path := range args {

		f, parse_err := geojson.UnmarshalFile(path)

		if parse_err != nil {
			panic(parse_err)
		}

		polys := f.GeomToPolygons()

		for _, p := range polys {
			fmt.Printf("%d points\n", len(p.OuterRing.Points()))
		}
	}

}
func (p WOFPointInPolygon) LoadGeoJSON(path string) (*geojson.WOFFeature, error) {

	t := time.Now()

	feature, err := geojson.UnmarshalFile(path)

	d := time.Since(t)

	var tm metrics.Timer
	tm = *p.Metrics.TimeToUnmarshal

	go tm.Update(d)

	if err != nil {
		p.Logger.Error("failed to unmarshal %s, because %s", path, err)
		return nil, err
	}

	var c metrics.Counter
	c = *p.Metrics.CountUnmarshal
	go c.Inc(1)

	return feature, err
}
func main() {

	/*

			# ASSUMING
		        # lat := 45.523668
		        # lon := -73.600159

			# PLAIN VANILLA POLYGON

			$> ./bin/pip /usr/local/mapzen/whosonfirst-data/data/404/529/181/404529181.geojson /usr/local/mapzen/whosonfirst-data/data/857/848/31/85784831.geojson
			/usr/local/mapzen/whosonfirst-data/data/404/529/181/404529181.geojson has this many polygons: 1
			/usr/local/mapzen/whosonfirst-data/data/404/529/181/404529181.geojson #1 has 3 interior rings
			/usr/local/mapzen/whosonfirst-data/data/404/529/181/404529181.geojson #1 contains point false
			/usr/local/mapzen/whosonfirst-data/data/404/529/181/404529181.geojson contains point: false
			/usr/local/mapzen/whosonfirst-data/data/404/529/181/404529181.geojson f.Contains() point: false
			---
			/usr/local/mapzen/whosonfirst-data/data/857/848/31/85784831.geojson has this many polygons: 1
			/usr/local/mapzen/whosonfirst-data/data/857/848/31/85784831.geojson #1 has 0 interior rings
			/usr/local/mapzen/whosonfirst-data/data/857/848/31/85784831.geojson #1 contains point true
			/usr/local/mapzen/whosonfirst-data/data/857/848/31/85784831.geojson contains point: true
			/usr/local/mapzen/whosonfirst-data/data/857/848/31/85784831.geojson f.Contains() point: true
			---

			# MULTI POLYGON

			$> ./bin/pip /usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson has this many polygons: 8
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #1 has 0 interior rings
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #1 contains point false
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #2 has 0 interior rings
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #2 contains point false
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #3 has 0 interior rings
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #3 contains point false
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #4 has 0 interior rings
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #4 contains point true
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #5 has 0 interior rings
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #5 contains point false
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #6 has 0 interior rings
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #6 contains point false
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #7 has 0 interior rings
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #7 contains point false
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #8 has 0 interior rings
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson #8 contains point false
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson contains point: true
			/usr/local/mapzen/whosonfirst-data/data/136/251/273/136251273.geojson f.Contains() point: true
			---

	*/

	flag.Parse()
	args := flag.Args()

	lat := 45.523668
	lon := -73.600159

	for _, path := range args {

		f, parse_err := geojson.UnmarshalFile(path)

		if parse_err != nil {
			panic(parse_err)
		}

		polygons := f.GeomToPolygons()
		contains := false

		fmt.Printf("%s has this many polygons: %d\n", path, len(polygons))

		for i, poly := range polygons {

			fmt.Printf("%s #%d has %d interior rings and a total of %d points\n", path, (i + 1), len(poly.InteriorRings), poly.CountPoints())

			c := poly.Contains(lat, lon)

			fmt.Printf("%s #%d contains point %t\n", path, (i + 1), c)

			if c {
				contains = true
			}
		}

		fmt.Printf("%s contains point: %t\n", path, contains)

		fmt.Printf("%s f.Contains() point: %t\n", path, f.Contains(lat, lon))
		fmt.Println("---")
	}

}