37 #include <QTextStream>
45 #include <ogr_srs_api.h>
46 #include <cpl_error.h>
49 #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
50 #define TO8(x) (x).toUtf8().constData()
51 #define TO8F(x) (x).toUtf8().constData()
53 #define TO8(x) (x).toLocal8Bit().constData()
54 #define TO8F(x) QFile::encodeName( x ).constData()
59 const QString &theVectorFileName,
76 , mWkbType( geometryType )
77 , mSymbologyExport( symbologyExport )
78 , mSymbologyScaleDenominator( 1.0 )
80 QString vectorFileName = theVectorFileName;
81 QString fileEncoding = theFileEncoding;
87 if ( theVectorFileName.
isEmpty() )
95 if ( driverName ==
"MapInfo MIF" )
97 ogrDriverName =
"MapInfo File";
99 else if ( driverName ==
"SpatiaLite" )
101 ogrDriverName =
"SQLite";
102 if ( !dsOptions.
contains(
"SPATIALITE=YES" ) )
104 dsOptions.
append(
"SPATIALITE=YES" );
107 else if ( driverName ==
"DBF file" )
109 ogrDriverName =
"ESRI Shapefile";
110 if ( !layOptions.
contains(
"SHPT=NULL" ) )
112 layOptions.
append(
"SHPT=NULL" );
118 ogrDriverName = driverName;
122 OGRSFDriverH poDriver;
136 if ( ogrDriverName ==
"ESRI Shapefile" )
143 if ( driverName ==
"ESRI Shapefile" && !vectorFileName.
endsWith(
".shp", Qt::CaseInsensitive ) )
145 vectorFileName +=
".shp";
147 else if ( driverName ==
"DBF file" && !vectorFileName.
endsWith(
".dbf", Qt::CaseInsensitive ) )
149 vectorFileName +=
".dbf";
152 #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM < 1700
155 for (
int i = 0; i < fields.
count(); ++i )
157 QString name = fields[i].name().left( 10 );
160 mErrorMessage =
QObject::tr(
"trimming attribute name '%1' to ten significant characters produces duplicate column name." )
161 .
arg( fields[i].name() );
171 else if ( driverName ==
"KML" )
173 if ( !vectorFileName.
endsWith(
".kml", Qt::CaseInsensitive ) )
175 vectorFileName +=
".kml";
178 if ( fileEncoding.
compare(
"UTF-8", Qt::CaseInsensitive ) != 0 )
181 fileEncoding =
"UTF-8";
196 Q_FOREACH (
const QString& ext, allExts )
198 if ( vectorFileName.
endsWith(
"." + ext, Qt::CaseInsensitive ) )
207 vectorFileName +=
"." + allExts[0];
214 char **options = NULL;
217 options =
new char *[ dsOptions.
size()+1 ];
218 for (
int i = 0; i < dsOptions.
size(); i++ )
220 options[i] = CPLStrdup( dsOptions[i].toLocal8Bit().data() );
222 options[ dsOptions.
size()] = NULL;
226 mDS = OGR_Dr_CreateDataSource( poDriver,
TO8F( vectorFileName ), options );
230 for (
int i = 0; i < dsOptions.
size(); i++ )
231 CPLFree( options[i] );
250 QgsDebugMsg(
"error finding QTextCodec for " + fileEncoding );
257 QgsDebugMsg(
"error finding QTextCodec for " + enc );
273 OGRwkbGeometryType wkbType =
static_cast<OGRwkbGeometryType
>( geometryType );
277 options =
new char *[ layOptions.
size()+1 ];
278 for (
int i = 0; i < layOptions.
size(); i++ )
280 options[i] = CPLStrdup( layOptions[i].toLocal8Bit().data() );
282 options[ layOptions.
size()] = NULL;
286 CPLSetConfigOption(
"SHAPE_ENCODING",
"" );
292 for (
int i = 0; i < layOptions.
size(); i++ )
293 CPLFree( options[i] );
299 if ( !settings.
value(
"/qgis/ignoreShapeEncoding",
true ).
toBool() )
301 CPLSetConfigOption(
"SHAPE_ENCODING", 0 );
306 if ( ogrDriverName ==
"ESRI Shapefile" )
308 QString layerName = vectorFileName.
left( vectorFileName.
indexOf(
".shp", Qt::CaseInsensitive ) );
309 QFile prjFile( layerName +
".qpj" );
310 if ( prjFile.
open( QIODevice::WriteOnly ) )
318 QgsDebugMsg(
"Couldn't open file " + layerName +
".qpj" );
331 OGRFeatureDefnH defn = OGR_L_GetLayerDefn(
mLayer );
342 for (
int fldIdx = 0; fldIdx < fields.
count(); ++fldIdx )
344 const QgsField& attrField = fields[fldIdx];
346 OGRFieldType ogrType = OFTString;
347 int ogrWidth = attrField.
length();
348 int ogrPrecision = attrField.
precision();
349 if ( ogrPrecision > 0 )
352 switch ( attrField.
type() )
354 case QVariant::LongLong:
356 ogrWidth = ogrWidth > 0 && ogrWidth <= 21 ? ogrWidth : 21;
360 case QVariant::String:
362 if ( ogrWidth <= 0 || ogrWidth > 255 )
367 ogrType = OFTInteger;
368 ogrWidth = ogrWidth > 0 && ogrWidth <= 10 ? ogrWidth : 10;
372 case QVariant::Double:
380 case QVariant::DateTime:
381 ogrType = OFTDateTime;
394 if ( ogrDriverName ==
"SQLite" && name.
compare(
"ogc_fid", Qt::CaseInsensitive ) == 0 )
397 for ( i = 0; i < 10; i++ )
402 for ( j = 0; j < fields.
size() && name.compare( fields[j].name(), Qt::CaseInsensitive ) != 0; j++ )
405 if ( j == fields.
size() )
423 OGR_Fld_SetWidth( fld, ogrWidth );
426 if ( ogrPrecision >= 0 )
428 OGR_Fld_SetPrecision( fld, ogrPrecision );
436 if ( OGR_L_CreateField(
mLayer, fld,
true ) != OGRERR_NONE )
443 OGR_Fld_Destroy( fld );
446 OGR_Fld_Destroy( fld );
449 QgsDebugMsg(
QString(
"returned field index for %1: %2" ).arg( name ).arg( ogrIdx ) );
450 if ( ogrIdx < 0 || existingIdxs.
contains( ogrIdx ) )
452 #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM < 1700
455 int fieldCount = OGR_FD_GetFieldCount( defn );
457 OGRFieldDefnH fdefn = OGR_FD_GetFieldDefn( defn, fieldCount - 1 );
460 const char *fieldName = OGR_Fld_GetNameRef( fdefn );
462 if ( attrField.
name().
left( strlen( fieldName ) ) == fieldName )
464 ogrIdx = fieldCount - 1;
469 ogrIdx = OGR_FD_GetFieldCount( defn ) - 1;
483 existingIdxs.
insert( ogrIdx );
497 *newFilename = vectorFileName;
502 return OGR_G_CreateGeometry(( OGRwkbGeometryType ) wkbType );
513 datasetOptions.
clear();
514 layerOptions.
clear();
516 driverMetadata.
insert(
"AVCE00",
518 "Arc/Info ASCII Coverage",
528 datasetOptions.
clear();
529 layerOptions.
clear();
531 datasetOptions.
insert(
"LINEFORMAT",
new SetOption(
533 "systems default line termination conventions. "
534 "This may be overridden here." ),
542 datasetOptions.
insert(
"MULTILINE",
new BoolOption(
543 QObject::tr(
"By default, BNA files are created in multi-line format. "
544 "For each record, the first line contains the identifiers and the "
545 "type/number of coordinates to follow. Each following line contains "
546 "a pair of coordinates." ),
550 datasetOptions.
insert(
"NB_IDS",
new SetOption(
551 QObject::tr(
"BNA records may contain from 2 to 4 identifiers per record. "
552 "Some software packages only support a precise number of identifiers. "
553 "You can override the default value (2) by a precise value" ),
558 <<
"NB_SOURCE_FIELDS",
562 datasetOptions.
insert(
"ELLIPSES_AS_ELLIPSES",
new BoolOption(
563 QObject::tr(
"The BNA writer will try to recognize ellipses and circles when writing a polygon. "
564 "This will only work if the feature has previously been read from a BNA file. "
565 "As some software packages do not support ellipses/circles in BNA data file, "
566 "it may be useful to tell the writer by specifying ELLIPSES_AS_ELLIPSES=NO not "
567 "to export them as such, but keep them as polygons." ),
571 datasetOptions.
insert(
"NB_PAIRS_PER_LINE",
new IntOption(
572 QObject::tr(
"Limit the number of coordinate pairs per line in multiline format." ),
576 datasetOptions.
insert(
"COORDINATE_PRECISION",
new IntOption(
577 QObject::tr(
"Set the number of decimal for coordinates. Default value is 10." ),
581 driverMetadata.
insert(
"BNA",
593 datasetOptions.
clear();
594 layerOptions.
clear();
596 layerOptions.
insert(
"LINEFORMAT",
new SetOption(
597 QObject::tr(
"By default when creating new .csv files they "
598 "are created with the line termination conventions "
599 "of the local platform (CR/LF on Win32 or LF on all other systems). "
600 "This may be overridden through the use of the LINEFORMAT option." ),
608 layerOptions.
insert(
"GEOMETRY",
new SetOption(
609 QObject::tr(
"By default, the geometry of a feature written to a .csv file is discarded. "
610 "It is possible to export the geometry in its WKT representation by "
611 "specifying GEOMETRY=AS_WKT. It is also possible to export point geometries "
612 "into their X,Y,Z components by specifying GEOMETRY=AS_XYZ, GEOMETRY=AS_XY "
613 "or GEOMETRY=AS_YX." ),
623 layerOptions.
insert(
"CREATE_CSVT",
new BoolOption(
624 QObject::tr(
"Create the associated .csvt file to describe the type of each "
625 "column of the layer and its optional width and precision." ),
629 layerOptions.
insert(
"SEPARATOR",
new SetOption(
638 layerOptions.
insert(
"WRITE_BOM",
new BoolOption(
639 QObject::tr(
"Write a UTF-8 Byte Order Mark (BOM) at the start of the file." ),
643 driverMetadata.
insert(
"CSV",
645 "Comma Separated Value [CSV]",
655 datasetOptions.
clear();
656 layerOptions.
clear();
658 layerOptions.
insert(
"SHPT",
new SetOption(
659 QObject::tr(
"Override the type of shapefile created. "
660 "Can be one of NULL for a simple .dbf file with no .shp file, POINT, "
661 "ARC, POLYGON or MULTIPOINT for 2D, or POINTZ, ARCZ, POLYGONZ or "
662 "MULTIPOINTZ for 3D. Shapefiles with measure values are not supported, "
663 "nor are MULTIPATCH files." ),
677 layerOptions.
insert(
"ENCODING",
new SetOption(
678 QObject::tr(
"set the encoding value in the DBF file. "
679 "The default value is LDID/87. It is not clear "
680 "what other values may be appropriate." ),
686 layerOptions.
insert(
"RESIZE",
new BoolOption(
687 QObject::tr(
"Set to YES to resize fields to their optimal size." ),
691 driverMetadata.
insert(
"ESRI",
703 datasetOptions.
clear();
704 layerOptions.
clear();
706 driverMetadata.
insert(
"DBF File",
718 datasetOptions.
clear();
719 layerOptions.
clear();
721 driverMetadata.
insert(
"FMEObjects Gateway",
723 "FMEObjects Gateway",
733 datasetOptions.
clear();
734 layerOptions.
clear();
736 layerOptions.
insert(
"WRITE_BBOX",
new BoolOption(
737 QObject::tr(
"Set to YES to write a bbox property with the bounding box "
738 "of the geometries at the feature and feature collection level." ),
742 layerOptions.
insert(
"COORDINATE_PRECISION",
new IntOption(
743 QObject::tr(
"Maximum number of figures after decimal separator to write in coordinates. "
744 "Default to 15. Truncation will occur to remove trailing zeros." ),
748 driverMetadata.
insert(
"GeoJSON",
760 datasetOptions.
clear();
761 layerOptions.
clear();
763 datasetOptions.
insert(
"FORMAT",
new SetOption(
764 QObject::tr(
"whether the document must be in RSS 2.0 or Atom 1.0 format. "
765 "Default value : RSS" ),
772 datasetOptions.
insert(
"GEOM_DIALECT",
new SetOption(
773 QObject::tr(
"The encoding of location information. Default value : SIMPLE. "
774 "W3C_GEO only supports point geometries. "
775 "SIMPLE or W3C_GEO only support geometries in geographic WGS84 coordinates." ),
783 datasetOptions.
insert(
"USE_EXTENSIONS",
new BoolOption(
784 QObject::tr(
"If defined to YES, extension fields will be written. "
785 "If the field name not found in the base schema matches "
786 "the foo_bar pattern, foo will be considered as the namespace "
787 "of the element, and a <foo:bar> element will be written. "
788 "Otherwise, elements will be written in the <ogr:> namespace." ),
792 datasetOptions.
insert(
"WRITE_HEADER_AND_FOOTER",
new BoolOption(
793 QObject::tr(
"If defined to NO, only <entry> or <item> elements will be written. "
794 "The user will have to provide the appropriate header and footer of the document." ),
798 datasetOptions.
insert(
"HEADER",
new StringOption(
799 QObject::tr(
"XML content that will be put between the <channel> element and the "
800 "first <item> element for a RSS document, or between the xml tag and "
801 "the first <entry> element for an Atom document. " ),
805 datasetOptions.
insert(
"TITLE",
new StringOption(
806 QObject::tr(
"Value put inside the <title> element in the header. "
807 "If not provided, a dummy value will be used as that element is compulsory." ),
811 datasetOptions.
insert(
"DESCRIPTION",
new StringOption(
812 QObject::tr(
"Value put inside the <description> element in the header. "
813 "If not provided, a dummy value will be used as that element is compulsory." ),
817 datasetOptions.
insert(
"LINK",
new StringOption(
818 QObject::tr(
"Value put inside the <link> element in the header. "
819 "If not provided, a dummy value will be used as that element is compulsory." ),
823 datasetOptions.
insert(
"UPDATED",
new StringOption(
824 QObject::tr(
"Value put inside the <updated> element in the header. "
825 "Should be formatted as a XML datetime. "
826 "If not provided, a dummy value will be used as that element is compulsory." ),
830 datasetOptions.
insert(
"AUTHOR_NAME",
new StringOption(
831 QObject::tr(
"Value put inside the <author><name> element in the header. "
832 "If not provided, a dummy value will be used as that element is compulsory." ),
836 datasetOptions.
insert(
"ID",
new StringOption(
837 QObject::tr(
"Value put inside the <id> element in the header. "
838 "If not provided, a dummy value will be used as that element is compulsory." ),
842 driverMetadata.
insert(
"GeoRSS",
854 datasetOptions.
clear();
855 layerOptions.
clear();
857 datasetOptions.
insert(
"XSISCHEMAURI",
new StringOption(
858 QObject::tr(
"If provided, this URI will be inserted as the schema location. "
859 "Note that the schema file isn't actually accessed by OGR, so it "
860 "is up to the user to ensure it will match the schema of the OGR "
861 "produced GML data file." ),
865 datasetOptions.
insert(
"XSISCHEMA",
new SetOption(
866 QObject::tr(
"This writes a GML application schema file to a corresponding "
867 ".xsd file (with the same basename). If INTERNAL is used the "
868 "schema is written within the GML file, but this is experimental "
869 "and almost certainly not valid XML. "
870 "OFF disables schema generation (and is implicit if XSISCHEMAURI is used)." ),
878 datasetOptions.
insert(
"PREFIX",
new StringOption(
879 QObject::tr(
"This is the prefix for the application target namespace." ),
883 datasetOptions.
insert(
"STRIP_PREFIX",
new BoolOption(
884 QObject::tr(
"Can be set to TRUE to avoid writing the prefix of the "
885 "application target namespace in the GML file." ),
889 datasetOptions.
insert(
"TARGET_NAMESPACE",
new StringOption(
890 QObject::tr(
"Defaults to 'http://ogr.maptools.org/'. "
891 "This is the application target namespace." ),
892 "http://ogr.maptools.org/"
895 datasetOptions.
insert(
"FORMAT",
new SetOption(
896 QObject::tr(
"If not specified, GML2 will be used." ),
905 datasetOptions.
insert(
"GML3_LONGSRS",
new BoolOption(
906 QObject::tr(
"only valid when FORMAT=GML3/GML3Degree/GML3.2) Default to YES. "
907 "If YES, SRS with EPSG authority will be written with the "
908 "'urn:ogc:def:crs:EPSG::' prefix. In the case, if the SRS is a "
909 "geographic SRS without explicit AXIS order, but that the same "
910 "SRS authority code imported with ImportFromEPSGA() should be "
911 "treated as lat/long, then the function will take care of coordinate "
912 "order swapping. If set to NO, SRS with EPSG authority will be "
913 "written with the 'EPSG:' prefix, even if they are in lat/long order." ),
917 datasetOptions.
insert(
"WRITE_FEATURE_BOUNDED_BY",
new BoolOption(
918 QObject::tr(
"only valid when FORMAT=GML3/GML3Degree/GML3.2) Default to YES. "
919 "If set to NO, the <gml:boundedBy> element will not be written for "
924 datasetOptions.
insert(
"SPACE_INDENTATION",
new BoolOption(
925 QObject::tr(
"Default to YES. If YES, the output will be indented with spaces "
926 "for more readability, but at the expense of file size." ),
931 driverMetadata.
insert(
"GML",
933 "Geography Markup Language [GML]",
943 datasetOptions.
clear();
944 layerOptions.
clear();
946 driverMetadata.
insert(
"GMT",
948 "Generic Mapping Tools [GMT]",
958 datasetOptions.
clear();
959 layerOptions.
clear();
961 layerOptions.
insert(
"FORCE_GPX_TRACK",
new BoolOption(
962 QObject::tr(
"By default when writing a layer whose features are of "
963 "type wkbLineString, the GPX driver chooses to write "
964 "them as routes. If FORCE_GPX_TRACK=YES is specified, "
965 "they will be written as tracks." ),
969 layerOptions.
insert(
"FORCE_GPX_ROUTE",
new BoolOption(
970 QObject::tr(
"By default when writing a layer whose features are of "
971 "type wkbMultiLineString, the GPX driver chooses to write "
972 "them as tracks. If FORCE_GPX_ROUTE=YES is specified, "
973 "they will be written as routes, provided that the multilines "
974 "are composed of only one single line." ),
978 datasetOptions.
insert(
"GPX_USE_EXTENSIONS",
new BoolOption(
979 QObject::tr(
"If GPX_USE_EXTENSIONS=YES is specified, "
980 "extra fields will be written inside the <extensions> tag." ),
984 datasetOptions.
insert(
"GPX_EXTENSIONS_NS",
new StringOption(
985 QObject::tr(
"Only used if GPX_USE_EXTENSIONS=YES and GPX_EXTENSIONS_NS_URL "
986 "is set. The namespace value used for extension tags. By default, 'ogr'." ),
990 datasetOptions.
insert(
"GPX_EXTENSIONS_NS_URL",
new StringOption(
991 QObject::tr(
"Only used if GPX_USE_EXTENSIONS=YES and GPX_EXTENSIONS_NS "
992 "is set. The namespace URI. By default, 'http://osgeo.org/gdal'." ),
993 "http://osgeo.org/gdal"
996 datasetOptions.
insert(
"LINEFORMAT",
new SetOption(
997 QObject::tr(
"By default files are created with the line termination "
998 "conventions of the local platform (CR/LF on win32 or LF "
999 "on all other systems). This may be overridden through use "
1000 "of the LINEFORMAT layer creation option which may have a value "
1001 "of CRLF (DOS format) or LF (Unix format)." ),
1009 driverMetadata.
insert(
"GPX",
1011 "GPS eXchange Format [GPX]",
1021 datasetOptions.
clear();
1022 layerOptions.
clear();
1024 driverMetadata.
insert(
"Interlis 1",
1028 "*.itf *.xml *.ili",
1036 datasetOptions.
clear();
1037 layerOptions.
clear();
1039 driverMetadata.
insert(
"Interlis 2",
1043 "*.itf *.xml *.ili",
1051 datasetOptions.
clear();
1052 layerOptions.
clear();
1054 datasetOptions.
insert(
"NameField",
new StringOption(
1055 QObject::tr(
"Allows you to specify the field to use for the KML <name> element. " ),
1059 datasetOptions.
insert(
"DescriptionField",
new StringOption(
1060 QObject::tr(
"Allows you to specify the field to use for the KML <description> element." ),
1064 datasetOptions.
insert(
"AltitudeMode",
new SetOption(
1065 QObject::tr(
"Allows you to specify the AltitudeMode to use for KML geometries. "
1066 "This will only affect 3D geometries and must be one of the valid KML options." ),
1068 <<
"relativeToGround"
1074 driverMetadata.
insert(
"KML",
1076 "Keyhole Markup Language [KML]",
1086 datasetOptions.
clear();
1087 layerOptions.
clear();
1089 layerOptions.
insert(
"SPATIAL_INDEX_MODE",
new SetOption(
1090 QObject::tr(
"Use this to turn on 'quick spatial index mode'. "
1091 "In this mode writing files can be about 5 times faster, "
1092 "but spatial queries can be up to 30 times slower." ),
1099 driverMetadata.
insert(
"MapInfo File",
1111 driverMetadata.
insert(
"MapInfo MIF",
1123 datasetOptions.
clear();
1124 layerOptions.
clear();
1126 datasetOptions.
insert(
"3D",
new BoolOption(
1127 QObject::tr(
"Determine whether 2D (seed_2d.dgn) or 3D (seed_3d.dgn) "
1128 "seed file should be used. This option is ignored if the SEED option is provided." ),
1132 datasetOptions.
insert(
"SEED",
new StringOption(
1137 datasetOptions.
insert(
"COPY_WHOLE_SEED_FILE",
new BoolOption(
1138 QObject::tr(
"Indicate whether the whole seed file should be copied. "
1139 "If not, only the first three elements will be copied." ),
1143 datasetOptions.
insert(
"COPY_SEED_FILE_COLOR_TABLEE",
new BoolOption(
1144 QObject::tr(
"Indicates whether the color table should be copied from the seed file." ),
1148 datasetOptions.
insert(
"MASTER_UNIT_NAME",
new StringOption(
1149 QObject::tr(
"Override the master unit name from the seed file with "
1150 "the provided one or two character unit name." ),
1154 datasetOptions.
insert(
"SUB_UNIT_NAME",
new StringOption(
1155 QObject::tr(
"Override the sub unit name from the seed file with the provided "
1156 "one or two character unit name." ),
1160 datasetOptions.
insert(
"SUB_UNITS_PER_MASTER_UNIT",
new IntOption(
1161 QObject::tr(
"Override the number of subunits per master unit. "
1162 "By default the seed file value is used." ),
1166 datasetOptions.
insert(
"UOR_PER_SUB_UNIT",
new IntOption(
1167 QObject::tr(
"Override the number of UORs (Units of Resolution) "
1168 "per sub unit. By default the seed file value is used." ),
1172 datasetOptions.
insert(
"ORIGIN",
new StringOption(
1173 QObject::tr(
"ORIGIN=x,y,z: Override the origin of the design plane. "
1174 "By default the origin from the seed file is used." ),
1178 driverMetadata.
insert(
"DGN",
1190 datasetOptions.
clear();
1191 layerOptions.
clear();
1193 driverMetadata.
insert(
"DGN",
1205 datasetOptions.
clear();
1206 layerOptions.
clear();
1208 datasetOptions.
insert(
"UPDATES",
new SetOption(
1209 QObject::tr(
"Should update files be incorporated into the base data on the fly. " ),
1216 datasetOptions.
insert(
"SPLIT_MULTIPOINT",
new BoolOption(
1217 QObject::tr(
"Should multipoint soundings be split into many single point sounding features. "
1218 "Multipoint geometries are not well handled by many formats, "
1219 "so it can be convenient to split single sounding features with many points "
1220 "into many single point features." ),
1224 datasetOptions.
insert(
"ADD_SOUNDG_DEPTH",
new BoolOption(
1225 QObject::tr(
"Should a DEPTH attribute be added on SOUNDG features and assign the depth "
1226 "of the sounding. This should only be enabled with SPLIT_MULTIPOINT is "
1231 datasetOptions.
insert(
"RETURN_PRIMITIVES",
new BoolOption(
1232 QObject::tr(
"Should all the low level geometry primitives be returned as special "
1233 "IsolatedNode, ConnectedNode, Edge and Face layers." ),
1237 datasetOptions.
insert(
"PRESERVE_EMPTY_NUMBERS",
new BoolOption(
1238 QObject::tr(
"If enabled, numeric attributes assigned an empty string as a value will "
1239 "be preserved as a special numeric value. This option should not generally "
1240 "be needed, but may be useful when translated S-57 to S-57 losslessly." ),
1244 datasetOptions.
insert(
"LNAM_REFS",
new BoolOption(
1245 QObject::tr(
"Should LNAM and LNAM_REFS fields be attached to features capturing "
1246 "the feature to feature relationships in the FFPT group of the S-57 file." ),
1250 datasetOptions.
insert(
"RETURN_LINKAGES",
new BoolOption(
1251 QObject::tr(
"Should additional attributes relating features to their underlying "
1252 "geometric primitives be attached. These are the values of the FSPT group, "
1253 "and are primarily needed when doing S-57 to S-57 translations." ),
1257 datasetOptions.
insert(
"RECODE_BY_DSSI",
new BoolOption(
1258 QObject::tr(
"Should attribute values be recoded to UTF-8 from the character encoding "
1259 "specified in the S57 DSSI record." ),
1265 driverMetadata.
insert(
"S57",
1277 datasetOptions.
clear();
1278 layerOptions.
clear();
1280 driverMetadata.
insert(
"SDTS",
1282 "Spatial Data Transfer Standard [SDTS]",
1283 QObject::tr(
"Spatial Data Transfer Standard [SDTS]" ),
1292 datasetOptions.
clear();
1293 layerOptions.
clear();
1295 datasetOptions.
insert(
"METADATA",
new BoolOption(
1296 QObject::tr(
"Can be used to avoid creating the geometry_columns and spatial_ref_sys "
1297 "tables in a new database. By default these metadata tables are created "
1298 "when a new database is created." ),
1303 datasetOptions.
insert(
"SPATIALITE",
new HiddenOption(
1308 datasetOptions.
insert(
"INIT_WITH_EPSG",
new HiddenOption(
1312 layerOptions.
insert(
"FORMAT",
new SetOption(
1313 QObject::tr(
"Controls the format used for the geometry column. Defaults to WKB."
1314 "This is generally more space and processing efficient, but harder "
1315 "to inspect or use in simple applications than WKT (Well Known Text)." ),
1322 layerOptions.
insert(
"LAUNDER",
new BoolOption(
1323 QObject::tr(
"Controls whether layer and field names will be laundered for easier use "
1324 "in SQLite. Laundered names will be converted to lower case and some special "
1325 "characters(' - #) will be changed to underscores." ),
1329 layerOptions.
insert(
"SPATIAL_INDEX",
new HiddenOption(
1333 layerOptions.
insert(
"COMPRESS_GEOM",
new HiddenOption(
1337 layerOptions.
insert(
"SRID",
new HiddenOption(
1341 layerOptions.
insert(
"COMPRESS_COLUMNS",
new StringOption(
1342 QObject::tr(
"column_name1[,column_name2, ...] A list of (String) columns that "
1343 "must be compressed with ZLib DEFLATE algorithm. This might be beneficial "
1344 "for databases that have big string blobs. However, use with care, since "
1345 "the value of such columns will be seen as compressed binary content with "
1346 "other SQLite utilities (or previous OGR versions). With OGR, when inserting, "
1347 "modifying or queryings compressed columns, compression/decompression is "
1348 "done transparently. However, such columns cannot be (easily) queried with "
1349 "an attribute filter or WHERE clause. Note: in table definition, such columns "
1350 "have the 'VARCHAR_deflate' declaration type." ),
1354 driverMetadata.
insert(
"SQLite",
1366 datasetOptions.
clear();
1367 layerOptions.
clear();
1369 datasetOptions.
insert(
"METADATA",
new BoolOption(
1370 QObject::tr(
"Can be used to avoid creating the geometry_columns and spatial_ref_sys "
1371 "tables in a new database. By default these metadata tables are created "
1372 "when a new database is created." ),
1376 datasetOptions.
insert(
"SPATIALITE",
new HiddenOption(
1380 datasetOptions.
insert(
"INIT_WITH_EPSG",
new BoolOption(
1381 QObject::tr(
"Insert the content of the EPSG CSV files into the spatial_ref_sys table. "
1382 "Set to NO for regular SQLite databases." ),
1386 layerOptions.
insert(
"FORMAT",
new HiddenOption(
1390 layerOptions.
insert(
"LAUNDER",
new BoolOption(
1391 QObject::tr(
"Controls whether layer and field names will be laundered for easier use "
1392 "in SQLite. Laundered names will be converted to lower case and some special "
1393 "characters(' - #) will be changed to underscores." ),
1397 layerOptions.
insert(
"SPATIAL_INDEX",
new BoolOption(
1398 QObject::tr(
"If the database is of the SpatiaLite flavour, and if OGR is linked "
1399 "against libspatialite, this option can be used to control if a spatial "
1400 "index must be created." ),
1404 layerOptions.
insert(
"COMPRESS_GEOM",
new BoolOption(
1405 QObject::tr(
"If the format of the geometry BLOB is of the SpatiaLite flavour, "
1406 "this option can be used to control if the compressed format for "
1407 "geometries (LINESTRINGs, POLYGONs) must be used" ),
1411 layerOptions.
insert(
"SRID",
new StringOption(
1412 QObject::tr(
"Used to force the SRID number of the SRS associated with the layer. "
1413 "When this option isn't specified and that a SRS is associated with the "
1414 "layer, a search is made in the spatial_ref_sys to find a match for the "
1415 "SRS, and, if there is no match, a new entry is inserted for the SRS in "
1416 "the spatial_ref_sys table. When the SRID option is specified, this "
1417 "search (and the eventual insertion of a new entry) will not be done: "
1418 "the specified SRID is used as such." ),
1422 layerOptions.
insert(
"COMPRESS_COLUMNS",
new StringOption(
1423 QObject::tr(
"column_name1[,column_name2, ...] A list of (String) columns that "
1424 "must be compressed with ZLib DEFLATE algorithm. This might be beneficial "
1425 "for databases that have big string blobs. However, use with care, since "
1426 "the value of such columns will be seen as compressed binary content with "
1427 "other SQLite utilities (or previous OGR versions). With OGR, when inserting, "
1428 "modifying or queryings compressed columns, compression/decompression is "
1429 "done transparently. However, such columns cannot be (easily) queried with "
1430 "an attribute filter or WHERE clause. Note: in table definition, such columns "
1431 "have the 'VARCHAR_deflate' declaration type." ),
1435 driverMetadata.
insert(
"SpatiaLite",
1446 datasetOptions.
clear();
1447 layerOptions.
clear();
1450 datasetOptions.
insert(
"HEADER",
new StringOption(
1451 QObject::tr(
"Override the header file used - in place of header.dxf." ),
1455 datasetOptions.
insert(
"TRAILER",
new StringOption(
1456 QObject::tr(
"Override the trailer file used - in place of trailer.dxf." ),
1461 driverMetadata.
insert(
"DXF",
1473 datasetOptions.
clear();
1474 layerOptions.
clear();
1476 datasetOptions.
insert(
"EXTENSION",
new SetOption(
1477 QObject::tr(
"Indicates the GeoConcept export file extension. "
1478 "TXT was used by earlier releases of GeoConcept. GXT is currently used." ),
1486 datasetOptions.
insert(
"CONFIG",
new StringOption(
1487 QObject::tr(
"path to the GCT : the GCT file describe the GeoConcept types definitions: "
1488 "In this file, every line must start with //# followed by a keyword. "
1489 "Lines starting with // are comments." ),
1494 driverMetadata.
insert(
"Geoconcept",
1506 datasetOptions.
clear();
1507 layerOptions.
clear();
1509 layerOptions.
insert(
"FEATURE_DATASET",
new StringOption(
1510 QObject::tr(
"When this option is set, the new layer will be created inside the named "
1511 "FeatureDataset folder. If the folder does not already exist, it will be created." ),
1515 layerOptions.
insert(
"GEOMETRY_NAME",
new StringOption(
1516 QObject::tr(
"Set name of geometry column in new layer. Defaults to 'SHAPE'." ),
1520 layerOptions.
insert(
"OID_NAME",
new StringOption(
1521 QObject::tr(
"Name of the OID column to create. Defaults to 'OBJECTID'." ),
1525 driverMetadata.
insert(
"FileGDB",
1544 for ( ; it != sDriverMetadata.
constEnd(); ++it )
1546 if ( it.
key().startsWith( driverName ) )
1548 driverMetadata = it.
value();
1570 OGRFeatureH poFeature = createFeature( feature );
1584 for ( ; symbolIt != symbols.
constEnd(); ++symbolIt )
1586 int nSymbolLayers = ( *symbolIt )->symbolLayerCount();
1587 for (
int i = 0; i < nSymbolLayers; ++i )
1591 if ( it == mSymbolLayerTable.constEnd() )
1599 currentStyle = ( *symbolIt )->symbolLayer( i )->ogrFeatureStyle( mmsf, musf );
1603 if ( symbolIt != symbols.
constBegin() || i != 0 )
1605 styleString.
append(
";" );
1607 styleString.
append( currentStyle );
1611 OGR_F_SetStyleString( poFeature, currentStyle.toLocal8Bit().data() );
1612 if ( !writeFeature(
mLayer, poFeature ) )
1624 if ( !writeFeature(
mLayer, poFeature ) )
1630 OGR_F_Destroy( poFeature );
1634 OGRFeatureH QgsVectorFileWriter::createFeature(
QgsFeature& feature )
1638 OGRFeatureH poFeature = OGR_F_Create( OGR_L_GetLayerDefn(
mLayer ) );
1644 OGRErr err = OGR_F_SetFID( poFeature, static_cast<long>( fid ) );
1645 if ( err != OGRERR_NONE )
1648 .arg( feature.
id() )
1649 .arg( err ).
arg( CPLGetLastErrorMsg() )
1655 for (
int fldIdx = 0; fldIdx <
mFields.
count(); ++fldIdx )
1669 switch ( attrValue.
type() )
1672 OGR_F_SetFieldInteger( poFeature, ogrField, attrValue.
toInt() );
1674 case QVariant::Double:
1675 OGR_F_SetFieldDouble( poFeature, ogrField, attrValue.
toDouble() );
1677 case QVariant::LongLong:
1678 case QVariant::UInt:
1679 case QVariant::ULongLong:
1680 case QVariant::String:
1683 case QVariant::Date:
1684 OGR_F_SetFieldDateTime( poFeature, ogrField,
1690 case QVariant::DateTime:
1691 OGR_F_SetFieldDateTime( poFeature, ogrField,
1700 case QVariant::Time:
1701 OGR_F_SetFieldDateTime( poFeature, ogrField,
1708 case QVariant::Invalid:
1735 OGRGeometryH mGeom2 = NULL;
1768 OGR_F_Destroy( poFeature );
1772 OGRErr err = OGR_G_ImportFromWkb( mGeom2, const_cast<unsigned char *>( geom->
asWkb() ), (
int ) geom->wkbSize() );
1773 if ( err != OGRERR_NONE )
1779 OGR_F_Destroy( poFeature );
1784 OGR_F_SetGeometryDirectly( poFeature, mGeom2 );
1788 OGRErr err = OGR_G_ImportFromWkb(
mGeom, const_cast<unsigned char *>( geom->
asWkb() ), (
int ) geom->wkbSize() );
1789 if ( err != OGRERR_NONE )
1795 OGR_F_Destroy( poFeature );
1800 OGR_F_SetGeometry( poFeature,
mGeom );
1806 bool QgsVectorFileWriter::writeFeature( OGRLayerH layer, OGRFeatureH feature )
1808 if ( OGR_L_CreateFeature( layer, feature ) != OGRERR_NONE )
1813 OGR_F_Destroy( feature );
1823 OGR_G_DestroyGeometry(
mGeom );
1828 OGR_DS_Destroy(
mDS );
1833 OSRDestroySpatialReference(
mOgrRef );
1847 bool skipAttributeCreation,
1850 double symbologyScale,
1854 if ( destCRS && layer )
1860 errorMessage, datasourceOptions, layerOptions, skipAttributeCreation, newFilename, symbologyExport, symbologyScale, filterExtent );
1874 bool skipAttributeCreation,
1877 double symbologyScale,
1885 bool shallTransform =
false;
1890 outputCRS = &( ct->
destCRS() );
1891 shallTransform =
true;
1896 outputCRS = &layer->
crs();
1905 QString srcFileName = theURIParts[0];
1910 *errorMessage =
QObject::tr(
"Cannot overwrite a OGR layer in place" );
1922 if ( onlySelected && !ids.
contains( fet.
id() ) )
1935 for (
int i = 0; i < fields.
size(); i++ )
1937 if ( fields.
at( i ).
type() == QVariant::LongLong )
1943 fields[i].setType( QVariant::Int );
1950 new QgsVectorFileWriter( fileName, fileEncoding, fields, wkbType, outputCRS, driverName, datasourceOptions, layerOptions, newFilename, symbologyExport );
1970 errorMessage->
clear();
1977 writer->addRendererAttributes( layer, allAttr );
2007 int n = 0, errors = 0;
2016 writer->startRender( layer );
2019 bool transactionsEnabled =
true;
2021 if ( OGRERR_NONE != OGR_L_StartTransaction( writer->
mLayer ) )
2023 QgsDebugMsg(
"Error when trying to enable transactions on OGRLayer." );
2024 transactionsEnabled =
false;
2030 if ( onlySelected && !ids.
contains( fet.
id() ) )
2033 if ( shallTransform )
2046 QString msg =
QObject::tr(
"Failed to transform a point while drawing a feature with ID '%1'. Writing stopped. (Exception: %2)" )
2050 *errorMessage = msg;
2059 if ( allAttr.
size() < 1 && skipAttributeCreation )
2067 if ( err !=
NoError && errorMessage )
2069 if ( errorMessage->
isEmpty() )
2071 *errorMessage =
QObject::tr(
"Feature write errors:" );
2077 if ( errors > 1000 )
2081 *errorMessage +=
QObject::tr(
"Stopping after %1 errors" ).
arg( errors );
2091 if ( transactionsEnabled )
2093 if ( OGRERR_NONE != OGR_L_CommitTransaction( writer->
mLayer ) )
2095 QgsDebugMsg(
"Error while committing transaction on OGRLayer." );
2099 writer->stopRender( layer );
2102 if ( errors > 0 && errorMessage && n > 0 )
2104 *errorMessage +=
QObject::tr(
"\nOnly %1 of %2 features written." ).
arg( n - errors ).
arg( n );
2117 const char *suffixes[] = {
".shp",
".shx",
".dbf",
".prj",
".qix",
".qpj" };
2118 for ( std::size_t i = 0; i <
sizeof( suffixes ) /
sizeof( *suffixes ); i++ )
2129 QgsDebugMsg(
QString(
"Removing file %1 failed: %2" ).arg( file, f.errorString() ) );
2148 int const drvCount = OGRGetDriverCount();
2150 for (
int i = 0; i < drvCount; ++i )
2152 OGRSFDriverH drv = OGRGetDriver( i );
2155 QString drvName = OGR_Dr_GetName( drv );
2156 if ( OGR_Dr_TestCapability( drv,
"CreateDataSource" ) != 0 )
2162 resultMap.
insert( filterString, drvName );
2175 int const drvCount = OGRGetDriverCount();
2178 for (
int i = 0; i < drvCount; ++i )
2180 OGRSFDriverH drv = OGRGetDriver( i );
2183 QString drvName = OGR_Dr_GetName( drv );
2184 if ( OGR_Dr_TestCapability( drv,
"CreateDataSource" ) != 0 )
2187 if ( drvName ==
"MapInfo File" )
2189 writableDrivers <<
"MapInfo MIF";
2191 else if ( drvName ==
"SQLite" )
2198 QString option =
"SPATIALITE=YES";
2199 char **options =
new char *[2];
2202 OGRSFDriverH poDriver;
2207 OGRDataSourceH ds = OGR_Dr_CreateDataSource( poDriver,
TO8F(
QString(
"/vsimem/spatialitetest.sqlite" ) ), options );
2210 writableDrivers <<
"SpatiaLite";
2211 OGR_Dr_DeleteDataSource( poDriver,
TO8F(
QString(
"/vsimem/spatialitetest.sqlite" ) ) );
2212 OGR_DS_Destroy( ds );
2215 CPLFree( options[0] );
2218 else if ( drvName ==
"ESRI Shapefile" )
2220 writableDrivers <<
"DBF file";
2222 writableDrivers << drvName;
2227 Q_FOREACH (
const QString& drvName, writableDrivers )
2235 resultMap.
insert( trLongName, drvName );
2247 for ( ; it != driverFormatMap.
constEnd(); ++it )
2249 if ( !filterString.
isEmpty() )
2250 filterString +=
";;";
2252 filterString += it.
key();
2254 return filterString;
2266 return trLongName +
" [OGR] (" + glob.
toLower() +
" " + glob.
toUpper() +
")";
2271 if ( codecName ==
"System" )
2279 c.
toInt( &isNumber );
2290 longName =
"Arc/Info ASCII Coverage";
2291 trLongName =
QObject::tr(
"Arc/Info ASCII Coverage" );
2297 longName =
"Atlas BNA";
2304 longName =
"Comma Separated Value [CSV]";
2305 trLongName =
QObject::tr(
"Comma Separated Value [CSV]" );
2311 longName =
"ESRI Shapefile";
2316 else if ( driverName.
startsWith(
"DBF file" ) )
2318 longName =
"DBF File";
2323 else if ( driverName.
startsWith(
"FMEObjects Gateway" ) )
2325 longName =
"FMEObjects Gateway";
2330 else if ( driverName.
startsWith(
"GeoJSON" ) )
2332 longName =
"GeoJSON";
2339 longName =
"GeoPackage";
2344 else if ( driverName.
startsWith(
"GeoRSS" ) )
2346 longName =
"GeoRSS";
2353 longName =
"Geography Markup Language [GML]";
2354 trLongName =
QObject::tr(
"Geography Markup Language [GML]" );
2360 longName =
"Generic Mapping Tools [GMT]";
2361 trLongName =
QObject::tr(
"Generic Mapping Tools [GMT]" );
2367 longName =
"GPS eXchange Format [GPX]";
2368 trLongName =
QObject::tr(
"GPS eXchange Format [GPX]" );
2372 else if ( driverName.
startsWith(
"Interlis 1" ) )
2374 longName =
"INTERLIS 1";
2376 glob =
"*.itf *.xml *.ili";
2379 else if ( driverName.
startsWith(
"Interlis 2" ) )
2381 longName =
"INTERLIS 2";
2383 glob =
"*.itf *.xml *.ili";
2388 longName =
"Keyhole Markup Language [KML]";
2389 trLongName =
QObject::tr(
"Keyhole Markup Language [KML]" );
2393 else if ( driverName.
startsWith(
"MapInfo File" ) )
2395 longName =
"Mapinfo TAB";
2401 else if ( driverName.
startsWith(
"MapInfo MIF" ) )
2403 longName =
"Mapinfo MIF";
2410 longName =
"Microstation DGN";
2417 longName =
"S-57 Base file";
2424 longName =
"Spatial Data Transfer Standard [SDTS]";
2425 trLongName =
QObject::tr(
"Spatial Data Transfer Standard [SDTS]" );
2429 else if ( driverName.
startsWith(
"SQLite" ) )
2431 longName =
"SQLite";
2437 else if ( driverName.
startsWith(
"SpatiaLite" ) )
2439 longName =
"SpatiaLite";
2446 longName =
"AutoCAD DXF";
2451 else if ( driverName.
startsWith(
"Geoconcept" ) )
2453 longName =
"Geoconcept";
2455 glob =
"*.gxt *.txt";
2458 else if ( driverName.
startsWith(
"FileGDB" ) )
2460 longName =
"ESRI FileGDB";
2493 #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1700
2494 mSymbolLayerTable.clear();
2495 OGRStyleTableH ogrStyleTable = OGR_STBL_Create();
2496 OGRStyleMgrH styleManager = OGR_SM_Create( ogrStyleTable );
2499 int nTotalLevels = 0;
2502 for ( ; symbolIt != symbolList.
end(); ++symbolIt )
2507 int nLevels = ( *symbolIt )->symbolLayerCount();
2508 for (
int i = 0; i < nLevels; ++i )
2510 mSymbolLayerTable.insert(( *symbolIt )->symbolLayer( i ),
QString::number( nTotalLevels ) );
2511 OGR_SM_AddStyle( styleManager,
QString::number( nTotalLevels ).toLocal8Bit(),
2512 ( *symbolIt )->symbolLayer( i )->ogrFeatureStyle( mmsf, musf ).
toLocal8Bit() );
2516 OGR_DS_SetStyleTableDirectly( ds, ogrStyleTable );
2544 startRender( layer );
2566 *errorMessage = msg;
2574 if ( !featureSymbol )
2580 if ( it == features.
end() )
2584 it.
value().append( fet );
2590 for (
int i = 0; i < symbols.
count(); i++ )
2596 if ( level < 0 || level >= 1000 )
2599 while ( level >= levels.
count() )
2601 levels[level].
append( item );
2606 int nTotalFeatures = 0;
2609 for (
int l = 0; l < levels.
count(); l++ )
2612 for (
int i = 0; i < level.
count(); i++ )
2616 if ( levelIt == features.
end() )
2625 int llayer = item.
layer();
2628 for ( ; featureIt != featureList.
end(); ++featureIt )
2631 OGRFeatureH ogrFeature = createFeature( *featureIt );
2638 QString styleString = levelIt.
key()->symbolLayer( llayer )->ogrFeatureStyle( mmsf, musf );
2642 if ( !writeFeature(
mLayer, ogrFeature ) )
2647 OGR_F_Destroy( ogrFeature );
2652 stopRender( layer );
2654 if ( nErrors > 0 && errorMessage )
2656 *errorMessage +=
QObject::tr(
"\nOnly %1 of %2 features written." ).
arg( nTotalFeatures - nErrors ).
arg( nTotalFeatures );
2673 return 1000 / scaleDenominator;
2690 return scaleDenominator / 1000;
2738 for (
int i = 0; i < rendererAttributes.
size(); ++i )
QgsFeatureId id() const
Get the feature ID for this feature.
qlonglong toLongLong(bool *ok) const
const QString & name() const
Gets the name of the field.
Wrapper for iterator of features from vector data provider or vector layer.
QByteArray fromUnicode(const QString &str) const
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
A rectangle specified with double values.
static QMap< QString, QString > supportedFiltersAndFormats()
Returns map with format filter string as key and OGR format key as value.
SymbologyExport symbologyExport() const
QString cap(int nth) const
QString & append(QChar ch)
QgsAttributeList attributeList() const
Returns list of attribute indexes.
iterator insert(const Key &key, const T &value)
OutputUnit
The unit of the output.
bool contains(const Key &key) const
const Key key(const T &value) const
WriterError mError
Contains error value if construction was not successful.
static bool deleteShapeFile(const QString &theFileName)
Delete a shapefile (and its accompanying shx / dbf / prf)
void push_back(const T &value)
QVariant maximumValue(int index)
Returns maximum value for an attribute column or invalid variant in case of error.
static QString fileFilterString()
Returns filter string that can be used for dialogs.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
QgsFields fields() const
Returns the list of fields of this layer.
UnitType
Map units that qgis supports.
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QDateTime toDateTime() const
SymbologyExport mSymbologyExport
double mSymbologyScaleDenominator
Scale for symbology export (e.g.
static void warning(const QString &msg)
Goes to qWarning.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
const_iterator constBegin() const
void setRendererScale(double scale)
const T & at(int i) const
QString toWkt() const
A helper to get an wkt representation of this srs.
int precision() const
Gets the precision of the field.
bool contains(const QString &str, Qt::CaseSensitivity cs) const
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
static void registerOgrDrivers()
Register OGR drivers ensuring this only happens once.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
virtual QList< QString > usedAttributes()=0
QString join(const QString &separator) const
WkbType
Used for symbology operations.
A convenience class for writing vector files to disk.
const_iterator insert(const T &value)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QVariant minimumValue(int index)
Returns minimum value for an attribute column or invalid variant in case of error.
QString tr(const char *sourceText, const char *disambiguation, int n)
QTextCodec * codecForLocale()
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
Needs to be called when a new render cycle is started.
QGis::WkbType wkbType() const
Returns the WKBType or WKBUnknown in case of error.
virtual void stopRender(QgsRenderContext &context)=0
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
static QgsWKBTypes::Type fromOldWkbType(QGis::WkbType type)
Converts from old (pre 2.10) WKB type to new WKB type.
QgsFeatureRendererV2 * rendererV2()
Return renderer V2.
The output shall be in millimeters.
QString number(int n, int base)
int count(const T &value) const
virtual Q_DECL_DEPRECATED QgsSymbolV2 * symbolForFeature(QgsFeature &feature)
To be overridden.
void append(const T &value)
QString fromUtf8(const char *str, int size)
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
int toInt(bool *ok) const
const QgsFeatureIds & selectedFeaturesIds() const
Return reference to identifiers of selected features.
#define FID_TO_NUMBER(fid)
void initAttributes(int fieldCount)
Initialize this feature with the given number of fields.
int toInt(bool *ok, int base) const
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
const_iterator constEnd() const
const char * constData() const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
The output shall be in map unitx.
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
This class wraps a request for features to a vector layer (or directly its vector data provider)...
~QgsVectorFileWriter()
Close opened shapefile for writing.
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Get the data source specification.
QList< int > QgsAttributeList
int symbolLayerCount()
Returns total number of symbol layers contained in the symbol.
bool addFeature(QgsFeature &feature, QgsFeatureRendererV2 *renderer=0, QGis::UnitType outputUnit=QGis::Meters)
Add feature to the currently opened shapefile.
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
int count() const
Return number of items.
QGis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
QGis::WkbType mWkbType
Geometry type which is being used.
QgsFeatureRequest & setFlags(const QgsFeatureRequest::Flags &flags)
Set flags that affect how features will be fetched.
Encapsulate a field in an attribute table or data source.
virtual Q_DECL_DEPRECATED QgsSymbolV2List symbols()
for symbol levels
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
QMap< int, int > mAttrIdxToOgrIdx
Map attribute indizes to OGR field indexes.
static WkbType singleType(WkbType type)
Map multi to single type.
OGRSpatialReferenceH mOgrRef
const T value(const Key &key) const
QByteArray toLocal8Bit() const
iterator find(const Key &key)
int renderingPass() const
QgsExpressionContext & expressionContext()
Gets the expression context.
QgsGeometry * geometry()
Get the geometry object associated with this feature.
static QMap< QString, QString > ogrDriverList()
Returns driver list that can be used for dialogs.
bool contains(const T &value) const
const char * typeToName(Type typ)
QString errorMessage()
Retrieves error message.
const Key key(const T &value) const
QString providerType() const
Return the provider type for this layer.
QString & replace(int position, int n, QChar after)
static WkbType multiType(WkbType type)
Map single to multitype type.
QVariant value(const QString &key, const QVariant &defaultValue) const
static QString convertCodecNameForEncodingOption(const QString &codecName)
Converts codec name to string passed to ENCODING layer creation option of OGR Shapefile.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
WriterError hasError()
Checks whether there were any errors in constructor.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QgsVectorFileWriter(const QString &vectorFileName, const QString &fileEncoding, const QgsFields &fields, QGis::WkbType geometryType, const QgsCoordinateReferenceSystem *srs, const QString &driverName="ESRI Shapefile", const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), QString *newFilename=0, SymbologyExport symbologyExport=NoSymbology)
Create shapefile and initialize it.
virtual Q_DECL_DEPRECATED QgsSymbolV2List symbolsForFeature(QgsFeature &feat)
return list of symbols used for rendering the feature.
void setSymbologyScaleDenominator(double d)
QStringList entryList(QFlags< QDir::Filter > filters, QFlags< QDir::SortFlag > sort) const
QTextCodec * codecForName(const QByteArray &name)
bool usingSymbolLevels() const
const char * typeName() const
Class for storing a coordinate reference system (CRS)
int length() const
Gets the length of the field.
int size() const
Return number of items.
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
int transform(const QgsCoordinateTransform &ct)
Transform this geometry as described by CoordinateTransform ct.
QString left(int n) const
QString completeBaseName() const
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
QString canonicalPath() const
double toDouble(bool *ok) const
iterator insert(const Key &key, const T &value)
Custom exception class for Coordinate Reference System related exceptions.
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
QgsSymbolLayerV2 * symbolLayer(int layer)
Returns a specific symbol layers contained in the symbol.
QgsVectorDataProvider * dataProvider()
Returns the data provider.
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
const_iterator constEnd() const
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
bool nextFeature(QgsFeature &f)
const_iterator constBegin() const
Geometry is not required. It may still be returned if e.g. required for a filter condition.
bool intersects(const QgsRectangle &r) const
Test for intersection with a rectangle (uses GEOS)
Represents a vector layer which manages a vector based data sets.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
int compare(const QString &other) const
bool exactMatch(const QString &str) const
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
const unsigned char * asWkb() const
Returns the buffer containing this geometry in WKB format.
OGRGeometryH createEmptyGeometry(QGis::WkbType wkbType)
static WriterError writeAsVectorFormat(QgsVectorLayer *layer, const QString &fileName, const QString &fileEncoding, const QgsCoordinateReferenceSystem *destCRS, const QString &driverName="ESRI Shapefile", bool onlySelected=false, QString *errorMessage=0, const QStringList &datasourceOptions=QStringList(), const QStringList &layerOptions=QStringList(), bool skipAttributeCreation=false, QString *newFilename=0, SymbologyExport symbologyExport=NoSymbology, double symbologyScale=1.0, const QgsRectangle *filterExtent=0)
Write contents of vector layer to an (OGR supported) vector formt.
static QString filterForDriver(const QString &driverName)
Creates a filter for an OGR driver key.
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.
const T value(const Key &key) const
static bool driverMetadata(const QString &driverName, MetaData &driverMetadata)
QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
QGis::UnitType mapUnits() const
Get the units that the projection is in.