OGR Geometry utilities

Package girs.feat.geom provides some utilities to create ogr geometries:

Import

from girs.feat import geom

Point

print geom.create_point(1, 2)
print geom.create_point_25d(1, 2, 3)
print geom.create_point_m(1, 2, 3)
print geom.create_point_zm(1, 2, 3, 4)

Output:

POINT (1 2 0)
POINT (1 2 3)
POINT (1 2)
POINT (1 2 3)

Data

p_list0 = [(0.00, 0.00), (1.00, 0.00), (1.00, 1.00), (0.00, 1.00)]
p_list0_25D = [(0.00, 0.00, 0.50), (1.00, 0.00, 0.50), (1.00, 1.00, 0.50), (0.00, 1.00, 0.50)]
p_list0_ZM = [(0.00, 0.00, 0.50, 0.25), (1.00, 0.00, 0.50, 0.25), (1.00, 1.00, 0.50, 0.25),
              (0.00, 1.00, 0.50, 0.25)]

Multi-point

print geom.create_multi_point(p_list0)
print geom.create_multi_point_25d(p_list0_25D)
print geom.create_multi_point_m(p_list0_25D)
print geom.create_multi_point_zm(p_list0_ZM)

Output:

MULTIPOINT (0 0 0,1 0 0,1 1 0,0 1 0)
MULTIPOINT (0 0 0.5,1 0 0.5,1 1 0.5,0 1 0.5)
MULTIPOINT (0 0,1 0,1 1,0 1)
MULTIPOINT (0 0 0.5,1 0 0.5,1 1 0.5,0 1 0.5)

Line-string

print geom.create_line_string(p_list0)
print geom.create_line_string_25d(p_list0_25D)
print geom.create_line_string_m(p_list0_25D)
print geom.create_line_string_zm(p_list0_ZM)

Output:

LINESTRING (0 0 0,1 0 0,1 1 0,0 1 0)
LINESTRING (0 0 0.5,1 0 0.5,1 1 0.5,0 1 0.5)
LINESTRING (0 0,1 0,1 1,0 1)
LINESTRING (0 0 0.5,1 0 0.5,1 1 0.5,0 1 0.5)

Data

p_list1 = [(0.25, 0.25), (0.75, 0.25), (0.75, 0.75), (0.25, 0.75)]
p_list1_25D = [(0.25, 0.25, 0.75), (0.75, 0.25, 0.75), (0.75, 0.75, 0.75), (0.25, 0.75, 0.75)]
p_list1_ZM = [(0.25, 0.25, 0.75, 0.25), (0.75, 0.25, 0.75, 0.25), (0.75, 0.75, 0.75, 0.25),
              (0.25, 0.75, 0.75, 0.25)]

Multiline string

print geom.create_multiline_string([p_list0, p_list1])
print geom.create_multiline_string_25d([p_list0_25D, p_list1_25D])
print geom.create_multiline_string_m([p_list0_25D, p_list1_25D])
print geom.create_multiline_string_zm([p_list0_ZM, p_list1_ZM])

Output:

