<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-ligatures:standardcontextual;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        font-size:10.0pt;
        font-family:"Courier New";
        mso-ligatures:none;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Consolas",serif;}
span.EmailStyle22
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        mso-ligatures:none;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Yea, I tried it in the consol and it worked, but does not work in my plugin code.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="mso-ligatures:none">From:</span></b><span style="mso-ligatures:none"> Bo Victor Thomsen <bo.victor.thomsen@gmail.com>
<br>
<b>Sent:</b> Wednesday, November 27, 2024 6:09 AM<br>
<b>To:</b> Catania, Luke A ERDC-RDE-GRL-VA CIV <Luke.A.Catania@erdc.dren.mil>; qgis-developer@lists.osgeo.org<br>
<b>Subject:</b> Re: [QGIS-Developer] Field Name limited to 10 characters for a geopackage<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p>Hi Luke -<span style="mso-ligatures:none"><o:p></o:p></span></p>
<p>Running this code in the QGIS Python console: <br>
<b><span style="font-family:"Courier New""><br>
vector_layer = iface.activeLayer()  # Active layer _is_ from GeoPackage<br>
field_name = 'Land Use Category'    # "New_field" changed to "field_name"<br>
<br>
new_field = QgsField(field_name, QVariant.String)<br>
vector_layer.dataProvider().addAttributes([new_field])</span></b><o:p></o:p></p>
<p>will add an extra column with the name "<b>Land Use Category</b>" to the GeoPackage layer
<o:p></o:p></p>
<pre><o:p> </o:p></pre>
<pre>Med venlig hilsen / Best regards<o:p></o:p></pre>
<pre><o:p> </o:p></pre>
<pre>Bo Victor Thomsen<o:p></o:p></pre>
<div>
<p class="MsoNormal">On 27/11/2024 05.48, Catania, Luke A ERDC-RDE-GRL-VA CIV via QGIS-Developer wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">I am using a geopackage as a data source and when I add a new field it is limited to 10 characters. I thought that was only a limitation for ESRI shapefiles.<br>
<br>
<br>
<o:p></o:p></p>
<p class="MsoNormal">New_field = “Land Use Category”<br>
new_field = QgsField(field_name, QVariant.String)<br>
vector_layer.dataProvider().addAttributes([new_field])<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Field name is truncated to <b>Land_Use_C</b><o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Luke Catania<o:p></o:p></p>
<p class="MsoNormal">US Army ERDC-GRL<o:p></o:p></p>
<p class="MsoNormal">JCMS Site Planning Developer<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"><span style="mso-ligatures:none"><br>
<br>
<o:p></o:p></span></p>
<pre>_______________________________________________<o:p></o:p></pre>
<pre>QGIS-Developer mailing list<o:p></o:p></pre>
<pre><a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a><o:p></o:p></pre>
<pre>List info: <a href="Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked">Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked</a><o:p></o:p></pre>
<pre>Unsubscribe: <a href="Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked">Blockedhttps://lists.osgeo.org/mailman/listinfo/qgis-developerBlocked</a><o:p></o:p></pre>
</blockquote>
</div>
</body>
</html>