[Qgis-developer] python bindings, shapefile creation : attributes

Martin Dobias wonder.sk at gmail.com
Fri Nov 23 11:43:06 EST 2007


Hi,

On Nov 23, 2007 11:09 AM, kimaidou <michael.douchin at laposte.net> wrote:
> Q1) Are the date, time, datetime format usable for the attributes ? Like
>
> # define fields for feature attributes
> fields = { 0 : QgsField("date", QVariant.Date),
>           1 : QgsField("time", QVariant.Time) }
>
> I am pretty sure no. But then, how do people handle this type of data ? A
> conversion to string type will cause the loose of "sort by date fonction"
> (and so)

Fields of type Date and Time are not yet supported (although it
shouldn't be a lot of work to add support for them).
But if you store date/time in some reasonable format (as a string or a
number) - e.g. 20061123 for today, you shouldn't have problems to do
some sorting.

> Q2) How can I tell the length and the precision of each attribute, so that
> the shapefile won't be to heavy. For example, each string column is coded
> with a length of 80, wich is space consuming.

You can either specify length in QgsField constructor (it's one of the
further optional parameters) or use setLength() function. See
documentation of QgsField class:
http://svn.qgis.org/api_doc/html/classQgsField.html

Martin



More information about the Qgis-developer mailing list