Help with assigning name and description to longitude and latitude points

I’ve been following this useful documentation to assign plate IDs and import multiple ODP locations into GPlates.

I am quite new to python and I was wondering if anyone has any suggestions as to the best way to assign more data to each point (such as name/description). Preferably from another column in my input text document.

Thanks

Hi solomon,

To read the name and description from your text file as extra (3rd and 4th) columns you can add something like the following to the try block in the example (that you linked to):

name = str(line_string_list[2])
description = str(line_string_list[3])

…also changing if len(line_string_list) < 2 to if len(line_string_list) < 4.

Then change:

input_points.append(pygplates.PointOnSphere(lat, lon))

…to:

input_points.append((pygplates.PointOnSphere(lat, lon), name, description))

…which is adding a 3-tuple (point, name, description) to the list of points (not just a point).

Then change:

for point in input_points:

…to:

for point, name, description in input_points:

…to extract the 3-tuple back into point, name, description.

And then add:

point_feature.set_name(name)
point_feature.set_description(description)

…after point_feature.set_geometry(point) to set the name and description in the feature.

So the above is about getting the point/name/description from the text file and getting the plate ID from the static polygons. If you had wanted to just get the point from the text file and the name/description/plateID from the static polygons then you would use the properties_to_copy argument of pygplates.partition_into_plates to specify which properties (like name and description) to copy from the static polygon to the point feature (in addition to the plate ID). Note that properties_to_copy can also be a function, so you can write your own function to copy whatever properties you like from the static polygon to the point feature.

Regards,
John

Please ignore that last response.

Hi John,

Thanks for your reply

I have added the line:
input_points.extend(name)
to your suggestions as the .append can only take one argument

This seems to work to create the list but then I get the following error
TypeError: cannot unpack non-iterable PointOnSphere object

from this line:

for point, name in input_points:

which makes me think something is up with the formatting of the list.

Let me know if you have any suggestions and again thanks so much this is going to be incredibly useful for my research.

Solomon

Actually you want to use append (instead of extend) since, in this example, we’re using it to add a single object (that object being a tuple).

To make it more clear you can write:

input_point = point, name
input_points.append(input_point)

…which is equivalent to:

input_points.append((point, name))

…where input_point is the tuple.

Basically a tuple is a way to pack more than one object (eg, point and name) into a single object. By the way, both input_point = point, name and input_point = (point, name) are the same in Python. As are for point, name in input_points and for (point, name) in input_points. But with input_points.append((point, name)) you need the parentheses, otherwise Python thinks you’re calling append(point, name) which is calling append() with two arguments/objects instead of one and you get the error you encountered.

And sorry, in my previous post I had made a typo (fixed now) where I had:

input_points.append((pygplates.PointOnSphere(lat, lon), name, description)

…when I should have had:

input_points.append((pygplates.PointOnSphere(lat, lon), name, description))

…note the extra ) at the end.

Regards,
John

Ahah that makes so much sense thank you so much! That’s worked really well and I’ve managed to also add a further column for feature type so I can display the points in different colours depending on lithologies.

This is kind of unrelated to the topic but do you know where I can find documentation on changing the symbols/colours in a more systematic way than in the GUI ColorByFeature section? For example it would be great if I could make the points bigger so they are clearer and show labels of their name next to them on the map but after doing lots of searching I think this might just not be possible.

Many thanks again for your time!

Solomon

Next year we will overhaul the symbology system in GPlates to allow specifying a specific symbol/size/colour for each feature (point/line/polygon) using rules.

In the meantime you can use the GUI like you mentioned, or you can use the symbol file format currently in GPlates (but to be replaced by the above-mentioned symbology system next year). Have a look at the example symbol file in the GPlates sample data (in SymbolFiles sub-directory). It allows you to specify one of four symbols for point features based on feature type. Here’s the example symbol file (where it notes the restrictions):

# GPlates symbol definition file 
# 
# This file format will be short-lived. 
#
# Each line of this file should be of the form:
#
# feature-type symbol-type symbol-size fill-state
#
# feature-type (text) should be the name of a gpml feature type, such as Volcano, HotSpot etc.
# (but do not prefix with gpml)
#
# Currently we only have support for features with point-like geometry,
# features with 'Position' in the Geometry Property panel of the Feature Creation Dialog
#
# symbol-type (text) must be one of:
# CIRCLE
# CROSS
# SQUARE
# TRIANGLE
#
# symbol-size should be a positive integer. 
# 
# fill-state is optional and should be one of:
# FILLED
# UNFILLED
#
# The default fill-state is FILLED. 
# Not all symbol-types will respect the fill-state (e.g. CROSS)
#
# To use this file in GPlates, load it into GPlates through Features->Load Symbol file...
# 
# Some restrictions on current symbol file usage:
# * Only one file at a time can be loaded
# * Symbol rules in the file will apply to all loaded collections.
# * Only point features will be drawn with symbols.
# * Symbol mapping is only by feature type.
#
MagneticAnomalyIdentification CROSS 2
Volcano TRIANGLE 4 FILLED
HotSpot SQUARE 3 FILLED
Seamount CIRCLE 2 UNFILLED

Hi John, that’s fantastic thank you! I’ve got everything working just as I need now thanks for all your help. One final question: I’m looking at deposition in the Pacific and so is it possible to make a 2D projection but centered around the Pacific ocean rather than the conventional atlas view?

Many thanks,

Solomon

Hi Solomon,

You can change the central meridian to a non-zero value (select View > Set Projection):

image

Regards,
John