リビジョン 972d1973
| src/com/torutk/tinymap/TinyMapModel.java | ||
|---|---|---|
|
*/
|
||
|
package com.torutk.tinymap;
|
||
|
|
||
|
import java.io.BufferedInputStream;
|
||
|
import java.io.File;
|
||
|
import java.io.FileInputStream;
|
||
|
import java.io.IOException;
|
||
|
import java.io.InputStream;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
import java.util.function.Function;
|
||
|
import java.util.stream.Stream;
|
||
|
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.shape.AbstractShape;
|
||
|
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;
|
||
|
|
||
|
/**
|
||
|
*
|
||
| ... | ... | |
|
*/
|
||
|
public class TinyMapModel {
|
||
|
private File mapFile;
|
||
|
private List<TinyMapPolyline> polylines;
|
||
|
|
||
|
private List<TinyMapPolyline> polylines = new ArrayList<>();
|
||
|
private Function<PointData, Point2D> projection;
|
||
|
|
||
|
public TinyMapModel(File selected) {
|
||
|
mapFile = selected;
|
||
|
projection = p -> new Point2D(p.getX() * 100_000, p.getY() * 100_000); // 1度100kmとした直交座標変換
|
||
|
}
|
||
|
|
||
|
public void setProjection(Function<PointData, Point2D> projection) {
|
||
|
this.projection = projection;
|
||
|
}
|
||
|
|
||
|
public Stream<TinyMapPolyline> stream() {
|
||
|
return polylines.stream();
|
||
|
}
|
||
|
|
||
|
public void loadLines() {
|
||
|
polylines = new ArrayList<>();
|
||
|
loadTestPattern();
|
||
|
public void loadLines() throws TinyMapException {
|
||
|
polylines.clear();
|
||
|
ValidationPreferences preferences = new ValidationPreferences();
|
||
|
preferences.setAllowUnlimitedNumberOfPointsPerShape(true);
|
||
|
try (InputStream inStream = new BufferedInputStream(new FileInputStream(mapFile))) {
|
||
|
ShapeFileReader reader = new ShapeFileReader(inStream, preferences);
|
||
|
AbstractShape shape = reader.next();
|
||
|
while (shape != null) {
|
||
|
if (shape.getShapeType() != ShapeType.POLYLINE) {
|
||
|
continue;
|
||
|
}
|
||
|
PolylineShape polyline = (PolylineShape) shape;
|
||
|
for (int i = 0; i < polyline.getNumberOfParts(); i++) {
|
||
|
TinyMapPolyline mapPolyline = createMapPolylineFrom(polyline, i);
|
||
|
polylines.add(mapPolyline);
|
||
|
}
|
||
|
shape = reader.next();
|
||
|
}
|
||
|
} catch (IOException | InvalidShapeFileException ex) {
|
||
|
throw new TinyMapException("シェープファイル読み込み時に例外発生", ex);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
TinyMapPolyline createMapPolylineFrom(PolylineShape shape, int part) {
|
||
|
PointData[] gcsPoints = shape.getPointsOfPart(part);
|
||
|
double[] xArray = new double[gcsPoints.length];
|
||
|
double[] yArray = new double[gcsPoints.length];
|
||
|
for (int i = 0; i < gcsPoints.length; i++) {
|
||
|
Point2D pcsPoint = projection.apply(gcsPoints[i]);
|
||
|
xArray[i] = pcsPoint.getX();
|
||
|
yArray[i] = pcsPoint.getY();
|
||
|
}
|
||
|
return new TinyMapPolyline(xArray, yArray);
|
||
|
}
|
||
|
|
||
|
private void loadTestPattern() {
|
||
|
for (int lat = -90; lat <= 90; lat += 10) {
|
||
|
double[] xs = new double[36];
|
||
シェープファイルからポリラインデータを読み込み表示