Geometric Operations

In this section, we consider some of the common kinds of geometries that arises in applications. These include Point, LineString, Polygon, GeometryCollection, MultiPolygon, MultiPoint, and MultiLineString.

Geometry Creation

To create geometries of different types,

point = ArchGDAL.createpoint(1.0, 2.0)
linestring = ArchGDAL.createlinestring([(i,i+1) for i in 1.0:3.0])
linearring = ArchGDAL.createlinearring([(0.,0.), (0.,1.), (1.,1.)])
simplepolygon = ArchGDAL.createpolygon([(0.,0.), (0.,1.), (1.,1.)])
complexpolygon = ArchGDAL.createpolygon([[(0.,0.), (0.,j), (j,j)] for j in 1.0:-0.1:0.9])
multipoint = ArchGDAL.createlinearring([(0.,0.), (0.,1.), (1.,1.)])
multilinestring = ArchGDAL.createmultilinestring([[(i,i+1) for i in j:j+3] for j in 1.0:5.0:6.0])
multipolygon = ArchGDAL.createmultipolygon([[[(0.,0.), (0.,j), (j,j)]] for j in 1.0:-0.1:0.9])
Geometry: MULTIPOLYGON (((0 0,0 1,1 1)),((0 0,0.0 0.9,0.9 0.9)))

Alternatively, they can be assembled from their components.

point = ArchGDAL.createpoint()
ArchGDAL.addpoint!(point, 1.0, 2.0)

linestring = ArchGDAL.createlinestring()
for i in 1.0:3.0
    ArchGDAL.addpoint!(linestring, i, i+1)

linearring = ArchGDAL.createlinearring()
for i in 1.0:3.0
    ArchGDAL.addpoint!(linearring, i, i+1)

polygon = ArchGDAL.createpolygon()
for j in 1.0:-0.1:0.9
    ring = ArchGDAL.createlinearring([(0.,0.), (0.,j), (j,j)])
    ArchGDAL.addgeom!(polygon, ring)

multipoint = ArchGDAL.createmultipoint()
for i in 1.0:3.0
    pt = ArchGDAL.createpoint(i, i+1)
    ArchGDAL.addgeom!(multipoint, pt)

multilinestring = ArchGDAL.createmultilinestring()
for j in 1.0:5.0:6.0
    line = ArchGDAL.createlinestring([(i,i+1) for i in j:j+3])
    ArchGDAL.addgeom!(multilinestring, line)

multipolygon = ArchGDAL.createmultipolygon()
for j in 1.0:-0.1:0.9
    poly = ArchGDAL.createpolygon([(0.,0.), (0.,j), (j,j)])
    ArchGDAL.addgeom!(multipolygon, poly)

They can also be constructed from other data formats such as:

Geometry Modification

The following methods are commonly used for retrieving elements of a geometry.

The following methods are commonly used for modifying or adding to a geometry.

Unary Operations

The following is an non-exhaustive list of unary operations available for geometries.



The following predicates return a Bool.

Immutable Operations

The following methods do not modify geom.

Mutable Operations

The following methods modifies the first argument geom.

Export Formats

Binary Operations

The following is an non-exhaustive list of binary operations available for geometries.


The following predicates return a Bool.

Prepared geometry

When repeatedly calling ArchGDAL.intersects(g1, g2) and ArchGDAL.contains(g1, g2) on the same geometry, for example, when intersecting 50 points with a 100 polygons, it is possible to increase performance by caching required–otherwise repeatedly calculated–information on geometries. You can do this by preparing a geometry by calling ArchGDAL.preparegeom(geom) and using the resulting prepared geometry as the first argument for ArchGDAL.intersects(g1, g2) or ArchGDAL.contains(g1, g2).

If you use a custom GDAL installation, you can check whether it supports prepared geometries by calling ArchGDAL.has_preparedgeom_support().

Immutable Operations

The following methods do not mutate the input geomteries g1 and g2.

Mutable Operations

The following method modifies the first argument g1.