<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    藤田様<br>
    <br>
    自動で採番する方法,など考えてもみなかったので,逆に勉強になっています。<br>
    たとえば,整数フィールドnに連番を入れるなら,次のようにすれば良いようです。<br>
    <br>
    IF(maximum("n") is NULL, 1 , maximum("n") + 1)<br>
    <br>
    <a
href="https://gis.stackexchange.com/questions/359757/unable-to-get-correct-row-number-in-attribute-table">qgis
      - Unable to get correct @row_number in Attribute Table -
      Geographic Information Systems Stack Exchange</a><br>
    <br>
    ただ,この方法は,お気づきの通り,レイヤが複数存在すると,同じ連番の地物が複数出てきます。<br>
    レイヤが複数あるならば,uuid等のハッシュを使った方が安全です。<br>
    <br>
    ちなみに,タイムスタンプを組み合わせることで,uuidの衝突リスクはさらに下げることができますね。<br>
    (タイムスタンプのみを使ったためか衝突が大問題になったのが,例のマイナンバーカードでした。)<br>
    たとえば,次のようにyyMMddとuuid(の一部)をidに使うことにすれば,年月日が異なる場合の衝突は100%防げます。<br>
    uuidは3桁もあれば十分かもしれません。<br>
    <br>
    concat(format_date(now(),'yyMMdd'),right(left(uuid(),4),3))<br>
    <br>
    色々な方法,何が良いかは,ケースバイケースかと思います。<br>
    ご参考になれば。<br>
    <br>
    田鎖<br>
    <br>
    <div class="moz-cite-prefix">On 2023/11/13 15:11, 藤田卓
      (OSGeoJapan-discuss 経由) wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAN3k7FpUgmmEZ+5cm0Oobi6LHzYxTYcbWvw3GWMa4t=dc0nqMQ@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">かやまさま
        <div><br>
        </div>
        <div>早速アドバイスいただきありがとうございます</div>
        <div>藤田です</div>
        <div><br>
        </div>
        <div>>ベクタのレイヤを作成した後 プロセッシングツールボックス -> ベクタテーブル -> 
          自動インクリメント属性を追加 で可能かもしれません。</div>
        <div>><a
href="https://docs.qgis.org/3.28/ja/docs/user_manual/processing_algs/qgis/vectortable.html#qgisaddautoincrementalfield"
            target="_blank" moz-do-not-send="true"
            class="moz-txt-link-freetext">https://docs.qgis.org/3.28/ja/docs/user_manual/processing_algs/qgis/vectortable.html#qgisaddautoincrementalfield</a></div>
        <div><br>
        </div>
        <div>ありがとうございます</div>
        <div>ご教授いただいた方法では、ベクタの新しい地物を追加する度に毎回、</div>
        <div>「
          ベクタのレイヤを作成した後 プロセッシングツールボックス -> ベクタテーブル -> 
          自動インクリメント属性を追加
          」を実行して</div>
        <div>出力してSHAPEを作成する必要があるということですね</div>
        <div><br>
        </div>
        <div>この場合は、過去に作成していた地物のIDは、変わらず、同じIDが付与することも可能ということでしょうか</div>
        <div>(編集の際は、地物の追加だけでなく、過去に作成した地物を削除、または過去に作成していた地物を編集する場合もある(IDはそのままにしたい)したりすることもありますが、過去のIDはそれぞれ引き継ぐもしく、削除した地物のIDは復活しないとしたいです)</div>
        <div><br>
        </div>
        <div>たびたびのお伺いとなってしまい申し訳ございません</div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">2023年11月13日(月) 13:58 Yoichi
          Kayama <<a href="mailto:yoichi.kayama@gmail.com"
            moz-do-not-send="true" class="moz-txt-link-freetext">yoichi.kayama@gmail.com</a>>:<br>
        </div>
        <blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          <div dir="ltr">藤田様
            <div><br>
            </div>
            <div>ベクタのレイヤを作成した後 プロセッシングツールボックス -> ベクタテーブル -> 
              自動インクリメント属性を追加 で可能かもしれません。</div>
            <div><br>
            </div>
            <div><a
