mif

    def to_mifg(cls, folder, province, items):
        schema = {
            'geometry': None,
            'properties': OrderedDict([
                ('ID', 'str:13'),
                ('Direction', 'str:1'),
                ('Geo_ID', 'str:13')
            ])
        }

        records = [{
            'geometry': None,
            'properties': {
                'ID': item.sw_id,
                'Direction': item.processed_direction,
                'Geo_ID': item.geo_id
            }
        } for item in items]

        file_path = os.path.join(folder, 'PlateLimit_Link{}.mif'.format(province))
        output_mifg(file_path, schema, records)

def output_mifg(file_path, schema, records):
    driver_args = {'ENCODING': 'CP936'}
    crs_wkt = 'GEOGCS[DATUM[]]'  # intentionally set invalid crs format so Fiona can output 'CoordSys Earth Projection 1, 0' and make PM happy

    if os.path.exists(file_path):
        os.remove(file_path)

    with fiona.open(file_path, 'w', driver='MapInfo File', schema=schema, crs_wkt=crs_wkt, encoding='gbk', **driver_args) as f:
        logging.info('# Generating file... path={}'.format(file_path))
        f.writerecords(records)
    if os.path.splitext(file_path)[-1] == '.mif':
        # 将格式统一为与sw一致
        os.system(r"sed -i '4s/Earth /Earth\r\n/g;4s/Projection 1, /Projection 1,/g;s/$/\r/g' %s" % (file_path))
        os.system(r"sed -i 's/$/\r/g' %s" % (file_path.replace(".mif", ".mid")))

你可能感兴趣的:(mif)