func test() { g1 := geos.Must(geos.FromWKT("LINESTRING(0 0, 3 3, 3 2, 4 2, 7 5)")) g2 := geos.Must(geos.FromWKT("LINESTRING(0 10, 1 0, 0 10, 10 10)")) g3 := geos.Must(geos.FromWKT("POINT(5 5)")) g4 := geos.Must(g3.Buffer(1)) g5 := geos.Must(geos.FromWKT("MULTIPOINT(5 6, 6 6, 3 8, 7 8)")) example("test.png", g1, g2, g4, g3, g5) }
func ex9() { wkt := []string{ "LINESTRING (2 10, 3 10, 4 9, 5 8)", "LINESTRING (5 8, 6 6, 6 5)", "LINESTRING (6 5, 9 6, 10 7, 11 9)", "LINESTRING (11 9, 11 10, 10 11)", "LINESTRING (6 5, 3 4, 2 3)", "LINESTRING (2 3, 1.5 2.5, 1 1, 1 0)", "LINESTRING (1 0, 0 0, 0 -1, 1 -2)", "LINESTRING (1 -2, 2 -2, 3 -1, 3 0, 1 0)", "LINESTRING (6 5, 6 3, 6.5 2.5)", "LINESTRING (6.5 2.5, 7.5 2, 8.5 1.5)", "LINESTRING (8.5 1.5, 9 0.5, 10 0.5, 11 1.5)", } var linestrings []*geos.Geometry for i := range wkt { linestrings = append(linestrings, geos.Must(geos.FromWKT(wkt[i]))) } example("example9-unmerged-linestrings.png", linestrings...) merged := geos.Must(geos.Must(geos.NewCollection(geos.MULTILINESTRING, linestrings...)).LineMerge()) example("example9-merged-linestrings.png", merged) }
func ExampleGeometry_LineInterpolatePoint() { line := geos.Must(geos.FromWKT("LINESTRING(25 50, 100 125, 150 190)")) pt := geos.Must(line.LineInterpolatePoint(0.20)) fmt.Println(pt) // Output: POINT (51.5974135047432014 76.5974135047432014) }
func main() { line, _ := geos.FromWKT("LINESTRING (0 0, 10 10, 20 20)") buf, _ := line.Buffer(2.5) fmt.Printf("Hello, world. Sqrt(2) = %v%v\n", newmath.Sqrt(2), buf) }
func main() { flag.Parse() poly := geos.Must(geos.FromWKT(*aoi)) bbox, err := geosconverter.GetBoundingBox(poly) if err != nil { log.Fatal(err) } //Source if len(*srcDriver) == 0 { *srcDriver = raster.FindDriverName(*src) } input, err := raster.Open(*srcDriver, *src) if err != nil { log.Fatal(err) } if c, ok := input.(closer); ok { defer c.Close() } var inputReader raster.TileReader if len(*srcLayer) > 0 { inputReader, err = input.OpenTileLayer(*srcLayer) } else { inputReader, err = raster.OpenTileLayerAt(input, 0) } if err != nil { log.Fatal(err) } //Destination if len(*dstDriver) == 0 { *dstDriver = raster.FindDriverName(*dst) } outputReader, err := raster.Open(*dstDriver, *dst) if err != nil { log.Fatal(err) } output, ok := outputReader.(raster.WritableTileSource) if !ok { log.Fatal("Output driver does not allow writing") } if c, ok := output.(closer); ok { defer c.Close() } outputWriter, err := output.CreateTileLayer(*dstLayer) if err != nil { log.Fatal(err) } //Initialize the copy copier, err := raster.NewCopier(inputReader, outputWriter) if err != nil { log.Fatal(err) } polygonFilter := geosconverter.IntersectsFilter(poly) if *replace { copier.Filter = polygonFilter } else { copier.Filter = raster.Any(outputWriter.Contains, polygonFilter) } //Iterate on each requested level and performs the copy for level := *lvlmin; level <= *lvlmax; level++ { log.Print("Level: ", level) if *replace { log.Print("Level ", level, " clearing in database") err := outputWriter.Clear(level) if err != nil { log.Fatal(err) } log.Print("Level ", level, " cleared in database") } tiles, err := raster.GetTileBlock(bbox, level) if err != nil { log.Fatal(err) } log.Print("BBOX (tiles): ", tiles) log.Print("Nb tiles in BBOX: ", tiles.Count()) bar := pb.StartNew(tiles.Count()) processed, err := copier.CopyBlock(tiles, func(level, x, y int, processed bool) { bar.Increment() }) if err != nil { log.Fatal(err) } bar.FinishPrint("End") log.Print("Nb tiles processed: ", processed) } }
func ex8() { l := geos.Must(geos.FromWKT("LINESTRING (0 2, 6 2, 3 4, 4.5 8, 1 8, 3 0)")) b := geos.Must(l.Buffer(0.5)) example("example8-buffer.png", b, l) }
func ex2() { a := geos.Must(geos.FromWKT("LINEARRING (0 3, 2 3, 3 1, 1 0, 0 1.5, 0 3)")) b := geos.Must(geos.FromWKT("LINEARRING (1 2, 1.5 4, 3.5 4, 4.5 2.5, 1 2)")) example("example2-a-b.png", a, b) }
func ex1() { example("example1.png", geos.Must(geos.FromWKT("LINESTRING (0 0, 10 10, 20 20)"))) }
func ex10() { l := geos.Must(geos.FromWKT("LINESTRING (0 2, 6 2, 3 4, 4.5 8, 1 8, 3 0)")) b := geos.Must(l.ConvexHull()) example("example10-convex-hull.png", b, l) }
ex3() ex4() ex5() ex6() ex7() ex8() ex9() ex10() } func ex1() { example("example1.png", geos.Must(geos.FromWKT("LINESTRING (0 0, 10 10, 20 20)"))) } var ( a = geos.Must(geos.FromWKT("POLYGON ((0 3, 2 3, 3 1, 1 0, 0 1.5, 0 3))")) b = geos.Must(geos.FromWKT("POLYGON ((1 2, 1.5 4, 3.5 4, 4.5 2.5, 1 2))")) ) func ex2() { a := geos.Must(geos.FromWKT("LINEARRING (0 3, 2 3, 3 1, 1 0, 0 1.5, 0 3)")) b := geos.Must(geos.FromWKT("LINEARRING (1 2, 1.5 4, 3.5 4, 4.5 2.5, 1 2)")) example("example2-a-b.png", a, b) } func ex3() { example("example3-intersection.png", a, b, geos.Must(a.Intersection(b))) } func ex4() { example("example4-union.png", a, b, geos.Must(a.Union(b)))
// Loads a CSV file from https://github.com/delight-im/FreeGeoDB // The expected CSV columns are: // 0 : id // 1 : coordinates_wkt // 2 : sovereign // 3 : name // 4 : formal // 5 : economy_level // 6 : income_level // 7 : iso_alpha2 // 8 : iso_alpha3 // 9 : iso_numeric3 // 10 : continent // 11 : subregion func load_freegeodb_countries_csv(rt *rtreego.Rtree, fname string) (int, error) { log.Println("Loading", fname, "...") f, err := os.Open(fname) if err != nil { return 0, err } defer f.Close() df, err := Decompressor(f) if err != nil { return 0, err } r := csv.NewReader(df) r.Comma = ',' _, err = r.Read() // Don't read header if err != nil { return 0, err } line := 0 loaded_objects := 0 for { cols, err := r.Read() if err == io.EOF { break } else if err != nil { return loaded_objects, err } line++ if len(cols) != 12 { return loaded_objects, fmt.Errorf("Invalid column format in", fname, cols) } if len(cols[7]) != 2 || len(cols[8]) != 3 || len(cols[3]) == 0 { continue } geodb_id, err := strconv.ParseInt(cols[0], 10, 64) if err != nil { log.Fatal("Error parsing", cols, line, err) } geom, err := geos.FromWKT(cols[1]) if err != nil { log.Fatal("Error parsing", cols, line, err) } rect, err := RtreeBboxg(geom, 1e-5) if err != nil { log.Fatal("Error getting bbox", cols, line, err) } obj := GeoObj{rect, &GeoData{ Id: geodb_id, CountryName: cols[3], CountryCode_2: cols[7], CountryCode_3: cols[8], Type: "country", Geom: geom}} rt.Insert(&obj) loaded_objects++ } return loaded_objects, nil }