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,
75 , mWkbType( geometryType )
76 , mSymbologyExport( symbologyExport )
77 , mSymbologyScaleDenominator( 1.0 )
79 QString vectorFileName = theVectorFileName;
80 QString fileEncoding = theFileEncoding;
84 if ( theVectorFileName.
isEmpty() )
92 if ( driverName ==
"MapInfo MIF" )
94 ogrDriverName =
"MapInfo File";
96 else if ( driverName ==
"SpatiaLite" )
98 ogrDriverName =
"SQLite";
99 if ( !dsOptions.
contains(
"SPATIALITE=YES" ) )
101 dsOptions.
append(
"SPATIALITE=YES" );
104 else if ( driverName ==
"DBF file" )
106 ogrDriverName =
"ESRI Shapefile";
107 if ( !layOptions.
contains(
"SHPT=NULL" ) )
109 layOptions.
append(
"SHPT=NULL" );
115 ogrDriverName = driverName;
119 OGRSFDriverH poDriver;
133 if ( ogrDriverName ==
"ESRI Shapefile" )
140 if ( driverName ==
"ESRI Shapefile" && !vectorFileName.
endsWith(
".shp", Qt::CaseInsensitive ) )
142 vectorFileName +=
".shp";
144 else if ( driverName ==
"DBF file" && !vectorFileName.
endsWith(
".dbf", Qt::CaseInsensitive ) )
146 vectorFileName +=
".dbf";
149 #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM < 1700
152 for (
int i = 0; i < fields.
count(); ++i )
154 QString name = fields[i].name().left( 10 );
157 mErrorMessage =
QObject::tr(
"trimming attribute name '%1' to ten significant characters produces duplicate column name." )
158 .
arg( fields[i].name() );
168 else if ( driverName ==
"KML" )
170 if ( !vectorFileName.
endsWith(
".kml", Qt::CaseInsensitive ) )
172 vectorFileName +=
".kml";
175 if ( fileEncoding.
compare(
"UTF-8", Qt::CaseInsensitive ) != 0 )
178 fileEncoding =
"UTF-8";
193 foreach (
QString ext, allExts )
195 if ( vectorFileName.
endsWith(
"." + ext, Qt::CaseInsensitive ) )
204 vectorFileName +=
"." + allExts[0];
211 char **options = NULL;
214 options =
new char *[ dsOptions.
size()+1 ];
215 for (
int i = 0; i < dsOptions.
size(); i++ )
217 options[i] = CPLStrdup( dsOptions[i].toLocal8Bit().data() );
219 options[ dsOptions.
size()] = NULL;
223 mDS = OGR_Dr_CreateDataSource( poDriver,
TO8F( vectorFileName ), options );
227 for (
int i = 0; i < dsOptions.
size(); i++ )
228 CPLFree( options[i] );
247 QgsDebugMsg(
"error finding QTextCodec for " + fileEncoding );
254 QgsDebugMsg(
"error finding QTextCodec for " + enc );
271 OGRwkbGeometryType wkbType =
static_cast<OGRwkbGeometryType
>( geometryType );
275 options =
new char *[ layOptions.
size()+1 ];
276 for (
int i = 0; i < layOptions.
size(); i++ )
278 options[i] = CPLStrdup( layOptions[i].toLocal8Bit().data() );
280 options[ layOptions.
size()] = NULL;
284 CPLSetConfigOption(
"SHAPE_ENCODING",
"" );
286 mLayer = OGR_DS_CreateLayer(
mDS,
TO8F( layerName ), ogrRef, wkbType, options );
290 for (
int i = 0; i < layOptions.
size(); i++ )
291 CPLFree( options[i] );
297 if ( !settings.
value(
"/qgis/ignoreShapeEncoding",
true ).
toBool() )
299 CPLSetConfigOption(
"SHAPE_ENCODING", 0 );
304 if ( ogrDriverName ==
"ESRI Shapefile" )
306 QString layerName = vectorFileName.
left( vectorFileName.
indexOf(
".shp", Qt::CaseInsensitive ) );
307 QFile prjFile( layerName +
".qpj" );
308 if ( prjFile.
open( QIODevice::WriteOnly ) )
316 QgsDebugMsg(
"Couldn't open file " + layerName +
".qpj" );
320 OSRDestroySpatialReference( ogrRef );
331 OGRFeatureDefnH defn = OGR_L_GetLayerDefn(
mLayer );
341 for (
int fldIdx = 0; fldIdx < fields.
count(); ++fldIdx )
343 const QgsField& attrField = fields[fldIdx];
345 OGRFieldType ogrType = OFTString;
346 int ogrWidth = attrField.
length();
347 int ogrPrecision = attrField.
precision();
348 if ( ogrPrecision > 0 )
351 switch ( attrField.
type() )
353 case QVariant::LongLong:
355 ogrWidth = ogrWidth > 0 && ogrWidth <= 21 ? ogrWidth : 21;
359 case QVariant::String:
361 if ( ogrWidth <= 0 || ogrWidth > 255 )
366 ogrType = OFTInteger;
367 ogrWidth = ogrWidth > 0 && ogrWidth <= 10 ? ogrWidth : 10;
371 case QVariant::Double:
379 case QVariant::DateTime:
380 ogrType = OFTDateTime;
393 if ( ogrDriverName ==
"SQLite" && name.
compare(
"ogc_fid", Qt::CaseInsensitive ) == 0 )
396 for ( i = 0; i < 10; i++ )
401 for ( j = 0; j < fields.
size() && name.compare( fields[j].name(), Qt::CaseInsensitive ) != 0; j++ )
404 if ( j == fields.
size() )
422 OGR_Fld_SetWidth( fld, ogrWidth );
425 if ( ogrPrecision >= 0 )
427 OGR_Fld_SetPrecision( fld, ogrPrecision );
435 if ( OGR_L_CreateField(
mLayer, fld,
true ) != OGRERR_NONE )
442 OGR_Fld_Destroy( fld );
445 OGR_Fld_Destroy( fld );
450 #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM < 1700
453 int fieldCount = OGR_FD_GetFieldCount( defn );
455 OGRFieldDefnH fdefn = OGR_FD_GetFieldDefn( defn, fieldCount - 1 );
458 const char *fieldName = OGR_Fld_GetNameRef( fdefn );
460 if ( attrField.
name().
left( strlen( fieldName ) ) == fieldName )
462 ogrIdx = fieldCount - 1;
467 ogrIdx = OGR_FD_GetFieldCount( defn ) - 1;
494 *newFilename = vectorFileName;
499 return OGR_G_CreateGeometry(( OGRwkbGeometryType ) wkbType );
510 datasetOptions.
clear();
511 layerOptions.
clear();
513 driverMetadata.
insert(
"AVCE00",
515 "Arc/Info ASCII Coverage",
525 datasetOptions.
clear();
526 layerOptions.
clear();
528 datasetOptions.
insert(
"LINEFORMAT",
new SetOption(
530 "systems default line termination conventions. "
531 "This may be overridden here." ),
539 datasetOptions.
insert(
"MULTILINE",
new BoolOption(
540 QObject::tr(
"By default, BNA files are created in multi-line format. "
541 "For each record, the first line contains the identifiers and the "
542 "type/number of coordinates to follow. Each following line contains "
543 "a pair of coordinates." ),
547 datasetOptions.
insert(
"NB_IDS",
new SetOption(
548 QObject::tr(
"BNA records may contain from 2 to 4 identifiers per record. "
549 "Some software packages only support a precise number of identifiers. "
550 "You can override the default value (2) by a precise value" ),
555 <<
"NB_SOURCE_FIELDS",
559 datasetOptions.
insert(
"ELLIPSES_AS_ELLIPSES",
new BoolOption(
560 QObject::tr(
"The BNA writer will try to recognize ellipses and circles when writing a polygon. "
561 "This will only work if the feature has previously been read from a BNA file. "
562 "As some software packages do not support ellipses/circles in BNA data file, "
563 "it may be useful to tell the writer by specifying ELLIPSES_AS_ELLIPSES=NO not "
564 "to export them as such, but keep them as polygons." ),
568 datasetOptions.
insert(
"NB_PAIRS_PER_LINE",
new IntOption(
569 QObject::tr(
"Limit the number of coordinate pairs per line in multiline format." ),
573 datasetOptions.
insert(
"COORDINATE_PRECISION",
new IntOption(
574 QObject::tr(
"Set the number of decimal for coordinates. Default value is 10." ),
578 driverMetadata.
insert(
"BNA",
590 datasetOptions.
clear();
591 layerOptions.
clear();
593 layerOptions.
insert(
"LINEFORMAT",
new SetOption(
594 QObject::tr(
"By default when creating new .csv files they "
595 "are created with the line termination conventions "
596 "of the local platform (CR/LF on Win32 or LF on all other systems). "
597 "This may be overridden through the use of the LINEFORMAT option." ),
605 layerOptions.
insert(
"GEOMETRY",
new SetOption(
606 QObject::tr(
"By default, the geometry of a feature written to a .csv file is discarded. "
607 "It is possible to export the geometry in its WKT representation by "
608 "specifying GEOMETRY=AS_WKT. It is also possible to export point geometries "
609 "into their X,Y,Z components by specifying GEOMETRY=AS_XYZ, GEOMETRY=AS_XY "
610 "or GEOMETRY=AS_YX." ),
620 layerOptions.
insert(
"CREATE_CSVT",
new BoolOption(
621 QObject::tr(
"Create the associated .csvt file to describe the type of each "
622 "column of the layer and its optional width and precision." ),
626 layerOptions.
insert(
"SEPARATOR",
new SetOption(
635 layerOptions.
insert(
"WRITE_BOM",
new BoolOption(
636 QObject::tr(
"Write a UTF-8 Byte Order Mark (BOM) at the start of the file." ),
640 driverMetadata.
insert(
"CSV",
642 "Comma Separated Value [CSV]",
652 datasetOptions.
clear();
653 layerOptions.
clear();
655 layerOptions.
insert(
"SHPT",
new SetOption(
656 QObject::tr(
"Override the type of shapefile created. "
657 "Can be one of NULL for a simple .dbf file with no .shp file, POINT, "
658 "ARC, POLYGON or MULTIPOINT for 2D, or POINTZ, ARCZ, POLYGONZ or "
659 "MULTIPOINTZ for 3D. Shapefiles with measure values are not supported, "
660 "nor are MULTIPATCH files." ),
674 layerOptions.
insert(
"ENCODING",
new SetOption(
675 QObject::tr(
"set the encoding value in the DBF file. "
676 "The default value is LDID/87. It is not clear "
677 "what other values may be appropriate." ),
683 layerOptions.
insert(
"RESIZE",
new BoolOption(
684 QObject::tr(
"Set to YES to resize fields to their optimal size." ),
688 driverMetadata.
insert(
"ESRI",
700 datasetOptions.
clear();
701 layerOptions.
clear();
703 driverMetadata.
insert(
"DBF File",
715 datasetOptions.
clear();
716 layerOptions.
clear();
718 driverMetadata.
insert(
"FMEObjects Gateway",
720 "FMEObjects Gateway",
730 datasetOptions.
clear();
731 layerOptions.
clear();
733 layerOptions.
insert(
"WRITE_BBOX",
new BoolOption(
734 QObject::tr(
"Set to YES to write a bbox property with the bounding box "
735 "of the geometries at the feature and feature collection level." ),
739 layerOptions.
insert(
"COORDINATE_PRECISION",
new IntOption(
740 QObject::tr(
"Maximum number of figures after decimal separator to write in coordinates. "
741 "Default to 15. Truncation will occur to remove trailing zeros." ),
745 driverMetadata.
insert(
"GeoJSON",
757 datasetOptions.
clear();
758 layerOptions.
clear();
760 datasetOptions.
insert(
"FORMAT",
new SetOption(
761 QObject::tr(
"whether the document must be in RSS 2.0 or Atom 1.0 format. "
762 "Default value : RSS" ),
769 datasetOptions.
insert(
"GEOM_DIALECT",
new SetOption(
770 QObject::tr(
"The encoding of location information. Default value : SIMPLE. "
771 "W3C_GEO only supports point geometries. "
772 "SIMPLE or W3C_GEO only support geometries in geographic WGS84 coordinates." ),
780 datasetOptions.
insert(
"USE_EXTENSIONS",
new BoolOption(
781 QObject::tr(
"If defined to YES, extension fields will be written. "
782 "If the field name not found in the base schema matches "
783 "the foo_bar pattern, foo will be considered as the namespace "
784 "of the element, and a <foo:bar> element will be written. "
785 "Otherwise, elements will be written in the <ogr:> namespace." ),
789 datasetOptions.
insert(
"WRITE_HEADER_AND_FOOTER",
new BoolOption(
790 QObject::tr(
"If defined to NO, only <entry> or <item> elements will be written. "
791 "The user will have to provide the appropriate header and footer of the document." ),
795 datasetOptions.
insert(
"HEADER",
new StringOption(
796 QObject::tr(
"XML content that will be put between the <channel> element and the "
797 "first <item> element for a RSS document, or between the xml tag and "
798 "the first <entry> element for an Atom document. " ),
802 datasetOptions.
insert(
"TITLE",
new StringOption(
803 QObject::tr(
"Value put inside the <title> element in the header. "
804 "If not provided, a dummy value will be used as that element is compulsory." ),
808 datasetOptions.
insert(
"DESCRIPTION",
new StringOption(
809 QObject::tr(
"Value put inside the <description> element in the header. "
810 "If not provided, a dummy value will be used as that element is compulsory." ),
814 datasetOptions.
insert(
"LINK",
new StringOption(
815 QObject::tr(
"Value put inside the <link> element in the header. "
816 "If not provided, a dummy value will be used as that element is compulsory." ),
820 datasetOptions.
insert(
"UPDATED",
new StringOption(
821 QObject::tr(
"Value put inside the <updated> element in the header. "
822 "Should be formatted as a XML datetime. "
823 "If not provided, a dummy value will be used as that element is compulsory." ),
827 datasetOptions.
insert(
"AUTHOR_NAME",
new StringOption(
828 QObject::tr(
"Value put inside the <author><name> element in the header. "
829 "If not provided, a dummy value will be used as that element is compulsory." ),
833 datasetOptions.
insert(
"ID",
new StringOption(
834 QObject::tr(
"Value put inside the <id> element in the header. "
835 "If not provided, a dummy value will be used as that element is compulsory." ),
839 driverMetadata.
insert(
"GeoRSS",
851 datasetOptions.
clear();
852 layerOptions.
clear();
854 datasetOptions.
insert(
"XSISCHEMAURI",
new StringOption(
855 QObject::tr(
"If provided, this URI will be inserted as the schema location. "
856 "Note that the schema file isn't actually accessed by OGR, so it "
857 "is up to the user to ensure it will match the schema of the OGR "
858 "produced GML data file." ),
862 datasetOptions.
insert(
"XSISCHEMA",
new SetOption(
863 QObject::tr(
"This writes a GML application schema file to a corresponding "
864 ".xsd file (with the same basename). If INTERNAL is used the "
865 "schema is written within the GML file, but this is experimental "
866 "and almost certainly not valid XML. "
867 "OFF disables schema generation (and is implicit if XSISCHEMAURI is used)." ),
875 datasetOptions.
insert(
"PREFIX",
new StringOption(
876 QObject::tr(
"This is the prefix for the application target namespace." ),
880 datasetOptions.
insert(
"STRIP_PREFIX",
new BoolOption(
881 QObject::tr(
"Can be set to TRUE to avoid writing the prefix of the "
882 "application target namespace in the GML file." ),
886 datasetOptions.
insert(
"TARGET_NAMESPACE",
new StringOption(
887 QObject::tr(
"Defaults to 'http://ogr.maptools.org/'. "
888 "This is the application target namespace." ),
889 "http://ogr.maptools.org/"
892 datasetOptions.
insert(
"FORMAT",
new SetOption(
893 QObject::tr(
"If not specified, GML2 will be used." ),
902 datasetOptions.
insert(
"GML3_LONGSRS",
new BoolOption(
903 QObject::tr(
"only valid when FORMAT=GML3/GML3Degree/GML3.2) Default to YES. "
904 "If YES, SRS with EPSG authority will be written with the "
905 "'urn:ogc:def:crs:EPSG::' prefix. In the case, if the SRS is a "
906 "geographic SRS without explicit AXIS order, but that the same "
907 "SRS authority code imported with ImportFromEPSGA() should be "
908 "treated as lat/long, then the function will take care of coordinate "
909 "order swapping. If set to NO, SRS with EPSG authority will be "
910 "written with the 'EPSG:' prefix, even if they are in lat/long order." ),
914 datasetOptions.
insert(
"WRITE_FEATURE_BOUNDED_BY",
new BoolOption(
915 QObject::tr(
"only valid when FORMAT=GML3/GML3Degree/GML3.2) Default to YES. "
916 "If set to NO, the <gml:boundedBy> element will not be written for "
921 datasetOptions.
insert(
"SPACE_INDENTATION",
new BoolOption(
922 QObject::tr(
"Default to YES. If YES, the output will be indented with spaces "
923 "for more readability, but at the expense of file size." ),
928 driverMetadata.
insert(
"GML",
930 "Geography Markup Language [GML]",
940 datasetOptions.
clear();
941 layerOptions.
clear();
943 driverMetadata.
insert(
"GMT",
945 "Generic Mapping Tools [GMT]",
955 datasetOptions.
clear();
956 layerOptions.
clear();
958 layerOptions.
insert(
"FORCE_GPX_TRACK",
new BoolOption(
959 QObject::tr(
"By default when writing a layer whose features are of "
960 "type wkbLineString, the GPX driver chooses to write "
961 "them as routes. If FORCE_GPX_TRACK=YES is specified, "
962 "they will be written as tracks." ),
966 layerOptions.
insert(
"FORCE_GPX_ROUTE",
new BoolOption(
967 QObject::tr(
"By default when writing a layer whose features are of "
968 "type wkbMultiLineString, the GPX driver chooses to write "
969 "them as tracks. If FORCE_GPX_ROUTE=YES is specified, "
970 "they will be written as routes, provided that the multilines "
971 "are composed of only one single line." ),
975 datasetOptions.
insert(
"GPX_USE_EXTENSIONS",
new BoolOption(
976 QObject::tr(
"If GPX_USE_EXTENSIONS=YES is specified, "
977 "extra fields will be written inside the <extensions> tag." ),
981 datasetOptions.
insert(
"GPX_EXTENSIONS_NS",
new StringOption(
982 QObject::tr(
"Only used if GPX_USE_EXTENSIONS=YES and GPX_EXTENSIONS_NS_URL "
983 "is set. The namespace value used for extension tags. By default, 'ogr'." ),
987 datasetOptions.
insert(
"GPX_EXTENSIONS_NS_URL",
new StringOption(
988 QObject::tr(
"Only used if GPX_USE_EXTENSIONS=YES and GPX_EXTENSIONS_NS "
989 "is set. The namespace URI. By default, 'http://osgeo.org/gdal'." ),
990 "http://osgeo.org/gdal"
993 datasetOptions.
insert(
"LINEFORMAT",
new SetOption(
994 QObject::tr(
"By default files are created with the line termination "
995 "conventions of the local platform (CR/LF on win32 or LF "
996 "on all other systems). This may be overridden through use "
997 "of the LINEFORMAT layer creation option which may have a value "
998 "of CRLF (DOS format) or LF (Unix format)." ),
1006 driverMetadata.
insert(
"GPX",
1008 "GPS eXchange Format [GPX]",
1018 datasetOptions.
clear();
1019 layerOptions.
clear();
1021 driverMetadata.
insert(
"Interlis 1",
1025 "*.itf *.xml *.ili",
1033 datasetOptions.
clear();
1034 layerOptions.
clear();
1036 driverMetadata.
insert(
"Interlis 2",
1040 "*.itf *.xml *.ili",
1048 datasetOptions.
clear();
1049 layerOptions.
clear();
1051 datasetOptions.
insert(
"NameField",
new StringOption(
1052 QObject::tr(
"Allows you to specify the field to use for the KML <name> element. " ),
1056 datasetOptions.
insert(
"DescriptionField",
new StringOption(
1057 QObject::tr(
"Allows you to specify the field to use for the KML <description> element." ),
1061 datasetOptions.
insert(
"AltitudeMode",
new SetOption(
1062 QObject::tr(
"Allows you to specify the AltitudeMode to use for KML geometries. "
1063 "This will only affect 3D geometries and must be one of the valid KML options." ),
1065 <<
"relativeToGround"
1071 driverMetadata.
insert(
"KML",
1073 "Keyhole Markup Language [KML]",
1083 datasetOptions.
clear();
1084 layerOptions.
clear();
1086 layerOptions.
insert(
"SPATIAL_INDEX_MODE",
new SetOption(
1087 QObject::tr(
"Use this to turn on 'quick spatial index mode'. "
1088 "In this mode writing files can be about 5 times faster, "
1089 "but spatial queries can be up to 30 times slower." ),
1096 driverMetadata.
insert(
"MapInfo File",
1108 driverMetadata.
insert(
"MapInfo MIF",
1120 datasetOptions.
clear();
1121 layerOptions.
clear();
1123 datasetOptions.
insert(
"3D",
new BoolOption(
1124 QObject::tr(
"Determine whether 2D (seed_2d.dgn) or 3D (seed_3d.dgn) "
1125 "seed file should be used. This option is ignored if the SEED option is provided." ),
1129 datasetOptions.
insert(
"SEED",
new StringOption(
1134 datasetOptions.
insert(
"COPY_WHOLE_SEED_FILE",
new BoolOption(
1135 QObject::tr(
"Indicate whether the whole seed file should be copied. "
1136 "If not, only the first three elements will be copied." ),
1140 datasetOptions.
insert(
"COPY_SEED_FILE_COLOR_TABLEE",
new BoolOption(
1141 QObject::tr(
"Indicates whether the color table should be copied from the seed file." ),
1145 datasetOptions.
insert(
"MASTER_UNIT_NAME",
new StringOption(
1146 QObject::tr(
"Override the master unit name from the seed file with "
1147 "the provided one or two character unit name." ),
1151 datasetOptions.
insert(
"SUB_UNIT_NAME",
new StringOption(
1152 QObject::tr(
"Override the sub unit name from the seed file with the provided "
1153 "one or two character unit name." ),
1157 datasetOptions.
insert(
"SUB_UNITS_PER_MASTER_UNIT",
new IntOption(
1158 QObject::tr(
"Override the number of subunits per master unit. "
1159 "By default the seed file value is used." ),
1163 datasetOptions.
insert(
"UOR_PER_SUB_UNIT",
new IntOption(
1164 QObject::tr(
"Override the number of UORs (Units of Resolution) "
1165 "per sub unit. By default the seed file value is used." ),
1169 datasetOptions.
insert(
"ORIGIN",
new StringOption(
1170 QObject::tr(
"ORIGIN=x,y,z: Override the origin of the design plane. "
1171 "By default the origin from the seed file is used." ),
1175 driverMetadata.
insert(
"DGN",
1187 datasetOptions.
clear();
1188 layerOptions.
clear();
1190 driverMetadata.
insert(
"DGN",
1202 datasetOptions.
clear();
1203 layerOptions.
clear();
1205 datasetOptions.
insert(
"UPDATES",
new SetOption(
1206 QObject::tr(
"Should update files be incorporated into the base data on the fly. " ),
1213 datasetOptions.
insert(
"SPLIT_MULTIPOINT",
new BoolOption(
1214 QObject::tr(
"Should multipoint soundings be split into many single point sounding features. "
1215 "Multipoint geometries are not well handled by many formats, "
1216 "so it can be convenient to split single sounding features with many points "
1217 "into many single point features." ),
1221 datasetOptions.
insert(
"ADD_SOUNDG_DEPTH",
new BoolOption(
1222 QObject::tr(
"Should a DEPTH attribute be added on SOUNDG features and assign the depth "
1223 "of the sounding. This should only be enabled with SPLIT_MULTIPOINT is "
1228 datasetOptions.
insert(
"RETURN_PRIMITIVES",
new BoolOption(
1229 QObject::tr(
"Should all the low level geometry primitives be returned as special "
1230 "IsolatedNode, ConnectedNode, Edge and Face layers." ),
1234 datasetOptions.
insert(
"PRESERVE_EMPTY_NUMBERS",
new BoolOption(
1235 QObject::tr(
"If enabled, numeric attributes assigned an empty string as a value will "
1236 "be preserved as a special numeric value. This option should not generally "
1237 "be needed, but may be useful when translated S-57 to S-57 losslessly." ),
1241 datasetOptions.
insert(
"LNAM_REFS",
new BoolOption(
1242 QObject::tr(
"Should LNAM and LNAM_REFS fields be attached to features capturing "
1243 "the feature to feature relationships in the FFPT group of the S-57 file." ),
1247 datasetOptions.
insert(
"RETURN_LINKAGES",
new BoolOption(
1248 QObject::tr(
"Should additional attributes relating features to their underlying "
1249 "geometric primitives be attached. These are the values of the FSPT group, "
1250 "and are primarily needed when doing S-57 to S-57 translations." ),
1254 datasetOptions.
insert(
"RECODE_BY_DSSI",
new BoolOption(
1255 QObject::tr(
"Should attribute values be recoded to UTF-8 from the character encoding "
1256 "specified in the S57 DSSI record." ),
1262 driverMetadata.
insert(
"S57",
1274 datasetOptions.
clear();
1275 layerOptions.
clear();
1277 driverMetadata.
insert(
"SDTS",
1279 "Spatial Data Transfer Standard [SDTS]",
1280 QObject::tr(
"Spatial Data Transfer Standard [SDTS]" ),
1289 datasetOptions.
clear();
1290 layerOptions.
clear();
1292 datasetOptions.
insert(
"METADATA",
new BoolOption(
1293 QObject::tr(
"Can be used to avoid creating the geometry_columns and spatial_ref_sys "
1294 "tables in a new database. By default these metadata tables are created "
1295 "when a new database is created." ),
1300 datasetOptions.
insert(
"SPATIALITE",
new HiddenOption(
1305 datasetOptions.
insert(
"INIT_WITH_EPSG",
new HiddenOption(
1309 layerOptions.
insert(
"FORMAT",
new SetOption(
1310 QObject::tr(
"Controls the format used for the geometry column. Defaults to WKB."
1311 "This is generally more space and processing efficient, but harder "
1312 "to inspect or use in simple applications than WKT (Well Known Text)." ),
1319 layerOptions.
insert(
"LAUNDER",
new BoolOption(
1320 QObject::tr(
"Controls whether layer and field names will be laundered for easier use "
1321 "in SQLite. Laundered names will be converted to lower case and some special "
1322 "characters(' - #) will be changed to underscores." ),
1326 layerOptions.
insert(
"SPATIAL_INDEX",
new HiddenOption(
1330 layerOptions.
insert(
"COMPRESS_GEOM",
new HiddenOption(
1334 layerOptions.
insert(
"SRID",
new HiddenOption(
1338 layerOptions.
insert(
"COMPRESS_COLUMNS",
new StringOption(
1339 QObject::tr(
"column_name1[,column_name2, ...] A list of (String) columns that "
1340 "must be compressed with ZLib DEFLATE algorithm. This might be beneficial "
1341 "for databases that have big string blobs. However, use with care, since "
1342 "the value of such columns will be seen as compressed binary content with "
1343 "other SQLite utilities (or previous OGR versions). With OGR, when inserting, "
1344 "modifying or queryings compressed columns, compression/decompression is "
1345 "done transparently. However, such columns cannot be (easily) queried with "
1346 "an attribute filter or WHERE clause. Note: in table definition, such columns "
1347 "have the 'VARCHAR_deflate' declaration type." ),
1351 driverMetadata.
insert(
"SQLite",
1363 datasetOptions.
clear();
1364 layerOptions.
clear();
1366 datasetOptions.
insert(
"METADATA",
new BoolOption(
1367 QObject::tr(
"Can be used to avoid creating the geometry_columns and spatial_ref_sys "
1368 "tables in a new database. By default these metadata tables are created "
1369 "when a new database is created." ),
1373 datasetOptions.
insert(
"SPATIALITE",
new HiddenOption(
1377 datasetOptions.
insert(
"INIT_WITH_EPSG",
new BoolOption(
1378 QObject::tr(
"Insert the content of the EPSG CSV files into the spatial_ref_sys table. "
1379 "Set to NO for regular SQLite databases." ),
1383 layerOptions.
insert(
"FORMAT",
new HiddenOption(
1387 layerOptions.
insert(
"LAUNDER",
new BoolOption(
1388 QObject::tr(
"Controls whether layer and field names will be laundered for easier use "
1389 "in SQLite. Laundered names will be convered to lower case and some special "
1390 "characters(' - #) will be changed to underscores." ),
1394 layerOptions.
insert(
"SPATIAL_INDEX",
new BoolOption(
1395 QObject::tr(
"If the database is of the SpatiaLite flavour, and if OGR is linked "
1396 "against libspatialite, this option can be used to control if a spatial "
1397 "index must be created." ),
1401 layerOptions.
insert(
"COMPRESS_GEOM",
new BoolOption(
1402 QObject::tr(
"If the format of the geometry BLOB is of the SpatiaLite flavour, "
1403 "this option can be used to control if the compressed format for "
1404 "geometries (LINESTRINGs, POLYGONs) must be used" ),
1408 layerOptions.
insert(
"SRID",
new StringOption(
1409 QObject::tr(
"Used to force the SRID number of the SRS associated with the layer. "
1410 "When this option isn't specified and that a SRS is associated with the "
1411 "layer, a search is made in the spatial_ref_sys to find a match for the "
1412 "SRS, and, if there is no match, a new entry is inserted for the SRS in "
1413 "the spatial_ref_sys table. When the SRID option is specified, this "
1414 "search (and the eventual insertion of a new entry) will not be done: "
1415 "the specified SRID is used as such." ),
1419 layerOptions.
insert(
"COMPRESS_COLUMNS",
new StringOption(
1420 QObject::tr(
"column_name1[,column_name2, ...] A list of (String) columns that "
1421 "must be compressed with ZLib DEFLATE algorithm. This might be beneficial "
1422 "for databases that have big string blobs. However, use with care, since "
1423 "the value of such columns will be seen as compressed binary content with "
1424 "other SQLite utilities (or previous OGR versions). With OGR, when inserting, "
1425 "modifying or queryings compressed columns, compression/decompression is "
1426 "done transparently. However, such columns cannot be (easily) queried with "
1427 "an attribute filter or WHERE clause. Note: in table definition, such columns "
1428 "have the 'VARCHAR_deflate' declaration type." ),
1432 driverMetadata.
insert(
"SpatiaLite",
1443 datasetOptions.
clear();
1444 layerOptions.
clear();
1448 QObject::tr(
"Override the header file used - in place of header.dxf." ),
1452 datasetOptions.
insert(
"TRAILER",
new StringOption(
1453 QObject::tr(
"Override the trailer file used - in place of trailer.dxf." ),
1458 driverMetadata.
insert(
"DXF",
1470 datasetOptions.
clear();
1471 layerOptions.
clear();
1473 datasetOptions.
insert(
"EXTENSION",
new SetOption(
1474 QObject::tr(
"Indicates the GeoConcept export file extension. "
1475 "TXT was used by earlier releases of GeoConcept. GXT is currently used." ),
1483 datasetOptions.
insert(
"CONFIG",
new StringOption(
1484 QObject::tr(
"path to the GCT : the GCT file describe the GeoConcept types definitions: "
1485 "In this file, every line must start with //# followed by a keyword. "
1486 "Lines starting with // are comments." ),
1491 driverMetadata.
insert(
"Geoconcept",
1503 datasetOptions.
clear();
1504 layerOptions.
clear();
1506 layerOptions.
insert(
"FEATURE_DATASET",
new StringOption(
1507 QObject::tr(
"When this option is set, the new layer will be created inside the named "
1508 "FeatureDataset folder. If the folder does not already exist, it will be created." ),
1512 layerOptions.
insert(
"GEOMETRY_NAME",
new StringOption(
1513 QObject::tr(
"Set name of geometry column in new layer. Defaults to 'SHAPE'." ),
1517 layerOptions.
insert(
"OID_NAME",
new StringOption(
1518 QObject::tr(
"Name of the OID column to create. Defaults to 'OBJECTID'." ),
1522 driverMetadata.
insert(
"FileGDB",
1541 for ( ; it != sDriverMetadata.
constEnd(); ++it )
1543 if ( it.
key().startsWith( driverName ) )
1545 driverMetadata = it.
value();
1567 OGRFeatureH poFeature = createFeature( feature );
1580 for ( ; symbolIt != symbols.
constEnd(); ++symbolIt )
1582 int nSymbolLayers = ( *symbolIt )->symbolLayerCount();
1583 for (
int i = 0; i < nSymbolLayers; ++i )
1587 if ( it == mSymbolLayerTable.constEnd() )
1595 currentStyle = ( *symbolIt )->symbolLayer( i )->ogrFeatureStyle( mmsf, musf );
1599 if ( symbolIt != symbols.
constBegin() || i != 0 )
1601 styleString.
append(
";" );
1603 styleString.
append( currentStyle );
1607 OGR_F_SetStyleString( poFeature, currentStyle.toLocal8Bit().data() );
1608 if ( !writeFeature(
mLayer, poFeature ) )
1620 if ( !writeFeature(
mLayer, poFeature ) )
1626 OGR_F_Destroy( poFeature );
1630 OGRFeatureH QgsVectorFileWriter::createFeature(
QgsFeature& feature )
1634 OGRFeatureH poFeature = OGR_F_Create( OGR_L_GetLayerDefn(
mLayer ) );
1640 OGRErr err = OGR_F_SetFID( poFeature, static_cast<long>( fid ) );
1641 if ( err != OGRERR_NONE )
1644 .arg( feature.
id() )
1645 .arg( err ).
arg( CPLGetLastErrorMsg() )
1651 for (
int fldIdx = 0; fldIdx <
mFields.
count(); ++fldIdx )
1665 switch ( attrValue.
type() )
1668 OGR_F_SetFieldInteger( poFeature, ogrField, attrValue.
toInt() );
1670 case QVariant::Double:
1671 OGR_F_SetFieldDouble( poFeature, ogrField, attrValue.
toDouble() );
1673 case QVariant::LongLong:
1674 case QVariant::UInt:
1675 case QVariant::ULongLong:
1676 case QVariant::String:
1679 case QVariant::Date:
1680 OGR_F_SetFieldDateTime( poFeature, ogrField,
1686 case QVariant::DateTime:
1687 OGR_F_SetFieldDateTime( poFeature, ogrField,
1696 case QVariant::Time:
1697 OGR_F_SetFieldDateTime( poFeature, ogrField,
1704 case QVariant::Invalid:
1748 OGR_F_Destroy( poFeature );
1752 OGRErr err = OGR_G_ImportFromWkb( mGeom2, const_cast<unsigned char *>( geom->
asWkb() ), (
int ) geom->wkbSize() );
1753 if ( err != OGRERR_NONE )
1759 OGR_F_Destroy( poFeature );
1764 OGR_F_SetGeometryDirectly( poFeature, mGeom2 );
1768 OGRErr err = OGR_G_ImportFromWkb(
mGeom, const_cast<unsigned char *>( geom->
asWkb() ), (
int ) geom->wkbSize() );
1769 if ( err != OGRERR_NONE )
1775 OGR_F_Destroy( poFeature );
1780 OGR_F_SetGeometry( poFeature,
mGeom );
1786 bool QgsVectorFileWriter::writeFeature( OGRLayerH layer, OGRFeatureH feature )
1788 if ( OGR_L_CreateFeature( layer, feature ) != OGRERR_NONE )
1793 OGR_F_Destroy( feature );
1803 OGR_G_DestroyGeometry(
mGeom );
1808 OGR_DS_Destroy(
mDS );
1822 bool skipAttributeCreation,
1825 double symbologyScale,
1829 if ( destCRS && layer )
1835 errorMessage, datasourceOptions, layerOptions, skipAttributeCreation, newFilename, symbologyExport, symbologyScale, filterExtent );
1849 bool skipAttributeCreation,
1852 double symbologyScale,
1860 bool shallTransform =
false;
1865 outputCRS = &( ct->
destCRS() );
1866 shallTransform =
true;
1871 outputCRS = &layer->
crs();
1880 QString srcFileName = theURIParts[0];
1885 *errorMessage =
QObject::tr(
"Cannot overwrite a OGR layer in place" );
1897 if ( onlySelected && !ids.
contains( fet.
id() ) )
1910 for (
int i = 0; i < fields.
size(); i++ )
1912 if ( fields[i].type() == QVariant::LongLong )
1918 fields[i].setType( QVariant::Int );
1925 new QgsVectorFileWriter( fileName, fileEncoding, fields, wkbType, outputCRS, driverName, datasourceOptions, layerOptions, newFilename, symbologyExport );
1945 errorMessage->
clear();
1952 writer->addRendererAttributes( layer, allAttr );
1982 int n = 0, errors = 0;
1991 writer->startRender( layer );
1994 bool transactionsEnabled =
true;
1996 if ( OGRERR_NONE != OGR_L_StartTransaction( writer->
mLayer ) )
1998 QgsDebugMsg(
"Error when trying to enable transactions on OGRLayer." );
1999 transactionsEnabled =
false;
2005 if ( onlySelected && !ids.
contains( fet.
id() ) )
2008 if ( shallTransform )
2021 QString msg =
QObject::tr(
"Failed to transform a point while drawing a feature with ID '%1'. Writing stopped. (Exception: %2)" )
2025 *errorMessage = msg;
2034 if ( allAttr.
size() < 1 && skipAttributeCreation )
2042 if ( err !=
NoError && errorMessage )
2044 if ( errorMessage->
isEmpty() )
2046 *errorMessage =
QObject::tr(
"Feature write errors:" );
2052 if ( errors > 1000 )
2056 *errorMessage +=
QObject::tr(
"Stopping after %1 errors" ).
arg( errors );
2066 if ( transactionsEnabled )
2068 if ( OGRERR_NONE != OGR_L_CommitTransaction( writer->
mLayer ) )
2070 QgsDebugMsg(
"Error while committing transaction on OGRLayer." );
2074 writer->stopRender( layer );
2077 if ( errors > 0 && errorMessage && n > 0 )
2079 *errorMessage +=
QObject::tr(
"\nOnly %1 of %2 features written." ).
arg( n - errors ).
arg( n );
2092 const char *suffixes[] = {
".shp",
".shx",
".dbf",
".prj",
".qix",
".qpj" };
2093 for ( std::size_t i = 0; i <
sizeof( suffixes ) /
sizeof( *suffixes ); i++ )
2104 QgsDebugMsg(
QString(
"Removing file %1 failed: %2" ).arg( file ).arg( f.errorString() ) );
2117 int const drvCount = OGRGetDriverCount();
2119 for (
int i = 0; i < drvCount; ++i )
2121 OGRSFDriverH drv = OGRGetDriver( i );
2124 QString drvName = OGR_Dr_GetName( drv );
2125 if ( OGR_Dr_TestCapability( drv,
"CreateDataSource" ) != 0 )
2131 resultMap.
insert( filterString, drvName );
2144 int const drvCount = OGRGetDriverCount();
2147 for (
int i = 0; i < drvCount; ++i )
2149 OGRSFDriverH drv = OGRGetDriver( i );
2152 QString drvName = OGR_Dr_GetName( drv );
2153 if ( OGR_Dr_TestCapability( drv,
"CreateDataSource" ) != 0 )
2156 if ( drvName ==
"MapInfo File" )
2158 writableDrivers <<
"MapInfo MIF";
2160 else if ( drvName ==
"SQLite" )
2167 QString option =
"SPATIALITE=YES";
2168 char **options =
new char *[2];
2171 OGRSFDriverH poDriver;
2176 OGRDataSourceH ds = OGR_Dr_CreateDataSource( poDriver,
TO8F(
QString(
"/vsimem/spatialitetest.sqlite" ) ), options );
2179 writableDrivers <<
"SpatiaLite";
2180 OGR_Dr_DeleteDataSource( poDriver,
TO8F(
QString(
"/vsimem/spatialitetest.sqlite" ) ) );
2181 OGR_DS_Destroy( ds );
2184 CPLFree( options[0] );
2187 else if ( drvName ==
"ESRI Shapefile" )
2189 writableDrivers <<
"DBF file";
2191 writableDrivers << drvName;
2196 foreach (
QString drvName, writableDrivers )
2204 resultMap.
insert( trLongName, drvName );
2216 for ( ; it != driverFormatMap.
constEnd(); ++it )
2218 if ( !filterString.
isEmpty() )
2219 filterString +=
";;";
2221 filterString += it.
key();
2223 return filterString;
2235 return trLongName +
" [OGR] (" + glob.
toLower() +
" " + glob.
toUpper() +
")";
2240 if ( codecName ==
"System" )
2248 c.
toInt( &isNumber );
2259 longName =
"Arc/Info ASCII Coverage";
2260 trLongName =
QObject::tr(
"Arc/Info ASCII Coverage" );
2266 longName =
"Atlas BNA";
2273 longName =
"Comma Separated Value [CSV]";
2274 trLongName =
QObject::tr(
"Comma Separated Value [CSV]" );
2280 longName =
"ESRI Shapefile";
2285 else if ( driverName.
startsWith(
"DBF file" ) )
2287 longName =
"DBF File";
2292 else if ( driverName.
startsWith(
"FMEObjects Gateway" ) )
2294 longName =
"FMEObjects Gateway";
2299 else if ( driverName.
startsWith(
"GeoJSON" ) )
2301 longName =
"GeoJSON";
2308 longName =
"GeoPackage";
2313 else if ( driverName.
startsWith(
"GeoRSS" ) )
2315 longName =
"GeoRSS";
2322 longName =
"Geography Markup Language [GML]";
2323 trLongName =
QObject::tr(
"Geography Markup Language [GML]" );
2329 longName =
"Generic Mapping Tools [GMT]";
2330 trLongName =
QObject::tr(
"Generic Mapping Tools [GMT]" );
2336 longName =
"GPS eXchange Format [GPX]";
2337 trLongName =
QObject::tr(
"GPS eXchange Format [GPX]" );
2341 else if ( driverName.
startsWith(
"Interlis 1" ) )
2343 longName =
"INTERLIS 1";
2345 glob =
"*.itf *.xml *.ili";
2348 else if ( driverName.
startsWith(
"Interlis 2" ) )
2350 longName =
"INTERLIS 2";
2352 glob =
"*.itf *.xml *.ili";
2357 longName =
"Keyhole Markup Language [KML]";
2358 trLongName =
QObject::tr(
"Keyhole Markup Language [KML]" );
2362 else if ( driverName.
startsWith(
"MapInfo File" ) )
2364 longName =
"Mapinfo TAB";
2370 else if ( driverName.
startsWith(
"MapInfo MIF" ) )
2372 longName =
"Mapinfo MIF";
2379 longName =
"Microstation DGN";
2386 longName =
"S-57 Base file";
2393 longName =
"Spatial Data Transfer Standard [SDTS]";
2394 trLongName =
QObject::tr(
"Spatial Data Transfer Standard [SDTS]" );
2398 else if ( driverName.
startsWith(
"SQLite" ) )
2400 longName =
"SQLite";
2406 else if ( driverName.
startsWith(
"SpatiaLite" ) )
2408 longName =
"SpatiaLite";
2415 longName =
"AutoCAD DXF";
2420 else if ( driverName.
startsWith(
"Geoconcept" ) )
2422 longName =
"Geoconcept";
2424 glob =
"*.gxt *.txt";
2427 else if ( driverName.
startsWith(
"FileGDB" ) )
2429 longName =
"ESRI FileGDB";
2462 #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1700
2463 mSymbolLayerTable.clear();
2464 OGRStyleTableH ogrStyleTable = OGR_STBL_Create();
2465 OGRStyleMgrH styleManager = OGR_SM_Create( ogrStyleTable );
2468 int nTotalLevels = 0;
2471 for ( ; symbolIt != symbolList.
end(); ++symbolIt )
2476 int nLevels = ( *symbolIt )->symbolLayerCount();
2477 for (
int i = 0; i < nLevels; ++i )
2479 mSymbolLayerTable.insert(( *symbolIt )->symbolLayer( i ),
QString::number( nTotalLevels ) );
2480 OGR_SM_AddStyle( styleManager,
QString::number( nTotalLevels ).toLocal8Bit(),
2481 ( *symbolIt )->symbolLayer( i )->ogrFeatureStyle( mmsf, musf ).
toLocal8Bit() );
2485 OGR_DS_SetStyleTableDirectly( ds, ogrStyleTable );
2508 startRender( layer );
2530 *errorMessage = msg;
2537 if ( !featureSymbol )
2543 if ( it == features.
end() )
2547 it.
value().append( fet );
2553 for (
int i = 0; i < symbols.
count(); i++ )
2559 if ( level < 0 || level >= 1000 )
2562 while ( level >= levels.
count() )
2564 levels[level].
append( item );
2569 int nTotalFeatures = 0;
2572 for (
int l = 0; l < levels.
count(); l++ )
2575 for (
int i = 0; i < level.
count(); i++ )
2579 if ( levelIt == features.
end() )
2588 int llayer = item.
layer();
2591 for ( ; featureIt != featureList.
end(); ++featureIt )
2594 OGRFeatureH ogrFeature = createFeature( *featureIt );
2601 QString styleString = levelIt.
key()->symbolLayer( llayer )->ogrFeatureStyle( mmsf, musf );
2605 if ( ! writeFeature(
mLayer, ogrFeature ) )
2610 OGR_F_Destroy( ogrFeature );
2615 stopRender( layer );
2617 if ( nErrors > 0 && errorMessage )
2619 *errorMessage +=
QObject::tr(
"\nOnly %1 of %2 features written." ).
arg( nTotalFeatures - nErrors ).
arg( nTotalFeatures );
2636 return 1000 / scaleDenominator;
2653 return scaleDenominator / 1000;
2666 void QgsVectorFileWriter::startRender(
QgsVectorLayer* vl )
const
2710 for (
int i = 0; i < rendererAttributes.
size(); ++i )
QgsFeatureId id() const
Get the feature ID for this feature.
static WkbType singleType(WkbType type)
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
QgsFeatureRendererV2 * rendererV2()
Return renderer V2.
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)
iterator insert(const Key &key, const T &value)
bool contains(const Key &key) const
const Key key(const T &value) const
WriterError mError
contains error value if construction was not successful
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.
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
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.
static bool deleteShapeFile(QString theFileName)
Delete a shapefile (and its accompanying shx / dbf / prf)
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
WkbType
Used for symbology operations.
virtual QList< QString > usedAttributes()=0
QString join(const QString &separator) const
A convenience class for writing vector files to disk.
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
static void logMessage(QString message, QString tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
QGis::WkbType wkbType() const
Returns the WKBType or WKBUnknown in case of error.
virtual void stopRender(QgsRenderContext &context)=0
virtual QgsSymbolV2List symbols()=0
for symbol levels
QString number(int n, int base)
int count(const T &value) const
void append(const T &value)
QString fromUtf8(const char *str, int size)
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
const_iterator constEnd() const
const char * constData() const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
This class wraps a request for features to a vector layer (or directly its vector data provider)...
~QgsVectorFileWriter()
close opened shapefile for writing
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
Encapsulate a field in an attribute table or data source.
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QMap< int, int > mAttrIdxToOgrIdx
map attribute indizes to OGR field indexes
const T value(const Key &key) const
QByteArray toLocal8Bit() const
iterator find(const Key &key)
int renderingPass() const
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)
QVariant value(const QString &key, const QVariant &defaultValue) const
Contains information about the context of a rendering operation.
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.
QgsAttributeList pendingAllAttributesList()
returns list of attributes
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 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.
UnitType
Map units that qgis supports.
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.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
QgsSymbolLayerV2 * symbolLayer(int layer)
Returns a specific symbol layers contained in the symbol.
QgsVectorDataProvider * dataProvider()
Returns the data provider.
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
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature)=0
to be overridden
QgsFeatureRequest & setFlags(Flags flags)
Set flags that affect how features will be fetched.
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.
virtual QString dataSourceUri() const
Get the data source specification.
static WkbType multiType(WkbType type)
void * OGRSpatialReferenceH
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