commit 20f481dac09ed618c108d7b36b56a4fd2fd1042b Author: Administrator Date: Sat May 20 20:15:38 2023 +0800 fitst diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..919ce1f --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..4731638 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..c7d8335 --- /dev/null +++ b/pom.xml @@ -0,0 +1,50 @@ + + 4.0.0 + + org.example + lll + 1.0-SNAPSHOT + jar + + lll + http://maven.apache.org + + + UTF-8 + 2.12.8 + + + + + junit + junit + 3.8.1 + test + + + com.github.deng0515001 + lnglat2Geo + 1.0.5 + + + org.scala-lang + scala-library + 2.11.2 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 17 + 17 + + + + + diff --git a/src/main/java/org/example/App.java b/src/main/java/org/example/App.java new file mode 100644 index 0000000..7857d4b --- /dev/null +++ b/src/main/java/org/example/App.java @@ -0,0 +1,35 @@ +package org.example; + +import com.dengxq.lnglat2Geo.entity.Admin; +import com.dengxq.lnglat2Geo.entity.CoordinateSystem$; +import scala.Enumeration.Value; + +import java.util.List; + +import com.dengxq.lnglat2Geo.GeoTrans; +import scala.collection.JavaConverters; + +/** + * Hello world! + */ +public class App { + public static void main(String[] args) { + String lon = "116.393353"; + String lat = "39.944625"; + getlocation(lon, lat); + } + + public static Admin getlocation(String lon, String lat) { + // 将Scala枚举类型转换为Java枚举类型 + List colorValues = JavaConverters.seqAsJavaListConverter( + CoordinateSystem$.MODULE$.values().toSeq() + ).asJava(); + + + Admin admin = GeoTrans.determineAdmin(Double.parseDouble(lon), Double.parseDouble(lat), colorValues.get(2), true); +// System.out.println(admin.province()); +// System.out.println(admin.city()); +// System.out.println(admin.district()); + return admin; + } +} diff --git a/src/main/java/org/example/CsvReaderx.java b/src/main/java/org/example/CsvReaderx.java new file mode 100644 index 0000000..6e746d8 --- /dev/null +++ b/src/main/java/org/example/CsvReaderx.java @@ -0,0 +1,76 @@ +package org.example; + +import com.dengxq.lnglat2Geo.GeoTrans; +import com.dengxq.lnglat2Geo.entity.Admin; +import com.dengxq.lnglat2Geo.entity.CoordinateSystem$; +import scala.Enumeration; +import scala.collection.JavaConverters; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class CsvReaderx { + public static void main(String[] args) { + // 将Scala枚举类型转换为Java枚举类型 + List colorValues = JavaConverters.seqAsJavaListConverter( + CoordinateSystem$.MODULE$.values().toSeq() + ).asJava(); + + String csvFile = "E:\\javacode\\lll\\src\\main\\java\\org\\example\\Animaliax1.csv"; + String csvFileto = "E:\\javacode\\lll\\src\\main\\java\\org\\example\\Animalia1.csv"; + String line = ""; + String csvDelimiter = ","; //csv分隔符,根据实际情况修改 + + try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) { + List csvData = new ArrayList<>(); + while ((line = br.readLine()) != null) { + String[] csvLine = line.split(csvDelimiter); + csvData.add(csvLine); + } + + try (FileWriter writer = new FileWriter(csvFileto)) { + // 打印读取到的数据 + for (String[] row : csvData) { +// System.out.println(row[0]); + List row1 = new ArrayList(); + for (String col : row) { + row1.add(col); + } + System.out.println("计算"); + try { + System.out.println(Double.parseDouble(row[1])); + System.out.println(Double.parseDouble(row[0])); + System.out.println(colorValues.get(2)); + + Admin admin = App.getlocation(row[1], row[0]); + row1.add(admin.province()); + row1.add(admin.city()); + row1.add(admin.district()); + writeRow(writer, row1, csvDelimiter); + } catch (ArrayIndexOutOfBoundsException e) { + row1.add(""); + row1.add(""); + row1.add(""); + writeRow(writer, row1, csvDelimiter); + System.out.println("经纬度为空"); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static void writeRow(FileWriter writer, List row, String delimiter) throws IOException { + String csvRow = String.join(delimiter, row); + writer.write(csvRow + System.lineSeparator()); + } +} + diff --git a/src/test/java/org/example/AppTest.java b/src/test/java/org/example/AppTest.java new file mode 100644 index 0000000..d5f435d --- /dev/null +++ b/src/test/java/org/example/AppTest.java @@ -0,0 +1,38 @@ +package org.example; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +}