Mercurial > repos > ecology > crsconverter
changeset 0:d19c3cbbdd7e draft
planemo upload for repository https://github.com/galaxyecology/tools-ecology/tree/master/tools/Phylodiversity_workflow commit 0de557d919c26eb0b5ab61504bc597d551503ac3
author | ecology |
---|---|
date | Tue, 20 May 2025 09:52:08 +0000 |
parents | |
children | 4bcab54d19eb |
files | CRSconverter.R CRSconverter.xml test-data/composite_dataset/composite_dataset_shp.html test-data/composite_dataset/shapefile.dbf test-data/composite_dataset/shapefile.prj test-data/composite_dataset/shapefile.shp test-data/composite_dataset/shapefile.shx test-data/output.bmp test-data/output.jpeg test-data/output.pdf test-data/output.png test-data/output.tiff test-data/shapefile/output.dbf test-data/shapefile/output.prj test-data/shapefile/output.shp test-data/shapefile/output.shx test-data/shapefile/shapefile_shp.html |
diffstat | 17 files changed, 370 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CRSconverter.R Tue May 20 09:52:08 2025 +0000 @@ -0,0 +1,84 @@ +#!/bin/Rscript +# GRID CREATION +args = commandArgs(trailingOnly=TRUE) + +library(sf) +library(tidyr) + + +save_as_pdf_fun <- function(){ + + pdf(file = "output.pdf") + plot(st_geometry(Transformed_spacial_coordinates)) + dev.off() +} + + +save_as_image_fun <- function(format){ + + filename <- paste0("output.", format) + # Ouvre le bon device graphique selon le format demandé + switch(format, + png = png(filename), + jpeg = jpeg(filename), + tiff = tiff(filename), + bmp = bmp(filename), + stop("Unsupported format: ", format) + ) + plot(st_geometry(Transformed_spacial_coordinates)) + dev.off() +} + + +save_as_shp_fun <- function(){ + write_sf(Transformed_spacial_coordinates, "output.shp") +} + + + + +if (length(args)<1){stop('please provide spacial coordinates files(.shp files)') +}else{ + Spacial_coordinates_files <- read_sf(as.character(args[1]), layer = 'shapefile') + output_file <- args[10] + + projection <- paste('+proj=' + , as.character(args[2]) + , ' +lat_0=' + , as.character(args[3]) + , ' +lon_0=' + , as.character(args[4]) + , ' +x_0=' + , as.character(args[5]) + , ' +y_0=' + , as.character(args[6]) + , ' +ellps=' + , as.character(args[7]) + , ' +datum=' + , as.character(args[7]) + , ' +units=' + , as.character(args[8]) + , ' +no_defs', sep = "", collapse = NULL) #presonalisation du systeme de références + + Transformed_spacial_coordinates <- st_transform(Spacial_coordinates_files, crs = projection) + + if (as.character(args[9]) == "pdf") { + save_as_pdf_fun() + + } else if (as.character(args[9]) == "shp") { + save_as_shp_fun() + + } else { + save_as_image_fun(as.character(args[9])) + } +} + + + + + + +#write.table(Transformed_spacial_coordinates, file = "output.tabular", sep="\t", row.names=FALSE) + #enregistrement dans quoi ? + +#this tool convert shp files to the right format for whatever you like ~a phylodiversity analysis
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CRSconverter.xml Tue May 20 09:52:08 2025 +0000 @@ -0,0 +1,250 @@ +<tool id="crsconverter" name="CRSconverter" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="21.05"> + <description>from environmental predictors for species distribution modeling</description> + + <macros> + <token name="@TOOL_VERSION@">1.0</token> + <token name="@VERSION_SUFFIX@">0</token> + </macros> + + <requirements> + <requirement type="package" version="1.0_16">r-sf</requirement> + <requirement type="package" version="1.3.1">r-tidyr</requirement> + </requirements> + + <required_files> + <include path="CRSconverter.R" /> + </required_files> + + <command detect_errors="exit_code"> + <![CDATA[ + Rscript '$__tool_directory__/CRSconverter.R' + #if $coordinates_file_input.is_of_type("shp") + ${os.path.join( $coordinates_file_input.extra_files_path, "shapefile.shp" )} + #else + '$coordinates_file_input' + #end if + ${advanced_options.projection} + ${advanced_options.latitude} + ${advanced_options.longitude} + ${advanced_options.X} + ${advanced_options.Y} + ${advanced_options.ellps_datum} + ${advanced_options.units} + ${output_file_format} + "output" + + #if $output_file_format == 'shp' + && + mkdir -p '$shapefile.extra_files_path' && + mv output.* ${shapefile.extra_files_path} + #else + && mv output.* '$output' + #end if + ]]> + </command> + <inputs> + <param name ="coordinates_file_input" type="data" format="shp" + label="shapefile" help="Provide coordinates files"/> + <section name="advanced_options" title= "Advanced Option" expanded="false"> + <param name ="projection" type="select" checked="true" + label="Projection type" help="Choose a projection ."> + <option value="laea" selected="true">laea</option> + </param> + <param name ="latitude" type="integer" value="0" + label="Latitude" help="Choose a projection ."/> + <param name ="longitude" type="integer" value="0" + label="Longitude" help="Choose a projection ."/> + <param name ="X" type="integer" value="0" + label="X" help="Choose a projection ."/> + <param name ="Y" type="integer" value="0" + label="Y" help="Choose a projection ."/> + <param name ="ellps_datum" type="select" checked="true" + label="Ellipsoid and Datum" help="Choose a projection ."> + <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> + <param name ="units" type="select" checked="true" + label="Units" help="Choose a projection ."> + <option value="m" selected="true">m</option> + <option value="Km">Km</option> + <option value="Hm">Hm</option> + </param> + </section> + + <param name ="output_file_format" type="select" checked="true" + label="Choose output format" help="choose"> + <option value="shp" selected="true">shp</option> + <option value="pdf">pdf</option> + <option value="png">png</option> + <option value="jpeg">jpeg</option> + <option value="tiff">tiff</option> + <option value="bmp">bmp</option> + </param> + </inputs> + + <outputs> + <data name="output" from_work_dir="output" format="xml" label="${on_string}.${output_file_format}"> + <filter> + output_file_format != 'shp' + </filter> + <change_format> + <when input="output_file_format" value="pdf" format="pdf"/> + <when input="output_file_format" value="png" format="png"/> + <when input="output_file_format" value="jpeg" format="jpg"/> + <when input="output_file_format" value="tiff" format="tiff"/> + <when input="output_file_format" value="bmp" format="bmp"/> + </change_format> + </data> + <data name="shapefile" format="shp" from_work_dir="shapefile" label="${on_string}.shapefile"> + <filter> + output_file_format == 'shp' + </filter> + </data> + </outputs> + + <tests> + <test expect_num_outputs="1"> + <param name="coordinates_file_input" value="composite_dataset/shapefile" ftype="shp"> + <composite_data value="composite_dataset/shapefile.shp"/> + <composite_data value="composite_dataset/shapefile.shx"/> + <composite_data value="composite_dataset/shapefile.dbf"/> + <composite_data value="composite_dataset/shapefile.prj"/> + </param> + <section name="advanced_options"> + <param name="projection" value="laea"/> + <param name="latitude" value="-90"/> + <param name="longitude" value="0"/> + <param name="X" value="0"/> + <param name="Y" value="0"/> + <param name="ellps_datum" value="WGS84"/> + <param name="units" value="m"/> + </section> + <param name ="output_file_format" value="shp"/> + + <output file="shapefile/shapefile_shp.html" name="shapefile"> + <extra_files type="file" name="output.shp" value="shapefile/output.shp"/> + <extra_files type="file" name="output.shx" value="shapefile/output.shx"/> + <extra_files type="file" name="output.dbf" value="shapefile/output.dbf" compare="sim_size" delta="50"/> + <extra_files type="file" name="output.prj" value="shapefile/output.prj"/> + </output> + </test> + <test expect_num_outputs="1"> + <param name="coordinates_file_input" value="composite_dataset/shapefile" ftype="shp"> + <composite_data value="composite_dataset/shapefile.shp"/> + <composite_data value="composite_dataset/shapefile.shx"/> + <composite_data value="composite_dataset/shapefile.dbf"/> + <composite_data value="composite_dataset/shapefile.prj"/> + </param> + <section name="advanced_options"> + <param name="projection" value="laea"/> + <param name="latitude" value="-90"/> + <param name="longitude" value="0"/> + <param name="X" value="0"/> + <param name="Y" value="0"/> + <param name="ellps_datum" value="WGS84"/> + <param name="units" value="m"/> + </section> + <param name ="output_file_format" value="pdf"/> + + <output file="output.pdf" name="output" ftype="pdf"/> + </test> + <test expect_num_outputs="1"> + <param name="coordinates_file_input" value="composite_dataset/shapefile" ftype="shp"> + <composite_data value="composite_dataset/shapefile.shp"/> + <composite_data value="composite_dataset/shapefile.shx"/> + <composite_data value="composite_dataset/shapefile.dbf"/> + <composite_data value="composite_dataset/shapefile.prj"/> + </param> + <section name="advanced_options"> + <param name="projection" value="laea"/> + <param name="latitude" value="-90"/> + <param name="longitude" value="0"/> + <param name="X" value="0"/> + <param name="Y" value="0"/> + <param name="ellps_datum" value="WGS84"/> + <param name="units" value="m"/> + </section> + <param name ="output_file_format" value="png"/> + + <output file="output.png" name="output" ftype="png"/> + </test> + <test expect_num_outputs="1"> + <param name="coordinates_file_input" value="composite_dataset/shapefile" ftype="shp"> + <composite_data value="composite_dataset/shapefile.shp"/> + <composite_data value="composite_dataset/shapefile.shx"/> + <composite_data value="composite_dataset/shapefile.dbf"/> + <composite_data value="composite_dataset/shapefile.prj"/> + </param> + <section name="advanced_options"> + <param name="projection" value="laea"/> + <param name="latitude" value="-90"/> + <param name="longitude" value="0"/> + <param name="X" value="0"/> + <param name="Y" value="0"/> + <param name="ellps_datum" value="WGS84"/> + <param name="units" value="m"/> + </section> + <param name ="output_file_format" value="jpeg"/> + + <output file="output.jpeg" name="output" ftype="jpg"/> + </test> + <test expect_num_outputs="1"> + <param name="coordinates_file_input" value="composite_dataset/shapefile" ftype="shp"> + <composite_data value="composite_dataset/shapefile.shp"/> + <composite_data value="composite_dataset/shapefile.shx"/> + <composite_data value="composite_dataset/shapefile.dbf"/> + <composite_data value="composite_dataset/shapefile.prj"/> + </param> + <section name="advanced_options"> + <param name="projection" value="laea"/> + <param name="latitude" value="-90"/> + <param name="longitude" value="0"/> + <param name="X" value="0"/> + <param name="Y" value="0"/> + <param name="ellps_datum" value="WGS84"/> + <param name="units" value="m"/> + </section> + <param name ="output_file_format" value="tiff"/> + + <output file="output.tiff" name="output" ftype="tiff"/> + </test> + <test expect_num_outputs="1"> + <param name="coordinates_file_input" value="composite_dataset/shapefile" ftype="shp"> + <composite_data value="composite_dataset/shapefile.shp"/> + <composite_data value="composite_dataset/shapefile.shx"/> + <composite_data value="composite_dataset/shapefile.dbf"/> + <composite_data value="composite_dataset/shapefile.prj"/> + </param> + <section name="advanced_options"> + <param name="projection" value="laea"/> + <param name="latitude" value="-90"/> + <param name="longitude" value="0"/> + <param name="X" value="0"/> + <param name="Y" value="0"/> + <param name="ellps_datum" value="WGS84"/> + <param name="units" value="m"/> + </section> + <param name ="output_file_format" value="bmp"/> + + <output file="output.bmp" name="output" ftype="bmp"/> + </test> + </tests> + + <help><![CDATA[ + This tool transforms geographical vector data (in shapefile format) to a specified coordinate reference system (CRS) + and allows you to export the result in various formats, including shapefile and image formats (PDF, PNG, JPEG, TIFF, BMP). + Ensure that the input files are in the correct formats: + - Shapefile : commposite file, shp format + ]]></help> + <citations> + <citation type="doi">10.32614/CRAN.package.sf</citation> + <citation type="doi">10.32614/CRAN.package.tidyr</citation> + </citations> +</tool>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/composite_dataset/composite_dataset_shp.html Tue May 20 09:52:08 2025 +0000 @@ -0,0 +1,17 @@ +<html><head><title>Shapefile Galaxy Composite Dataset</title></head><p/> +<div>This composite dataset is composed of the following files:<p/><ul> +<li><a href="shapefile.shp" type="application/binary">shapefile.shp (Geometry File (shp))</a></li> +<li><a href="shapefile.shx" type="application/binary">shapefile.shx (Geometry index File (shx))</a></li> +<li><a href="shapefile.dbf" type="application/binary">shapefile.dbf (Columnar attributes for each shape (dbf))</a></li> +<li><a href="shapefile.prj" type="application/binary">shapefile.prj (Projection description (prj))</a> (optional)</li> +<li><a href="shapefile.sbn" type="application/binary">shapefile.sbn (Spatial index of the features (sbn))</a> (optional)</li> +<li><a href="shapefile.sbx" type="application/binary">shapefile.sbx (Spatial index of the features (sbx))</a> (optional)</li> +<li><a href="shapefile.fbn" type="application/binary">shapefile.fbn (Read only spatial index of the features (fbn))</a> (optional)</li> +<li><a href="shapefile.fbx" type="application/binary">shapefile.fbx (Read only spatial index of the features (fbx))</a> (optional)</li> +<li><a href="shapefile.ain" type="application/binary">shapefile.ain (Attribute index of the active fields in a table (ain))</a> (optional)</li> +<li><a href="shapefile.aih" type="application/binary">shapefile.aih (Attribute index of the active fields in a table (aih))</a> (optional)</li> +<li><a href="shapefile.atx" type="application/binary">shapefile.atx (Attribute index for the dbf file (atx))</a> (optional)</li> +<li><a href="shapefile.ixs" type="application/binary">shapefile.ixs (Geocoding index (ixs))</a> (optional)</li> +<li><a href="shapefile.mxs" type="application/binary">shapefile.mxs (Geocoding index in ODB format (mxs))</a> (optional)</li> +<li><a href="shapefile.shp.xml" type="application/binary">shapefile.shp.xml (Geospatial metadata in XML format (xml))</a> (optional)</li> +</ul></div></html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/composite_dataset/shapefile.prj Tue May 20 09:52:08 2025 +0000 @@ -0,0 +1,1 @@ +PROJCS["WGS_1984_Antarctic_Polar_Stereographic",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Stereographic_South_Pole"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",0.0],PARAMETER["Standard_Parallel_1",-71.0],UNIT["Meter",1.0]]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/shapefile/output.prj Tue May 20 09:52:08 2025 +0000 @@ -0,0 +1,1 @@ +PROJCS["unknown",GEOGCS["GCS_unknown",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Azimuthal_Equal_Area"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",0.0],PARAMETER["Latitude_Of_Origin",-90.0],UNIT["Meter",1.0]] \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/shapefile/shapefile_shp.html Tue May 20 09:52:08 2025 +0000 @@ -0,0 +1,17 @@ +<html><head><title>Shapefile Galaxy Composite Dataset</title></head><p/> +<div>This composite dataset is composed of the following files:<p/><ul> +<li><a href="shapefile.shp" type="application/binary">shapefile.shp (Geometry File (shp))</a></li> +<li><a href="shapefile.shx" type="application/binary">shapefile.shx (Geometry index File (shx))</a></li> +<li><a href="shapefile.dbf" type="application/binary">shapefile.dbf (Columnar attributes for each shape (dbf))</a></li> +<li><a href="shapefile.prj" type="application/binary">shapefile.prj (Projection description (prj))</a> (optional)</li> +<li><a href="shapefile.sbn" type="application/binary">shapefile.sbn (Spatial index of the features (sbn))</a> (optional)</li> +<li><a href="shapefile.sbx" type="application/binary">shapefile.sbx (Spatial index of the features (sbx))</a> (optional)</li> +<li><a href="shapefile.fbn" type="application/binary">shapefile.fbn (Read only spatial index of the features (fbn))</a> (optional)</li> +<li><a href="shapefile.fbx" type="application/binary">shapefile.fbx (Read only spatial index of the features (fbx))</a> (optional)</li> +<li><a href="shapefile.ain" type="application/binary">shapefile.ain (Attribute index of the active fields in a table (ain))</a> (optional)</li> +<li><a href="shapefile.aih" type="application/binary">shapefile.aih (Attribute index of the active fields in a table (aih))</a> (optional)</li> +<li><a href="shapefile.atx" type="application/binary">shapefile.atx (Attribute index for the dbf file (atx))</a> (optional)</li> +<li><a href="shapefile.ixs" type="application/binary">shapefile.ixs (Geocoding index (ixs))</a> (optional)</li> +<li><a href="shapefile.mxs" type="application/binary">shapefile.mxs (Geocoding index in ODB format (mxs))</a> (optional)</li> +<li><a href="shapefile.shp.xml" type="application/binary">shapefile.shp.xml (Geospatial metadata in XML format (xml))</a> (optional)</li> +</ul></div></html>