def __init__(self, calibration_pack, proj4): super(MetricCalibration, self).__init__(calibration_pack) self.proj4 = proj4 self._metric_proj4 = self._get_metric_proj4() self._in_metric_projection = self.proj4 == self._metric_proj4 self._transform_to_metric_xy = get_transformPoint( self.proj4, self._metric_proj4) self._transform_to_projected_xy = get_transformPoint( self._metric_proj4, self.proj4) self._metric_xy1 = self._to_metric_xy((0, 0))
def run(target_folder, coordinate_table, coordinate_column_x, coordinate_column_y, source_proj4, target_proj4): target_path = join(target_folder, 'converted_coordinate_table.csv') try: transform_x_y = get_transformPoint(source_proj4, target_proj4) except GeometryError: try: get_spatialReference(source_proj4) except GeometryError: exit(SPATIAL_REFERENCE_INVALID % ('source', source_proj4)) try: get_spatialReference(target_proj4) except GeometryError: exit(SPATIAL_REFERENCE_INVALID % ('target', target_proj4)) columns = list(coordinate_table.columns) column_x_index = _get_column_index(columns, coordinate_column_x, 'x') column_y_index = _get_column_index(columns, coordinate_column_y, 'y') columns, order_x_y = _prepare_columns(columns, target_proj4) csv_writer = csv.writer(open(target_path, 'w')) csv_writer.writerow(columns) for index, row in enumerate(coordinate_table.values): row = list(row) old_x, old_y = row[column_x_index], row[column_y_index] try: new_x, new_y = transform_x_y(old_x, old_y) except RuntimeError: print_error(COORDINATES_NOT_TRANSFORMED, index, old_x, old_y) csv_writer.writerow(row + ['', '']) continue csv_writer.writerow(row + order_x_y(new_x, new_y)) return [ ('converted_coordinate_table_path', target_path), ]
def _get_metric_proj4(self): if '+proj=utm' in self.proj4: return self.proj4 to_ll = get_transformPoint( self.proj4, '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs') longitude, latitude = to_ll(*self.to_projected_xy((0, 0))) zone_number = utm.conversion.latlon_to_zone_number(latitude, longitude) zone_letter = utm.conversion.latitude_to_zone_letter(latitude) return '+proj=utm +zone=%s%s +ellps=WGS84 +units=m +no_defs' % ( zone_number, ' +south' if zone_letter < 'N' else '')
def get_pixel_centers(points_paths, image_scope): if not points_paths: return [] pixel_centers = [] for points_path in points_paths: points_proj4, projected_centers = load_points(points_path)[:2] transform_point = get_transformPoint(points_proj4, image_scope.proj4) pixel_centers.extend( filter(image_scope.is_pixel_center, (image_scope.to_pixel_xy(transform_point(*_)) for _ in projected_centers))) return pixel_centers
def run( target_folder, coordinate_table, coordinate_column_x, coordinate_column_y, source_proj4, target_proj4): target_path = join(target_folder, 'converted_coordinate_table.csv') try: transform_x_y = get_transformPoint(source_proj4, target_proj4) except GeometryError: try: get_spatialReference(source_proj4) except GeometryError: exit(SPATIAL_REFERENCE_INVALID % ('source', source_proj4)) try: get_spatialReference(target_proj4) except GeometryError: exit(SPATIAL_REFERENCE_INVALID % ('target', target_proj4)) columns = list(coordinate_table.columns) column_x_index = _get_column_index(columns, coordinate_column_x, 'x') column_y_index = _get_column_index(columns, coordinate_column_y, 'y') columns, order_x_y = _prepare_columns(columns, target_proj4) csv_writer = csv.writer(open(target_path, 'w')) csv_writer.writerow(columns) for index, row in enumerate(coordinate_table.values): row = list(row) old_x, old_y = row[column_x_index], row[column_y_index] try: new_x, new_y = transform_x_y(old_x, old_y) except RuntimeError: print_error(COORDINATES_NOT_TRANSFORMED, index, old_x, old_y) csv_writer.writerow(row + ['', '']) continue csv_writer.writerow(row + order_x_y(new_x, new_y)) return [ ('converted_coordinate_table_path', target_path), ]
def test_get_transformPoint_runs(self): transformPoint0 = get_transformPoint(proj4LL, proj4LL) transformPoint1 = get_transformPoint(proj4LL, proj4SM) self.assertNotEqual(transformPoint0(0, 0), transformPoint1(0, 0))