diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..805cd61 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +.classpath +.project +.settings/ +*.class +*.zip +*.jar +*.tar.gz +/target/ +!/src/main/resources/* +!/src/test/resources/* +/src/test/data/*~ +/src/test/data/*.log +/src/test/data/cameradata/ +/src/test/data/output +nbbuild.xml +nbactions.xml +Thumbs.db +/nbproject/ diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100755 index 0000000..a37e276 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,43 @@ +The MIT License (MIT) + +Copyright (c) 2014 Yuu Hayashi + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + +以下に定める条件に従い、本ソフトウェアおよび関連文書のファイル(以下「ソフトウェア」)の複製を取得するすべて +の人に対し、ソフトウェアを無制限に扱うことを無償で許可します。これには、ソフトウェアの複製を使用、複写、変 +更、結合、掲載、頒布、サブライセンス、および/または販売する権利、およびソフトウェアを提供する相手に同じこ +とを許可する権利も無制限に含まれます。 + +上記の著作権表示および本許諾表示を、ソフトウェアのすべての複製または重要な部分に記載するものとします。 + +ソフトウェアは「現状のまま」で、明示であるか暗黙であるかを問わず、何らの保証もなく提供されます。ここでいう保証 +とは、商品性、特定の目的への適合性、および権利非侵害についての保証も含みますが、それに限定されるもので +はありません。 作者または著作権者は、契約行為、不法行為、またはそれ以外であろうと、ソフトウェアに起因または +関連し、あるいはソフトウェアの使用またはその他の扱いによって生じる一切の請求、損害、その他の義務について何 +らの責任も負わないものとします。 + +---------------- + +osm.jp.gpx.GeoDistance.java は'やまだらけ'様の著作物です。 + Copyright (C) 2007-2012 やまだらけ + The MIT License (MIT) + 参照元: http://yamadarake.jp/trdi/report000001.html + 「Cords.java」を改変 diff --git a/README.md b/README.md new file mode 100755 index 0000000..427b607 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# haya4-jpmesh + +地域メッシュコードを扱うライブラリ + +## See + +* [haya4-jpmesh wiki](http://surveyor.mydns.jp/gitbucket/haya4/haya4-jpmesh/wiki) + +## License + +* [MIT License](LICENSE.txt) + +------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml new file mode 100755 index 0000000..29b15f4 --- /dev/null +++ b/pom.xml @@ -0,0 +1,129 @@ + + 4.0.0 + haya4.tools + haya4-jpmesh + 0.0.1-SNAPSHOT + haya4-jpmesh + jar + + scm:git:http://surveyor.mydns.jp/gitbucket/git/haya4/haya4-jpmesh.git + http://surveyor.mydns.jp/gitbucket/haya4/haya4-jpmesh/wiki + scm:git:http://surveyor.mydns.jp/gitbucket/git/haya4/haya4-jpmesh.git + ${version} + + + + + MIT License + http://www.opensource.org/licenses/mit-license.php + + + + + + Yuu Hayashi + hayashi.yuu@gmail.com + surveyor + http://surveyor.mydns.jp/ + + + + + UTF-8 + 1.8 + ${java.version} + ${java.version} + + + 4.13.1 + 1.3 + 25.1 + + + + + + surveyor.haya4 + Internal Release Repository + http://surveyor.mydns.jp/archiva/repository/haya4/ + + + surveyor.snapshots + Archiva Managed Snapshot Repository + http://surveyor.mydns.jp/archiva/repository/snapshots/ + + + + + + + osgeo + OSGeo Release Repository + https://repo.osgeo.org/repository/release/ + false + true + + + + + osgeo-snapshot + OSGeo Snapshot Repository + https://repo.osgeo.org/repository/snapshot/ + true + false + + + + + + + org.geotools + gt-main + ${geotools.version} + + + + + org.hamcrest + hamcrest-core + ${hamcrest.version} + test + jar + + + junit + junit + ${junit.version} + test + jar + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + + + org.apache.maven.plugins + maven-site-plugin + 3.7.1 + + ja + ${project.build.sourceEncoding} + ${site.encoding} + + + + + + + \ No newline at end of file diff --git a/src/main/java/haya4/tools/jpmesh/Jpmesh.java b/src/main/java/haya4/tools/jpmesh/Jpmesh.java new file mode 100644 index 0000000..f93bc7e --- /dev/null +++ b/src/main/java/haya4/tools/jpmesh/Jpmesh.java @@ -0,0 +1,57 @@ +package haya4.tools.jpmesh; + +import java.awt.geom.Rectangle2D; + +import org.geotools.geometry.DirectPosition2D; + +public class Jpmesh { + + /** + * 地域メッシュコードの位置(南西角)を取得する + * @param str 地域メッシュコード + * @return 地域メッシュコードの南西角位置 + */ + public static DirectPosition2D getPosition(String str) { + if (str != null) { + if (str.length() == 8) { + double lat1 = Double.parseDouble(str.substring(0, 2)); + double lat2 = Double.parseDouble(str.substring(4, 5)); + double lat3 = Double.parseDouble(str.substring(6, 7)); + + double lon1 = Double.parseDouble(str.substring(2, 4)); + double lon2 = Double.parseDouble(str.substring(5, 6)); + double lon3 = Double.parseDouble(str.substring(7, 8)); + + double lat = (((lat1 / 1.5 * 3600) + (lat2 * 5 * 60) + (lat3 * 60)) / 3600); + double lon = ((((lon1 + 100) * 3600) + (lon2 * 7.5 * 60) + (lon3 * 45)) / 3600); + return new DirectPosition2D(lon, lat); + } + } + return null; + } + + /** + * 地域メッシュコードの位置(中央)を取得する + * @param str 地域メッシュコード + * @return 地域メッシュコードの中央位置 + */ + public static DirectPosition2D getCenterPosition(String str) { + DirectPosition2D ret = getPosition(str); + if (ret != null) { + double lat = (ret.getY() + (30d / 2 / 3600d)); + double lon = (ret.getX() + (45d / 2 / 3600d)); + return new DirectPosition2D(lon, lat); + } + return null; + } + + public static Rectangle2D getRectangle(String str) { + DirectPosition2D ret = getPosition(str); + if (ret != null) { + double lat = (ret.getY()); + double lon = (ret.getX()); + return new Rectangle2D.Double(lon, lat, (45d / 3600d), (30d / 3600d)); + } + return null; + } +} diff --git a/src/main/java/haya4/tools/jpmesh/Position.java b/src/main/java/haya4/tools/jpmesh/Position.java new file mode 100644 index 0000000..67fea40 --- /dev/null +++ b/src/main/java/haya4/tools/jpmesh/Position.java @@ -0,0 +1,25 @@ +package haya4.tools.jpmesh; + +public class Position { + double lat = 0.0d; + double lon = 0.0d; + + public Position() { + this.lat = 0.0d; + this.lon = 0.0d; + } + + public Position(double lat, double lon) { + this.lat = lat; + this.lon = lon; + } + + public double getX() { + return this.lat; + } + + public double getY() { + return this.lon; + } + +} diff --git a/src/test/java/haya4/tools/jpmesh/JpmeshTest.java b/src/test/java/haya4/tools/jpmesh/JpmeshTest.java new file mode 100755 index 0000000..0542aaf --- /dev/null +++ b/src/test/java/haya4/tools/jpmesh/JpmeshTest.java @@ -0,0 +1,43 @@ +package haya4.tools.jpmesh; + +import static org.junit.Assert.*; + +import java.awt.geom.Rectangle2D; + +import org.geotools.geometry.DirectPosition2D; +import org.junit.Test; + +public class JpmeshTest { + + @Test + public void getPositionTest() { + DirectPosition2D ret = Jpmesh.getPosition(null); + assertNull(ret); + + ret = Jpmesh.getPosition("53394526 "); + assertNull(ret); + + ret = Jpmesh.getPosition("53394526"); + assertNotNull(ret); + assertEquals(35.7d, ret.getY(), 0.000001d); + assertEquals(139.7d, ret.getX(), 0.000001d); + } + + @Test + public void getCenterTest() { + DirectPosition2D center = Jpmesh.getCenterPosition("53394526"); + assertNotNull(center); + assertEquals(35.7041666d, center.getY(), 0.000001d); + assertEquals(139.70625d, center.getX(), 0.000001d); + } + + @Test + public void getRectangleTest() { + Rectangle2D rect = Jpmesh.getRectangle("53394526"); + assertNotNull(rect); + assertEquals(35.7d, rect.getY(), 0.000001d); + assertEquals(139.7d, rect.getX(), 0.000001d); + assertEquals(0.0083333d, rect.getHeight(), 0.000001d); + assertEquals(0.0125, rect.getWidth(), 0.000001d); + } +}