href="https://docs.qgis.org/3.28/ja/docs/user_manual/processing_algs/qgis/vectortable.html#qgisaddautoincrementalfield"
                target="_blank" moz-do-not-send="true"
                class="moz-txt-link-freetext">https://docs.qgis.org/3.28/ja/docs/user_manual/processing_algs/qgis/vectortable.html#qgisaddautoincrementalfield</a><br>
            </div>
          </div>
          <br>
          <div class="gmail_quote">
            <div dir="ltr" class="gmail_attr">2023年11月13日(月) 12:39 藤田卓
              (OSGeoJapan-discuss 経由) <<a
                href="mailto:osgeojapan-discuss@lists.osgeo.org"
                target="_blank" moz-do-not-send="true"
                class="moz-txt-link-freetext">osgeojapan-discuss@lists.osgeo.org</a>>:<br>
            </div>
            <blockquote class="gmail_quote"
style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
              <div dir="ltr">
                <div dir="ltr">みなさま
                  <div><br>
                  </div>
                  <div>日本自然保護協会の藤田と申します。</div>
                  <div>QGISについて1つ教えていただきたいことがあり、ご連絡いたしました。</div>
                  <div><br>
                  </div>
                  <div><br>
                  </div>
                  <div><br>
                  </div>
                  <div><b>【質問】</b></div>
                  <div>
                    <div>QGISでshapeファイルのユニークID(地物毎に固有の値)を作成する際に、<br>
                    </div>
                    <div>既存の地物だけでなく、新しく地物を追加した際に自動的にユニークIDが入力される方法<br>
                    </div>
                    <div>として、</div>
                  </div>
                  <div><br>
                  </div>
                  <div>uuid() を使用する方法があるようですが</div>
                  <div><span style="background-color:rgb(252,229,205)"><b>uuid() 以外の 関数を用いて自動でユニークIDを入力できる方法はないでしょうか</b></span><br>
                  </div>
                  <div>(もしくは uuid() を38文字より縮めるなどができるか?)</div>
                  <div><br>
                  </div>
                  <div><b>【質問した理由】</b></div>
                  <div><u>uuid()の場合、IDが38文字と長いため、ファイルサイズが大きくなる、扱いがやや面倒との懸念もあり</u></div>
                  <div>$idなど、6~10桁などの数値など短いIDでユニークIDを自動生成できる方法で</div>
                  <div>新しく地物を追加した際に自動的にユニークIDを 追加できないかと考えております<br>
                  </div>
                  <div><br>
                  </div>
                  <div><br>
                    アドバイスいただけましたら幸いです<br>
                  </div>
                  <div><br>
                  </div>
                </div>
                <div dir="ltr" class="gmail_signature">
                  <div dir="ltr">
                    <div>
                      <div
style="color:rgb(0,0,0);font-family:Helvetica,sans-serif;font-size:12px;display:inline-block;vertical-align:top">
                        <div style="text-align:right"><br>
                        </div>
                        <div style="text-align:right"><img
src="https://www.nacsj.or.jp/official/wp-content/uploads/2022/01/20220104-1302_7c87c318a0003fb134b00df95fd4f05d.png"
style="border: 0px; vertical-align: middle; margin: 0px 5px 0px 0px;"
                            moz-do-not-send="true" width="96"
                            height="93"><br>
                        </div>
                        <div style="text-align:right"><br>
                        </div>
                        <div style="text-align:right"><br>
                        </div>
                      </div>
                      <span
style="color:rgb(0,0,0);font-family:Helvetica,sans-serif;font-size:12px"> </span>
                      <div
style="display:inline-block;vertical-align:top;padding:0px 0px 0px 5px">
                        <div>
                          <div
style="color:rgb(0,0,0);font-family:Helvetica,sans-serif;font-weight:bold;padding:0px 0px 5px"><br>
                          </div>
                          <div
