├── .Rbuildignore ├── .gitignore ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── R ├── SampleInfile.R ├── SampleInfile_subset.R └── plotshpcreate.R ├── README.md ├── UAStools.Rproj ├── data ├── SampleInfile.rda └── SampleInfile_Subset.rda ├── inst └── CITATION └── man ├── SampleInfile.Rd ├── SampleInfile_Subset.Rd └── plotshpcreate.Rd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # History files 2 | .Rhistory 3 | .Rapp.history 4 | 5 | # Session Data files 6 | .RData 7 | 8 | # Example code in package build process 9 | *-Ex.R 10 | 11 | # Output files from R CMD build 12 | /*.tar.gz 13 | 14 | # Output files from R CMD check 15 | /*.Rcheck/ 16 | 17 | # RStudio files 18 | .Rproj.user/ 19 | 20 | # produced vignettes 21 | vignettes/*.html 22 | vignettes/*.pdf 23 | 24 | # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 25 | .httr-oauth 26 | 27 | # knitr and R markdown default cache directories 28 | /*_cache/ 29 | /cache/ 30 | 31 | # Temporary files created by R markdown 32 | *.utf8.md 33 | *.knit.md 34 | 35 | # Shiny token, see https://shiny.rstudio.com/articles/shinyapps.html 36 | rsconnect/ 37 | .Rproj.user 38 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: UAStools 2 | Type: Package 3 | Title: Tools for Field Based Remote Sensing Applications within Plot Based Agriculture 4 | Version: 0.4.0 5 | Date: 09/10/2020 6 | Author: Steven L. Anderson II, 7 | Seth C. Murray 8 | Maintainer: Steven L. Anderson II 9 | Description: This package provide a function to automate field plot shapefile (.shp) polygons for use in data extraction of remote sensing data sets. 10 | License: GPL-2 11 | Encoding: UTF-8 12 | Depends: R (>= 3.5.0) 13 | LazyData: true 14 | Imports: rgdal (>= 1.2-18), sp (>= 1.2-7) 15 | RoxygenNote: 7.1.1 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(plotshpcreate) 4 | import(rgdal) 5 | import(sp) 6 | -------------------------------------------------------------------------------- /R/SampleInfile.R: -------------------------------------------------------------------------------- 1 | #' @title Infile Sample Dataset 2 | #' 3 | #' @description Example of infile structure for the plotshpcreat function. 4 | #' Contains the preperation file used to design the CS17-G2FE experiment, which 5 | #' contains 594 two row plots and 1188 observations. 6 | #' 7 | #' @name SampleInfile 8 | #' @docType data 9 | #' @usage SampleInfile 10 | #' @format A dataframe containg the preperation file used to design the CS17-G2FE experiment, which 11 | #' contains 594 two row plots and 1188 observations. 12 | #' 13 | #' We recommend have repeated Barcodes and Plot numbers if there are multirow plots (mrowplot>1) as 14 | #' the plotshpcreatre function accounts for this redundance within the function. 15 | #' [,1] Loc An abbreviation to identify the trial location and year (character) 16 | #' [,2] Test An abbreviation to define the trial name (character) 17 | #' [,3] Plot The number of each plot (numeric) 18 | #' [,4] Barcode A unique identifier for each plot (character) 19 | #' [,5] Stock The seed source which is planted in each plot (character) 20 | #' [,6] Pedigree Information defining the lineage of the seed source (character) 21 | #' [,7] Entry An additional unique identifer commonly used to track consistent pedigrees from different seed stocks (numeric) 22 | #' [,8] Rep The replicate number of each plot (numeric) 23 | #' [,9] Range The range [also called row] number of each plot in the experimental grid (numeric) 24 | #' [,10] Row The row [also called column] number of each plot in the experimental grid (numeric) 25 | #' @note 26 | #' Only Range, Row, Plot, and Barcode variables are necessary for the the proper execution of plotshpcreate, 27 | #' but additional columns may be included in the dataframe. 28 | #' @keywords datasets infile sample 29 | NULL 30 | -------------------------------------------------------------------------------- /R/SampleInfile_subset.R: -------------------------------------------------------------------------------- 1 | #' @title Infile Sample Dataset for subset examples 2 | #' 3 | #' @description Example of infile structure for the plotshpcreat function. 4 | #' Contains the preperation file used to design the CS17-G2FE experiment, which 5 | #' contains 594 two row plots and 1188 observations. 6 | #' 7 | #' @name SampleInfile_Subset 8 | #' @docType data 9 | #' @usage SampleInfile_Subset 10 | #' @format A dataframe containg the preperation file used to design the CS17-G2FE experiment, which 11 | #' contains 288 two row plots and 1152 observations. 12 | #' 13 | #' We recommend have repeated Barcodes and Plot numbers if there are multirow plots (mrowplot>1) as 14 | #' the plotshpcreatre function accounts for this redundance within the function. 15 | #' [,1] Loc An abbreviation to identify the trial location and year (character) 16 | #' [,2] Test An abbreviation to define the trial name (character) 17 | #' [,3] Plot The number of each plot (numeric) 18 | #' [,4] Barcode A unique identifier for each plot (character) 19 | #' [,5] Stock The seed source which is planted in each plot (character) 20 | #' [,6] Pedigree Information defining the lineage of the seed source (character) 21 | #' [,7] Entry An additional unique identifer commonly used to track consistent pedigrees from different seed stocks (numeric) 22 | #' [,8] Rep The replicate number of each plot (numeric) 23 | #' [,9] Range The range [also called row] number of each plot in the experimental grid (numeric) 24 | #' [,10] Row The row [also called column] number of each plot in the experimental grid (numeric) 25 | #' @note 26 | #' Only Range, Row, Plot, and Barcode variables are necessary for the the proper execution of plotshpcreate, 27 | #' but additional columns may be included in the dataframe. 28 | #' @keywords datasets infile sample 29 | NULL 30 | -------------------------------------------------------------------------------- /R/plotshpcreate.R: -------------------------------------------------------------------------------- 1 | #' @title Plot Shapefile Create 2 | #' 3 | #' @description Methods for constructing multipolygon ESRI shapefiles (.shp) 4 | #' with individual polygons containing agricultural plot boundaries. Utilizes 5 | #' AB line to rotate polygons to the appropriate geospatial direction of research 6 | #' plots, allowing for simple overlay upon Unmanned Aerial System (UAS) or other 7 | #' geospatial datasets (e.g. orthomosaics, point clouds, etc.) for feature extraction. 8 | #' 9 | #' It is recommended to define working directory for output files prior to executing plotshpcreate. 10 | #' 11 | #' @param A Vector of UTM coordinates (Easting,Northing) of "A" point, which corresponds 12 | #' to the bottom left corner of the first field plot. 13 | #' Note: This point is where the function begins building polygons. This point is intended 14 | #' to be the midpoint of alley at the front of the first plot and the midpoint of the 15 | #' @param B Vector of UTM coordinates (Easting,Northing) of "B" point, which corresponds 16 | #' to the top left corner of the field trial within the same row as the "A" point 17 | #' @param UTMzone Character parameter defining UTM zone number. Default is NULL and will result in an coordinate reference system of "NA". 18 | #' @param Hemisphere Character parameter that designates the Northern "N" or Southern "S" Hemisphere. Default is "N". 19 | #' @param infile Data frame containing seed preperation file and experimental design 20 | #' (i.e. coordinates of plots within the design grid) 21 | #' @param outfile Character assignment to define outputfile names. If left null, default 22 | #' file names will be produced. 23 | #' @param nrowplot Number of adjacent rows that constitute a plot.Setting this parameter 24 | #' to greater than one allows for different polygon options. Default set to 1. 25 | #' @param multirowind Logic parameter that indicates if adjacent plot rows should be 26 | #' combined and treated as a single plot shapefile and unique idenfifier. Setting to false 27 | #' will combine adjacent plots and construct a single polygon that encompasses 28 | #' all adjacent rows within a plot. Default set to true. 29 | #' @param rowspc Row (i.e. column) spacing of a single row. Default 2.5 feet in reference to 30 | #' 30 inch row spacing. 31 | #' @param rowbuf Distance removed from both sides of rowspc to create a buffer zone between 32 | #' plots boundaries. Default is 0.1 feet. 33 | #' @param rangespc Range (i.e. row) spacing of a single row. This dimesnsion referes to the total 34 | #' plot length including half alley distance on either side of the plot. Default 25 feet. 35 | #' @param rangebuf Distance removed from both sides of rangespc to create a buffer zone between 36 | #' plots boundaries. Default is 2 feet in reference to four foot allies. Note: If alleys are 37 | #' 4 feet rangebuf should be set to 2 feet to remove from both ends of the polygon. 38 | #' @param stagger Numeric vector of length three defining [1] row where staggers starts, 39 | #' [2] rows sowed by planted in a single pass, and [3] stagger offset distance from A point. 40 | #' @param plotsubset Defines how many adjacent rows should be excluded from the shapefile. 41 | #' This parameter is useful for multirow plots where the central plots are of interest. If plotsubset=1, 42 | #' the outer row will be removed from both sides of the plot. 43 | #' @param field Character vector to indicate the trial the shapefile is being developed for. 44 | #' Recommended format example: CS17-G2FE, which inicated location (CS), year (17), and trial (G2FE). 45 | #' @param unit Character vector that the unit of measure for the polygon dimesnions. Default is "feet". 46 | #' Units can also be input as meters using unit="meter". 47 | #' @param SquarePlot Logic parameter to indicated if PDF file is desired for visualization of none rotated polygons. 48 | #' @param RotatePlot Logic parameter to indicated if PDF file is desired for visualization of rotated polygons. 49 | #' @import rgdal sp 50 | #' @export 51 | #' @return NULL 52 | #' @note it is recommendeed to repeat unique Barcodes and Plot numbers if there are multirow plots (mrowplot>1) as 53 | #' the plotshpcreatre function accounts for this redundance within the function. 54 | #' 55 | #' @examples 56 | #' 57 | #' 58 | #' ### Creates shape file for each individual with the inclusion of multirow plot design 59 | #' ### with nrowplot>1 and multirowind=T. Unique identifiers are subset by the location 60 | #' ### of the adjacent plots reading from left to right in geographical space. 61 | #' 62 | #' ### Set working directory to where you want the files to be saved 63 | #' setwd("C://Temp") 64 | #' 65 | #' plotshpcreate(A=c(746239.817,3382052.264), #Point A c(Easting_0.0,Northing_0.0) 66 | #' B=c(746334.224,3382152.870), #Point B c(Easting_1.0,Northing_1.0) 67 | #' UTMzone="14", 68 | #' Hemisphere="N", 69 | #' infile=SampleInfile, 70 | #' outfile="Ind_Multirow_plots", 71 | #' nrowplot=2, 72 | #' multirowind=TRUE, 73 | #' rowspc=2.5, 74 | #' rowbuf=0.1, ### Will take off both sides of the plot 75 | #' rangespc=25, 76 | #' rangebuf=2, ### Half the alley width 77 | #' plotsubset=NULL, 78 | #' field="CS17-G2FE", 79 | #' unit="feet", 80 | #' SquarePlot=TRUE, 81 | #' RotatePlot=TRUE) 82 | #' 83 | #' # Creates shape file by combining adacent row of unique plots of multirow plot design 84 | #' # within a single polygone with nrowplot>1 and multirowind=T. If a plot is two rows wide 85 | #' # the shape file will encompass the plot as a whole. 86 | #' 87 | #' ### Set working directory to where you want the files to be saved 88 | #' setwd("C://Temp") 89 | #' plotshpcreate(A=c(746239.817,3382052.264), #Point A c(Easting_0.0,Northing_0.0) 90 | #' B=c(746334.224,3382152.870), #Point B c(Easting_1.0,Northing_1.0) 91 | #' UTMzone="14", 92 | #' Hemisphere="N" 93 | #' infile=SampleInfile, 94 | #' outfile="Multirowplotscombined", 95 | #' nrowplot=2, 96 | #' multirowind=FALSE, 97 | #' rowspc=2.5, 98 | #' rowbuf=0.1, ### Will take off both sides of the plot 99 | #' rangespc=25, 100 | #' rangebuf=2, ### Half the alley width 101 | #' plotsubset=NULL, 102 | #' field="CS17-G2FE", 103 | #' unit="feet", 104 | #' SquarePlot=TRUE, 105 | #' RotatePlot=TRUE) 106 | #' 107 | #' # If the experiment is a single row plot design utilize nrowplot=1. 108 | 109 | 110 | #### x<-read.csv("C://Temp//plotshpcreate_6plottest.csv",header=T) 111 | 112 | plotshpcreate<-function(A=NULL, #Point A c(Easting_0.0,Northing_0.0) 113 | B=NULL, #Point B c(Easting_1.0,Northing_1.0) 114 | UTMzone=NULL, 115 | Hemisphere="N", 116 | infile=NULL, 117 | outfile=NULL, 118 | nrowplot=1, 119 | multirowind=FALSE, 120 | rowspc=2.5, 121 | rowbuf=0.1, ### Will take off both sides of the plot 122 | rangespc=25, 123 | rangebuf=2, ### Half the alley width 124 | stagger=NULL, ### c(row where staggers starts, planter rows, stagger distance) 125 | plotsubset=0, 126 | field=NULL, 127 | unit="feet", 128 | SquarePlot=TRUE, 129 | RotatePlot=TRUE){ 130 | # infile<-x 131 | if (!requireNamespace("rgdal", quietly = TRUE)) { 132 | stop("Package \"rgdal\" needed for this function to work. Please install it.", 133 | call. = FALSE) 134 | } 135 | 136 | if (!requireNamespace("sp", quietly = TRUE)) { 137 | stop("Package \"sp\" needed for this function to work. Please install it.", 138 | call. = FALSE) 139 | } 140 | 141 | if (!is.null(stagger)){ 142 | if(stagger[[1]]==1){ 143 | stop("Stagger must be in reference to plots beyond first plot polygon, i.e. stagger[[1]]!=1", 144 | call. = FALSE) 145 | } 146 | if(stagger[[1]]>(stagger[[2]]+1)){ 147 | stop("Stagger is based on planter dimesions ans was built for consistent stagger throughout the trial, 148 | i.e. stagger[[1]] !> (stagger[[2]]+1)", 149 | call. = FALSE) 150 | } 151 | if(nrowplot>1 & multirowind==F & (nrowplot>(stagger[[2]]/2))){ 152 | stop("Combined plots will not be correctly adjusted by stagger due to: 153 | 154 | nrowplot>(stagger[[2]]/2) 155 | 156 | ~~~Recommend setting multirowind=T~~~", 157 | call. = FALSE) 158 | } 159 | if(nrowplot>1 & multirowind==F & ((stagger[[2]]%%nrowplot)!=0)){ 160 | stop("Combined plots will not be correctly adjusted by stagger due to: 161 | 162 | stagger[[2]]%%nrowplot)!=0 163 | 164 | ~~~Recommend setting multirowind=T~~~~", 165 | call. = FALSE) 166 | } 167 | if(nrowplot>1 & multirowind==F & 168 | (((stagger[[2]]-(stagger[[2]]-stagger[[1]]-1))%%nrowplot)!=0)){ 169 | stop("Combined plots will not be correctly adjusted by stagger due to: 170 | 171 | (((stagger[[2]]-(stagger[[2]]-stagger[[1]]-1))%%nrowplot)!=0) 172 | 173 | ~~~Recommend setting multirowind=T~~~~", 174 | call. = FALSE) 175 | } 176 | } 177 | 178 | 179 | options(digits=12) 180 | 181 | ### Order infile by plot numbers numerically, then by row number 182 | infile<-infile[order(as.numeric(infile$Plot),as.numeric(infile$Row)),] 183 | 184 | nRange<- length(unique(infile$Range)) 185 | nRow<- length(unique(infile$Row)) 186 | 187 | nPlot<- nrow(infile) 188 | 189 | if (nPlot != (nRange*nRow)) 190 | {warning("Length of file is not equal to number of plots: may cause errors, please remove blank rows at end of file and check row/range numbering")} 191 | 192 | # rm(FirstPlot,LastPlot) 193 | for (i in 1:nPlot){ 194 | ### Find bottom left plot 195 | if (infile$Range[i]==min(infile$Range)&& infile$Row[i]==min(infile$Row)) {BLCornerPlot<-i} 196 | ### Find bottom right plot 197 | if (infile$Range[i]==min(infile$Range)&& infile$Row[i]==max(infile$Row)) {BRCornerPlot<-i} 198 | ### Find top right plot 199 | if (infile$Range[i]==max(infile$Range)&& infile$Row[i]==max(infile$Row)) {TRCornerPlot<-i} 200 | ### Find back left plot 201 | if (infile$Range[i]==max(infile$Range)&& infile$Row[i]==min(infile$Row)) {TLCornerPlot<-i} 202 | } 203 | 204 | ### Takes AB line diffences for delta calculation 205 | DeltaEasting<- B[[1]]-A[[1]] 206 | DeltaNorthing<- B[[2]]-A[[2]] 207 | 208 | # DeltaEasting<- Easting_1.0-Easting_0.0 209 | # DeltaNorthing<- Northing_1.0-Northing_0.0 210 | 211 | #Calculates theta in Radians 212 | DirectionTheta<- atan(abs(DeltaNorthing)/abs(DeltaEasting)) #Radians 213 | 214 | ### R circles rotate counter clockwise starting at [0,1] i.e right 90 deg of circle 215 | ### Theta is for plot orientation in radians 216 | ### srt_theta is for text rotation in plots in degress 217 | ## QUADRANT I ## 218 | if(DeltaNorthing>0 && DeltaEasting>0){ 219 | Theta<-(((3*pi)/2)+DirectionTheta) 220 | srt_theta<-90-DirectionTheta*(180/pi) 221 | } 222 | ## QUADRANT II ## 223 | if(DeltaNorthing>0 && DeltaEasting<0){ 224 | Theta<-(((pi)/2)-DirectionTheta) 225 | srt_theta<-270+DirectionTheta*(180/pi) 226 | } 227 | ## QUADRANT III ## 228 | if(DeltaNorthing<0 && DeltaEasting<0){ 229 | Theta<-(((pi)/2)+DirectionTheta) 230 | srt_theta<-DirectionTheta*(180/pi) 231 | } 232 | ## QUADRANT IV ## 233 | if(DeltaNorthing<0 && DeltaEasting>0){ 234 | Theta<-(((3*pi)/2)-DirectionTheta) 235 | srt_theta<-270+DirectionTheta*(180/pi) 236 | } 237 | 238 | if(unit=="feet"){ 239 | RangeSpacingM<-rangespc/3.281 #meter 240 | RowSpacingM<- rowspc/3.281 #meter 241 | RangeBufferM<-rangebuf/3.281 #meter 242 | RowBufferM<- rowbuf/3.281 #meter 243 | staggerM<-stagger[[3]]/3.281 244 | } 245 | 246 | if(unit=="meter"){ 247 | RangeSpacingM<-rangespc #meter 248 | RowSpacingM<- rowspc #meter 249 | RangeBufferM<-rangebuf #meter 250 | RowBufferM<- rowbuf #meter 251 | staggerM<-stagger[[3]] 252 | } 253 | 254 | 255 | ZeroZero<-matrix(0,1,2) 256 | ZeroZero[1,1] <- 0 #Easting_0.0 257 | ZeroZero[1,2] <- 0 #Northing_0.0 258 | 259 | 260 | 261 | ### When plots are perfectly perpendicular as if planted perfectly north to south 262 | ### column 12 added to retain orginial row numbering for stagger 263 | PlotsSquareM<-matrix(NA,nPlot,12) 264 | PlotsSquareM[,1]<- infile$Plot # Plot number 265 | PlotsSquareM[,2]<- infile$Range-min(infile$Range)+1 #RANGE = Y 266 | PlotsSquareM[,3]<-PlotsSquareM[,12]<- infile$Row-min(infile$Row)+1 #ROW = X 267 | rownames(PlotsSquareM)<-rep(NA,nPlot) 268 | 269 | if(nrowplot==1){ 270 | rownames(PlotsSquareM)<-infile$Barcode 271 | } 272 | # PlotsSquareM[,12]<- as.character(infile$Barcode) # Plot number 273 | 274 | #################################################################### 275 | #################################################################### 276 | ##### Combining Multi-row adjacent plots to a single plot ########## 277 | #################################################################### 278 | #################################################################### 279 | if(nrowplot>1 & multirowind==F & plotsubset==0){ 280 | 281 | if(unit=="feet"){ 282 | RangeSpacingM<-rangespc/3.281 #meter 283 | RowSpacingM<- (nrowplot*rowspc)/3.281 #meter 284 | RangeBufferM<-rangebuf/3.281 #meter 285 | RowBufferM<- rowbuf/3.281 #meter 286 | staggerM<-stagger[[3]]/3.281 287 | } 288 | 289 | if(unit=="meter"){ 290 | RangeSpacingM<-rangespc #meter 291 | RowSpacingM<- (nrowplot*rowspc) #meter 292 | RangeBufferM<-rangebuf #meter 293 | RowBufferM<- rowbuf #meter 294 | staggerM<-stagger[[3]] 295 | } 296 | 297 | # rowspc<-rowspc*nrowplot 298 | 299 | ID<-unique(as.character(infile$Barcode)) 300 | 301 | for(i in 1:length(ID)){ 302 | 303 | #### Finds rows in PlotsSquareM 304 | rownames(PlotsSquareM)[which(PlotsSquareM[,1]==infile$Plot[infile$Barcode==ID[[i]]])]<-ID[i] 305 | } 306 | 307 | PlotsSquareM<-PlotsSquareM[PlotsSquareM[,3]==(1+plotsubset) | PlotsSquareM[,3] %in% seq(1+nrowplot+plotsubset,max(PlotsSquareM[,3]),nrowplot),] 308 | 309 | # nPlot<-nrow(PlotsSquareM) 310 | 311 | PlotsSquareM[,12]<-PlotsSquareM[,3] 312 | for (i in 1:length(PlotsSquareM[,3])){ 313 | if(PlotsSquareM[i,3]==1){next} 314 | else(PlotsSquareM[i,3]<-ceiling(PlotsSquareM[i,3]/nrowplot)) 315 | } 316 | 317 | 318 | ########### Subseting out region of larger plot ################ 319 | if(plotsubset!=0){ 320 | if(nrowplot==1){ 321 | stop("nrowplot == 1 : Cannot subset singular plot.", 322 | call. = FALSE) 323 | } 324 | if(nrowplot<3){ 325 | stop("nrowplot < 3 : Cannot subset central plot. \n Recommend nrowplot=2, multirowind==T,plotsubset=NULL. ", 326 | call. = FALSE) 327 | } 328 | if(nrowplot==2*plotsubset){ 329 | stop("nrowplot==2*plotsubset : no polygons will be created ", 330 | call. = FALSE) 331 | } 332 | 333 | } 334 | 335 | rowbuff<-rowbuf+(rowspc*plotsubset) 336 | } 337 | 338 | #################################################################### 339 | #################################################################### 340 | ##### Formatting Adjacent Plot to Unique IDs w/o combining ######### 341 | #################################################################### 342 | #################################################################### 343 | if((nrowplot>1 & multirowind==T)|(plotsubset!=0)){ 344 | 345 | IDs<-unique(as.character(infile$Barcode)) 346 | 347 | PolygonsToMake <- vector('list', length(IDs)) 348 | 349 | # i=1 350 | # k=1 351 | for(i in 1:length(IDs)){ 352 | # for (j in 1:nRow){ 353 | ### Subsets out all rows of PlotsSquareM whwere the row numbers are 354 | ### equal to the unique barcode for each iteration if "i" 355 | 356 | subset_PSM<-PlotsSquareM[which(PlotsSquareM[,1]==infile$Plot[infile$Barcode==IDs[[i]]]),] 357 | 358 | # subset_PSM<-rbind(subset_PSM,subset_PSM) 359 | # subset_PSM[2,3]<-50 360 | nrow_subset<-nrow(subset_PSM) 361 | for (k in 1:nrow_subset){ 362 | 363 | ### Looking for the min row number of plots with the same plot number 364 | ### iteritively creating unquie barcodes with left to right numbering of rows 1 to nrowplot 365 | if(k==nrow_subset){ 366 | 367 | rownames(PlotsSquareM)[which(PlotsSquareM[,1]==subset_PSM[1] & 368 | PlotsSquareM[,3]==subset_PSM[3])]<-paste(IDs[[i]],k,sep="_") 369 | 370 | } 371 | 372 | if(k1 & multirowind==T & plotsubset!=0){ 443 | PlotsSquareM<-PlotSquare4plot<-new_PSM[new_PSM[,13]==1,] 444 | } 445 | 446 | #################################################################### 447 | #################################################################### 448 | #################################################################### 449 | #################################################################### 450 | ### remember the point is in the middle of the plot not the furrow 451 | #### ^^^^^ I Think this is wrong -Steve 1/22/2019 452 | 453 | # i<-2 454 | 455 | # PlotsSquareM<-PlotsSquareM[PlotsSquareM[,13]==1,] 456 | 457 | for (i in 1:nrow(PlotsSquareM)) { 458 | 459 | 460 | PlotsSquareM[i,4]<- ZeroZero[1,1]+((PlotsSquareM[i,2]-1)*RangeSpacingM) # Y bottom left Range 461 | PlotsSquareM[i,5]<- ZeroZero[1,2]+((PlotsSquareM[i,3]-1)* RowSpacingM) # X bottom left Row 462 | 463 | PlotsSquareM[i,6]<- ZeroZero[1,1]+((PlotsSquareM[i,2]-1)*RangeSpacingM ) # Y bottom right Range 464 | PlotsSquareM[i,7]<- ZeroZero[1,2]+((PlotsSquareM[i,3])* RowSpacingM) # X bottom right Row 465 | 466 | PlotsSquareM[i,8]<- ZeroZero[1,1]+((PlotsSquareM[i,2])*RangeSpacingM ) # Y top right Range 467 | PlotsSquareM[i,9]<- ZeroZero[1,2]+((PlotsSquareM[i,3])* RowSpacingM) # X top right Row 468 | 469 | PlotsSquareM[i,10]<- ZeroZero[1,1]+((PlotsSquareM[i,2])*RangeSpacingM ) # Y top left Range 470 | PlotsSquareM[i,11]<- ZeroZero[1,2]+((PlotsSquareM[i,3]-1)* RowSpacingM) # X top left Row 471 | 472 | 473 | 474 | 475 | if(!is.null(stagger)){ 476 | # 477 | # 478 | # if (!is.null(stagger)){ 479 | # stag_vector<-c() 480 | # for (i in 1:nrow(PlotsSquareM)){ 481 | # if(PlotsSquareM[i,3]=stagger[[1]]){ 489 | # a<-floor((PlotsSquareM[i,3]-stagger[[1]])+1) 490 | # b<-ceiling((a+stagger[[2]])/stagger[[2]]) 491 | # if(b%%2==0 492 | # } 493 | # 494 | # } 495 | # } 496 | # } 497 | # stag_vector<-rep(c(rep(1,stagger[[2]]),rep(0,stagger[[2]])),(nRow-stagger[[1]])/(stagger[[2]]*2)) 498 | 499 | 500 | 501 | if((ceiling((floor((PlotsSquareM[i,12]-stagger[[1]])+1)+stagger[[2]])/stagger[[2]])%%2)==0){ 502 | 503 | PlotSquare4plot[i,4]<- ZeroZero[1,1]+((PlotsSquareM[i,2]-1)*RangeSpacingM)+staggerM # Y bottom left Range 504 | PlotSquare4plot[i,5]<- ZeroZero[1,2]+((PlotsSquareM[i,3]-1)* RowSpacingM) # X bottom left Row 505 | 506 | PlotSquare4plot[i,6]<- ZeroZero[1,1]+((PlotsSquareM[i,2]-1)*RangeSpacingM )+staggerM # Y bottom right Range 507 | PlotSquare4plot[i,7]<- ZeroZero[1,2]+((PlotsSquareM[i,3])* RowSpacingM) # X bottom right Row 508 | 509 | PlotSquare4plot[i,8]<- ZeroZero[1,1]+((PlotsSquareM[i,2])*RangeSpacingM )+staggerM # Y top right Range 510 | PlotSquare4plot[i,9]<- ZeroZero[1,2]+((PlotsSquareM[i,3])* RowSpacingM) # X top right Row 511 | 512 | PlotSquare4plot[i,10]<- ZeroZero[1,1]+((PlotsSquareM[i,2])*RangeSpacingM )+staggerM # Y top left Range 513 | PlotSquare4plot[i,11]<- ZeroZero[1,2]+((PlotsSquareM[i,3]-1)* RowSpacingM) # X top left Row 514 | } 515 | 516 | if((ceiling((floor((PlotsSquareM[i,12]-stagger[[1]])+1)+stagger[[2]])/stagger[[2]])%%2)!=0){ 517 | 518 | PlotSquare4plot[i,4]<- ZeroZero[1,1]+((PlotsSquareM[i,2]-1)*RangeSpacingM) # Y bottom left Range 519 | PlotSquare4plot[i,5]<- ZeroZero[1,2]+((PlotsSquareM[i,3]-1)* RowSpacingM) # X bottom left Row 520 | 521 | PlotSquare4plot[i,6]<- ZeroZero[1,1]+((PlotsSquareM[i,2]-1)*RangeSpacingM ) # Y bottom right Range 522 | PlotSquare4plot[i,7]<- ZeroZero[1,2]+((PlotsSquareM[i,3])* RowSpacingM) # X bottom right Row 523 | 524 | PlotSquare4plot[i,8]<- ZeroZero[1,1]+((PlotsSquareM[i,2])*RangeSpacingM ) # Y top right Range 525 | PlotSquare4plot[i,9]<- ZeroZero[1,2]+((PlotsSquareM[i,3])* RowSpacingM) # X top right Row 526 | 527 | PlotSquare4plot[i,10]<- ZeroZero[1,1]+((PlotsSquareM[i,2])*RangeSpacingM ) # Y top left Range 528 | PlotSquare4plot[i,11]<- ZeroZero[1,2]+((PlotsSquareM[i,3]-1)* RowSpacingM) # X top left Row 529 | } 530 | } 531 | } 532 | 533 | 534 | #PlotsSquareM[c(BLCornerPlot, BRCornerPlot, TRCornerPlot, TLCornerPlot, FirstPlot, LastPlot),] 535 | 536 | ### THis is the red boxes 537 | ## has the data we care about 538 | 539 | 540 | PlotsSquareMBuf<-PlotsSquareBuf4plot<-PlotsSquareM 541 | 542 | for (i in 1:nrow(PlotsSquareMBuf)) { 543 | 544 | 545 | 546 | PlotsSquareMBuf[i,4]<- ZeroZero[1,1]+((PlotsSquareMBuf[i,2]-1)*RangeSpacingM ) + RangeBufferM # Y bottom left 547 | PlotsSquareMBuf[i,5]<- ZeroZero[1,2]+((PlotsSquareMBuf[i,3]-1)* RowSpacingM) + RowBufferM # X bottom left 548 | 549 | PlotsSquareMBuf[i,6]<- ZeroZero[1,1]+((PlotsSquareMBuf[i,2]-1)*RangeSpacingM ) +RangeBufferM # Y bottom right 550 | PlotsSquareMBuf[i,7]<- ZeroZero[1,2]+((PlotsSquareMBuf[i,3])* RowSpacingM) - RowBufferM # X bottom right 551 | 552 | PlotsSquareMBuf[i,8]<- ZeroZero[1,1]+((PlotsSquareMBuf[i,2])*RangeSpacingM ) -RangeBufferM # Y top right 553 | PlotsSquareMBuf[i,9]<- ZeroZero[1,2]+((PlotsSquareMBuf[i,3])* RowSpacingM) - RowBufferM # X top right 554 | 555 | PlotsSquareMBuf[i,10]<- ZeroZero[1,1]+((PlotsSquareMBuf[i,2])*RangeSpacingM ) - RangeBufferM # Y top left 556 | PlotsSquareMBuf[i,11]<- ZeroZero[1,2]+((PlotsSquareMBuf[i,3]-1)* RowSpacingM) + RowBufferM # X top left 557 | 558 | 559 | 560 | if(!is.null(stagger)){ 561 | if((ceiling((floor((PlotsSquareM[i,12]-stagger[[1]])+1)+stagger[[2]])/stagger[[2]])%%2)==0){ 562 | 563 | PlotsSquareBuf4plot[i,4]<- ZeroZero[1,1]+((PlotsSquareMBuf[i,2]-1)*RangeSpacingM ) + RangeBufferM +staggerM # Y bottom left 564 | PlotsSquareBuf4plot[i,5]<- ZeroZero[1,2]+((PlotsSquareMBuf[i,3]-1)* RowSpacingM) + RowBufferM # X bottom left 565 | 566 | PlotsSquareBuf4plot[i,6]<- ZeroZero[1,1]+((PlotsSquareMBuf[i,2]-1)*RangeSpacingM ) +RangeBufferM +staggerM # Y bottom right 567 | PlotsSquareBuf4plot[i,7]<- ZeroZero[1,2]+((PlotsSquareMBuf[i,3])* RowSpacingM) - RowBufferM # X bottom right 568 | 569 | PlotsSquareBuf4plot[i,8]<- ZeroZero[1,1]+((PlotsSquareMBuf[i,2])*RangeSpacingM ) -RangeBufferM +staggerM # Y top right 570 | PlotsSquareBuf4plot[i,9]<- ZeroZero[1,2]+((PlotsSquareMBuf[i,3])* RowSpacingM) - RowBufferM # X top right 571 | 572 | PlotsSquareBuf4plot[i,10]<- ZeroZero[1,1]+((PlotsSquareMBuf[i,2])*RangeSpacingM ) - RangeBufferM + staggerM # Y top left 573 | PlotsSquareBuf4plot[i,11]<- ZeroZero[1,2]+((PlotsSquareMBuf[i,3]-1)* RowSpacingM) + RowBufferM # X top left 574 | } 575 | 576 | if((ceiling((floor((PlotsSquareM[i,12]-stagger[[1]])+1)+stagger[[2]])/stagger[[2]])%%2)!=0){ 577 | PlotsSquareBuf4plot[i,4]<- ZeroZero[1,1]+((PlotsSquareMBuf[i,2]-1)*RangeSpacingM ) + RangeBufferM # Y bottom left 578 | PlotsSquareBuf4plot[i,5]<- ZeroZero[1,2]+((PlotsSquareMBuf[i,3]-1)* RowSpacingM) + RowBufferM # X bottom left 579 | 580 | PlotsSquareBuf4plot[i,6]<- ZeroZero[1,1]+((PlotsSquareMBuf[i,2]-1)*RangeSpacingM ) +RangeBufferM # Y bottom right 581 | PlotsSquareBuf4plot[i,7]<- ZeroZero[1,2]+((PlotsSquareMBuf[i,3])* RowSpacingM) - RowBufferM # X bottom right 582 | 583 | PlotsSquareBuf4plot[i,8]<- ZeroZero[1,1]+((PlotsSquareMBuf[i,2])*RangeSpacingM ) -RangeBufferM # Y top right 584 | PlotsSquareBuf4plot[i,9]<- ZeroZero[1,2]+((PlotsSquareMBuf[i,3])* RowSpacingM) - RowBufferM # X top right 585 | 586 | PlotsSquareBuf4plot[i,10]<- ZeroZero[1,1]+((PlotsSquareMBuf[i,2])*RangeSpacingM ) - RangeBufferM # Y top left 587 | PlotsSquareBuf4plot[i,11]<- ZeroZero[1,2]+((PlotsSquareMBuf[i,3]-1)* RowSpacingM) + RowBufferM # X top left 588 | } 589 | } 590 | } 591 | 592 | 593 | if(nrowplot>1 & multirowind==F & plotsubset!=0){ 594 | 595 | ID<-unique(as.character(infile$Barcode)) 596 | plots<-unique(as.numeric(PlotsSquareM[,1])) 597 | 598 | newPlotDF<-data.frame() 599 | newPlotBufDF<-data.frame() 600 | for (i in 1:length(plots)){ 601 | pulls<-PlotsSquareM[PlotsSquareM[,1]==plots[i],] 602 | pulls<-as.data.frame(pulls[pulls[,13]==1,]) 603 | 604 | pulls1<-pulls[pulls[,12]==min(pulls[,12]),] 605 | pulls1[,4]<-min(pulls[,4]) # Y bottom left Range 606 | pulls1[,5]<-min(pulls[,5]) # X bottom left Row 607 | pulls1[,6]<-min(pulls[,6]) # Y bottom right Range 608 | pulls1[,7]<-max(pulls[,7]) # X bottom right Row 609 | pulls1[,8]<-max(pulls[,8]) # Y top right Range 610 | pulls1[,9]<-max(pulls[,9]) # X top right Row 611 | pulls1[,10]<-max(pulls[,10]) # Y top left Range 612 | pulls1[,11]<-min(pulls[,11]) # X top left Row 613 | rownames(pulls1)<-strsplit(rownames(pulls1),"_")[[1]][1] 614 | 615 | newPlotDF<-rbind(newPlotDF,pulls1) 616 | 617 | Bpulls<-PlotsSquareMBuf[PlotsSquareMBuf[,1]==plots[i],] 618 | Bpulls<-as.data.frame(Bpulls[Bpulls[,13]==1,]) 619 | 620 | Bpulls1<-Bpulls[Bpulls[,12]==min(Bpulls[,12]),] 621 | Bpulls1[,4]<-min(Bpulls[,4]) # Y bottom left Range 622 | Bpulls1[,5]<-min(Bpulls[,5]) # X bottom left Row 623 | Bpulls1[,6]<-min(Bpulls[,6]) # Y bottom right Range 624 | Bpulls1[,7]<-max(Bpulls[,7]) # X bottom right Row 625 | Bpulls1[,8]<-max(Bpulls[,8]) # Y top right Range 626 | Bpulls1[,9]<-max(Bpulls[,9]) # X top right Row 627 | Bpulls1[,10]<-max(Bpulls[,10]) # Y top left Range 628 | Bpulls1[,11]<-min(Bpulls[,11]) # X top left Row 629 | rownames(Bpulls1)<-strsplit(rownames(Bpulls1),"_")[[1]][1] 630 | 631 | newPlotBufDF<-rbind(newPlotBufDF,Bpulls1) 632 | } 633 | PlotsSquareM<-as.matrix(newPlotDF) 634 | PlotsSquareMBuf<-as.matrix(newPlotBufDF) 635 | } 636 | 637 | # if(nrowplot>1 & multirowind==F){ 638 | # # for(i in 1:length(ID)){ 639 | # # rownames(PlotsSquareM)[which(PlotsSquareM[,1]==infile$Plot[infile$Barcode==ID[[i]]])]<-ID[i] 640 | # # } 641 | # # 642 | # # PlotsSquareM<-PlotsSquareM[PlotsSquareM[,3]==(1+plotsubset) | PlotsSquareM[,3] %in% seq(1+nrowplot+plotsubset,max(PlotsSquareM[,3]),nrowplot),] 643 | # # 644 | # # nPlot<-nrow(PlotsSquareM) 645 | # 646 | # # PlotsSquareM[,12]<-PlotsSquareM[,3] 647 | # for (i in 1:length(PlotsSquareM[,3])){ 648 | # if(PlotsSquareM[i,3]==1){next} 649 | # else(PlotsSquareM[i,3]<-ceiling(PlotsSquareM[i,3]/nrowplot)) 650 | # } 651 | # 652 | # } 653 | 654 | 655 | ###### PLOTTING SIZE OF PLOT DIMENSIONS ############ 656 | if (SquarePlot==T){ 657 | if(is.null(stagger)){ 658 | PlotSquare4plot<-PlotsSquareM 659 | PlotsSquareBuf4plot<-PlotsSquareMBuf 660 | } 661 | 662 | PlotY<- cbind(PlotSquare4plot[,4], PlotSquare4plot[,6], PlotSquare4plot[,8], PlotSquare4plot[,10]) #Ranges 663 | PlotX<- cbind(PlotSquare4plot[,5], PlotSquare4plot[,7], PlotSquare4plot[,9], PlotSquare4plot[,11]) #Rows outline 664 | 665 | PlotYBuf<- cbind(PlotsSquareBuf4plot[,4], PlotsSquareBuf4plot[,6], PlotsSquareBuf4plot[,8], PlotsSquareBuf4plot[,10]) #Ranges buffered 666 | PlotXBuf<- cbind(PlotsSquareBuf4plot[,5], PlotsSquareBuf4plot[,7], PlotsSquareBuf4plot[,9], PlotsSquareBuf4plot[,11]) #Ranges buffered 667 | 668 | 669 | ########## Square Visualization of Trial Plots ############## 670 | pdf(paste(field,outfile,"Square_plots.pdf",sep="_"), 671 | width=15, 672 | height=15) 673 | 674 | plot(c(0,nRow*RowSpacingM), c(0,nRange*RangeSpacingM), type="n", xlab = "ROWS (meters)", ylab = "RANGES (meters)") # Plot lines in field 675 | 676 | if(nrowplot>1 & multirowind==F & plotsubset==0){ 677 | plot(c(0,max(PlotSquare4plot[,3])*RowSpacingM), c(0,nRange*RangeSpacingM), type="n", xlab = "ROWS (meters)", ylab = "RANGES (meters)") # Plot lines in field 678 | } 679 | 680 | for (i in 1:nrow(PlotSquare4plot)) { 681 | for (j in 1:4) { 682 | points(PlotX[i,j], PlotY[i,j]) 683 | } 684 | polygon(PlotX[i,], PlotY[i,]) 685 | polygon(PlotXBuf[i,], PlotYBuf[i,], col="RED") 686 | text( ((PlotXBuf[i,1]+PlotXBuf[i,3])/2), ((PlotYBuf[i,1]+PlotYBuf[i,3])/2), labels= PlotsSquareM[i,1], pos = NULL, col = "WHITE", cex=0.7,srt=0 ) 687 | } 688 | dev.off() 689 | } 690 | 691 | 692 | ########## ADJUST PLOT CORNERS TO NOT CENTER OF PLOT ############## 693 | 694 | ThetaPlotCorner<-Theta 695 | EastingCorner_0.0<-A[1] 696 | NorthingCorner_0.0<-A[2] 697 | 698 | if(!is.null(stagger)){ 699 | ## QUADRANT I ## 700 | if(DeltaNorthing>0 && DeltaEasting>0){ 701 | EastingCorner_0.0_stag<-EastingCorner_0.0-staggerM*sin(ThetaPlotCorner) 702 | NorthingCorner_0.0_stag<-NorthingCorner_0.0+staggerM*cos(ThetaPlotCorner) 703 | } 704 | ## QUADRANT II ## 705 | if(DeltaNorthing>0 && DeltaEasting<0){ 706 | EastingCorner_0.0_stag<-EastingCorner_0.0-staggerM*cos(ThetaPlotCorner) 707 | NorthingCorner_0.0_stag<-NorthingCorner_0.0+staggerM*sin(ThetaPlotCorner) 708 | } 709 | ## QUADRANT III ## 710 | if(DeltaNorthing<0 && DeltaEasting<0){ 711 | EastingCorner_0.0_stag<-EastingCorner_0.0-staggerM*cos(ThetaPlotCorner) 712 | NorthingCorner_0.0_stag<-NorthingCorner_0.0+staggerM*sin(ThetaPlotCorner) 713 | } 714 | ## QUADRANT IV ## 715 | if(DeltaNorthing<0 && DeltaEasting>0){ 716 | EastingCorner_0.0_stag<-EastingCorner_0.0+staggerM*cos(ThetaPlotCorner) 717 | NorthingCorner_0.0_stag<-NorthingCorner_0.0-staggerM*sin(ThetaPlotCorner) 718 | } 719 | } 720 | 721 | PlotsAdjustedM<- PlotsSquareM 722 | PlotsAdjustedMBuf<- PlotsSquareMBuf 723 | 724 | 725 | #################################################################### 726 | #################################################################### 727 | ######## Rotating Plot Boundaries Based on AB Line ################# 728 | #################################################################### 729 | #################################################################### 730 | for (i in 1:nrow(PlotsAdjustedM)) { 731 | if(is.null(stagger)){ 732 | 733 | PlotsAdjustedM[i,4]<- (PlotsSquareM[i,4]*cos(Theta))+ (PlotsSquareM[i,5]*sin(Theta)) + NorthingCorner_0.0 # Y bottom left ranges 734 | PlotsAdjustedM[i,5]<- (PlotsSquareM[i,5]*cos(Theta))- (PlotsSquareM[i,4]*sin(Theta)) + EastingCorner_0.0 # X bottom left rows 735 | 736 | #BottomRight 737 | PlotsAdjustedM[i,6]<- (PlotsSquareM[i,6]*cos(Theta))+ (PlotsSquareM[i,7]*sin(Theta)) + NorthingCorner_0.0 # Y bottom right ranges 738 | PlotsAdjustedM[i,7]<- (PlotsSquareM[i,7]*cos(Theta))- (PlotsSquareM[i,6]*sin(Theta)) + EastingCorner_0.0 # X bottom right rows 739 | 740 | #TopRight 741 | PlotsAdjustedM[i,8]<- (PlotsSquareM[i,8]*cos(Theta))+ (PlotsSquareM[i,9]*sin(Theta)) + NorthingCorner_0.0 # Y top right ranges 742 | PlotsAdjustedM[i,9]<- (PlotsSquareM[i,9]*cos(Theta))- (PlotsSquareM[i,8]*sin(Theta)) + EastingCorner_0.0 # X top right rows 743 | 744 | #TopLeft 745 | PlotsAdjustedM[i,10]<- (PlotsSquareM[i,10]*cos(Theta))+ (PlotsSquareM[i,11]*sin(Theta)) + NorthingCorner_0.0 # Y top left ranges 746 | PlotsAdjustedM[i,11]<- (PlotsSquareM[i,11]*cos(Theta))- (PlotsSquareM[i,10]*sin(Theta)) + EastingCorner_0.0 # X top left rows 747 | 748 | ##BottomLeft Adjusted Buffer 749 | PlotsAdjustedMBuf[i,4]<- (PlotsSquareMBuf[i,4]*cos(Theta))+ (PlotsSquareMBuf[i,5]*sin(Theta)) + NorthingCorner_0.0 # Y bottom left ranges 750 | PlotsAdjustedMBuf[i,5]<- (PlotsSquareMBuf[i,5]*cos(Theta))- (PlotsSquareMBuf[i,4]*sin(Theta)) + EastingCorner_0.0 # X bottom left rows 751 | 752 | #BottomRight Adjusted Buffer 753 | PlotsAdjustedMBuf[i,6]<- (PlotsSquareMBuf[i,6]*cos(Theta))+ (PlotsSquareMBuf[i,7]*sin(Theta)) + NorthingCorner_0.0# Y bottom right ranges 754 | PlotsAdjustedMBuf[i,7]<- (PlotsSquareMBuf[i,7]*cos(Theta))- (PlotsSquareMBuf[i,6]*sin(Theta)) + EastingCorner_0.0 # X bottom right rows 755 | 756 | #TopRight Adjusted Buffer 757 | PlotsAdjustedMBuf[i,8]<- (PlotsSquareMBuf[i,8]*cos(Theta))+ (PlotsSquareMBuf[i,9]*sin(Theta)) + NorthingCorner_0.0# Y top right ranges 758 | PlotsAdjustedMBuf[i,9]<- (PlotsSquareMBuf[i,9]*cos(Theta))- (PlotsSquareMBuf[i,8]*sin(Theta)) + EastingCorner_0.0 # X top right rows 759 | 760 | #TopLeft Adjusted Buffer 761 | PlotsAdjustedMBuf[i,10]<- (PlotsSquareMBuf[i,10]*cos(Theta))+ (PlotsSquareMBuf[i,11]*sin(Theta)) + NorthingCorner_0.0# Y top left ranges 762 | PlotsAdjustedMBuf[i,11]<- (PlotsSquareMBuf[i,11]*cos(Theta))- (PlotsSquareMBuf[i,10]*sin(Theta)) + EastingCorner_0.0 # X top left rows 763 | } 764 | 765 | 766 | if(!is.null(stagger)){ 767 | if((ceiling((floor((PlotsSquareM[i,12]-stagger[[1]])+1)+stagger[[2]])/stagger[[2]])%%2)==0){ 768 | 769 | #BottomLeft 770 | PlotsAdjustedM[i,4]<- (PlotsSquareM[i,4]*cos(Theta))+ (PlotsSquareM[i,5]*sin(Theta)) + NorthingCorner_0.0_stag # Y bottom left ranges 771 | PlotsAdjustedM[i,5]<- (PlotsSquareM[i,5]*cos(Theta))- (PlotsSquareM[i,4]*sin(Theta)) + EastingCorner_0.0_stag # X bottom left rows 772 | 773 | #BottomRight 774 | PlotsAdjustedM[i,6]<- (PlotsSquareM[i,6]*cos(Theta))+ (PlotsSquareM[i,7]*sin(Theta)) + NorthingCorner_0.0_stag # Y bottom right ranges 775 | PlotsAdjustedM[i,7]<- (PlotsSquareM[i,7]*cos(Theta))- (PlotsSquareM[i,6]*sin(Theta)) + EastingCorner_0.0_stag # X bottom right rows 776 | 777 | #TopRight 778 | PlotsAdjustedM[i,8]<- (PlotsSquareM[i,8]*cos(Theta))+ (PlotsSquareM[i,9]*sin(Theta)) + NorthingCorner_0.0_stag # Y top right ranges 779 | PlotsAdjustedM[i,9]<- (PlotsSquareM[i,9]*cos(Theta))- (PlotsSquareM[i,8]*sin(Theta)) + EastingCorner_0.0_stag # X top right rows 780 | 781 | #TopLeft 782 | PlotsAdjustedM[i,10]<- (PlotsSquareM[i,10]*cos(Theta))+ (PlotsSquareM[i,11]*sin(Theta)) + NorthingCorner_0.0_stag # Y top left ranges 783 | PlotsAdjustedM[i,11]<- (PlotsSquareM[i,11]*cos(Theta))- (PlotsSquareM[i,10]*sin(Theta)) + EastingCorner_0.0_stag # X top left rows 784 | 785 | ##BottomLeft Adjusted Buffer 786 | PlotsAdjustedMBuf[i,4]<- (PlotsSquareMBuf[i,4]*cos(Theta))+ (PlotsSquareMBuf[i,5]*sin(Theta)) + NorthingCorner_0.0_stag # Y bottom left ranges 787 | PlotsAdjustedMBuf[i,5]<- (PlotsSquareMBuf[i,5]*cos(Theta))- (PlotsSquareMBuf[i,4]*sin(Theta)) + EastingCorner_0.0_stag # X bottom left rows 788 | 789 | #BottomRight Adjusted Buffer 790 | PlotsAdjustedMBuf[i,6]<- (PlotsSquareMBuf[i,6]*cos(Theta))+ (PlotsSquareMBuf[i,7]*sin(Theta)) + NorthingCorner_0.0_stag# Y bottom right ranges 791 | PlotsAdjustedMBuf[i,7]<- (PlotsSquareMBuf[i,7]*cos(Theta))- (PlotsSquareMBuf[i,6]*sin(Theta)) + EastingCorner_0.0_stag # X bottom right rows 792 | 793 | #TopRight Adjusted Buffer 794 | PlotsAdjustedMBuf[i,8]<- (PlotsSquareMBuf[i,8]*cos(Theta))+ (PlotsSquareMBuf[i,9]*sin(Theta)) + NorthingCorner_0.0_stag# Y top right ranges 795 | PlotsAdjustedMBuf[i,9]<- (PlotsSquareMBuf[i,9]*cos(Theta))- (PlotsSquareMBuf[i,8]*sin(Theta)) + EastingCorner_0.0_stag # X top right rows 796 | 797 | #TopLeft Adjusted Buffer 798 | PlotsAdjustedMBuf[i,10]<- (PlotsSquareMBuf[i,10]*cos(Theta))+ (PlotsSquareMBuf[i,11]*sin(Theta)) + NorthingCorner_0.0_stag# Y top left ranges 799 | PlotsAdjustedMBuf[i,11]<- (PlotsSquareMBuf[i,11]*cos(Theta))- (PlotsSquareMBuf[i,10]*sin(Theta)) + EastingCorner_0.0_stag # X top left rows 800 | 801 | } 802 | 803 | 804 | if((ceiling((floor((PlotsSquareM[i,12]-stagger[[1]])+1)+stagger[[2]])/stagger[[2]])%%2)!=0){ 805 | #BottomLeft 806 | PlotsAdjustedM[i,4]<- (PlotsSquareM[i,4]*cos(Theta))+ (PlotsSquareM[i,5]*sin(Theta)) + NorthingCorner_0.0 # Y bottom left ranges 807 | PlotsAdjustedM[i,5]<- (PlotsSquareM[i,5]*cos(Theta))- (PlotsSquareM[i,4]*sin(Theta)) + EastingCorner_0.0 # X bottom left rows 808 | 809 | #BottomRight 810 | PlotsAdjustedM[i,6]<- (PlotsSquareM[i,6]*cos(Theta))+ (PlotsSquareM[i,7]*sin(Theta)) + NorthingCorner_0.0 # Y bottom right ranges 811 | PlotsAdjustedM[i,7]<- (PlotsSquareM[i,7]*cos(Theta))- (PlotsSquareM[i,6]*sin(Theta)) + EastingCorner_0.0 # X bottom right rows 812 | 813 | #TopRight 814 | PlotsAdjustedM[i,8]<- (PlotsSquareM[i,8]*cos(Theta))+ (PlotsSquareM[i,9]*sin(Theta)) + NorthingCorner_0.0 # Y top right ranges 815 | PlotsAdjustedM[i,9]<- (PlotsSquareM[i,9]*cos(Theta))- (PlotsSquareM[i,8]*sin(Theta)) + EastingCorner_0.0 # X top right rows 816 | 817 | #TopLeft 818 | PlotsAdjustedM[i,10]<- (PlotsSquareM[i,10]*cos(Theta))+ (PlotsSquareM[i,11]*sin(Theta)) + NorthingCorner_0.0 # Y top left ranges 819 | PlotsAdjustedM[i,11]<- (PlotsSquareM[i,11]*cos(Theta))- (PlotsSquareM[i,10]*sin(Theta)) + EastingCorner_0.0 # X top left rows 820 | 821 | ##BottomLeft Adjusted Buffer 822 | PlotsAdjustedMBuf[i,4]<- (PlotsSquareMBuf[i,4]*cos(Theta))+ (PlotsSquareMBuf[i,5]*sin(Theta)) + NorthingCorner_0.0 # Y bottom left ranges 823 | PlotsAdjustedMBuf[i,5]<- (PlotsSquareMBuf[i,5]*cos(Theta))- (PlotsSquareMBuf[i,4]*sin(Theta)) + EastingCorner_0.0 # X bottom left rows 824 | 825 | #BottomRight Adjusted Buffer 826 | PlotsAdjustedMBuf[i,6]<- (PlotsSquareMBuf[i,6]*cos(Theta))+ (PlotsSquareMBuf[i,7]*sin(Theta)) + NorthingCorner_0.0# Y bottom right ranges 827 | PlotsAdjustedMBuf[i,7]<- (PlotsSquareMBuf[i,7]*cos(Theta))- (PlotsSquareMBuf[i,6]*sin(Theta)) + EastingCorner_0.0 # X bottom right rows 828 | 829 | #TopRight Adjusted Buffer 830 | PlotsAdjustedMBuf[i,8]<- (PlotsSquareMBuf[i,8]*cos(Theta))+ (PlotsSquareMBuf[i,9]*sin(Theta)) + NorthingCorner_0.0# Y top right ranges 831 | PlotsAdjustedMBuf[i,9]<- (PlotsSquareMBuf[i,9]*cos(Theta))- (PlotsSquareMBuf[i,8]*sin(Theta)) + EastingCorner_0.0 # X top right rows 832 | 833 | #TopLeft Adjusted Buffer 834 | PlotsAdjustedMBuf[i,10]<- (PlotsSquareMBuf[i,10]*cos(Theta))+ (PlotsSquareMBuf[i,11]*sin(Theta)) + NorthingCorner_0.0# Y top left ranges 835 | PlotsAdjustedMBuf[i,11]<- (PlotsSquareMBuf[i,11]*cos(Theta))- (PlotsSquareMBuf[i,10]*sin(Theta)) + EastingCorner_0.0 # X top left rows 836 | 837 | } 838 | } 839 | } 840 | names(PlotsAdjustedM) <- c( "Plot", "Range", "Row", "YBL", "XBL", "YBR", "XBR", "YTR", "XTR", "YTL", "XTL") 841 | names(PlotsAdjustedMBuf) <- c( "Plot", "Range", "Row", "YBLbuf", "XBLbuf", "YBRbuf", "XBRbuf", "YTRbuf", "XTRbuf", "YTLbuf", "XTLbuf") 842 | 843 | 844 | ###### PLOTTING SIZE OF PLOT DIMENSIONS ############ 845 | if (RotatePlot==T){ 846 | PlotY<- cbind(PlotsAdjustedM[,4], PlotsAdjustedM[,6], PlotsAdjustedM[,8], PlotsAdjustedM[,10]) 847 | PlotX<- cbind(PlotsAdjustedM[,5], PlotsAdjustedM[,7], PlotsAdjustedM[,9], PlotsAdjustedM[,11]) 848 | 849 | ###### PLOTTING SIZE OF PLOT DIMENSIONS ############ 850 | PlotYBuf<- cbind(PlotsAdjustedMBuf[,4], PlotsAdjustedMBuf[,6], PlotsAdjustedMBuf[,8], PlotsAdjustedMBuf[,10]) 851 | PlotXBuf<- cbind(PlotsAdjustedMBuf[,5], PlotsAdjustedMBuf[,7], PlotsAdjustedMBuf[,9], PlotsAdjustedMBuf[,11]) 852 | 853 | ########## PLOTTING ############## 854 | pdf(paste(field,outfile,"Rotated_plots.pdf",sep="_"), 855 | width=30, 856 | height=30) 857 | plot(c(min(PlotX),max(PlotX)), c(min(PlotY),max(PlotY)), type="n", xlab = "UTM Easting Coordinates (m)", ylab = "UTM Northing Coordinates (m)") # Plot lines in field 858 | 859 | for (i in 1:nrow(PlotsAdjustedM)) { 860 | for (j in 1:4) { 861 | points(PlotX[i,j], PlotY[i,j]) 862 | } 863 | polygon(PlotX[i,], PlotY[i,]) 864 | polygon(PlotXBuf[i,], PlotYBuf[i,], col="RED") 865 | text( ((PlotX[i,1]+PlotX[i,3])/2), ((PlotY[i,1]+PlotY[i,3])/2), labels= PlotsSquareM[i,1], pos = NULL, col = "BLUE", cex=0.7, srt=srt_theta) 866 | } 867 | dev.off() 868 | } 869 | 870 | 871 | ################################################################### 872 | # ########## Make Shape Files4 ############## 873 | # if(multirowind!=T){ 874 | 875 | # if (file.exists(paste(output,"\\",field,".shp",sep="")) | 876 | # file.exists(paste(output,"\\",field,".dbf",sep="")) | 877 | # file.exists(paste(output,"\\",field,".shx",sep=""))) 878 | # { 879 | # file.remove(paste(output,"\\",field,".shp",sep="")) 880 | # file.remove(paste(output,"\\",field,".dbf",sep="")) 881 | # file.remove(paste(output,"\\",field,".shx",sep="")) 882 | # } 883 | 884 | 885 | PolygonsToMake <- vector('list', length(nPlot)) 886 | for (i in 1: nrow(PlotsAdjustedM)) { 887 | PolygonsToMake[[i]] <- Polygons(list(Polygon(matrix(c(PlotsAdjustedM[i,c(5,7,9,11,5)], 888 | PlotsAdjustedM[i,c(4,6,8,10,4)]),5,2), 889 | hole=FALSE)), 890 | rownames(PlotsAdjustedM)[i]) 891 | } 892 | 893 | if(is.null(UTMzone)){ 894 | SpatialPolygonsToMake <- SpatialPolygons((PolygonsToMake)) 895 | warning("Coordinate reference system not defined 'UTMzone=NULL'; This may result in difficulties loading shapefiles into other programs.") 896 | } 897 | 898 | if(!is.null(UTMzone)&Hemisphere=="N"){ 899 | SpatialPolygonsToMake <- SpatialPolygons((PolygonsToMake), 900 | proj4string = CRS( 901 | as.character(paste("+proj=utm +zone=",UTMzone," +datum=NAD83 +units=m +no_defs +ellps=GRS80",sep="")) 902 | )) 903 | } 904 | 905 | if(!is.null(UTMzone)&Hemisphere=="S"){ 906 | SpatialPolygonsToMake <- SpatialPolygons((PolygonsToMake), 907 | proj4string = CRS( 908 | as.character(paste("+proj=utm +zone=",UTMzone," +south +datum=NAD83 +units=m +no_defs +ellps=GRS80",sep="")) 909 | )) 910 | } 911 | 912 | SpatialPolygonsToMake.df <- SpatialPolygonsDataFrame(SpatialPolygonsToMake, 913 | data.frame(id=rownames(PlotsAdjustedM), 914 | row.names=rownames(PlotsAdjustedM))) 915 | 916 | 917 | FolderpathGPSPlots<-paste(field,"_",outfile,".shp",sep="") 918 | writeOGR(SpatialPolygonsToMake.df, 919 | FolderpathGPSPlots, 920 | field, 921 | verbose = TRUE, 922 | overwrite_layer = T, 923 | driver="ESRI Shapefile") 924 | 925 | 926 | ########## Make Shape Files4 ############## 927 | # ord_infile<-infile[order(infile$Range,infile$Row)] 928 | 929 | # IDs<- as.character(infile$Barcode) 930 | 931 | PolygonsToMake <- vector('list', length(nPlot)) 932 | for (i in 1: nrow(PlotsAdjustedM)) { 933 | PolygonsToMake[[i]] <- Polygons(list(Polygon(matrix(c(PlotsAdjustedMBuf[i,c(5,7,9,11,5)], 934 | PlotsAdjustedMBuf[i,c(4,6,8,10,4)]),5,2), hole=FALSE)), 935 | rownames(PlotsAdjustedMBuf)[i]) 936 | } 937 | 938 | if(is.null(UTMzone)){ 939 | SpatialPolygonsToMake <- SpatialPolygons((PolygonsToMake)) 940 | warning("Coordinate reference system not defined 'UTMzone=NULL'; This may result in difficulties loading shapefiles into other programs.") 941 | } 942 | 943 | if(!is.null(UTMzone)&Hemisphere=="N"){ 944 | SpatialPolygonsToMake <- SpatialPolygons((PolygonsToMake), 945 | proj4string = CRS( 946 | as.character(paste("+proj=utm +zone=",UTMzone," +datum=NAD83 +units=m +no_defs +ellps=GRS80",sep="")) 947 | )) 948 | } 949 | 950 | if(!is.null(UTMzone)&Hemisphere=="S"){ 951 | SpatialPolygonsToMake <- SpatialPolygons((PolygonsToMake), 952 | proj4string = CRS( 953 | as.character(paste("+proj=utm +zone=",UTMzone," +south +datum=NAD83 +units=m +no_defs +ellps=GRS80",sep="")) 954 | )) 955 | } 956 | 957 | SpatialPolygonsToMake.df <- SpatialPolygonsDataFrame(SpatialPolygonsToMake, 958 | data.frame(id=rownames(PlotsAdjustedMBuf), 959 | row.names=rownames(PlotsAdjustedMBuf))) 960 | 961 | 962 | FolderpathGPSPlots<-paste(field,outfile,"buff.shp",sep="_") 963 | writeOGR(SpatialPolygonsToMake.df, 964 | FolderpathGPSPlots, 965 | paste(field,"Buff",sep="_"), 966 | verbose = TRUE, 967 | overwrite_layer = T, 968 | driver="ESRI Shapefile") 969 | 970 | 971 | } 972 | # } 973 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [R/UAStools](https://github.com/andersst91/UAStools/wiki) 2 | 3 | ### Authors: 4 | Steven L. Anderson II (andersst@tamu.edu) 5 | Seth C. Murray (sethmurray@tamu.edu) 6 | 7 | ### Description: 8 | UAStools is a package developed to provide useful tools for working with remote sensing data set, specifically in reference to field-based, agriculture research plots. Currently, the [plotshpcreate.R](https://github.com/andersst91/UAStools/wiki/plotshpcreate.R) function is available to construct a multi-polygon shapefile (.shp) of a reasearch trial, with individual polygons defining specific research plot. A full video tutorial is availible with accompanied [script](files/path/to/file "ALT TEXT"). 9 | 10 | # Installation 11 | Make sure you have the latest version of [R](https://cran.r-project.org/). 12 | 13 | [R/UAStools](https://github.com/andersst91/UAStools/wiki) is availible on [GitHub](https://github.com/andersst91/UAStools). 14 | 15 | You then need to install the [devtools](https://github.com/r-lib/devtools) package, plus a set of package dependencies: [sp](https://cran.r-project.org/web/packages/sp/index.html) and [rgdal](https://cran.r-project.org/web/packages/rgdal/index.html). (Additional, secondary dependencies will also be installed.) 16 | 17 | To install [R/UAStools](https://github.com/andersst91/UAStools/wiki) execute the following commands in R: 18 | 19 | install.packages("devtools") 20 | library("devtools") 21 | devtools::install_github("andersst91/UAStools") 22 | library("UAStools") 23 | 24 | # Availible Functions 25 | ## [plotshpcreate.R](https://github.com/andersst91/UAStools/wiki/plotshpcreate.R) 26 | Construct a multi-polygon shapefile (.shp) of a reasearch trial, with individual polygons defining specific research field plots. 27 | Visit the wiki page for more details: https://github.com/andersst91/UAStools/wiki/plotshpcreate.R 28 | 29 | ### Note: Make sure to setwd() before executing [plotshpcreate.R](https://github.com/andersst91/UAStools/wiki/plotshpcreate.R)!!! 30 | 31 | ?plotshpcreate 32 | ?SampleInfile 33 | 34 | ### Citation 35 | 36 | To cite R/UAStools in publications, use: 37 | 38 | Anderson, S.L., S. Murray, L. Malambo, C. Ratcliff, S. Popescu, D. Cope, et al. 2019. Prediction of Maize Grain Yield Before Maturity Using Improved Temporal Height Estimates of Unmanned Aerial Systems. The Plant Phenome Journal. doi:10.2135/tppj2019.02.0004 39 | 40 | ### Liscense 41 | [Licensed](LICENSE) under [GPL-2](https://www.r-project.org/Licenses/GPL-2). 42 | -------------------------------------------------------------------------------- /UAStools.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | PackageRoxygenize: rd,collate,namespace,vignette 19 | -------------------------------------------------------------------------------- /data/SampleInfile.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andersst91/UAStools/de8d9507f6159abce9355cb2f1c113e5bf0afd61/data/SampleInfile.rda -------------------------------------------------------------------------------- /data/SampleInfile_Subset.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andersst91/UAStools/de8d9507f6159abce9355cb2f1c113e5bf0afd61/data/SampleInfile_Subset.rda -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | citHeader("To cite the UAStools package in publications use:") 2 | 3 | 4 | citEntry(entry="Article", 5 | 6 | title = "Prediction of Maize Grain Yield Before Maturity Using Improved Temporal Height Estimate of Unmanned Aerial Systems", 7 | author = personList(as.person("Steven L. Anderson II"), 8 | as.person("Seth C. Murray"), 9 | as.person("Lonesome Malambo"), 10 | as.person("Colby Ratcliff"), 11 | as.person("Sorin Popescu"), 12 | as.person("Dale Cope"), 13 | as.person("Anjin Chang"), 14 | as.person("Jinhu Jung"), 15 | as.person("J. Alex Thomasson")), 16 | year = "2019", 17 | journal = "The Plant Phenome Journal", 18 | volume = "2", 19 | issue = "1", 20 | doi = "10.2135/tppj2019.02.0004", 21 | url = "http://dx.doi.org/10.2135/tppj2019.02.0004", 22 | 23 | textVersion = "Anderson, S. L., Murray, S. C., Malambo, L., Ratcliff, C., Popescu, S., Cope, D., Chang, A., Jung, J., & Thomasson, J. A. (2019). Prediction of Maize Grain Yield before Maturity Using Improved Temporal Height Estimates of Unmanned Aerial Systems. The Plant Phenome Journal, 2(1). doi:10.2135/tppj2019.02.0004." 24 | ) -------------------------------------------------------------------------------- /man/SampleInfile.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/SampleInfile.R 3 | \docType{data} 4 | \name{SampleInfile} 5 | \alias{SampleInfile} 6 | \title{Infile Sample Dataset} 7 | \format{ 8 | A dataframe containg the preperation file used to design the CS17-G2FE experiment, which 9 | contains 594 two row plots and 1188 observations. 10 | 11 | We recommend have repeated Barcodes and Plot numbers if there are multirow plots (mrowplot>1) as 12 | the plotshpcreatre function accounts for this redundance within the function. 13 | [,1] Loc An abbreviation to identify the trial location and year (character) 14 | [,2] Test An abbreviation to define the trial name (character) 15 | [,3] Plot The number of each plot (numeric) 16 | [,4] Barcode A unique identifier for each plot (character) 17 | [,5] Stock The seed source which is planted in each plot (character) 18 | [,6] Pedigree Information defining the lineage of the seed source (character) 19 | [,7] Entry An additional unique identifer commonly used to track consistent pedigrees from different seed stocks (numeric) 20 | [,8] Rep The replicate number of each plot (numeric) 21 | [,9] Range The range [also called row] number of each plot in the experimental grid (numeric) 22 | [,10] Row The row [also called column] number of each plot in the experimental grid (numeric) 23 | } 24 | \usage{ 25 | SampleInfile 26 | } 27 | \description{ 28 | Example of infile structure for the plotshpcreat function. 29 | Contains the preperation file used to design the CS17-G2FE experiment, which 30 | contains 594 two row plots and 1188 observations. 31 | } 32 | \note{ 33 | Only Range, Row, Plot, and Barcode variables are necessary for the the proper execution of plotshpcreate, 34 | but additional columns may be included in the dataframe. 35 | } 36 | \keyword{datasets} 37 | \keyword{infile} 38 | \keyword{sample} 39 | -------------------------------------------------------------------------------- /man/SampleInfile_Subset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/SampleInfile_Subset.R 3 | \docType{data} 4 | \name{SampleInfile_Subset} 5 | \alias{SampleInfile_Subset} 6 | \title{Infile Sample Dataset for subset examples} 7 | \format{ 8 | A dataframe containg the preperation file used to design the CS17-G2FE experiment, which 9 | contains 288 two row plots and 1152 observations. 10 | 11 | We recommend have repeated Barcodes and Plot numbers if there are multirow plots (mrowplot>1) as 12 | the plotshpcreatre function accounts for this redundance within the function. 13 | [,1] Loc An abbreviation to identify the trial location and year (character) 14 | [,2] Test An abbreviation to define the trial name (character) 15 | [,3] Plot The number of each plot (numeric) 16 | [,4] Barcode A unique identifier for each plot (character) 17 | [,5] Stock The seed source which is planted in each plot (character) 18 | [,6] Pedigree Information defining the lineage of the seed source (character) 19 | [,7] Entry An additional unique identifer commonly used to track consistent pedigrees from different seed stocks (numeric) 20 | [,8] Rep The replicate number of each plot (numeric) 21 | [,9] Range The range [also called row] number of each plot in the experimental grid (numeric) 22 | [,10] Row The row [also called column] number of each plot in the experimental grid (numeric) 23 | } 24 | \usage{ 25 | SampleInfile_Subset 26 | } 27 | \description{ 28 | Example of infile structure for the plotshpcreat function. 29 | Contains the preperation file used to design the CS17-G2FE experiment, which 30 | contains 594 two row plots and 1188 observations. 31 | } 32 | \note{ 33 | Only Range, Row, Plot, and Barcode variables are necessary for the the proper execution of plotshpcreate, 34 | but additional columns may be included in the dataframe. 35 | } 36 | \keyword{datasets} 37 | \keyword{infile} 38 | \keyword{sample} 39 | -------------------------------------------------------------------------------- /man/plotshpcreate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plotshpcreate.R 3 | \name{plotshpcreate} 4 | \alias{plotshpcreate} 5 | \title{Plot Shapefile Create} 6 | \usage{ 7 | plotshpcreate( 8 | A = NULL, 9 | B = NULL, 10 | UTMzone = NULL, 11 | Hemisphere = "N", 12 | infile = NULL, 13 | outfile = NULL, 14 | nrowplot = 1, 15 | multirowind = FALSE, 16 | rowspc = 2.5, 17 | rowbuf = 0.1, 18 | rangespc = 25, 19 | rangebuf = 2, 20 | stagger = NULL, 21 | plotsubset = 0, 22 | field = NULL, 23 | unit = "feet", 24 | SquarePlot = TRUE, 25 | RotatePlot = TRUE 26 | ) 27 | } 28 | \arguments{ 29 | \item{A}{Vector of UTM coordinates (Easting,Northing) of "A" point, which corresponds 30 | to the bottom left corner of the first field plot. 31 | Note: This point is where the function begins building polygons. This point is intended 32 | to be the midpoint of alley at the front of the first plot and the midpoint of the} 33 | 34 | \item{B}{Vector of UTM coordinates (Easting,Northing) of "B" point, which corresponds 35 | to the top left corner of the field trial within the same row as the "A" point} 36 | 37 | \item{UTMzone}{Character parameter defining UTM zone number. Default is NULL and will result in an coordinate reference system of "NA".} 38 | 39 | \item{Hemisphere}{Character parameter that designates the Northern "N" or Southern "S" Hemisphere. Default is "N".} 40 | 41 | \item{infile}{Data frame containing seed preperation file and experimental design 42 | (i.e. coordinates of plots within the design grid)} 43 | 44 | \item{outfile}{Character assignment to define outputfile names. If left null, default 45 | file names will be produced.} 46 | 47 | \item{nrowplot}{Number of adjacent rows that constitute a plot.Setting this parameter 48 | to greater than one allows for different polygon options. Default set to 1.} 49 | 50 | \item{multirowind}{Logic parameter that indicates if adjacent plot rows should be 51 | combined and treated as a single plot shapefile and unique idenfifier. Setting to false 52 | will combine adjacent plots and construct a single polygon that encompasses 53 | all adjacent rows within a plot. Default set to true.} 54 | 55 | \item{rowspc}{Row (i.e. column) spacing of a single row. Default 2.5 feet in reference to 56 | 30 inch row spacing.} 57 | 58 | \item{rowbuf}{Distance removed from both sides of rowspc to create a buffer zone between 59 | plots boundaries. Default is 0.1 feet.} 60 | 61 | \item{rangespc}{Range (i.e. row) spacing of a single row. This dimesnsion referes to the total 62 | plot length including half alley distance on either side of the plot. Default 25 feet.} 63 | 64 | \item{rangebuf}{Distance removed from both sides of rangespc to create a buffer zone between 65 | plots boundaries. Default is 2 feet in reference to four foot allies. Note: If alleys are 66 | 4 feet rangebuf should be set to 2 feet to remove from both ends of the polygon.} 67 | 68 | \item{stagger}{Numeric vector of length three defining [1] row where staggers starts, 69 | [2] rows sowed by planted in a single pass, and [3] stagger offset distance from A point.} 70 | 71 | \item{plotsubset}{Defines how many adjacent rows should be excluded from the shapefile. 72 | This parameter is useful for multirow plots where the central plots are of interest. If plotsubset=1, 73 | the outer row will be removed from both sides of the plot.} 74 | 75 | \item{field}{Character vector to indicate the trial the shapefile is being developed for. 76 | Recommended format example: CS17-G2FE, which inicated location (CS), year (17), and trial (G2FE).} 77 | 78 | \item{unit}{Character vector that the unit of measure for the polygon dimesnions. Default is "feet". 79 | Units can also be input as meters using unit="meter".} 80 | 81 | \item{SquarePlot}{Logic parameter to indicated if PDF file is desired for visualization of none rotated polygons.} 82 | 83 | \item{RotatePlot}{Logic parameter to indicated if PDF file is desired for visualization of rotated polygons.} 84 | } 85 | \description{ 86 | Methods for constructing multipolygon ESRI shapefiles (.shp) 87 | with individual polygons containing agricultural plot boundaries. Utilizes 88 | AB line to rotate polygons to the appropriate geospatial direction of research 89 | plots, allowing for simple overlay upon Unmanned Aerial System (UAS) or other 90 | geospatial datasets (e.g. orthomosaics, point clouds, etc.) for feature extraction. 91 | 92 | It is recommended to define working directory for output files prior to executing plotshpcreate. 93 | } 94 | \note{ 95 | it is recommendeed to repeat unique Barcodes and Plot numbers if there are multirow plots (mrowplot>1) as 96 | the plotshpcreatre function accounts for this redundance within the function. 97 | } 98 | \examples{ 99 | 100 | 101 | ### Creates shape file for each individual with the inclusion of multirow plot design 102 | ### with nrowplot>1 and multirowind=T. Unique identifiers are subset by the location 103 | ### of the adjacent plots reading from left to right in geographical space. 104 | 105 | ### Set working directory to where you want the files to be saved 106 | setwd("C://Temp") 107 | 108 | plotshpcreate(A=c(746239.817,3382052.264), #Point A c(Easting_0.0,Northing_0.0) 109 | B=c(746334.224,3382152.870), #Point B c(Easting_1.0,Northing_1.0) 110 | UTMzone="14", 111 | Hemisphere="N", 112 | infile=SampleInfile, 113 | outfile="Ind_Multirow_plots", 114 | nrowplot=2, 115 | multirowind=TRUE, 116 | rowspc=2.5, 117 | rowbuf=0.1, ### Will take off both sides of the plot 118 | rangespc=25, 119 | rangebuf=2, ### Half the alley width 120 | plotsubset=NULL, 121 | field="CS17-G2FE", 122 | unit="feet", 123 | SquarePlot=TRUE, 124 | RotatePlot=TRUE) 125 | 126 | # Creates shape file by combining adacent row of unique plots of multirow plot design 127 | # within a single polygone with nrowplot>1 and multirowind=T. If a plot is two rows wide 128 | # the shape file will encompass the plot as a whole. 129 | 130 | ### Set working directory to where you want the files to be saved 131 | setwd("C://Temp") 132 | plotshpcreate(A=c(746239.817,3382052.264), #Point A c(Easting_0.0,Northing_0.0) 133 | B=c(746334.224,3382152.870), #Point B c(Easting_1.0,Northing_1.0) 134 | UTMzone="14", 135 | Hemisphere="N" 136 | infile=SampleInfile, 137 | outfile="Multirowplotscombined", 138 | nrowplot=2, 139 | multirowind=FALSE, 140 | rowspc=2.5, 141 | rowbuf=0.1, ### Will take off both sides of the plot 142 | rangespc=25, 143 | rangebuf=2, ### Half the alley width 144 | plotsubset=NULL, 145 | field="CS17-G2FE", 146 | unit="feet", 147 | SquarePlot=TRUE, 148 | RotatePlot=TRUE) 149 | 150 | # If the experiment is a single row plot design utilize nrowplot=1. 151 | } 152 | --------------------------------------------------------------------------------