Created
July 16, 2013 20:45
-
-
Save rclark/6012494 to your computer and use it in GitHub Desktop.
Layer generation action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def publish(context, data_dict): | |
# Gather inputs | |
resource_id = data_dict.get("resource_id", None) | |
layer_name = data_dict.get("layer_name", resource_id) | |
username = context.get("user", None) | |
package_id = data_dict.get("package_id", None) | |
lat_field = data_dict.get("col_latitude", None) | |
lng_field = data_dict.get("col_longitude", None) | |
# Check that you have everything you need | |
if None in [resource_id, layer_name, username, package_id]: | |
raise Exception("Not enough information to publish resource") | |
# Publish a layer | |
l = Layer.publish(package_id, resource_id, layer_name, username, lat_field=lat_field, lng_field=lng_field) | |
# Confirm that everything went according to plan | |
if l is None: | |
raise Exception("Layer generation failed") | |
else: | |
# csv content should be spatialized or a shapefile uploaded, Geoserver updated, resources appended. | |
# l should be a Layer instance. Return whatever you wish to | |
return "Success" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment