You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>Regular expressions are mini-language used to represent character patterns. There are many variations
127
127
of regular expression syntax - QGis uses the syntax provided by the <a href="http://qt-project.org/doc/qt-4.8/qregexp.html">QRegExp</a> class of the <a href="http://qt.digia.com">Qt</a> framework.</p>
128
-
<p>In a regular expression delimited file each line is treated as a record. Each match of the regular expression in the line is treated as the end of a field.</p>
128
+
<p>In a regular expression delimited file each line is treated as a record. Each match of the regular expression in the line is treated as the end of a field. If the regular expression contains capture groups
129
+
then these are extracted as fields. </p>
130
+
<p>The regular expression is treated slightly differently if it is anchored to the start of the line (that is, the pattern starts with "^".
131
+
In this case the regular expression is matched against each line. If the line does not match it is discarded
132
+
as an invalid record. Each capture group in the expression is treated as a field. The regular expression
133
+
is invalid if it does not have capture groups. As an example this can be used as a (somewhat
134
+
unintuitive) means of loading data with fixed width fields. For example if the data has fields of 5
135
+
characters, 10 characters, and 2 fields of 20 characters, then this can be loaded with a regular
136
+
expression such as
137
+
<pre>
138
+
^(.{5})(.{10})(.{20})(.{20}).*
139
+
</pre>
140
+
<p>
141
+
(If the records are possibly not completely filled then the counts could be entered as {,5}, meaning
142
+
up to 5 characters, so that the regular expression will not fail).
143
+
</p>
129
144
130
145
<h4><a name="wkt">How WKT text is interpreted</a></h4>
131
146
<p>
@@ -172,3 +187,51 @@ id|wkt<br />
172
187
</ul>
173
188
174
189
<h4><a name="python">Using delimited text layers in Python</a></h4>
190
+
<p>Delimited text data sources can be creating from Python in a similar way to other vector layers.
191
+
The pattern is:
192
+
</p>
193
+
<pre>
194
+
from PyQt4.QtCore import QUrl, QString<br />
195
+
from qgis.core import QgsVectorLayer, QgsMapLayerRegistry<br />
<p>The configuration of the delimited text layer is defined by adding query items to the uri.
209
+
The following options can be added
210
+
</p>
211
+
<ul>
212
+
<li><i>encoding=..</i> defines the file encoding. The default is "UTF-8"</li>
213
+
<li><i>type=(csv|regexp|whitespace)</i>< defines the delimiter type. Valid values are csv,
214
+
regexp, and whitespace (which is just a special case of regexp). Default is csv.</li>
215
+
<li><i>delimiter=...</i> defines the delimiters that will be used for csv formatted files,
216
+
or the regular expression for regexp formatted files. Default is , for CSV files. There is
217
+
no default for regexp files.</li>
218
+
<li><i>quote=..</i> (for csv files) defines the characters used to quote fields. Default is "</li>
219
+
<li><i>escape=..</i> (for csv files) defines the characters used to escape the special meaning of the next character. Default is "</li>
220
+
<li><i>skipLines=#</i> defines the number of lines to discard from the beginning of the file. Default is 0.</li>
221
+
<li><i>useHeader=(yes|no)</i> defines whether the first data record contains the names of the data fields. Default is yes.</li>
222
+
<li><i>trimFields=(yes|no)</i> defines whether leading and trailing whitespace is to be removed from unquoted fields. Default is no.</li>
223
+
<li><i>maxFields=#</i> defines the maximum number of fields that will be loaded from the file.
224
+
Additional fields in each record will be discarded. Default is 0 - display all fields.
225
+
(This option is not available from the delimited text layer dialog box).</li>
226
+
<li><i>skipEmptyFields=(yes|no)</i> defines whether empty unquoted fields will be discarded if they are empty (applied after trimFields). Default is no.</li>
227
+
<li><i>decimalPoint=.</i> specifies an alternative character that may be used as a decimal point in numeric fields. Default is a point (full stop) character.</li>
228
+
<li><i>wktField=fieldname</i> specifies the name or number (starting at 1) of the field containing a well known text geometry definition</li>
229
+
<li><i>xField=fieldname</i> specifies the name or number (starting at 1) of the field the X coordinate (only applies if wktField is not defined)</li>
230
+
<li><i>yField=fieldname</i> specifies the name or number (starting at 1) of the field the Y coordinate (only applies if wktField is not defined)</li>
231
+
<li><i>geomType=(auto|point|line|polygon|none)</i> specifies type of geometry for wkt fields, or none to load the file as an attribute-only table. Default is auto.</li>
232
+
<li><i>crs=...</i> specifies the coordinate system to use for the vector layer, in a format accepted by QgsCoordinateReferenceSystem.createFromString (for example "EPSG:4167"). If this is not
233
+
specified then a dialog box may request this information from the user.</li>
234
+
<li><i>quiet=(yes|no)</i> specifies whether errors encountered loading the layer are presented in a dialog box (they will be written to the QGis log in any case). Default is no.</li>
0 commit comments