-
Notifications
You must be signed in to change notification settings - Fork 224
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
Plot point type geopandas.GeoDataFrames as points directly instead of as lines #1373
Comments
I think I can do that. I'll prefer Solution 2, it seems cleaner and does not involve the plot function that is used in many cases that do not involve pointed Geopandas DataFrame. |
Cool, I've assigned you to the task, feel free to open a Pull Request to work on it and let us know if you need any help 😁 |
I am trying to find a way to specify the style attributes in the temporary OGR_GMT file looking in the following GMT doc page and didn't find the solution. any suggestion on how to set the style in the temporary OGR_GMT file? |
Good question 😅 I'm not sure if it works to be honest, but I know |
So, I tried already your suggestion and you can not set -S in the header. trying to set "# @sc1c" for example will lead to the following error:
with ttt.gmt being
we get and when "# @g" set to POLYGON as follow
we get |
Hmm I see. As I understand it, GMT defaults to plotting lines (even when using Since |
Ping @PaulWessel for comments on this before we merge #1405. |
This behavior predates our understanding of GIS and geometries. However, GMT is generic and if the user wants to plot points, lines, or polygons then that is up the them, not a data set. So I think the only real solution here is for PyGMT to decide if you want to intervene and impose geometry rules. |
I agree with @weiji14 that it's more intuitive to plot symbols rather than lines if the data geometry is Point or MultiPoint. I'm not familiar with geopandas, but my big concern is the inconsistency between passing a GeoDataFrame and passing a file. If I understand it correctly, after PR #1405 is merged, when a GeoDataFrames with a Point/MultiPoint geometry is passed, the data points will be plotted as symbols (square in 2D and cube in 3D). However, if someone saves the GeoDataFrame into a OGR/GMT file, and passes the file to PyGMT, data points will be plotted as lines. Am I understanding it right? |
Yes, this is correct, and is probably more intuitive for a user used to plotting Point/MultiPoint geometries as point symbols.
The problem here is that an OGR/GMT file with a header line containing |
As answered by @PaulWessel in #1373 (comment), it's likely that GMT won't change the behavior. |
That's ok. So the question is, do we prefer PyGMT to:
|
Well, we can discuss this. There is a difference between a plain data file with coordinates and a shapefile or OGR/GMT file that says it has points. I could entertain suggestions to have plot and plot3d give errors if the -S is not selected when geometry is points. |
Option 2 definitely will cause some confusion. For option 3, the problem is, how can PyGMT determines if a text file is a plain text file or an OGR/GMT file. If it's an OGR/GMT file, how can PyGMT know its geometry? As I understand it, PyGMT has to read the file to detect its format and geometry, which is very inefficient if a file is large. |
the major difference between a plain text file and a GMT file is a GMT file contains a header.
Only the header is needed to understand the geometry, so only a few lines are needed. The issue is how to deal with the other acceptable file formats. |
Ok, so for Option 3, how about we detect if a Point type OGR/GMT file is passed in using the following conditions:
If both these conditions are met, we then set the default style |
Sounds a good compromise to me. |
O.K, should I add it at #1405 or on a different pull request? |
Please put it in a separate Pull Request. Oh and btw @yohaimagen, since you belong to the |
Reopening as we need to handle OGR/GMT files too, being done at #1438, but see also upstream GMT issue at GenericMappingTools/gmt#5629. |
Description of the desired feature
scipy-sprint
issues which are easierPyGMT added initial support for plotting geopandas.GeoDataFrame objects in #1000 (see also #608). However, GMT by default will plot lines even if you give it points like so:
Having lines show up can be counter-intuitive, especially to new users unfamiliar with how GMT works. The workaround is to use
fig.plot(data=cities, style="s0.2c", color="black")
so that circles are plotted instead of lines. Ideally however, a POINT based GeoDataFrame should just be plotted as that, points.What needs to be done 🧐
To enable point GeoDataFrames to be plotted directly as points, there are probably a few ways we can update PyGMT's code.
Solution 1
Update the
plot.py
code to add a default style when points are given but nostyle
/-S
argument is given. This would involve changing the code somewhere along here:pygmt/pygmt/src/plot.py
Lines 210 to 211 in d90b3fc
Note that the code for
plot3d
would also need to be updated too at:pygmt/pygmt/src/plot3d.py
Lines 179 to 180 in d90b3fc
Solution 2
Alternatively, we could set the style in the temporary OGR_GMT file somehow, which would involve modifying the code somewhere along here:
pygmt/pygmt/helpers/tempfile.py
Lines 133 to 134 in d90b3fc
Solution 3
Anyone have a better idea? Let's discuss!
Are you willing to help implement and maintain this feature? Happy to mentor someone on tackling this issue.
The text was updated successfully, but these errors were encountered: