GeoScript

Language for Examples

Language for Examples

Table Of Contents

Previous topic

Geometry Operations

Next topic

Prepared Geometries

Geometry Relationships

code chooser

Intersection

>>> from geoscript import geom

>>> poly1 = geom.fromWKT('POLYGON ((0 0, 8 0, 8 8, 0 8, 0 0))')
>>> poly2 = geom.fromWKT('POLYGON ((5 5, 13 5, 13 13, 5 13, 5 5))')
>>> poly1.intersection(poly2)
POLYGON ((5 8, 8 8, 8 5, 5 5, 5 8))
>> var GEOM = require("geoscript/geom");

>> var poly1 = GEOM.fromWKT("POLYGON ((0 0, 8 0, 8 8, 0 8, 0 0))");
>> var poly2 = GEOM.fromWKT("POLYGON ((5 5, 13 5, 13 13, 5 13, 5 5))");
>> poly1.intersection(poly2)
<Polygon [[[5, 8], [8, 8], [8, 5], [5, 5], [5, 8]]]>
scala> import org.geoscript.geometry.Geometry
scala> val poly1 = Geometry.fromWKT("POLYGON ((0 0, 8 0, 8 8, 0 8, 0 0))")
poly1: org.geoscript.geometry.Geometry = POLYGON ((0 0, 8 0, 8 8, 0 8, 0 0))

scala> val poly2 = Geometry.fromWKT("POLYGON ((5 5, 13 5, 13 13, 5 13, 5 5))")
poly2: org.geoscript.geometry.Geometry = POLYGON ((5 5, 13 5, 13 13, 5 13, 5 5))

scala> poly1 intersection poly2
res0: org.geoscript.geometry.Geometry = POLYGON ((5 8, 8 8, 8 5, 5 5, 5 8))
groovy:000> import geoscript.geom.*
===> [import geoscript.geom.*]

groovy:000> poly1 = Geometry.fromWKT("POLYGON ((0 0, 8 0, 8 8, 0 8, 0 0))")
===> POLYGON ((0 0, 8 0, 8 8, 0 8, 0 0))

groovy:000> poly2 = Geometry.fromWKT("POLYGON ((5 5, 13 5, 13 13, 5 13, 5 5))")
===> POLYGON ((5 5, 13 5, 13 13, 5 13, 5 5))

groovy:000> poly1.intersection(poly2)
===> POLYGON ((5 8, 8 8, 8 5, 5 5, 5 8))

Union

>>> from geoscript import geom

>>> poly1 = geom.fromWKT('POLYGON ((0 0, 8 0, 8 8, 0 8, 0 0))')
>>> poly2 = geom.fromWKT('POLYGON ((5 5, 13 5, 13 13, 5 13, 5 5))')
>>> poly1.union(poly2)
POLYGON ((8 5, 8 0, 0 0, 0 8, 5 8, 5 13, 13 13, 13 5, 8 5))
>> var GEOM = require("geoscript/geom");

>> var poly1 = GEOM.fromWKT("POLYGON ((0 0, 8 0, 8 8, 0 8, 0 0))");
>> var poly2 = GEOM.fromWKT("POLYGON ((5 5, 13 5, 13 13, 5 13, 5 5))");
>> poly1.union(poly2)
<Polygon [[[8, 5], [8, 0], [0, 0], [0, 8], [5, 8], [5, 13], [13, 13],...>
scala> import org.geoscript.geometry.Geometry
scala> val poly1 = Geometry.fromWKT("POLYGON ((0 0, 8 0, 8 8, 0 8, 0 0))")
poly1: org.geoscript.geometry.Geometry = POLYGON ((0 0, 8 0, 8 8, 0 8, 0 0))

scala> val poly2 = Geometry.fromWKT("POLYGON ((5 5, 13 5, 13 13, 5 13, 5 5))")
poly2: org.geoscript.geometry.Geometry = POLYGON ((5 5, 13 5, 13 13, 5 13, 5 5))

scala> poly1 union poly2
res0: org.geoscript.geometry.Geometry = POLYGON ((8 5, 8 0, 0 0, 0 8, 5 8, 5 13, 13 13, 13 5, 8 5))
groovy:000> import geoscript.geom.*
===> [import geoscript.geom.*]

groovy:000> poly1 = Geometry.fromWKT("POLYGON ((0 0, 8 0, 8 8, 0 8, 0 0))")
===> POLYGON ((0 0, 8 0, 8 8, 0 8, 0 0))

groovy:000> poly2 = Geometry.fromWKT("POLYGON ((5 5, 13 5, 13 13, 5 13, 5 5))")
===> POLYGON ((5 5, 13 5, 13 13, 5 13, 5 5))

groovy:000> poly1.union(poly2)
===> POLYGON ((8 5, 8 0, 0 0, 0 8, 5 8, 5 13, 13 13, 13 5, 8 5))