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

Adding crs_converter to Galaxy ecology #119

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tools/crs_converter/.shed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: crs_converter
owner: ecology
description: Geospatial transformation of a shapefile Coordinate Reference Systems
homepage_url: https://github.com/Rassine/Rassine-tools-Gecology/tree/master/tools/crs_converter
long_description: |
This tool was created to be part of a phylodiversity workflow. It creates a PROJ4 string from the option selected by the users and use the string to convert the coordinate reference system of a given geospatial file into another one. This tool also offers to produce output in different formats for wider options of manipulation and visualisation.
remote_repository_url: https://github.com/galaxyecology/tools-ecology/tree/master/tools/crs_converter
type: unrestricted
categories:
- Ecology
auto_tool_repositories:
name_template: "{{ tool_id }}"
description_template: "Convert Coordinate Reference Systems of shapefiles"
140 changes: 140 additions & 0 deletions tools/crs_converter/CRS_macros.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<macros>
<xml name='ellps_options'>
<param name ='ellps' type='select' checked='true'
label='Ellipsoid and Datum' help='The name of built-in ellipsoid definition. Defines shape and center of earth simplified model used for projection.
See https://proj.org/en/9.4/usage/ellipsoids.html#ellipsoids for more informations.'>
Copy link
Collaborator

Choose a reason for hiding this comment

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

more information in the help section ?

<option value='GRS80'>GRS80</option>
<option value='airy'>airy</option>
<option value='bessel'>bessel</option>
<option value='clrk66'>clrk66</option>
<option value='WGS60'>WGS60</option>
<option value='WGS66'>WGS66</option>
<option value='WGS72'>WGS72</option>
<option value='WGS84' selected='true'>WGS84</option>
<option value='sphere'>sphere</option>
</param>
</xml>


<xml name='latitude_options'>
<param name ='lat_0' type='integer' value='0'
label='Latitude' help='Latitude of natural origin,
latitude of false origin or latitude of projection centre
(naming and meaning depend on the projection method).'/>
</xml>


<xml name='latitude_1_options'>
<param name ='lat_1' type='integer' value='1'
label='Latitude 1' help='First standard parallel.'/>
</xml>


<xml name='latitude_2_options'>
<param name ='lat_2' type='integer' value='1'
label='Latitude 2' help='Second standard parallel.'/>
</xml>


<xml name='latitude_ts_options'>
<param name ='lat_ts' type='integer' value='0'
label='Latitude of true scale' help='Defines the latitude where scale is not distorted.
Takes precedence over scale factor K if both options are used together.'/>
</xml>


<xml name='longitude_options'>
<param name ='lon_0' type='integer' value='0'
label='Longitude' help='Central meridian/longitude of natural origin,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same the help is not clear for me

longitude of origin or longitude of false origin
(naming and meaning depend on the projection method).'/>
</xml>


<xml name='X_options'>
<param name ='x_0' type='integer' value='0'
label='X' help='False easting, easting at false origin or easting at projection centre.
(naming and meaning depend on the projection method). Always in meters. Use Ex: Shifting projection on an East-Weast axis'/>
</xml>


<xml name='Y_options'>
<param name ='y_0' type='integer' value='0'
label='Y' help='False northing, northing at false origin or northing at projection centre.
(naming and meaning depend on the projection method). Always in meters. Use Ex: Shifting projection on a North-South axis'/>
</xml>


<xml name='K_options'>
<param name='k_0' type='integer' value='1' min='1'
label='Scale factor K' help='Scale factor. Determines scale factor used in the projection.'/>
</xml>


<xml name='zone_options'>
<param name ='zone' type='integer' value='1' min='1' max='60'
label='Select which UTM zone to use' help='Can be a value between 1-60.'/>
</xml>


<xml name='south_options'>
<param name ='south' type='boolean' checked='false'
label='South hemisphere' help='Add this flag when using the UTM on the southern hemisphere.'/>
</xml>


<xml name='approx_options'>
<param name ='approx' type='boolean' checked='false'
label='Approximation algorithm' help='Use faster, less accurate algorithm for the Transverse Mercator.'/>
</xml>


<xml name='algo_options'>
<param name ='algo' type='select' optional='false'
label='Selects the algorithm to use.' help='Default value is poder_engsager.
When using auto, an heuristics based on the input coordinate is used to
determine if the faster Evenden-Snyder method can be used for faster
computation without causing an error greater than 0.1 mm
(for an ellipsoid of the size of Earth)'>
<option value='auto'>Auto</option>
<option value='evenden_snyder'>Evenden Snyder</option>
<option value='poder_engsager' selected='true'>Poder Engsager</option>
</param>
</xml>


<xml name='asc_lon_options'>
<param name ='asc_lon' type='integer' value='0'
label='Ascending Longitude' help='Longitude of the ascending node for the orbit (decimal degrees).'/>
</xml>


<xml name='inc_angle_options'>
<param name ='inc_angle' type='integer' value='90'
label='Inclination angle' help='Inclination (vertical tilt) of the orbit
with respect to the reference plane, measured at the ascending node (decimal degrees).'/>
</xml>


<xml name='ps_rev_options'>
<param name ='ps_rev' type='integer' value='1'
label='Revolution time' help='Time required for a single orbit (days).'/>
</xml>


<xml name='units_options'>
<param name ='units' type='select' checked='true'
label='Units' help='Default is meter.'>
<option value='m' selected='true'>m</option>
<option value='mm'>mm</option>
<option value='cm'>cm</option>
<option value='dm'>dm</option>
<option value='km'>km</option>
<option value='kmi'>International Nautical Mile (kmi)</option>
<option value='us-in'>US in</option>
<option value='us-ft'>US ft</option>
<option value='us-yd'>US yd</option>
<option value='us-mi'>US mi</option>
</param>
</xml>
</macros>
56 changes: 56 additions & 0 deletions tools/crs_converter/CRSconverter.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/Rscript

library(sf)
library(tidyr)

args = commandArgs(trailingOnly=TRUE)
output_list <- strsplit(as.character(args[2]), ',')[[1]]



save_as_pdf_fun <- function(){

pdf(file = 'PDF_output.pdf')
plot(st_geometry(Transformed_spacial_coordinates))
dev.off()
}


save_as_shp_fun <- function(){

write_sf(Transformed_spacial_coordinates, 'shapefile.shp')
}


save_as_image_fun <- function(format){

img_fun = as.list(paste(format, '_output.', format, sep = '', collapse = NULL))
do.call(format, img_fun)
plot(st_geometry(Transformed_spacial_coordinates))
dev.off()
}



if (length(args)<2){stop('Insufficient number of argument, please review command Line')
}else{
Spacial_coordinates_files <- read_sf(as.character(args[1]), layer = 'shapefile')
projection <- as.character(args[4])

for (n_arg in 5:length(args)) {
projection <- paste(projection, as.character(args[n_arg]),sep = '', collapse = NULL)
}

projection <- paste(projection, ' +no_defs',sep = '', collapse = NULL)
Transformed_spacial_coordinates <- st_transform(Spacial_coordinates_files, crs = projection)
for (a in output_list) {
if (as.character(a) == 'pdf') {
save_as_pdf_fun()
next

} else if (as.character(a) == 'shp') {
save_as_shp_fun()
next

} else { save_as_image_fun(as.character(a)) }
}}
Loading
Loading