1"""Ground control points""" 2 3import uuid 4 5 6class GroundControlPoint(object): 7 """A mapping of row, col image coordinates to x, y, z.""" 8 9 def __init__(self, row=None, col=None, x=None, y=None, z=None, 10 id=None, info=None): 11 """Create a new ground control point 12 13 Parameters 14 ---------- 15 row, col : float, required 16 The row (or line) and column (or pixel) coordinates that 17 map to spatial coordinate values ``y`` and ``x``, 18 respectively. 19 x, y : float, required 20 Spatial coordinates of a ground control point. 21 z : float, optional 22 Optional ``z`` coordinate. 23 id : str, optional 24 A unique identifer for the ground control point. 25 info : str, optional 26 A short description for the ground control point. 27 """ 28 if any(x is None for x in (row, col, x, y)): 29 raise ValueError("row, col, x, and y are required parameters.") 30 if id is None: 31 id = str(uuid.uuid4()) 32 self.id = id 33 self.info = info 34 self.row = row 35 self.col = col 36 self.x = x 37 self.y = y 38 self.z = z 39 40 def __repr__(self): 41 args = ', '.join(['{}={}'.format(att, repr(getattr(self, att))) 42 for att in ('row', 'col', 'x', 'y', 'z', 'id', 'info') 43 if getattr(self, att) is not None]) 44 return "GroundControlPoint({})".format(args) 45 46 def asdict(self): 47 """A dict representation of the GCP""" 48 return {'id': self.id, 'info': self.info, 'row': self.row, 49 'col': self.col, 'x': self.x, 'y': self.y, 'z': self.z} 50 51 @property 52 def __geo_interface__(self): 53 """A GeoJSON representation of the GCP""" 54 coords = [self.x, self.y] 55 if self.z is not None: 56 coords.append(self.z) 57 return {'id': self.id, 'type': 'Feature', 58 'geometry': {'type': 'Point', 'coordinates': tuple(coords)}, 59 'properties': self.asdict()} 60