Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e28a3e
commit 271f55a
Showing
5 changed files
with
65 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...mpler/src/main/java/org/openforis/collect/earth/sampler/adhoc/UruguayDisplacedPoints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.openforis.collect.earth.sampler.adhoc; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.openforis.collect.earth.core.utils.CsvReaderUtils; | ||
import org.openforis.collect.earth.sampler.utils.CoordinateUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.opencsv.CSVReader; | ||
import com.opencsv.CSVWriter; | ||
|
||
public class UruguayDisplacedPoints { | ||
|
||
|
||
public static void main(String[] args) { | ||
|
||
Logger logger = LoggerFactory.getLogger( UruguayDisplacedPoints.class ); | ||
File fileToDivide = new File("C:/temp/urugua2.csv"); | ||
if( !fileToDivide.exists() ){ | ||
throw new IllegalArgumentException("The file selected does not exist"); | ||
} | ||
|
||
try ( | ||
FileWriter fw = new FileWriter( new File("C:/temp/modified2.csv") ); | ||
CSVWriter writer = new CSVWriter( fw ); | ||
CSVReader reader = CsvReaderUtils.getCsvReader(fileToDivide.getPath(), false, true ); | ||
){ | ||
|
||
List<String[]> modified = new ArrayList<>(); | ||
|
||
// read first line | ||
String[] csvRow; | ||
|
||
// First divide the lines into the files by column ( or a single file if the user chose not to divide using a column) | ||
while ((csvRow = reader.readNext()) != null ) { | ||
|
||
Double yCoordinate = Double.parseDouble( csvRow[1] ); | ||
Double xCoordinate = Double.parseDouble( csvRow[2] ); | ||
|
||
double[] pointWithOffset = CoordinateUtils.getPointWithOffset( new double[]{ yCoordinate, xCoordinate }, 1500, 1500); | ||
|
||
csvRow[1] = Double.toString( pointWithOffset[0] ); | ||
csvRow[2] = Double.toString( pointWithOffset[1] ); | ||
|
||
modified.add( csvRow ); | ||
} | ||
|
||
for (String[] row : modified) { | ||
writer.writeNext(row); | ||
} | ||
|
||
} catch (Exception e) { | ||
logger.error("Error processing CSV file", e); | ||
} | ||
} | ||
} |