def convert_shapefile(shapefilename, srid=<NUM_LIT>):
<EOL>ds = DataSource(shapefilename)<EOL>is_uf = shapefilename.upper().find('<STR_LIT>') != -<NUM_LIT:1><EOL>transform_coord = None<EOL>if srid != SRID:<EOL><INDENT>transform_coord = CoordTransform(SpatialReference(srid), SpatialReference(SRID))<EOL><DEDENT>if is_uf:<EOL><INDENT>model = UF<EOL><DEDENT>else:<EOL><INDENT>model = Municipio<EOL><DEDENT>ct = <NUM_LIT:0><EOL>for f in ds[<NUM_LIT:0>]:<EOL><INDENT>if f.geom.coord_dim != <NUM_LIT:2>:<EOL><INDENT>f.geom.coord_dim = <NUM_LIT:2><EOL><DEDENT>if isinstance(f.geom, Polygon):<EOL><INDENT>g = OGRGeometry(OGRGeomType('<STR_LIT>'))<EOL>g.add(f.geom)<EOL><DEDENT>else:<EOL><INDENT>g = f.geom<EOL><DEDENT>if transform_coord:<EOL><INDENT>g.transform(transform_coord)<EOL><DEDENT>g.coord_dim = <NUM_LIT:2><EOL>kwargs = {}<EOL>if is_uf:<EOL><INDENT>kwargs['<STR_LIT>'] = capitalize_name(unicode(f.get(CAMPO_NOME_UF), '<STR_LIT>'))<EOL>kwargs['<STR_LIT>'] = g.ewkt<EOL>kwargs['<STR_LIT>'] = f.get(CAMPO_GEOCODIGO_UF)<EOL>kwargs['<STR_LIT>'] = capitalize_name(unicode(f.get(CAMPO_REGIAO_UF), '<STR_LIT>'))<EOL>kwargs['<STR_LIT>'] = UF_SIGLAS_DICT.get(kwargs['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>kwargs['<STR_LIT>'] = capitalize_name(unicode(f.get(CAMPO_NOME_MU), '<STR_LIT>'))<EOL>kwargs['<STR_LIT>'] = g.ewkt<EOL>kwargs['<STR_LIT>'] = f.get(CAMPO_GEOCODIGO_MU)<EOL>kwargs['<STR_LIT>'] = UF.objects.get(pk=f.get(CAMPO_GEOCODIGO_MU)[:<NUM_LIT:2>])<EOL>kwargs['<STR_LIT>'] = kwargs['<STR_LIT>'].uf<EOL>kwargs['<STR_LIT>'] = slugify(kwargs['<STR_LIT>'])<EOL>if Municipio.objects.filter(nome_abreviado=kwargs['<STR_LIT>']).count() > <NUM_LIT:0>:<EOL><INDENT>kwargs['<STR_LIT>'] = u'<STR_LIT>' % (kwargs['<STR_LIT>'], kwargs['<STR_LIT>'].lower())<EOL><DEDENT><DEDENT>instance = model(**kwargs)<EOL>instance.save()<EOL>ct += <NUM_LIT:1><EOL><DEDENT>print(ct, (is_uf and "<STR_LIT>" or "<STR_LIT>"))<EOL>
shapefilename: considera nomenclatura de shapefile do IBGE para determinar se é UF
               ou Municípios.
               ex. 55UF2500GC_SIR.shp para UF e 55MU2500GC_SIR.shp para Municípios
srid: 4674 (Projeção SIRGAS 2000)