style="color:rgb(0,0,0);font-family:Helvetica,sans-serif;font-weight:bold;padding:0px 0px 5px">藤田卓 
                                  /  Dr. Taku FUJITA<br>
                          </div>
                          <div style="padding:0px 0px 5px"><font
                              size="1" face="Helvetica, sans-serif"
                              color="#000000">(理学博士・ 技術士(環境部門)</font><br>
                          </div>
                          <div
style="color:rgb(0,0,0);font-family:Helvetica,sans-serif"><b><font
                                size="1">公益財団法人 日本自然保護協会(NACS-J</font></b><b><font
                                size="1">)</font></b></div>
                          <div><font size="1"><font
                                face="Helvetica, sans-serif"
                                color="#000000"><b>生物多様性保全部</b></font><br>
                            </font></div>
                        </div>
                        <div
style="font-family:Helvetica,sans-serif;color:rgb(0,0,0)"><font size="1"><a
                              href="mailto:fujita@nacsj.or.jp"
style="color:rgb(51,122,183);background-color:transparent"
                              target="_blank" moz-do-not-send="true"
                              class="moz-txt-link-freetext">fujita@nacsj.or.jp</a> | <a
                              href="https://www.nacsj.or.jp/"
style="color:rgb(51,122,183);background-color:transparent"
                              target="_blank" moz-do-not-send="true"
                              class="moz-txt-link-freetext">https://www.nacsj.or.jp/</a> </font><span
                            style="font-size:12px"> </span><font
                            size="1"><br>
                          </font></div>
                        <div
style="font-family:Helvetica,sans-serif;color:rgb(0,0,0);padding:0px"><font
                            size="1">TEL: 03-3553-4101 (代表) </font></div>
                        <div
style="font-family:Helvetica,sans-serif;color:rgb(0,0,0);font-size:10px;padding:5px 0px 0px">〒104-0033
                          東京都中央区新川1-16-10 ミトヨビル2F</div>
                        <div
style="font-family:Helvetica,sans-serif;text-align:center;color:rgb(0,0,0);font-size:10px;padding:5px 0px 0px"><b
                            style="color:rgb(32,33,36)"><font
                              color="#274e13">★70周年キャンペーン★ </font></b><b
                            style="font-size:small"><a
                              href="https://www.nacsj.or.jp/activist"
                              style="color:rgb(17,85,204)"
                              target="_blank" moz-do-not-send="true"><font
                                size="1">https://www.nacsj.or.jp/activist</font></a></b><br>
                        </div>
                        <div
style="font-family:Helvetica,sans-serif;color:rgb(0,0,0);padding:5px 0px 0px"><font
style="text-align:center;color:rgb(32,33,36)"><span
                              style="font-size:10px">  </span><a
                              href="https://www.facebook.com/NACSJ"
style="color:rgb(17,85,204);font-size:10px" target="_blank"
                              moz-do-not-send="true"><img
src="https://www.nacsj.or.jp/official/wp-content/uploads/2022/01/FBnew.png"
                                alt="FB"
style="text-align: right; color: rgb(0, 0, 0);" moz-do-not-send="true"></a></font><font
style="font-size:10px;text-align:center;color:rgb(32,33,36)"><font
                              color="#000000"><font size="2">  </font></font></font><a
                            href="https://twitter.com/NACSJ"
style="color:rgb(17,85,204);text-align:center" target="_blank"
                            moz-do-not-send="true"><img
src="https://www.nacsj.or.jp/official/wp-content/uploads/2022/01/TW.png"
                              alt="TW"
style="color: rgb(61, 133, 198); font-size: x-small;"
                              moz-do-not-send="true"></a><span
style="text-align:center;color:rgb(32,33,36)">   </span><a
href="https://www.instagram.com/nacsj_official/"
style="color:rgb(17,85,204);text-align:center" target="_blank"
                            moz-do-not-send="true"><img
src="https://www.nacsj.or.jp/official/wp-content/uploads/2022/01/IG.png"
                              alt="Instagram" moz-do-not-send="true"></a><span
style="text-align:center;color:rgb(32,33,36)">   </span><a
href="https://www.youtube.com/channel/UClUy3wg5i1qB1GYT6YxRTDQ"
style="color:rgb(17,85,204);text-align:center" target="_blank"
                            moz-do-not-send="true"><img
src="https://www.nacsj.or.jp/official/wp-content/uploads/2022/01/youtube-1.png"
                              alt="Youtube" moz-do-not-send="true"></a><font
style="font-size:10px;text-align:center;color:rgb(32,33,36)"><font
                              color="#000000">  </font><font
                              color="#3d85c6"> </font></font></div>
                        <div style="font-family:Helvetica,sans-serif"><font
style="font-size:10px;text-align:center;color:rgb(32,33,36)"><font
                              color="#3d85c6"><br>
                            </font></font></div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              _______________________________________________<br>
              OSGeoJapan-discuss mailing list<br>
              <a href="mailto:OSGeoJapan-discuss@lists.osgeo.org"
                target="_blank" moz-do-not-send="true"
                class="moz-txt-link-freetext">OSGeoJapan-discuss@lists.osgeo.org</a><br>
              <a
href="https://lists.osgeo.org/mailman/listinfo/osgeojapan-discuss"
                rel="noreferrer" target="_blank" moz-do-not-send="true"
                class="moz-txt-link-freetext">https://lists.osgeo.org/mailman/listinfo/osgeojapan-discuss</a><br>
            </blockquote>
          </div>
        </blockquote>
      </div>
      <br clear="all">
      <div><br>
      </div>
      <span class="gmail_signature_prefix">-- </span><br>
      <div dir="ltr" class="gmail_signature">
        <div dir="ltr">
          <div>
            <div
style="color:rgb(0,0,0);font-family:Helvetica,sans-serif;font-size:12px;display:inline-block;vertical-align:top">
              <div style="text-align:right"><br>
              </div>
              <div style="text-align:right"><img
src="https://www.nacsj.or.jp/official/wp-content/uploads/2022/01/20220104-1302_7c87c318a0003fb134b00df95fd4f05d.png"
style="border: 0px; vertical-align: middle; margin: 0px 5px 0px 0px;"
                  moz-do-not-send="true" width="96" height="93"><br>
              </div>
              <div style="text-align:right"><br>
              </div>
              <div style="text-align:right"><br>
              </div>
            </div>
            <span
style="color:rgb(0,0,0);font-family:Helvetica,sans-serif;font-size:12px"> </span>
            <div
style="display:inline-block;vertical-align:top;padding:0px 0px 0px 5px">
              <div>
                <div
style="color:rgb(0,0,0);font-family:Helvetica,sans-serif;font-weight:bold;padding:0px 0px 5px"><br>
                </div>
                <div
style="color:rgb(0,0,0);font-family:Helvetica,sans-serif;font-weight:bold;padding:0px 0px 5px">藤田卓 
                        /  Dr. Taku FUJITA<br>
                </div>
                <div style="padding:0px 0px 5px"><font size="1"
                    face="Helvetica, sans-serif" color="#000000">(理学博士・
                    技術士(環境部門)</font><br>
                </div>
                <div
style="color:rgb(0,0,0);font-family:Helvetica,sans-serif"><b><font
                      size="1">公益財団法人 日本自然保護協会(NACS-J</font></b><b><font
                      size="1">)</font></b></div>
                <div><font size="1"><font face="Helvetica, sans-serif"
                      color="#000000"><b>生物多様性保全部</b></font><br>
                  </font></div>
              </div>
              <div
style="font-family:Helvetica,sans-serif;color:rgb(0,0,0)"><font size="1"><a
                    href="mailto:fujita@nacsj.or.jp"
style="color:rgb(51,122,183);background-color:transparent"
                    target="_blank" moz-do-not-send="true"
                    class="moz-txt-link-freetext">fujita@nacsj.or.jp</a> | <a
                    href="https://www.nacsj.or.jp/"
style="color:rgb(51,122,183);background-color:transparent"
                    target="_blank" moz-do-not-send="true"
                    class="moz-txt-link-freetext">https://www.nacsj.or.jp/</a> </font><span
                  style="font-size:12px"> </span><font size="1"><br>
                </font></div>
              <div
style="font-family:Helvetica,sans-serif;color:rgb(0,0,0);padding:0px"><font
                  size="1">TEL: 03-3553-4101 (代表) </font></div>
              <div
style="font-family:Helvetica,sans-serif;color:rgb(0,0,0);font-size:10px;padding:5px 0px 0px">〒104-0033
                東京都中央区新川1-16-10 ミトヨビル2F</div>
              <div
style="font-family:Helvetica,sans-serif;text-align:center;color:rgb(0,0,0);font-size:10px;padding:5px 0px 0px"><b
                  style="color:rgb(32,33,36)"><font color="#274e13">★70周年キャンペーン★ </font></b><b
                  style="font-size:small"><a
                    href="https://www.nacsj.or.jp/activist"
                    style="color:rgb(17,85,204)" target="_blank"
                    moz-do-not-send="true"><font size="1">https://www.nacsj.or.jp/activist</font></a></b><br>
              </div>
              <div
style="font-family:Helvetica,sans-serif;color:rgb(0,0,0);padding:5px 0px 0px"><font
                  style="text-align:center;color:rgb(32,33,36)"><span
                    style="font-size:10px">  </span><a
                    href="https://www.facebook.com/NACSJ"
                    style="color:rgb(17,85,204);font-size:10px"
                    target="_blank" moz-do-not-send="true"><img
src="https://www.nacsj.or.jp/official/wp-content/uploads/2022/01/FBnew.png"
                      alt="FB"
                      style="text-align: right; color: rgb(0, 0, 0);"
                      moz-do-not-send="true"></a></font><font
style="font-size:10px;text-align:center;color:rgb(32,33,36)"><font
                    color="#000000"><font size="2">  </font></font></font><a
                  href="https://twitter.com/NACSJ"
                  style="color:rgb(17,85,204);text-align:center"
                  target="_blank" moz-do-not-send="true"><img
src="https://www.nacsj.or.jp/official/wp-content/uploads/2022/01/TW.png"
                    alt="TW"
style="color: rgb(61, 133, 198); font-size: x-small;"
                    moz-do-not-send="true"></a><span
                  style="text-align:center;color:rgb(32,33,36)">   </span><a
                  href="https://www.instagram.com/nacsj_official/"
                  style="color:rgb(17,85,204);text-align:center"
                  target="_blank" moz-do-not-send="true"><img
src="https://www.nacsj.or.jp/official/wp-content/uploads/2022/01/IG.png"
                    alt="Instagram" moz-do-not-send="true"></a><span
                  style="text-align:center;color:rgb(32,33,36)">   </span><a
href="https://www.youtube.com/channel/UClUy3wg5i1qB1GYT6YxRTDQ"
                  style="color:rgb(17,85,204);text-align:center"
                  target="_blank" moz-do-not-send="true"><img
src="https://www.nacsj.or.jp/official/wp-content/uploads/2022/01/youtube-1.png"
                    alt="Youtube" moz-do-not-send="true"></a><font
style="font-size:10px;text-align:center;color:rgb(32,33,36)"><font
                    color="#000000">  </font><font color="#3d85c6"> </font></font></div>
              <div style="font-family:Helvetica,sans-serif"><font
style="font-size:10px;text-align:center;color:rgb(32,33,36)"><font
                    color="#3d85c6"><br>
                  </font></font></div>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
OSGeoJapan-discuss mailing list
<a class="moz-txt-link-abbreviated" href="mailto:OSGeoJapan-discuss@lists.osgeo.org">OSGeoJapan-discuss@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/osgeojapan-discuss">https://lists.osgeo.org/mailman/listinfo/osgeojapan-discuss</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>