示例#1
0
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)
}
示例#2
0
func drawGeoms(m image.Image, ctxt draw2d.GraphicContext, geoms ...*geos.Geometry) {
	// get envelope and calculate scale fn
	var env Envelope
	if len(geoms) > 1 {
		coll, err := geos.NewCollection(geos.GEOMETRYCOLLECTION, geoms...)
		if err != nil {
			log.Fatal(err)
		}
		union, err := coll.UnaryUnion()
		if err != nil {
			log.Fatal(err)
		}
		env = envelope(union)
	} else {
		env = envelope(geoms[0])
	}
	scale := func(x, y float64) (float64, float64) {
		x = env.Px(x)*(WIDTH-2*PAD) + PAD
		y = HEIGHT - (env.Py(y)*(HEIGHT-2*PAD) + PAD)
		return x, y
	}

	var draw func(geoms ...*geos.Geometry)

	draw = func(geoms ...*geos.Geometry) {
		for i, g := range geoms {
			// pick color
			c := colors[i%len(colors)]
			// switch type
			_type, err := g.Type()
			if err != nil {
				log.Fatal(err)
			}
			switch _type {
			case geos.POINT:
				drawPoint(ctxt, g, c, 4.0, scale)
			case geos.LINESTRING, geos.LINEARRING:
				drawLine(ctxt, g, c, 4.0, scale)
			case geos.POLYGON:
				drawPolygon(ctxt, g, c, darken(c), 3.0, scale)
			case geos.MULTIPOINT, geos.MULTILINESTRING, geos.MULTIPOLYGON, geos.GEOMETRYCOLLECTION:
				n, err := g.NGeometry()
				if err != nil {
					log.Fatal(err)
				}
				var subgeoms []*geos.Geometry
				for i := 0; i < n; i++ {
					subgeoms = append(subgeoms, geos.Must(g.Geometry(i)))
				}
				draw(subgeoms...)
			default:
				log.Fatalf("unknown geometry type %v", _type)
			}
		}
	}

	draw(geoms...)
}
示例#3
0
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)
}
示例#4
0
func drawPolygon(ctxt draw2d.GraphicContext, g *geos.Geometry, fillColor color.Color, strokeColor color.Color, width float64, scale func(x, y float64) (float64, float64)) {
	ctxt.SetFillColor(fillColor)
	ctxt.SetStrokeColor(strokeColor)
	ctxt.SetLineWidth(width)
	// exterior ring
	ring := geos.Must(g.ExteriorRing())
	cs, err := ring.coordSeq()
	if err != nil {
		log.Fatal(err)
	}
	lineCoordSeq(ctxt, cs, scale)
	ctxt.FillStroke()
	// interior rings...
}
示例#5
0
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)
}
示例#6
0
func ex7() {
	example("example7-symdifference.png", geos.Must(a.SymDifference(b)))
}
示例#7
0
func ex6() {
	example("example6-difference.png", a, b, geos.Must(b.Difference(a)))
}
示例#8
0
func ex5() {
	example("example5-difference.png", a, b, geos.Must(a.Difference(b)))
}
示例#9
0
func ex4() {
	example("example4-union.png", a, b, geos.Must(a.Union(b)))
}
示例#10
0
func ex3() {
	example("example3-intersection.png", a, b, geos.Must(a.Intersection(b)))
}
示例#11
0
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)
}
示例#12
0
func ex1() {
	example("example1.png", geos.Must(geos.FromWKT("LINESTRING (0 0, 10 10, 20 20)")))
}
示例#13
0
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)
}
示例#14
0
	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)))
示例#15
0
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)
}