Skip to content
Permalink
Browse files

Now using file encoding for saving attributes and values in new shape…

…files.

The file encoding is selected in the Save As dialog.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6323 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
homann
homann committed Dec 28, 2006
1 parent 8abf9ce commit 29587427be755f591f5150d3ab9543af66c84499
Showing with 22 additions and 15 deletions.
  1. +4 −4 src/gui/qgisapp.cpp
  2. +18 −11 src/providers/ogr/qgsogrprovider.cpp
@@ -2570,22 +2570,22 @@ void QgisApp::newVectorLayer()
#ifdef QGISDEBUG
qWarning("ogr provider loaded");
#endif
typedef bool (*createEmptyDataSourceProc)(const QString&, const QString&, QGis::WKBTYPE, \
typedef bool (*createEmptyDataSourceProc)(const QString&, const QString&, const QString&, QGis::WKBTYPE, \
const std::list<std::pair<QString, QString> >&);
createEmptyDataSourceProc createEmptyDataSource=(createEmptyDataSourceProc)myLib->resolve("createEmptyDataSource");
if(createEmptyDataSource)
{
if(geometrytype == QGis::WKBPoint)
{
createEmptyDataSource(filename,fileformat,QGis::WKBPoint, attributes);
createEmptyDataSource(filename,fileformat, enc, QGis::WKBPoint, attributes);
}
else if (geometrytype == QGis::WKBLineString)
{
createEmptyDataSource(filename,fileformat,QGis::WKBLineString, attributes);
createEmptyDataSource(filename,fileformat, enc, QGis::WKBLineString, attributes);
}
else if(geometrytype == QGis::WKBPolygon)
{
createEmptyDataSource(filename,fileformat,QGis::WKBPolygon, attributes);
createEmptyDataSource(filename,fileformat, enc, QGis::WKBPolygon, attributes);
}
else
{
@@ -1048,7 +1048,7 @@ bool QgsOgrProvider::addFeature(QgsFeature* f)

//find a matching field for the new attribute
QString newAttribute = (f->attributeMap())[i].fieldName();
int targetAttributeId = fdef->GetFieldIndex(newAttribute);
int targetAttributeId = fdef->GetFieldIndex(mEncoding->fromUnicode(newAttribute).constData());
if(targetAttributeId == -1)
{
continue;
@@ -1066,7 +1066,11 @@ bool QgsOgrProvider::addFeature(QgsFeature* f)
}
else if(fdef->GetFieldDefn(targetAttributeId)->GetType()==OFTString)
{
feature->SetField(targetAttributeId,s.ascii());
#ifdef QGISDEBUG
std::cerr << "Writing string attribute " << newAttribute.toLocal8Bit().data() <<
" with " << s.toLocal8Bit().data() << ", encoding " << mEncoding->name().data() << "\n";
#endif
feature->SetField(targetAttributeId,mEncoding->fromUnicode(s).constData());
}
else
{
@@ -1107,7 +1111,7 @@ bool QgsOgrProvider::addAttributes(std::map<QString,QString> const & name)
{
if(iter->second=="OFTInteger")
{
OGRFieldDefn fielddefn(iter->first,OFTInteger);
OGRFieldDefn fielddefn(mEncoding->fromUnicode(iter->first).data(),OFTInteger);
if(ogrLayer->CreateField(&fielddefn)!=OGRERR_NONE)
{
QgsLogger::warning("QgsOgrProvider.cpp: writing of OFTInteger field failed");
@@ -1116,7 +1120,7 @@ bool QgsOgrProvider::addAttributes(std::map<QString,QString> const & name)
}
else if(iter->second=="OFTReal")
{
OGRFieldDefn fielddefn(iter->first,OFTReal);
OGRFieldDefn fielddefn(mEncoding->fromUnicode(iter->first).data(),OFTReal);
if(ogrLayer->CreateField(&fielddefn)!=OGRERR_NONE)
{
QgsLogger::warning("QgsOgrProvider.cpp: writing of OFTReal field failed");
@@ -1125,7 +1129,7 @@ bool QgsOgrProvider::addAttributes(std::map<QString,QString> const & name)
}
else if(iter->second=="OFTString")
{
OGRFieldDefn fielddefn(iter->first,OFTString);
OGRFieldDefn fielddefn(mEncoding->fromUnicode(iter->first).data(),OFTString);
if(ogrLayer->CreateField(&fielddefn)!=OGRERR_NONE)
{
QgsLogger::warning("QgsOgrProvider.cpp: writing of OFTString field failed");
@@ -1176,7 +1180,7 @@ bool QgsOgrProvider::changeAttributeValues(std::map<int,std::map<QString,QString
of->SetField ( f, value.toDouble() );
break;
case OFTString:
of->SetField ( f, value.ascii() );
of->SetField ( f, mEncoding->fromUnicode(value).constData());
break;
default:
QgsLogger::warning("QgsOgrProvider::changeAttributeValues, Unknown field type,\
@@ -1646,8 +1650,8 @@ QGISEXTERN bool isProvider()
@param vectortype point/line/polygon or multitypes
@param attributes a list of name/type pairs for the initial attributes
@return true in case of success*/
QGISEXTERN bool createEmptyDataSource(const QString& uri,const QString& format, QGis::WKBTYPE vectortype, \
const std::list<std::pair<QString, QString> >& attributes)
QGISEXTERN bool createEmptyDataSource(const QString& uri,const QString& format, const QString& encoding,\
QGis::WKBTYPE vectortype, const std::list<std::pair<QString, QString> >& attributes)
{
OGRSFDriver* driver;
OGRRegisterAll();
@@ -1706,11 +1710,14 @@ const std::list<std::pair<QString, QString> >& attributes)
}

//create the attribute fields

QTextCodec* codec=QTextCodec::codecForName(encoding.toLocal8Bit().data());

for(std::list<std::pair<QString, QString> >::const_iterator it= attributes.begin(); it != attributes.end(); ++it)
{
if(it->second == "Real")
{
OGRFieldDefn field(it->first, OFTReal);
OGRFieldDefn field(codec->fromUnicode(it->first).data(), OFTReal);
field.SetPrecision(3);
field.SetWidth(32);
if(layer->CreateField(&field) != OGRERR_NONE)
@@ -1720,15 +1727,15 @@ const std::list<std::pair<QString, QString> >& attributes)
}
else if(it->second == "Integer")
{
OGRFieldDefn field(it->first, OFTInteger);
OGRFieldDefn field(codec->fromUnicode(it->first).data(), OFTInteger);
if(layer->CreateField(&field) != OGRERR_NONE)
{
QgsLogger::warning("creation of OFTInteger field failed");
}
}
else if(it->second == "String")
{
OGRFieldDefn field(it->first, OFTString);
OGRFieldDefn field(codec->fromUnicode(it->first).data(), OFTString);
if(layer->CreateField(&field) != OGRERR_NONE)
{
QgsLogger::warning("creation of OFTString field failed");

0 comments on commit 2958742

Please sign in to comment.
You can’t perform that action at this time.