<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Bo Victor,</p>
    <p>there's an important mention in the email you quote: "The effect
      of this option is that when a layer is of type Polygon, it will be
      <br>
      converted in the target format as MultiPolygon,".    In your
      situation, the original layer geometry type is Geometry. There's
      no way that -nlt promote_to_multi can know that your geometries
      will actually be all polygon, or all linestring, and thus change
      the target layer geometry type.</p>
    <p>We would probably a new option to ogr2ogr that would generalize
      the following open option of the shapefile driver:</p>
    <p>ADJUST_GEOM_TYPE=NO/FIRST_SHAPE/ALL_SHAPES. Defines how layer
      geometry type is computed, in particular to distinguish shapefiles
      that have shapes with significant values in the M dimension from
      the ones where the M values are set to the nodata value. By
      default (FIRST_SHAPE), the driver will look at the first shape and
      if it has M values it will expose the layer as having a M
      dimension. By specifying ALL_SHAPES, the driver will iterate over
      features until a shape with a valid M value is found to decide the
      appropriate layer type.</p>
    <p>You may file an enhancement ticket about that if you wish<br>
    </p>
    <p>Even<br>
    </p>
    <div class="moz-cite-prefix">Le 31/07/2022 à 10:00, Bo Victor
      Thomsen a écrit :<br>
    </div>
    <blockquote type="cite"
      cite="mid:bc65b462-c77a-5b58-21fe-56218dbe7a91@gmail.com">
      <p>Thanks to Hugues and Richard for responding to my questions.</p>
      However, I'm using the ogr2ogr inside a DOS .cmd file like this: <br>
      <p>for /R D:\tmp %%f in (*.tab) do ogr2ogr --config PG_USE_COPY
        yes -progress -lco OVERWRITE=YES -lco SCHEMA=mat -dim XY -a_srs
        EPSG:25832 -f "PostgreSQL" PG:"host=localhost port=5432 user=***
        password=*** dbname=geodata" "%%f"<br>
      </p>
      <p>I.e. iterating through a directory plus sub-directories and
        converting every found tab file into a table into schema "mat"
        using ogr2ogr<br>
      </p>
      <p>The tab files contains either points, linestrings or polygons.
        Polygons and linestrings can be a mix of simple and
        multi-objects. Each tab-file contains only one main type.<br>
      </p>
      <p>So I can't use "-nlt multipolygons". And the point of this
        project was to get rid of a fairly complex postgres based
        function that checks an uploaded table and change its geometry
        type using "alter table ... using st_multi(geom)" type of
        commands.</p>
      <p>That was why I tried to use "-nlt promote_to_multi". According
        to this mail: <br>
      </p>
      <p><a class="moz-txt-link-freetext"
href="https://lists.osgeo.org/pipermail/gdal-dev/2012-September/034128.html"
          moz-do-not-send="true">https://lists.osgeo.org/pipermail/gdal-dev/2012-September/034128.html</a></p>
      <p>Even Rouault describes the exact behaviour I'm looking for:
        Simple linestrings / polygons will be changed to multi types and
        points will be left alone. And the geometry type will be set to
        a "multi*" as needed.<br>
      </p>
      <p>What actually happens is that linestrings, polygons <i>and</i>
        points all are changed to multi type, but the geometry type
        remains "Geometry".<br>
      </p>
      <p><br>
      </p>
      <pre class="moz-signature" cols="72">Med venlig hilsen / Kind regards

Bo Victor Thomsen</pre>
      <div class="moz-cite-prefix">Den 25-07-2022 kl. 15:52 skrev Hugues
        François:<br>
      </div>
      <blockquote type="cite"
        cite="mid:742711968.14136783.1658757125530.JavaMail.zimbra@inrae.fr">
        <div>
          <div>Hi,</div>
          <div><br data-mce-bogus="1">
          </div>
          <div>I guess you should either</div>
          <div>=> drop the created table prior to launch the ogr2ogr
            command with the -nlt PROMOTE_TO_MULTI switch</div>
          <div>=> or maually alter the existing table: ALTER TABLE
            schema.table ALTER COLUMN geom TYPE geometry(MultiPolygon,
            SRID) using ST_MULTI(geom)</div>
          <div><br data-mce-bogus="1">
          </div>
          <div>HTH,</div>
          <div>Hug</div>
          <div><br>
          </div>
          <div><br data-mce-bogus="1">
          </div>
          <hr id="zwchr" data-marker="__DIVIDER__">
          <div data-marker="__HEADERS__"><b>De: </b>"Richard Greenwood"
            <a class="moz-txt-link-rfc2396E"
              href="mailto:richard.greenwood@gmail.com"
              moz-do-not-send="true"><richard.greenwood@gmail.com></a><br>
            <b>À: </b>"Bo Victor Thomsen" <a
              class="moz-txt-link-rfc2396E"
              href="mailto:bo.victor.thomsen@gmail.com"
              moz-do-not-send="true"><bo.victor.thomsen@gmail.com></a><br>
            <b>Cc: </b>"gdal dev" <a class="moz-txt-link-rfc2396E"
              href="mailto:gdal-dev@lists.osgeo.org"
              moz-do-not-send="true"><gdal-dev@lists.osgeo.org></a><br>
            <b>Envoyé: </b>Lundi 25 Juillet 2022 15:32:35<br>
            <b>Objet: </b>Re: [gdal-dev] New behaviour of
            "PROMOTE_TO_MULTI" ?<br>
          </div>
          <div><br>
          </div>
          <div data-marker="__QUOTED_TEXT__">
            <div dir="ltr">Have you tried -nlt MultiPolygon?</div>
            <br>
            <div class="gmail_quote">
              <div dir="ltr" class="gmail_attr">On Mon, Jul 25, 2022 at
                2:54 AM Bo Victor Thomsen <<a
                  href="mailto:bo.victor.thomsen@gmail.com"
                  target="_blank" class="moz-txt-link-freetext"
                  moz-do-not-send="true">bo.victor.thomsen@gmail.com</a>>
                wrote:<br>
              </div>
              <blockquote class="gmail_quote">
                <div>
                  <p>I have a MapInfo .tab file containing polygons,
                    both simple and multipolygons (and only polygons).</p>
                  <p>Using this command: (all ogr2ogr commands are
                    one-liners, but examples are split for lucidity)<br>
                  </p>
                  <p>ogr2ogr <br>
                      --config PG_USE_COPY yes <br>
                      -progress <br>
                      -lco OVERWRITE=YES <br>
                      -dim XY <br>
                      -f "PostgreSQL" PG:"host=localhost port=5432
                    user=*** password=*** dbname=geodata" <br>
                      FREDSKOV.TAB<br>
                  </p>
                  <p>will (correctly) create a table in Postgres of
                    PostGIS type "Geometry" <br>
                  </p>
                  <p>If I change the command to:</p>
                  <p>ogr2ogr <br>
                      --config PG_USE_COPY yes <br>
                      -progress <br>
                      -lco OVERWRITE=YES <br>
                      -dim XY <br>
                    <b>  -nlt PROMOTE_TO_MULTI</b><br>
                      -f "PostgreSQL" PG:"host=localhost port=5432
                    user=*** password=*** dbname=geodata" <br>
                      FREDSKOV.TAB</p>
                  <p>I would expect the table to change the PostGIS type
                    to "MultiPolygon". However it still is registered as
                    "Geometry".<br>
                  </p>
                  <p>Checking the table using SQL command:</p>
                  <p>SELECT ST_geometrytype(wkb_geometry), count(*) FROM
                    mat.fredskov group by 1</p>
                  <p>affirms, that all geometries now is of type
                    "ST_MultiPolygon".</p>
                  <p>AFAIK, this is a new behaviour. Or what ? <br>
                  </p>
                  <p>Postgres/Postgis version : 13.2,  3.1 <br>
                  </p>
                  <p>OGR2OGR version:  both 3.4 andf 3.6 dev.<br>
                  </p>
                  <p><br>
                  </p>
                  <p><br>
                  </p>
                  <p><br>
                  </p>
                  <pre>-- 
Med venlig hilsen / Kind regards

Bo Victor Thomsen</pre>
                </div>
                _______________________________________________<br>
                gdal-dev mailing list<br>
                <a href="mailto:gdal-dev@lists.osgeo.org"
                  target="_blank" class="moz-txt-link-freetext"
                  moz-do-not-send="true">gdal-dev@lists.osgeo.org</a><br>
                <a
                  href="https://lists.osgeo.org/mailman/listinfo/gdal-dev"
                  rel="noreferrer" target="_blank"
                  class="moz-txt-link-freetext" moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
              </blockquote>
            </div>
            <br>
            <br>
            -- <br>
            <div dir="ltr" class="gmail_signature">
              <div dir="ltr">Richard W. Greenwood<br>
                <a href="http://www.greenwoodmap.com" target="_blank"
                  moz-do-not-send="true">www.greenwoodmap.com</a></div>
            </div>
            <br>
            <br>
            [Fichier texte:ATT00001]<br>
          </div>
        </div>
      </blockquote>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
gdal-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/gdal-dev">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a>
</pre>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
<a class="moz-txt-link-freetext" href="http://www.spatialys.com">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
  </body>
</html>