MULTILINESTRING ((0 0 0,1 0 0,1 1 0,0 1 0),(0.25 0.25 0,0.75...
MULTILINESTRING ((0 0 0.5,1 0 0.5,1 1 0.5,0 1 0.5),(0.25 0.2...
MULTILINESTRING ((0 0,1 0,1 1,0 1),(0.25 0.25,0.75 0.25,0.75...
MULTILINESTRING ((0 0 0.5,1 0 0.5,1 1 0.5,0 1 0.5),(0.25 0.2...

Polygon

print geom.create_polygon(p_list0)
print geom.create_polygon([p_list0, p_list1])
print geom.create_polygon_25d(p_list0_25D)
print geom.create_polygon_25d([p_list0_25D, p_list1_25D])
print geom.create_polygon_m(p_list0_25D)
print geom.create_polygon_m([p_list0_25D, p_list1_25D])
print geom.create_polygon_zm(p_list0_ZM)
print geom.create_polygon_zm([p_list0_ZM, p_list1_ZM])

Output:

POLYGON ((0 0 0,1 0 0,1 1 0,0 1 0,0 0 0))
POLYGON ((0 0 0,1 0 0,1 1 0,0 1 0,0 0 0),(0.25 0.25 0,0.75 0...
POLYGON ((0 0 0.5,1 0 0.5,1 1 0.5,0 1 0.5,0 0 0.5))
POLYGON ((0 0 0.5,1 0 0.5,1 1 0.5,0 1 0.5,0 0 0.5),(0.25 0.2...
POLYGON ((0 0,1 0,1 1,0 1,0 0))
POLYGON ((0 0,1 0,1 1,0 1,0 0),(0.25 0.25,0.75 0.25,0.75 0.7...
POLYGON ((0 0 0.5,1 0 0.5,1 1 0.5,0 1 0.5,0 0 0.5))
POLYGON ((0 0 0.5,1 0 0.5,1 1 0.5,0 1 0.5,0 0 0.5),(0.25 0.2...

Data

p_list2 = [(p[0]+1, p[1]) for p in p_list0]
p_list3 = [(p[0]+1, p[1]) for p in p_list1]
p_list2_25D = [(p[0]+1, p[1], p[2]) for p in p_list0_25D]
p_list3_25D = [(p[0]+1, p[1], p[2]) for p in p_list1_25D]
p_list2_ZM = [(p[0]+1, p[1], p[2], p[3]) for p in p_list0_ZM]
p_list3_ZM = [(p[0]+1, p[1], p[2], p[3]) for p in p_list1_ZM]

Multi-polygon

print geom.create_multipolygon(p_list0)
print geom.create_multipolygon([p_list0, p_list2])
print geom.create_multipolygon([[p_list0, p_list1], p_list2])
print geom.create_multipolygon([[p_list0, p_list1], [p_list2, p_list3]])

Output:

MULTIPOLYGON (((0 0 0,1 0 0,1 1 0,0 1 0,0 0 0)))
MULTIPOLYGON (((0 0 0,1 0 0,1 1 0,0 1 0,0 0 0)),((1 0 0,2 0 ...
MULTIPOLYGON (((0 0 0,1 0 0,1 1 0,0 1 0,0 0 0),(0.25 0.25 0,...
MULTIPOLYGON (((0 0 0,1 0 0,1 1 0,0 1 0,0 0 0),(0.25 0.25 0,...
print geom.create_multipolygon_25d(p_list0_25D)
print geom.create_multipolygon_25d([p_list0_25D, p_list2_25D])
print geom.create_multipolygon_25d([[p_list0_25D, p_list1_25D], p_list2_25D])
print geom.create_multipolygon_25d([[p_list0_25D, p_list1_25D],
                                    [p_list2_25D, p_list3_25D]])

Output:

MULTIPOLYGON (((0 0,1 0,1 1,0 1,0 0)))
MULTIPOLYGON (((0 0,1 0,1 1,0 1,0 0)),((1 0,2 0,2 1,1 1,1 0)...
MULTIPOLYGON (((0 0,1 0,1 1,0 1,0 0),(0.25 0.25,0.75 0.25,0....
MULTIPOLYGON (((0 0,1 0,1 1,0 1,0 0),(0.25 0.25,0.75 0.25,0....
print geom.create_multipolygon_m(p_list0_25D)
print geom.create_multipolygon_m([p_list0_25D, p_list2_25D])
print geom.create_multipolygon_m([[p_list0_25D, p_list1_25D], p_list2_25D])
print geom.create_multipolygon_m([[p_list0_25D, p_list1_25D],
                                  [p_list2_25D, p_list3_25D]])
print geom.create_multipolygon_zm(p_list0_ZM)
print geom.create_multipolygon_zm([p_list0_ZM, p_list2_ZM])
print geom.create_multipolygon_zm([[p_list0_ZM, p_list1_ZM], p_list2_ZM])
print geom.create_multipolygon_zm([[p_list0_ZM, p_list1_ZM],
                                   [p_list2_ZM, p_list3_ZM]])

Output:

MULTIPOLYGON (((0 0 0.5,1 0 0.5,1 1 0.5,0 1 0.5,0 0 0.5)))
MULTIPOLYGON (((0 0 0.5,1 0 0.5,1 1 0.5,0 1 0.5,0 0 0.5)),((...
MULTIPOLYGON (((0 0 0.5,1 0 0.5,1 1 0.5,0 1 0.5,0 0 0.5),(0....
MULTIPOLYGON (((0 0 0.5,1 0 0.5,1 1 0.5,0 1 0.5,0 0 0.5),(0....