Coder Social home page Coder Social logo

Comments (22)

dwcaress avatar dwcaress commented on July 29, 2024

from mb-system.

joa-quim avatar joa-quim commented on July 29, 2024

Dave, just let me add that I'm sad that you decided to go into the C++ way. C++ is simply no good neighbor. Now the possibility of having the MB programs adapted to be GMT modules. like mbcontour for example, and hence be easily accessible from other languages like Matlab or Julia is definitively gone.

from mb-system.

dwcaress avatar dwcaress commented on July 29, 2024

from mb-system.

joa-quim avatar joa-quim commented on July 29, 2024

Dave,

All GMT modules end up as shared libraries. Shared libraries in C++ suffer from the name mangling issue and are not callable by other languages (not even C). That is why C++ is no good neighbor.

Regarding the GeoTiffs, sorry I don't get. grdimage does that since the option to write GeoTiffs was added many years ago.

from mb-system.

PaulWessel avatar PaulWessel commented on July 29, 2024

I think Dave is particular about what is written to the geotiff. THe easy solution would be to rip out most of mbgrdtiff and simply do a module call to GMT_grdimage and return a GMT_IMAGE, which mbgrdtiff can then write out as it sees fit.

from mb-system.

dwcaress avatar dwcaress commented on July 29, 2024

from mb-system.

joa-quim avatar joa-quim commented on July 29, 2024

Ok, this is a simple example with geotiff grids. Tried to project it to make it more clear but some shit in propagating the proj coords metadata is happening

grdimage does not create geotiffs with other than the image. I.e., not images with vector lines. But psconvert does it.

grdmath -R0/20/30/50 -I0.1 X Y MUL = lixo.grd
grdedit lixo.grd -J+proj=longlat
grdconvert lixo.grd lixo.tif=gd:GTiff
gdalinfo lixo.tif

Driver: GTiff/GeoTIFF
Files: lixo.tif
Size is 201, 201
Coordinate System is:
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
...

from mb-system.

dwcaress avatar dwcaress commented on July 29, 2024

from mb-system.

joa-quim avatar joa-quim commented on July 29, 2024

Dave, you'll excuse me but I don't remember that we have done that failed test. I will be making a PR in GMT to fix some bugs related to the non-propagation in some cases of the CRS info when writing either nc or GTiff files. But that is a separate issue. With those fixes one can do
(But maybe it will work for you because the bugs occurred when one uses the -J+proj=utm+zone=32 and the necessary space before +zone was not introduced in some part of the code)

gmt grdmath -R0/20/30/50 -I0.1 X Y MUL = lixo.grd
gmt grdproject lixo.grd -J"+proj=utm +zone=32" -Glixo_utm.grd
gmt grdconvert lixo_utm.grd lixo_utm.tiff=gd:GTiff

gmt grdimage lixo_utm.grd  -JX8c -I+d -Ba -BWSen -P -K > gimg_tif.ps
echo 10 40 | mapproject -J"+proj=utm +zone=32" | gmt psxy -JX8c -Rlixo_utm.grd -Sc1c -Gwhite -O -K >> gimg_tif.ps
gmt grdimage lixo_utm.tiff -JX8c -I+d -Ba -BwSen -X8.5c -O -K >> gimg_tif.ps
echo 10 40 | mapproject -J"+proj=utm +zone=32" | gmt psxy -JX8 -Rlixo_utm.tiff -Sc1c -Gwhite -O -K >> gimg_tif.ps

gmt grdimage lixo_utm.grd -I+d -Agrdimg.tiff        # This is a shaded GTiff IMAGE, not a GRID

gmt grdimage grdimg.tiff -JX8c -X-8.5c -Y8.5c -Ba -BWseN -O -K >> gimg_tif.ps
echo 10 40 | gmt mapproject -J"+proj=utm +zone=32" | gmt psxy -JX8c -Rgrdimg.tiff -Sc1c -Gwhite -O >> gimg_tif.ps

and get
gimg_tif

from mb-system.

joa-quim avatar joa-quim commented on July 29, 2024

PR submitted in GMT. But with this we hijacked the original issue. Sorry.

from mb-system.

PaulWessel avatar PaulWessel commented on July 29, 2024

BTW, I am this close to having redone mbgrdtiff via a call to GMT_grdimage.

from mb-system.

PaulWessel avatar PaulWessel commented on July 29, 2024

I have hacked up a new version of mbgrdtiff.c that uses a call to GMT_grdimage to do the work. Since I am unable to use your github version directly [there must be something that is brew-specific about the configure process], I did this with 5.7.5. Since the new version adds a few new things and deletes most of the old grdimage-lookalike code I think you can easily do this with what is attached and insert into your master version. Here are the steps:

  1. The main differences is a new static function called mbgrdtiff_get_image that takes your options and builds a command string and then calls grdimage and receives the image. Just insert that code into your mbgrdtiff.c above the main function.
  2. Instead of the old image calculations, just keep the new call to that new function and the next three lines, i.e., everything between

/*---------------------------- This is the mbgrdtiff main code ----------------------------*/
and
/*------------------------- Write out the GeoTiff and world files -------------------------*/

  1. Compile with -Wall and remove all the unused variables. I tested this and both the new and old 5.7.5 mbgrdtiff gives me the same tiff file.

One caveat is that this requires GMT 6.x since I had to fix some issues in grdimage to make this work.

mbgrdtiff_new.c.txt

from mb-system.

PaulWessel avatar PaulWessel commented on July 29, 2024

Note the old mbgrdtiff lists options in the usage message that are not available in that module (-B, -K, -P, -X, etc). I deleted all of those.
Also, looks like 5.7.5 version crashes since it is accessing Grid_orig[0] in a fprintf (stderr message long after Grid_orig has been destroyed.

from mb-system.

dwcaress avatar dwcaress commented on July 29, 2024

Ok, thanks. I will try it out. Jumping back to the beginning of the thread, I've duplicated the build error you found when building with prerequisites installed through MacPorts.

from mb-system.

dwcaress avatar dwcaress commented on July 29, 2024

And I fixed the build error that died at mbsvpselect. I needed to add libproj_CPPFLAGS to AM_CPPFLAGS in src/utilities/Makefile.am, and then resconstruct the build system. This fix has been merged into master.

from mb-system.

PaulWessel avatar PaulWessel commented on July 29, 2024

Great, I will give it a try. if that works, would you want me to submit a PR for the tiff stuff instead?

from mb-system.

dwcaress avatar dwcaress commented on July 29, 2024

Does this work with the GMT 6.0.0 release?

from mb-system.

PaulWessel avatar PaulWessel commented on July 29, 2024

No, since it doing this I found a bug. This was the first time we called GMT_grdimage and wanted a memory reference to an image back, so had not been tested before. Minor bug, but not in 6.0.0.

from mb-system.

dwcaress avatar dwcaress commented on July 29, 2024

So, no, don't put it into a PR. You've given me the code - I need to wrap it in conditionals so we can still build and work with GMT 6.0.0, and for the time being, GMT 5.4.5. I'll try to do it moderately cleanly. I take it the required mods to GMT are merged into your master branch, correct?

Thanks. This is definitely an improvement.

from mb-system.

PaulWessel avatar PaulWessel commented on July 29, 2024

OK, that is fine. Yes, the fix has ben committed to our master branch. Let me know if anything fails.

from mb-system.

dwcaress avatar dwcaress commented on July 29, 2024

from mb-system.

schwehr avatar schwehr commented on July 29, 2024

Dave, just let me add that I'm sad that you decided to go into the C++ way. C++ is simply no good neighbor. Now the possibility of having the MB programs adapted to be GMT modules. like mbcontour for example, and hence be easily accessible from other languages like Matlab or Julia is definitively gone.

I strongly disagree with your blanket statement about C++.

C++ doesn't impact the ABI if used from a C API. e.g. gdal and lots of other open source projects. IMHO, C++ ( > 11 ) makes for much more robust internals to libraries. I did nothing with C++ in MB-System that impacts the ABI. If it was up to me, all of MB-System would be C++ >= 17 with a C APIs for basic use by others. The reliability and standardization of basic functionality is such a huge win.

from mb-system.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.