-
Notifications
You must be signed in to change notification settings - Fork 13
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
unify the geometries of COBs in Muller2016 #226
Comments
I see that it’s been modified to use If it became an issue you could instead have something like:
|
Good pick up, @jcannon-gplates! |
Has there been any progress made on this? |
Can we find a RA to do this? |
The COBs in GeoData 2.5 are polylines. Shall we follow it as example and convert all COB polygons in Muller2016 to polylines? Alternatively, we can create two COB files for Muller2016, one with polygons and the other with polylines. Hi @bsim8882, |
Let's follow John's suggestion #302 (comment) I think we should allow users to do both way, polyline->ploygon and polygon->polyline. |
@michaelchin, I use the script above to convert the agegridding-masking COBs to polygons for plotting/analysis. I don't know if GPlately has these at all, but for example, for Müller et al. 2019 it is the file on the USyd-github in |
Thanks @nickywright Yes, you are right. We should not change the COBs in GeoData. We will mainly focus on fixing the COBs in Muller2016 in this Issue. For model Muller2019, we are using a file named Global_EarthByte_GeeK07_COBLineSegments_2019_v1.gpmlz and it looks similar to the one in GeoData. I wonder if there is such a file in model Muller2016 as well. Anyway, it is no harm to add new functions to convert between polylines and polygons in GPlately. And Bianca can use this Issue to get started with GPlates development work. |
I agree that adding the polylines-->polygons function would be super handy! |
Yes I think converting polygons to polylines is fine. But converting polylines to polygons has the problem Nicky mentioned (ie, polylines aren't closed). One idea for conversion script is to detect if the polylines are closed and only convert if so. I vaguely recall some old datasets that ended up being closed polylines instead of polygons. These would be good for converting to polygons. Some random issues that may arise when converting an entire dataset to a single geometry type as required for #214:
|
Yes, I agree that we need a comprehensive plan down the road. For this Issue, I would like to focus on fixing the COBs for Muller2016 model only. We can create new github Issues to track the various ideas. But I would like to make this one simple and clear. I don't want Bianca feel overwhelmed at this stage. |
No problem 👍. Yes, let's wait and see how this pans out. And then later we can create a new issue if something more comprehensive is needed. |
@jcannon-gplates I might have done something wrong or misunderstood the gplately/gplately/utils/convert_geometries.py Lines 36 to 41 in 8655930
|
@bsim8882 Could you please try to follow the instructions in the source code? Thanks. gplately/tests-dir/unittest/test_convert_geometries.py Lines 27 to 44 in 8655930
|
I think your understanding is correct. I suspect what is happening is the property name of the original polyline is not the default geometry property name. And so This is why I noted to myself in the PR here that...
...because I think using It's actually a little bit tricky to do this properly. Perhaps something like this, which converts any polylines to polygons (in a single feature), retaining their property names and leaving non-polylines unchanged: # First step: gather all geometry property names (ignore other properties).
geometry_property_names = []
for property in feature:
# If it's a geometry property then add the property name to the list.
if property.get_value().get_geometry():
geometry_property_names.append(property.get_name())
# Second step: convert polylines to polygons (don't convert other geometry types).
for geometry_property_name in geometry_property_names:
# Get all geometries with the current property name.
#
# NOTE: I'm specifying the property name rather than relying on the default.
geometries_with_property_name = feature.get_geometries(geometry_property_name)
# Among the current geometries, convert any polylines to polygons (leave the other types alone).
for geometry_index, geometry in enumerate(geometries_with_property_name):
if isinstance(geometry, pygplates.PolylineOnSphere):
# As a bonus, only convert polyline if it is closed (ie, its first and last vertices are equal).
# Otherwise converting to a polygon will be dodgy (as Nicky pointed out).
if geometry[0] == geometry[-1]:
polygon = pygplates.PolygonOnSphere(geometry)
geometries_with_property_name[geometry_index] = polygon
# Set all geometries with the current property name.
#
# NOTE: I'm specifying the property name rather than relying on the default.
feature.set_geometry(geometries_with_property_name, geometry_property_name) ...where the first step gathers all the property names associated with geometry properties (ie, ignores plate ID properties, etc). And the second step only converts polylines to polygons (and only if the polylines are closed). Also, it doesn't change the property names inadvertently. And it retains any original points, multi-points and polygons. A similar thing could be done for converting the other way - from polygons to polylines (except without checking that polygons are closed). A final note, this should pretty much avoid any GPGIM issues, but there's still a small chance it could happen if a particular geometry property name only supports a subset of geometry types (eg, might only support polygons, not polylines, and so can't convert polygon to polyline). But I don't think any of these properties actually exist in the GPGIM currently (for example, the gpml:centerLineOf property supports all geometry types). In any case, if there was a problem then the |
hi @bsim8882 commit 926b315 looks great. Just one tiny thing, normally we don't check in data/log/generated files. Ideally, we only check in source code/configuration files(basically files with a good reason to track). And do you want to try do this function? gplately/gplately/utils/convert_geometries.py Lines 83 to 103 in 0a72e3f
@jcannon-gplates Do you have better ideas of converting polygons to polylines? |
There's a tricky gotcha here. If you convert using: polyline = pygplates.PolylineOnSphere(polygon) ...then it'll convert the exterior ring only (ignoring any interior rings). But it'll also make sure the converted polyline is closed (because it knows it's a polygon). Alternatively, if you do this: polyline = pygplates.PolylineOnSphere(polygon.get_exterior_ring_points()) ...then it won't ensure the converted polyline is closed (because it doesn't know the points are from a polygon). For example, if you convert a triangle polygon (with vertices A, B, C) to a polyline then:
So I'd recommend the first case if we're only converting the exterior ring of a polygon to a polyline. |
Then there's the question of whether to also make polylines from interior rings? To be honest, I'm not sure. Maybe @nickywright has an idea on whether there are datasets where, say, a polygon with 2 interior rings should be converted to 3 separate polylines (one for the exterior ring and two for the interior rings)? If so, then I can add to pyGPlates the ability to do: polylines = pygplates.PolylineOnSphere(polygon, convert_interior_rings=True) ...where specifying Update: Actually it'd probably be more like: polylines = pygplates.PolylineOnSphere.convert_from(polygon, convert_interior_rings=True) ...since |
Hi @bsim8882 let's do what John said above. It is simple and clean.
|
Does converting polygons to polylines impact on the masking of age grids? |
I am unsure about this. @jcannon-gplates do you know anything about this? |
For regular masking (ie, not continent contouring)... It looks like polylines are converted to polygons in
...so that's good. However, I'm not sure what Lines 802 to 803 in ece4c2d
...it may be that it should instead be called with Lines 296 to 298 in ece4c2d
|
For continent contouring... Luckily it looks like polylines are converted to polygons before the contouring begins: gplately/gplately/ptt/continent_contours.py Lines 641 to 653 in ece4c2d
As noted, it only works if the polylines are closed. But if we've converted polygons to polylines beforehand then they will be closed polylines. |
So overall it might be ok with the above-mentioned fixup for regular (non-contoured) masking. The only other issue is polygons with interior holes would not have the holes contribute to the mask. |
Currently, the geometries of COBs in Muller2016 are a mixture of polygons and polylines. The mixture is causing problem when being plotted in GPlately. We need to modify the COBs and make the geometries all polygons(or polylines?).
Thanks to @nickywright for providing us with a code snippet to convert polylines to polygons.
Thanks to @jcannon-gplates for providing valuable suggestion.
The text was updated successfully, but these errors were encountered: