<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;
      charset=windows-1252">
  </head>
  <body>
    <p>Joaquim,</p>
    <p>ogr2ogr -t_srs passes the CRS object as an argument of the
      GDALDataset::CreateLayer() API</p>
    <p>GDALDataset::SetProjection() / GDALSetProjection() is (at least
      in all implementations of in-tree drivers) reserved for the raster
      API, and raster drivers that support the Create() API.</p>
    <p>Similarly GDALDataset::GetSpatialRef() / <span lang="EN-US">GDALGetSpatialRef()
        is for the raster API</span></p>
    <p><span lang="EN-US">For the vector API, use
        OGRLayer::GetSpatialRef() (different layers in a same dataset
        could have different CRS)</span></p>
    <p><span lang="EN-US">Best regards,<br>
      </span></p>
    <p><span lang="EN-US">Even<br>
      </span></p>
    <div class="moz-cite-prefix">Le 28/03/2021 à 19:57, Joaquim Manuel
      Freire Luís a écrit :<br>
    </div>
    <blockquote type="cite"
cite="mid:AM6PR04MB395973D2E5D4C48C1F8C37C1A67F9@AM6PR04MB3959.eurprd04.prod.outlook.com">
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <div class="WordSection1">
        <p class="MsoNormal"><span lang="EN-US">Hi,</span></p>
        <p class="MsoNormal"><span lang="EN-US"> </span></p>
        <p class="MsoNormal"><span lang="EN-US">I am trying to use the
            GDAL shared lib directly from Julia and there are things
            that keep breaking my head. For example, the lines below use
            a mix of GMT and GDAL wrapper functions calls that
            <b>WORK</b>. First command creates a GMT dataset with two
            UTM points type with an assigned coordinate system. Next, in
            2), I create a GDAL dataset of a LineString, convert it to
            geog in 3) and save it to file using the OGR_GMT driver in
            4)</span></p>
        <p class="MsoNormal"><span lang="EN-US"> </span></p>
        <p class="MsoNormal"><span lang="FR">1) D2 =
            mat2ds([588977.324434907 4095339.69117669; 579551.921920776
            4150721.71333039], proj="+proj=utm +zone=29");</span></p>
        <p class="MsoNormal"><span lang="FR">2) ds = gmt2gd(D2);</span></p>
        <p class="MsoNormal"><span lang="EN-US">3) ds2=ogr2ogr(ds,
            ["-t_srs", "+proj=longlat", "-overwrite"])</span></p>
        <p class="MsoNormal"><span lang="FR">4) ogr2ogr(ds2,
            dest="lixo2.gmt")</span></p>
        <p class="MsoNormal"><span lang="FR"> </span></p>
        <p class="MsoNormal"><span lang="EN-US">Now the troubles. When I
            tried to use GDALSetProjection() I got an error like this</span></p>
        <p class="MsoNormal"><span lang="EN-US"> </span></p>
        <p class="MsoNormal"><span lang="EN-US">ERROR 6: /vsimem/##269:
            Dataset does not support the SetSpatialRef() method.</span></p>
        <p class="MsoNormal"><span lang="EN-US"> </span></p>
        <p class="MsoNormal"><span lang="EN-US">So I found that I could
            set the CRS with GDALDatasetCreateLayer() while creating a
            layer on the dataset (using the Memory driver)</span></p>
        <p class="MsoNormal"><span lang="EN-US">(<a
href="https://github.com/GenericMappingTools/GMT.jl/blob/master/src/gdal_utils.jl#L254"
              moz-do-not-send="true">https://github.com/GenericMappingTools/GMT.jl/blob/master/src/gdal_utils.jl#L254</a>)</span></p>
        <p class="MsoNormal"><span lang="EN-US"> </span></p>
        <p class="MsoNormal"><span lang="EN-US">But oddly trying to
            inquiry the *<b>ds</b>* with GDALGetSpatialRef() returns an
            empty pointer. I.e.:</span></p>
        <p class="MsoNormal"><span lang="EN-US"> </span></p>
        <p class="MsoNormal"><span lang="EN-US">julia>
            Gdal.GDALGetSpatialRef(ds.ptr)</span></p>
        <p class="MsoNormal"><span lang="EN-US">Ptr{Nothing}
            @0x0000000000000000</span></p>
        <p class="MsoNormal"><span lang="EN-US"> </span></p>
        <p class="MsoNormal"><span lang="EN-US">However the CSR was well
            sored in some place because the ="lixo2.gmt” is correct (it
            has this)</span></p>
        <p class="MsoNormal"><span lang="EN-US"> </span></p>
        <p class="MsoNormal"># @VGMT1.0 @GLINESTRING</p>
        <p class="MsoNormal">#
          @R-8.1/-8/37/37.5                                                      
        </p>
        <p class="MsoNormal"># @Jp"+proj=longlat +datum=WGS84 +no_defs"</p>
        <p class="MsoNormal"><span lang="EN-US">#
            @Jw"GEOGCS[\"unknown\",DATUM[\"WGS_1984\",SPHEROID[\"WGS
84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Longitude\",EAST],AXIS[\"Latitude\",NORTH]]"</span></p>
        <p class="MsoNormal"><span lang="EN-US"># FEATURE_DATA</span></p>
        <p class="MsoNormal"><span lang="EN-US">> </span></p>
        <p class="MsoNormal"><span lang="EN-US">-8 37.0</span></p>
        <p class="MsoNormal"><span lang="EN-US">-8.1 37.5</span></p>
        <p class="MsoNormal"><span lang="EN-US"> </span></p>
        <p class="MsoNormal"><span lang="EN-US">But my trouble is that I
            want to fish the CRS from the ogr2ogr dataset (the ds2
            above) so that I can convert back from GDAL to GMT (which I
            already can) without having to save to a file in disk.</span></p>
        <p class="MsoNormal"><span lang="EN-US"> </span></p>
        <p class="MsoNormal"><span lang="EN-US">So basically my question
            is where is that CRS stored and how can I access it?</span></p>
        <p class="MsoNormal"><span lang="EN-US"> </span></p>
        <p class="MsoNormal"><span lang="EN-US">Thanks</span></p>
        <p class="MsoNormal"><span lang="EN-US"> </span></p>
        <p class="MsoNormal"><span lang="EN-US">Joaquim</span></p>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></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>