プロジェクト

全般

プロフィール

« | » 

リビジョン 1616c8a9

高徹 高橋 徹 さんがほぼ12年前に追加

シェープファイルをロードして表示するまで作成

余分なラインが表示される問題あり

差分を表示:

learn/java/javafx/HelloMap/nbproject/project.properties
jar.compress=false
javac.classpath=\
${javafx.classpath.extension}:\
${libs.ShapefileReader.classpath}
${libs.ShapefileReader.classpath}:\
${libs.Proj4J.classpath}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
......
${java.home}/lib/javaws.jar:\
${java.home}/lib/deploy.jar:\
${java.home}/lib/plugin.jar
javafx.deploy.adddesktopshortcut=false
javafx.deploy.addstartmenushortcut=false
javafx.deploy.allowoffline=true
# If true, application update mode is set to 'background', if false, update mode is set to 'eager'
javafx.deploy.backgroundupdate=false
javafx.deploy.disable.proxy=false
javafx.deploy.embedJNLP=true
javafx.deploy.includeDT=true
javafx.deploy.permissionselevated=true
javafx.deploy.installpermanently=false
javafx.deploy.permissionselevated=false
# \u5404\u5b9f\u884c\u306e\u524d\u306b\u30c7\u30d7\u30ed\u30a4\u30e1\u30f3\u30c8\u30fb\u30a2\u30fc\u30c6\u30a3\u30d5\u30a1\u30af\u30c8\u306e\u4e00\u6642\u30b3\u30d4\u30fc\u3092\u4f5c\u6210\u3057\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u306b\u306ftrue\u306b\u8a2d\u5b9a\u3057\u307e\u3059(\u540c\u6642\u5b9f\u884c\u3092\u7121\u52b9\u306b\u3057\u307e\u3059)
javafx.disable.concurrent.runs=false
# \u540c\u3058WebStart\u304a\u3088\u3073Run-in-Browser\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u8907\u6570\u306e\u540c\u6642\u5b9f\u884c\u3092\u6709\u52b9\u306b\u3059\u308b\u306b\u306ftrue\u306b\u8a2d\u5b9a\u3057\u307e\u3059
......
javafx.rebase.libs=false
javafx.run.height=600
javafx.run.width=800
javafx.signing.enabled=true
javafx.signing.blob=false
javafx.signing.enabled=false
javafx.signing.type=self
# Pre-JavaFX 2.0 WebStart is deactivated in JavaFX 2.0+ projects
jnlp.enabled=false
......
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
native.bundling.enabled=false
platform.active=default_platform
project.license=apache20
run.classpath=\
learn/java/javafx/HelloMap/src/hellomap/HelloMapView.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.canvas.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" fx:controller="hellomap.HelloMapViewController">
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="hellomap.HelloMapViewController">
<children>
<Button layoutX="126" layoutY="90" text="Click Me!" onAction="#handleButtonAction" fx:id="button" />
<Label layoutX="126" layoutY="120" minHeight="16" minWidth="69" fx:id="label" />
<Button fx:id="button" layoutX="237.0" layoutY="161.0" onAction="#handleMapLoadAction" text="Load Map" AnchorPane.bottomAnchor="14.0" AnchorPane.rightAnchor="14.0" /><Canvas fx:id="map" height="200.0" layoutX="7.0" width="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="7.0" AnchorPane.rightAnchor="113.0" AnchorPane.topAnchor="0.0" /><Label fx:id="scaleLabel" layoutX="275.04296875" layoutY="5.5" text="Label" AnchorPane.rightAnchor="13.95703125" AnchorPane.topAnchor="5.5" />
</children>
</AnchorPane>
learn/java/javafx/HelloMap/src/hellomap/HelloMapViewController.java
*/
package hellomap;
import java.io.File;
import java.net.URL;
import java.nio.file.Paths;
import java.util.List;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Point2D;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Label;
import javafx.scene.paint.Color;
import javafx.scene.transform.Affine;
import javafx.stage.FileChooser;
import javafx.util.converter.NumberStringConverter;
import org.nocrala.tools.gis.data.esri.shapefile.exception.InvalidShapeFileException;
/**
*
......
*/
public class HelloMapViewController implements Initializable {
private static final Logger logger = Logger.getLogger(HelloMapViewController.class.getName());
private static final double DOT_PITCH_METER = 0.247 / 1_000;
private static final Affine IDENTITY_TRANSFORM = new Affine();
private double SCALE_RATE = 1.4;
@FXML
private Canvas map;
@FXML
private Label label;
private Label scaleLabel;
private Affine transform = new Affine();
private List<MapPolyline> polylines;
private DoubleProperty scaleProperty = new SimpleDoubleProperty(1);
private Point2D dragStartPoint;
private Point2D translateAtDragStart;
private Point2D translate = new Point2D(0f, 0f);
/**
* シェープファイルをロードする。
*
* @param event
*/
@FXML
private void handleButtonAction(ActionEvent event) {
System.out.println("You clicked me!");
label.setText("Hello World!");
private void handleMapLoadAction(ActionEvent event) {
FileChooser chooser = new FileChooser();
chooser.setTitle("Select ESRI Shapefile");
chooser.setInitialDirectory(Paths.get(System.getProperty("user.home"), "Documents", "mapdata").toFile());
chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Shapefile", "*.shp"));
File selected = chooser.showOpenDialog(map.getScene().getWindow());
if (selected != null) {
logger.log(Level.INFO, "Loading shapefile {0}", selected);
MapModel loader = new MapModel(selected);
try {
loader.load();
polylines = loader.getShapes();
drawMap();
} catch (InvalidShapeFileException ex) {
logger.log(Level.SEVERE, "ERROR: Shape file ", ex);
}
}
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
scaleLabel.textProperty().bindBidirectional(scaleProperty, new NumberStringConverter());
transform = new Affine(scaleProperty.get(), 0f, 0f, 0f, -scaleProperty.get(), 0f);
map.setOnScroll(ev -> {
scaleProperty.set((ev.getDeltaY() >= 0) ? scaleProperty.get() * SCALE_RATE : scaleProperty.get() / SCALE_RATE);
transform.setToTransform(scaleProperty.get(), 0f, translate.getX(), 0f, -scaleProperty.get(), translate.getY());
drawMap();
});
map.setOnMousePressed(ev -> {
dragStartPoint = new Point2D(ev.getSceneX(), ev.getSceneY());
translateAtDragStart = translate;
});
map.setOnMouseDragged(ev -> {
Point2D dragPoint = new Point2D(ev.getSceneX(), ev.getSceneY());
translate = translateAtDragStart.add(dragPoint.subtract(dragStartPoint));
transform.setToTransform(scaleProperty.get(), 0f, translate.getX(), 0f, -scaleProperty.get(), translate.getY());
drawMap();
});
}
private void drawMap() {
logger.info(() -> String.format("transform=%s", transform));
GraphicsContext gc = map.getGraphicsContext2D();
clearMap();
gc.setTransform(transform);
gc.setStroke(Color.RED);
gc.setLineWidth(1); // / scaleProperty.get());
for (MapPolyline shape : polylines) {
gc.strokePolyline(shape.getxPoints(), shape.getyPoints(), shape.getNumPoints());
}
logger.info("after draw");
}
private void clearMap() {
GraphicsContext gc = map.getGraphicsContext2D();
gc.setTransform(IDENTITY_TRANSFORM);
gc.clearRect(0f, 0f, map.getWidth(), map.getHeight());
}
/**
* 地図縮尺(例: 1 / 10,000)をAffineのscaleに変換する.
*
* @param reduce 縮尺の母数(例: 10,000)
* @return
*/
double mapToScale(double reduce) {
return reduce * DOT_PITCH_METER;
}
}
learn/java/javafx/HelloMap/src/hellomap/MapLoader.java
/*
* Copyright 2014 toru.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hellomap;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.nocrala.tools.gis.data.esri.shapefile.ShapeFileReader;
import org.nocrala.tools.gis.data.esri.shapefile.ValidationPreferences;
import org.nocrala.tools.gis.data.esri.shapefile.exception.InvalidShapeFileException;
import org.nocrala.tools.gis.data.esri.shapefile.header.ShapeFileHeader;
import org.nocrala.tools.gis.data.esri.shapefile.shape.AbstractShape;
import org.nocrala.tools.gis.data.esri.shapefile.shape.ShapeType;
/**
* ESRIシェープファイル形式を読み込み、ヴェクターデータを取得するクラス。
*
* @author toru
*/
public class MapLoader {
private File shapeFile;
private ValidationPreferences preferences;
private ShapeFileHeader header;
private List<AbstractShape> shapes = new ArrayList<>();
/**
* ESRIシェープファイルを指定するコンストラクタ。
*
* @param file ESRIシェープファイル
*/
public MapLoader(File file) {
if (!file.isFile() || !file.canRead()) {
throw new RuntimeException("file " + file + " is not readable.");
}
preferences = new ValidationPreferences();
preferences.setAllowUnlimitedNumberOfPointsPerShape(true);
shapeFile = file;
}
/**
* 予め指定されたESRIシェープファイルをロードする。
*
* @return ESRIシェープファイルをロードした{@code MapLoader}インスタンス
* @throws InvalidShapeFileException 指定されたシェープファイルが正しくない場合
*/
public MapLoader load() throws InvalidShapeFileException {
try (InputStream inStream = new BufferedInputStream(new FileInputStream(shapeFile))) {
ShapeFileReader reader = new ShapeFileReader(inStream, preferences);
header = reader.getHeader();
AbstractShape shape = reader.next();
while (shape != null) {
shapes.add(shape);
shape = reader.next();
}
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
return this;
}
/**
* ロードしたシェープファイルの種類を返却する。
*
* @return シェープファイルの種類
*/
public ShapeType getShapeType() {
return header.getShapeType();
}
/**
* ロードしたシェープファイルに含まれるシェープ一覧を不変コレクションで返却する。
*
* @return ロードしたシェープファイルに含まれるシェープの不変{@code List}
*/
public List<AbstractShape> getShapes() {
return Collections.unmodifiableList(shapes);
}
}
learn/java/javafx/HelloMap/src/hellomap/MapModel.java
/*
* Copyright 2014 toru.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hellomap;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.geometry.Point2D;
import org.nocrala.tools.gis.data.esri.shapefile.ShapeFileReader;
import org.nocrala.tools.gis.data.esri.shapefile.ValidationPreferences;
import org.nocrala.tools.gis.data.esri.shapefile.exception.InvalidShapeFileException;
import org.nocrala.tools.gis.data.esri.shapefile.header.ShapeFileHeader;
import org.nocrala.tools.gis.data.esri.shapefile.shape.PointData;
import org.nocrala.tools.gis.data.esri.shapefile.shape.ShapeType;
import org.nocrala.tools.gis.data.esri.shapefile.shape.shapes.PolylineShape;
import org.osgeo.proj4j.CRSFactory;
import org.osgeo.proj4j.CoordinateReferenceSystem;
import org.osgeo.proj4j.CoordinateTransform;
import org.osgeo.proj4j.CoordinateTransformFactory;
import org.osgeo.proj4j.ProjCoordinate;
/**
* ESRIシェープファイル形式を読み込み、ヴェクターデータを取得するクラス。
*
* @author toru
*/
public class MapModel {
private static final Logger logger = Logger.getLogger(MapModel.class.getName());
private File shapeFile;
private ValidationPreferences preferences;
private ShapeFileHeader header;
private List<MapPolyline> shapes = new ArrayList<>();
private Function<PointData, Point2D> projection;
private CRSFactory crsFactory = new CRSFactory();
private CoordinateTransformFactory coordinateTransformFactory = new CoordinateTransformFactory();
/**
* ESRIシェープファイルを指定するコンストラクタ。
*
* @param file ESRIシェープファイル
*/
public MapModel(File file) {
if (!file.isFile() || !file.canRead()) {
throw new RuntimeException("file " + file + " is not readable.");
}
preferences = new ValidationPreferences();
preferences.setAllowUnlimitedNumberOfPointsPerShape(true);
shapeFile = file;
projection = createProjection(140, 36);
}
/**
* 予め指定されたESRIシェープファイルをロードする。
*
* @return ESRIシェープファイルをロードした{@code MapModel}インスタンス
* @throws InvalidShapeFileException 指定されたシェープファイルが正しくない場合
*/
public MapModel load() throws InvalidShapeFileException {
try (InputStream inStream = new BufferedInputStream(new FileInputStream(shapeFile))) {
ShapeFileReader reader = new ShapeFileReader(inStream, preferences);
header = reader.getHeader();
PolylineShape shape = (PolylineShape) reader.next();
int numRead = 0;
while (shape != null) {
MapPolyline mapPolyline = new MapPolyline(projection);
mapPolyline.setGcsPolyline(shape);
shapes.add(mapPolyline);
shape = (PolylineShape) reader.next();
numRead++;
}
logger.log(Level.INFO, "Read {0} shapes from a shapefile '{1}'", new Object[]{numRead, shapeFile});
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
return this;
}
/**
* ロードしたシェープファイルの種類を返却する。
*
* @return シェープファイルの種類
*/
public ShapeType getShapeType() {
return header.getShapeType();
}
/**
* ロードしたシェープファイルに含まれるシェープ一覧を不変コレクションで返却する。
*
* @return ロードしたシェープファイルに含まれるシェープの不変{@code List}
*/
public List<MapPolyline> getShapes() {
return Collections.unmodifiableList(shapes);
}
private Function<PointData, Point2D> createProjection(double lon, double lat) {
CoordinateReferenceSystem crsWgs84 = crsFactory.createFromName("EPSG:4326");
CoordinateReferenceSystem crsAzEq = crsFactory.createFromParameters(
"Azimuthal_Equidistant",
String.format("+proj=aeqd +lat_0=%f +lon_0=%f +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs", lat, lon));
CoordinateTransform projection = coordinateTransformFactory.createTransform(crsWgs84, crsAzEq);
return point -> {
ProjCoordinate gcsPoint = new ProjCoordinate(point.getX(), point.getY());
ProjCoordinate pcsPoint = new ProjCoordinate();
pcsPoint = projection.transform(gcsPoint, pcsPoint);
return new Point2D(pcsPoint.x, pcsPoint.y);
};
}
}
learn/java/javafx/HelloMap/src/hellomap/MapPolyline.java
/*
* Copyright 2014 TAKAHASHI,Toru.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hellomap;
import java.util.function.Function;
import javafx.geometry.Point2D;
import org.nocrala.tools.gis.data.esri.shapefile.shape.PointData;
import org.nocrala.tools.gis.data.esri.shapefile.shape.shapes.PolylineShape;
/**
* 投影座標系におけるポリライン情報を保持するクラス。
*
* @author TAKAHASHI,Toru
*/
public class MapPolyline {
private PolylineShape gcsShape;
private double[] xPoints;
private double[] yPoints;
private Function<PointData, Point2D> projection;
/**
* 投影変換なし(緯度経度をそのまま直交座標とする)で生成する。
*/
public MapPolyline() {
projection = p -> new Point2D(p.getX(), p.getY());
}
/**
* 投影変換関数を指定して生成する。
*
* @param project 投影変換
*/
public MapPolyline(Function<PointData, Point2D> project) {
this.projection = project;
}
/**
* GCS(地理座標系)で定義されたポリラインを受け取りPCS(投影座標系)のポリラインを保持する。
*
* @param gcsShape シェープファイルのポリライン
*/
public void setGcsPolyline(PolylineShape gcsShape) {
this.gcsShape = gcsShape;
xPoints = new double[gcsShape.getNumberOfPoints()];
yPoints = new double[gcsShape.getNumberOfPoints()];
project();
}
/**
* 保持するGCSのポリラインから、保持する投影変換を行う。
*/
public void project() {
PointData[] gcsPoints = gcsShape.getPoints();
int numPoints = gcsPoints.length;
for (int i = 0; i < numPoints; i++) {
Point2D pcsPoint = project(gcsPoints[i]);
xPoints[i] = pcsPoint.getX();
yPoints[i] = pcsPoint.getY();
}
}
/**
* 単一の地理座標を投影変換する。
*
* @param gcsPoint 地理座標
* @return 指定した地理座標を保持する投影変換で投影した座標
*/
private Point2D project(PointData gcsPoint) {
return projection.apply(gcsPoint);
}
public double[] getxPoints() {
return xPoints;
}
public double[] getyPoints() {
return yPoints;
}
public int getNumPoints() {
return xPoints.length;
}
}
learn/java/javafx/HelloMap/test/hellomap/HelloMapViewControllerTest.java
/*
* Copyright 2014 TAKAHASHI,Toru.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hellomap;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author TAKAHASHI,Toru
*/
public class HelloMapViewControllerTest {
public HelloMapViewControllerTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
public void mapToScaleのテスト() {
HelloMapViewController sut = new HelloMapViewController();
double ret = sut.mapToScale(10_000);
System.out.println("10_000 => " + ret);
}
}
learn/java/javafx/HelloMap/test/hellomap/MapLoaderTest.java
/*
* Copyright 2014 toru.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hellomap;
import java.io.File;
import java.nio.file.Paths;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.is;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.nocrala.tools.gis.data.esri.shapefile.shape.ShapeType;
/**
*
* @author toru
*/
public class MapLoaderTest {
File shapefile;
MapLoader mapLoader;
public MapLoaderTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
shapefile = Paths.get("mapdata", "world_coastline", "10m_coastline.shp").toFile();
mapLoader = new MapLoader(shapefile);
}
@After
public void tearDown() {
}
@Test
public void testLoad() throws Exception {
MapLoader ret = mapLoader.load();
assertThat(ret, is(mapLoader));
}
@Test
public void testGetShapeType() throws Exception {
ShapeType type = mapLoader.load().getShapeType();
System.out.println("ShapeType = " + type);
}
@Test
public void testGetShapes() {
}
}
learn/java/javafx/HelloMap/test/hellomap/MapModelTest.java
/*
* Copyright 2014 toru.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hellomap;
import java.io.File;
import java.nio.file.Paths;
import static org.hamcrest.CoreMatchers.is;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.nocrala.tools.gis.data.esri.shapefile.shape.ShapeType;
import org.osgeo.proj4j.CRSFactory;
import org.osgeo.proj4j.CoordinateReferenceSystem;
import org.osgeo.proj4j.CoordinateTransform;
import org.osgeo.proj4j.CoordinateTransformFactory;
import org.osgeo.proj4j.ProjCoordinate;
import org.osgeo.proj4j.proj.EquidistantAzimuthalProjection;
/**
*
* @author toru
*/
public class MapModelTest {
File shapefile;
MapModel mapLoader;
public MapModelTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
shapefile = Paths.get("mapdata", "world_coastline", "10m_coastline.shp").toFile();
mapLoader = new MapModel(shapefile);
}
@After
public void tearDown() {
}
@Test
public void testLoad() throws Exception {
MapModel ret = mapLoader.load();
assertThat(ret, is(mapLoader));
}
@Test
public void testGetShapeType() throws Exception {
ShapeType type = mapLoader.load().getShapeType();
System.out.println("ShapeType = " + type);
}
@Test
public void testGetShapes() {
}
@Test
public void 正距方位投影の基礎テスト() {
EquidistantAzimuthalProjection proj = new EquidistantAzimuthalProjection(36, 140);
ProjCoordinate xy = new ProjCoordinate();
xy = proj.project(Math.toRadians(36), Math.toRadians(140), xy);
System.out.printf("(N %d°, E %d°) => %f, %f%n", 36, 140, xy.x, xy.y);
xy = proj.project(Math.toRadians(35), Math.toRadians(140), xy);
System.out.printf("(N %d°, E %d°) => %f, %f%n", 35, 140, xy.x, xy.y);
}
@Test
public void CRSFactoryのテスト() {
CRSFactory crsFactory = new CRSFactory();
CoordinateReferenceSystem crsAzEq = crsFactory.createFromName("ESRI:54032"); // World Azimuthal Equidistant
System.out.println("CoordinateReferenceSystem = " + crsAzEq.getName());
System.out.println(crsAzEq.getParameterString());
CoordinateReferenceSystem crsAzEqJpn = crsFactory.createFromParameters("Azimuthal_Equidistant_JPN",
"+proj=aeqd +lat_0=35 +lon_0=135 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs");
System.out.println("CoordinateReferenceSystem = " + crsAzEqJpn.getName());
System.out.println(crsAzEqJpn.getParameterString());
CoordinateReferenceSystem crsWgs84 = crsFactory.createFromName("EPSG:4326");
System.out.println("CoordinateReferenceSystem = " + crsWgs84.getName());
System.out.println(crsWgs84.getParameterString());
}
@Test
public void 投影変換のテスト() {
CRSFactory crsFactory = new CRSFactory();
CoordinateReferenceSystem crsWgs84 = crsFactory.createFromName("EPSG:4326");
CoordinateReferenceSystem crsAzEqJpn = crsFactory.createFromParameters(
"crsAzEq_Jpn", "+proj=aeqd +lat_0=35 +lon_0=135 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=km +no_defs");
CoordinateTransformFactory transformFactory = new CoordinateTransformFactory();
CoordinateTransform transform = transformFactory.createTransform(crsWgs84, crsAzEqJpn);
ProjCoordinate gcsPoint = new ProjCoordinate(135, 35);
ProjCoordinate pcsPoint = new ProjCoordinate();
pcsPoint = transform.transform(gcsPoint, pcsPoint);
System.out.println("(N 35°, E135°) => " + pcsPoint.x + ", " + pcsPoint.y);
ProjCoordinate gcsPoint2 = new ProjCoordinate(136, 35);
pcsPoint = transform.transform(gcsPoint2, pcsPoint);
System.out.println("(N 35°, E136°) => " + pcsPoint.x + ", " + pcsPoint.y);
}
}
learn/java/javafx/HelloMap/test/hellomap/MapPolylineTest.java
/*
* Copyright 2014 TAKAHASHI,Toru.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hellomap;
import java.util.function.Function;
import javafx.geometry.Point2D;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.nocrala.tools.gis.data.esri.shapefile.shape.PointData;
/**
*
* @author TAKAHASHI,Toru
*/
public class MapPolylineTest {
Function<PointData, Point2D> project;
public MapPolylineTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
public void 正距方位投影その1() {
}
}

他の形式にエクスポート: Unified diff