Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First cut to use the GEOS library to compute buffer zones around polylines #2961

Merged
merged 10 commits into from
Jul 2, 2020

Conversation

joa-quim
Copy link
Member

@joa-quim joa-quim commented Mar 23, 2020

This PR is a first cut in using the GEOS library. This library is a common but not mandatory dependency of GDAL. It's also a damn poorly documented lib, which makes it very hard to learn how to use.

It needs to be build with -DHAVE_GEOS and add this to ConfigUser.make.

	set (GEOS_INCLUDE_DIR "/path/to/geos/include/")
	set (GEOS_LIBRARY     "path/to/geos/lib/libgeos_c.lib")

I have added a tmp -Z option to gmtspatial to compute buffer zones around polylines. It works nicely but we need to create an infrastructure to accommodate all the power the use of this lib can bring to GMT.

Example usage with julia:

buf = gmtspatial([0.0 0; 1 1], Z=1);
plot(buf, aspect=:equal)
plot!([0.0 0; 1 1], savefig="buf.png", show=true)

buf

@PaulWessel
Copy link
Member

Do you know if this is Cartesian only or does it work on spherical surfaces?

@joa-quim
Copy link
Member Author

joa-quim commented Mar 23, 2020

Almost (100% - eps) sure it's Cartesian only. But. as I said, it's unbelievable how GEOS is so poorly documented. Had to build it in debug mode, and use debugger, to find out why it was failing for apparently simple calls.

@PaulWessel
Copy link
Member

Fake name GEO(s) then.

@joa-quim
Copy link
Member Author

Probably it stands for GEOmetries as that is the basic building block.

@joa-quim joa-quim mentioned this pull request Apr 2, 2020
@joa-quim
Copy link
Member Author

Should we commit this? It can do more but the buffer line is already a quite useful thing.

@PaulWessel
Copy link
Member

If you have not already, please merge master into that branch first and make sure no conflicts and run all tests, etc. Then we can continue discussing after the first intro session coming up.

@PaulWessel
Copy link
Member

May need to spell out the endif in Cmake:

CMake Warning (dev) in src/CMakeLists.txt:

  A logical block opening on the line

    /Users/pwessel/GMTdev/gmt-dev/src/CMakeLists.txt:158 (if)

  closes on the line

    /Users/pwessel/GMTdev/gmt-dev/src/CMakeLists.txt:162 (endif)

  with mis-matching arguments.
This warning is for project developers.  Use -Wno-dev to suppress it.

@PaulWessel
Copy link
Member

A few more things - do I need to set anything to try this branch?

[155/254] Building C object src/CMakeFiles/gmtlib.dir/gmtspatial.c.o
../src/gmtspatial.c:2184:11: warning: implicit declaration of function 'geos_methods' is invalid in C99 [-Wimplicit-function-declaration]
                error = geos_methods(GMT, D, Ctrl->Out.file, Ctrl->S.width, "buffer");
                        ^
../src/gmtspatial.c:2185:3: warning: implicit declaration of function 'finishGEOS' is invalid in C99 [-Wimplicit-function-declaration]
                finishGEOS();
                ^
../src/gmtspatial.c:2190:11: warning: implicit declaration of function 'geos_methods' is invalid in C99 [-Wimplicit-function-declaration]
                error = geos_methods(GMT, D, Ctrl->Out.file, 0, "centroid");
                        ^
../src/gmtspatial.c:2191:3: warning: implicit declaration of function 'finishGEOS' is invalid in C99 [-Wimplicit-function-declaration]
                finishGEOS();
                ^

and

ndefined symbols for architecture x86_64:
  "_geos_methods", referenced from:
      _GMT_gmtspatial in gmtspatial.c.o
ld: symbol(s) not found for architecture x86_64

@PaulWessel
Copy link
Member

It seems like it found the library though:

-- Found GEOS: /opt/local/lib/libgeos_c.dylib (3.8.1)

@joa-quim
Copy link
Member Author

It needs to be build with -DHAVE_GEOS and I need to find again how my example worked (probably after dinner)

Copy link
Member

@PaulWessel PaulWessel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But since it found the geos library, why did it complain about the function prototypes?

@joa-quim
Copy link
Member Author

Because we need an automatic way of setting HAVE_GEOS when the lib is found. Since it is not set, the call to finishGEOS(); lead to errors.

@PaulWessel
Copy link
Member

Looks like you dont have anything about GEOS in gmt_confit.h.in? E.g., something like this that gets configured

#cmakedefine HAVE_GDAL

@joa-quim
Copy link
Member Author

joa-quim commented Jul 1, 2020

Don't get what is happening. The build is failing on Windows apparently because it finds geos.lib (which is the c++ lib) instead if geos_c.lib. But works on *nix, although I can't find the logs (always so damn complicated to find the logs).
It works for me locally, but I set in my ConfigUser.cmake

        set (GEOS_INCLUDE_DIR "/path/to/geos/include/")
	set (GEOS_LIBRARY     "path/to/geos/lib/libgeos_c.lib")

@joa-quim joa-quim changed the title WIP First cut to use the GEOS library to compute buffer zones around polylines First cut to use the GEOS library to compute buffer zones around polylines Jul 1, 2020
@seisman
Copy link
Member

seisman commented Jul 2, 2020

Now the CI on Win passes.

@joa-quim
Copy link
Member Author

joa-quim commented Jul 2, 2020

Good, so ready to merge.

@joa-quim joa-quim merged commit cc22c20 into master Jul 2, 2020
@joa-quim joa-quim deleted the buffer_GEOS branch July 2, 2020 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants