Compare commits
20 Commits
7d9580965f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 325cdb6c67 | |||
| fb7a210501 | |||
| b8cfa7301a | |||
| bdeaf2d777 | |||
| a03711e0ad | |||
| 3026a1e5f0 | |||
| 3e40017904 | |||
| 8455b93b5b | |||
| 94ec22b5ac | |||
| 1052cde48a | |||
| fdf9110c45 | |||
| 31f424e3e9 | |||
| 16546a247f | |||
| e011b74f03 | |||
| e3cfd57d6e | |||
| e0d5a043b6 | |||
| 6931334fc6 | |||
| 1f4c5b52f2 | |||
| f4d2d60286 | |||
| 119658de07 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -92,6 +92,7 @@ http-client.private.env.json
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
logfile*.txt
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
@@ -112,3 +113,5 @@ http-client.private.env.json
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
# Pliki binarne, generowane.
|
||||
*.bin
|
||||
|
||||
2
.idea/compiler.xml
generated
2
.idea/compiler.xml
generated
@@ -6,7 +6,7 @@
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="teren-funkcje" />
|
||||
<module name="terrain-utilities" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
|
||||
8
.idea/modules.xml
generated
8
.idea/modules.xml
generated
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/terrain-utilities.iml" filepath="$PROJECT_DIR$/.idea/terrain-utilities.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
13
logback.xml
13
logback.xml
@@ -1,24 +1,27 @@
|
||||
<configuration>
|
||||
<timestamp key="bySecond" datePattern="yyyyMMdd'T'HHmmss"/>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<!-- <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>-->
|
||||
<pattern>%-30(%d{HH:mm:ss.SSS} [%thread]) %-5level %logger{32} - %msg%n</pattern>
|
||||
<pattern>%-20(%d{HH:mm:ss.SSS} [%thread]) %-5level %logger{1} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
|
||||
<file>terrain.log</file>
|
||||
<file>logfile-${bySecond}.txt</file>
|
||||
<!-- <file>terrain.log</file>-->
|
||||
<append>true</append>
|
||||
<encoder>
|
||||
<!-- <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>-->
|
||||
<pattern>%-30(%d{HH:mm:ss.SSS} [%thread]) %-5level %logger{32} - %msg%n</pattern>
|
||||
<!-- <pattern>%-30(%d{HH:mm:ss.SSS} [%thread]) %-5level %logger{0} - %msg%n</pattern>-->
|
||||
<pattern>%-20(%d{HH:mm:ss.SSS} [%thread]) %-5level :: %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="pl.wat.ms4ds.terenfunkcje" level="trace">
|
||||
<logger name="pl.wat.ms4ds.terrain" level="debug">
|
||||
<appender-ref ref="FILE"/>
|
||||
</logger>
|
||||
|
||||
<root level="trace">
|
||||
<root level="debug">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
</configuration>
|
||||
36
pom.xml
36
pom.xml
@@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ms4ds</groupId>
|
||||
<artifactId>teren-funkcje</artifactId>
|
||||
<artifactId>teren-utils</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<repositories>
|
||||
@@ -15,9 +15,10 @@
|
||||
<url>https://nexus.rulka.pl/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<javafx.version>25.0.1</javafx.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
@@ -96,7 +97,7 @@
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<mainClass>pl.wat.ms4ds.terenfunkcje.nmt.NMTDataProvider</mainClass>
|
||||
<mainClass>pl.wat.ms4ds.terrain.nmt.NmtDataProvider</mainClass>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<Class-Path>teren-funkcje-1.0.2-SNAPSHOT.jar</Class-Path>
|
||||
@@ -153,20 +154,15 @@
|
||||
<artifactId>common-types</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>log4j</groupId>-->
|
||||
<!-- <artifactId>log4j</artifactId>-->
|
||||
<!-- <version>1.2.17</version>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
<version>1.5.20</version>
|
||||
<version>1.5.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.5.20</version>
|
||||
<version>1.5.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
@@ -179,5 +175,25 @@
|
||||
<artifactId>shapefilereader</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-controls</artifactId>
|
||||
<version>${javafx.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-fxml</artifactId>
|
||||
<version>${javafx.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-graphics</artifactId>
|
||||
<version>${javafx.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-swing</artifactId>
|
||||
<version>${javafx.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,35 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Arkusz {
|
||||
|
||||
ArrayList<WezelDrogowy> wezly = new ArrayList<>();
|
||||
// arkusz mapy zawiera luki rozlacznie (jeden luk moze nalezec tylko do jednego arkusza)
|
||||
ArrayList<LukDrogowy> luki = new ArrayList<>();
|
||||
|
||||
// liczba arkuszy mapy
|
||||
static int lx = 0;
|
||||
static int ly = 0;
|
||||
|
||||
/**
|
||||
* Funkcja porownuje wspolrzedne leksykograficznie.
|
||||
* @param x1
|
||||
* @param y1
|
||||
* @param x2
|
||||
* @param y2
|
||||
* @return
|
||||
*/
|
||||
static boolean mniejszeWspolrzedne(int x1, int y1, int x2, int y2) {
|
||||
if (x1 < x2) {
|
||||
return true;
|
||||
}
|
||||
if (x1 > x2) {
|
||||
return false;
|
||||
}
|
||||
if (y1 < y2) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje;
|
||||
|
||||
abstract class BigSquare {
|
||||
abstract Kwadrat getKwadrat(int Id_X, int Id_Y);
|
||||
|
||||
protected transient String fileName;
|
||||
public int xRefMs = 0;
|
||||
public int yRefMs = 0;
|
||||
public transient int liczbaZmian = 0;
|
||||
// TODO zamienic na 100
|
||||
static final int LICZBA_ZMIAN_DO_ZAPISU = 100000;
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje;
|
||||
|
||||
|
||||
/**
|
||||
* Klasa algorytmiczna do wyznaczania kwadratów odcinka (dyskretyzacja odcinka kwadratami/pikselami).
|
||||
*/
|
||||
public class Bresenham {
|
||||
|
||||
static int sign(int a) {
|
||||
if (a > 0)
|
||||
return 1;
|
||||
if (a < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Metoda generuje tablicę współrzędnych gridowych kolejnych punktów/kwadratów podanego odcinka.
|
||||
* <p>
|
||||
* Wykorzystuje algorytm Bresenhama.
|
||||
*
|
||||
* @param x1 współrzędna x początku
|
||||
* @param y1 współrzędna y początku
|
||||
* @param x2 współrzędna x końca
|
||||
* @param y2 współrzędna y końca
|
||||
* @return tablicę kolejnych kwadratów tworzących odcinek o zadanych końcach
|
||||
*/
|
||||
public static GridCoord[] generateSegment(int x1, int y1, int x2, int y2) {
|
||||
int x = x1;
|
||||
int y = y1;
|
||||
int dx = x2 - x1;
|
||||
int dy = y2 - y1;
|
||||
final int sx = sign(dx);
|
||||
final int sy = sign(dy);
|
||||
if (dx < 0) {
|
||||
dx = -dx;
|
||||
}
|
||||
if (dy < 0) {
|
||||
dy = -dy;
|
||||
}
|
||||
final int ddx = 2 * dx;
|
||||
final int ddy = 2 * dy;
|
||||
int p;
|
||||
if (dx >= dy) {
|
||||
// poruszamy się po x
|
||||
p = ddy - dx;
|
||||
GridCoord[] res = new GridCoord[dx + 1];
|
||||
for (int i = 0; i <= dx; i++) {
|
||||
res[i] = new GridCoord(x, y);
|
||||
if (p > 0) {
|
||||
y += sy;
|
||||
p -= ddx;
|
||||
}
|
||||
x += sx;
|
||||
p += ddy;
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
// poruszamy sie po y
|
||||
p = ddx - dy;
|
||||
GridCoord[] res = new GridCoord[dy + 1];
|
||||
for (int i = 0; i <= dy; i++) {
|
||||
res[i] = new GridCoord(x, y);
|
||||
if (p > 0) {
|
||||
x += sx;
|
||||
p -= ddy;
|
||||
}
|
||||
y += sy;
|
||||
p += ddx;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void print(GridCoord[] segment) {
|
||||
StringBuilder sb = new StringBuilder(300);
|
||||
sb.append('[');
|
||||
int last = segment.length - 1;
|
||||
for (int i = 0; i < segment.length; i++) {
|
||||
sb.append('(');
|
||||
sb.append(segment[i].x);
|
||||
sb.append(',');
|
||||
sb.append(segment[i].y);
|
||||
sb.append(')');
|
||||
if (i < last) {
|
||||
sb.append('|');
|
||||
}
|
||||
}
|
||||
sb.append(']');
|
||||
System.out.println(sb);
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
//
|
||||
// var segment = generateSegmentSquares(10, 3, 1, 6);
|
||||
// var segment2 = generateSegmentSquares(1, 6, 10, 3);
|
||||
// var line = generateSegmentSquares(2, 1, 5, 8);
|
||||
// var line1 = generateSegmentSquares(5, 8, 2, 1);
|
||||
// var line2 = generateSegmentSquares(1, 6, 6, 11);
|
||||
// var line3 = generateSegmentSquares(11, 6, 6, 1);
|
||||
//
|
||||
// final int low = 300;
|
||||
// final int xHigh = 2000;
|
||||
// final int yHigh = 1000;
|
||||
// final int TRIAL_LENGTH = 100;
|
||||
// System.out.println("Start trial 1");
|
||||
// long t0 = System.nanoTime();
|
||||
// long sumLen = 0;
|
||||
// for (int i = 0; i < TRIAL_LENGTH; i++) {
|
||||
// int x1 = low + RandomStream.uniformInt(-20, 20);
|
||||
// int y1 = low + RandomStream.uniformInt(-20, 20);
|
||||
// int x2 = low + RandomStream.uniformInt(-20, 20);
|
||||
// int y2 = low + RandomStream.uniformInt(-20, 20);
|
||||
// int dx = Math.abs(x2 - x1);
|
||||
// int dy = Math.abs(y2 - y1);
|
||||
// if (dx == dy) {
|
||||
// continue;
|
||||
// }
|
||||
// var seg1 = generateSegmentSquares(x1, y1, x2, y2);
|
||||
// print(seg1);
|
||||
// }
|
||||
// long dt = System.nanoTime() - t0;
|
||||
// dt /= 1_000_000;
|
||||
// System.out.println("Czas = " + dt + " [ms]");
|
||||
// sumLen = 0;
|
||||
// System.out.println("Start trial 2");
|
||||
// t0 = System.nanoTime();
|
||||
// for (int i = 0; i < TRIAL_LENGTH * 10000; i++) {
|
||||
// int x1 = low + RandomStream.uniformInt(50);
|
||||
// int y1 = low + RandomStream.uniformInt(50);
|
||||
// int x2 = 2 * xHigh + RandomStream.uniformInt(1000);
|
||||
// int y2 = 2 * yHigh + RandomStream.uniformInt(2000);
|
||||
// int dx = Math.abs(x2 - x1);
|
||||
// int dy = Math.abs(y2 - y1);
|
||||
// if (dx == dy) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// var seg1 = generateSegmentSquares(x1, y1, x2, y2);
|
||||
//
|
||||
// sumLen += seg1.length;
|
||||
// }
|
||||
// dt = System.nanoTime() - t0;
|
||||
// dt /= 1_000_000;
|
||||
// System.out.println("Czas = " + dt + " [ms] - len=" + sumLen);
|
||||
//
|
||||
//// var seg1 = generateSegment(1, 1, 3, 5);
|
||||
//// var seg2 = generateSegment(14, 4, 3, 8);
|
||||
//// System.out.println(seg1);
|
||||
// }
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class GeoCoord {
|
||||
public double lat;
|
||||
public double lon;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,689 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje;
|
||||
|
||||
//import pl.wat.wcy.exception.IdKwadratuException;
|
||||
|
||||
|
||||
import pl.wat.ms4ds.common.EGeoDirection;
|
||||
|
||||
public class GridCoord {
|
||||
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
/**
|
||||
* Konstruktor klasy na bazie współrzędnych geograficznych.
|
||||
*
|
||||
* @param lon długość geograficzna
|
||||
* @param lat szerokość geograficzna
|
||||
*/
|
||||
public GridCoord(double lon, double lat) {
|
||||
double xms_f = (lon + 180) * MapConsts.DEG_MS;
|
||||
long xms = (long) xms_f;
|
||||
x = zamienWspXmsNaIdKwadratuX(xms);
|
||||
|
||||
double yms_f = (lat + 90) * MapConsts.DEG_MS;
|
||||
long yms = (long) yms_f;
|
||||
y = zamienWspYmsNaIdKwadratuY(yms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zamienia dlugosc geog. xms w milisekundach na IdKwadrat.x.
|
||||
*
|
||||
* @param xms długość geograficzna (lon) w milisekundach
|
||||
* @return współrzędna GridCoord.x
|
||||
*/
|
||||
public static int zamienWspXmsNaIdKwadratuX(long xms) {
|
||||
// wspolrzedne geograficzne w milisekundach zawieraja sie w zakresie:
|
||||
// 0 <= x < 360 dlugosc geograficzna
|
||||
// 0 <= y <= 180 szerokosc geograficzna
|
||||
if ((xms < 0) || (xms >= 360 * MapConsts.DEG_MS)) {
|
||||
// poza zakresem
|
||||
return -1;
|
||||
}
|
||||
long x = xms;
|
||||
if (x < MapConsts.X_REF_MS) {
|
||||
// // poza zakresem
|
||||
long dx = x + MapConsts.ANGLE_360_MS - MapConsts.X_REF_MS;
|
||||
if (dx > MapConsts.DX_REF_MS) {
|
||||
return -1;
|
||||
}
|
||||
x += MapConsts.ANGLE_360_MS;
|
||||
}
|
||||
// if (x > MapConsts.X_REF_MS + MapConsts.DX_REF_MS) {
|
||||
// // poza zakresem
|
||||
// return -1;
|
||||
// }
|
||||
// indeksowanie kwadratow pola walki zaczyna sie od (0, 0)
|
||||
double xx = (x - MapConsts.X_REF_MS) * ODWROT_SS_DX_MS;
|
||||
// x = (x - MapConsts.X_REF_MS) / MapConsts.SS_DX_MS;
|
||||
return (int) xx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zamienia szerokosc geog. yms w milisekundach na IdKwadrat.y.
|
||||
*
|
||||
* @param yms szerokosc geograficzna (lat) w milisekundach
|
||||
* @return współrzędna GridCoord.y
|
||||
*/
|
||||
public static int zamienWspYmsNaIdKwadratuY(long yms) {
|
||||
// wspolrzedne geograficzne w milisekundach zawieraja sie w zakresie:
|
||||
// 0 <= x < 360 dlugosc geograficzna
|
||||
// 0 <= y <= 180 szerokosc geograficzna
|
||||
// if ((yms < MapConsts.Y_REF_MS) || (yms > MapConsts.Y_REF_MS + MapConsts.DY_REF_MS)) {
|
||||
// // poza zakresem
|
||||
// return -1;
|
||||
// }
|
||||
if (yms < MapConsts.Y_REF_MS) {
|
||||
// poza zakresem
|
||||
return -1;
|
||||
}
|
||||
// indeksowanie kwadratow pola walki zaczyna sie od (0, 0)
|
||||
double yy = (yms - MapConsts.Y_REF_MS) * ODWROT_SS_DY_MS;
|
||||
// long y = (yms - MapConsts.Y_REF_MS) / MapConsts.SS_DY_MS;
|
||||
return (int) yy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zamienia długość geograficzną na współrzędna x GridCoord.
|
||||
*
|
||||
* @param lon długość geograficzna
|
||||
* @return współrzędna x klasy GridCoord
|
||||
*/
|
||||
public static int zamienDlugoscGeoNaIdKwadratuX(double lon) {
|
||||
double xms_f = (lon + 180) * MapConsts.DEG_MS;
|
||||
return zamienWspXmsNaIdKwadratuX((long) xms_f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zamienia szerokość geograficzną na współrzędna y GridCoord.
|
||||
*
|
||||
* @param lat szerokość geograficzna
|
||||
* @return współrzędna y klasy GridCoord
|
||||
*/
|
||||
public static int zamienSzerokoscGeoNaIdKwadratuY(double lat) {
|
||||
double yms_f = (lat + 90) * MapConsts.DEG_MS;
|
||||
return zamienWspYmsNaIdKwadratuY((long) yms_f);
|
||||
}
|
||||
|
||||
public GridCoord kwadratSasiedni(EGeoDirection kier) {
|
||||
GridCoord idKwSasiedni = new GridCoord();
|
||||
switch (kier) {
|
||||
case NORTH:
|
||||
idKwSasiedni.x = x;
|
||||
idKwSasiedni.y = y + 1;
|
||||
break;
|
||||
case NORTHEAST:
|
||||
idKwSasiedni.x = x + 1;
|
||||
idKwSasiedni.y = y + 1;
|
||||
break;
|
||||
case EAST:
|
||||
idKwSasiedni.x = x + 1;
|
||||
idKwSasiedni.y = y;
|
||||
break;
|
||||
case SOUTHEAST:
|
||||
idKwSasiedni.x = x + 1;
|
||||
idKwSasiedni.y = y - 1;
|
||||
break;
|
||||
case SOUTH:
|
||||
idKwSasiedni.x = x;
|
||||
idKwSasiedni.y = y - 1;
|
||||
break;
|
||||
case SOUTHWEST:
|
||||
idKwSasiedni.x = x - 1;
|
||||
idKwSasiedni.y = y - 1;
|
||||
break;
|
||||
case WEST:
|
||||
idKwSasiedni.x = x - 1;
|
||||
idKwSasiedni.y = y;
|
||||
break;
|
||||
case NORTHWEST:
|
||||
idKwSasiedni.x = x - 1;
|
||||
idKwSasiedni.y = y + 1;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
return idKwSasiedni;
|
||||
}
|
||||
|
||||
public void kwadratSasiedni(GridCoord idKwSasiedni, EGeoDirection kier) {
|
||||
switch (kier) {
|
||||
case NORTH:
|
||||
idKwSasiedni.x = x;
|
||||
idKwSasiedni.y = y + 1;
|
||||
break;
|
||||
case NORTHEAST:
|
||||
idKwSasiedni.x = x + 1;
|
||||
idKwSasiedni.y = y + 1;
|
||||
break;
|
||||
case EAST:
|
||||
idKwSasiedni.x = x + 1;
|
||||
idKwSasiedni.y = y;
|
||||
break;
|
||||
case SOUTHEAST:
|
||||
idKwSasiedni.x = x + 1;
|
||||
idKwSasiedni.y = y - 1;
|
||||
break;
|
||||
case SOUTH:
|
||||
idKwSasiedni.x = x;
|
||||
idKwSasiedni.y = y - 1;
|
||||
break;
|
||||
case SOUTHWEST:
|
||||
idKwSasiedni.x = x - 1;
|
||||
idKwSasiedni.y = y - 1;
|
||||
break;
|
||||
case WEST:
|
||||
idKwSasiedni.x = x - 1;
|
||||
idKwSasiedni.y = y;
|
||||
break;
|
||||
case NORTHWEST:
|
||||
idKwSasiedni.x = x - 1;
|
||||
idKwSasiedni.y = y + 1;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
public GridCoord[] dajSasiadow() {
|
||||
GridCoord[] sasiedzi = new GridCoord[8];
|
||||
sasiedzi[0] = new GridCoord(x, y + 1);
|
||||
sasiedzi[1] = new GridCoord(x + 1, y + 1);
|
||||
sasiedzi[2] = new GridCoord(x + 1, y);
|
||||
sasiedzi[3] = new GridCoord(x + 1, y - 1);
|
||||
sasiedzi[4] = new GridCoord(x, y - 1);
|
||||
sasiedzi[5] = new GridCoord(x - 1, y - 1);
|
||||
sasiedzi[6] = new GridCoord(x - 1, y);
|
||||
sasiedzi[7] = new GridCoord(x - 1, y + 1);
|
||||
return sasiedzi;
|
||||
}
|
||||
|
||||
public static GridCoord[] dajSasiadow(int x, int y) {
|
||||
GridCoord[] sasiedzi = new GridCoord[8];
|
||||
sasiedzi[0] = new GridCoord(x, y + 1);
|
||||
sasiedzi[1] = new GridCoord(x + 1, y + 1);
|
||||
sasiedzi[2] = new GridCoord(x + 1, y);
|
||||
sasiedzi[3] = new GridCoord(x + 1, y - 1);
|
||||
sasiedzi[4] = new GridCoord(x, y - 1);
|
||||
sasiedzi[5] = new GridCoord(x - 1, y - 1);
|
||||
sasiedzi[6] = new GridCoord(x - 1, y);
|
||||
sasiedzi[7] = new GridCoord(x - 1, y + 1);
|
||||
return sasiedzi;
|
||||
}
|
||||
|
||||
public static GridCoord[] dajSasiadow(GridCoord centralny) {
|
||||
GridCoord[] sasiedzi = new GridCoord[8];
|
||||
sasiedzi[0] = new GridCoord(centralny.x, centralny.y + 1);
|
||||
sasiedzi[1] = new GridCoord(centralny.x + 1, centralny.y + 1);
|
||||
sasiedzi[2] = new GridCoord(centralny.x + 1, centralny.y);
|
||||
sasiedzi[3] = new GridCoord(centralny.x + 1, centralny.y - 1);
|
||||
sasiedzi[4] = new GridCoord(centralny.x, centralny.y - 1);
|
||||
sasiedzi[5] = new GridCoord(centralny.x - 1, centralny.y - 1);
|
||||
sasiedzi[6] = new GridCoord(centralny.x - 1, centralny.y);
|
||||
sasiedzi[7] = new GridCoord(centralny.x - 1, centralny.y + 1);
|
||||
return sasiedzi;
|
||||
}
|
||||
|
||||
public GridCoord[] dajOtoczenie() {
|
||||
GridCoord[] sasiedzi = new GridCoord[9];
|
||||
sasiedzi[0] = new GridCoord(x, y);
|
||||
sasiedzi[1] = new GridCoord(x, y + 1);
|
||||
sasiedzi[2] = new GridCoord(x + 1, y + 1);
|
||||
sasiedzi[3] = new GridCoord(x + 1, y);
|
||||
sasiedzi[4] = new GridCoord(x + 1, y - 1);
|
||||
sasiedzi[5] = new GridCoord(x, y - 1);
|
||||
sasiedzi[6] = new GridCoord(x - 1, y - 1);
|
||||
sasiedzi[7] = new GridCoord(x - 1, y);
|
||||
sasiedzi[8] = new GridCoord(x - 1, y + 1);
|
||||
return sasiedzi;
|
||||
}
|
||||
|
||||
public static GridCoord[] dajOtoczenie(int x, int y) {
|
||||
GridCoord[] sasiedzi = new GridCoord[9];
|
||||
sasiedzi[0] = new GridCoord(x, y);
|
||||
sasiedzi[1] = new GridCoord(x, y + 1);
|
||||
sasiedzi[2] = new GridCoord(x + 1, y + 1);
|
||||
sasiedzi[3] = new GridCoord(x + 1, y);
|
||||
sasiedzi[4] = new GridCoord(x + 1, y - 1);
|
||||
sasiedzi[5] = new GridCoord(x, y - 1);
|
||||
sasiedzi[6] = new GridCoord(x - 1, y - 1);
|
||||
sasiedzi[7] = new GridCoord(x - 1, y);
|
||||
sasiedzi[8] = new GridCoord(x - 1, y + 1);
|
||||
return sasiedzi;
|
||||
}
|
||||
|
||||
public static GridCoord[] dajOtoczenie(GridCoord centralny) {
|
||||
GridCoord[] sasiedzi = new GridCoord[8];
|
||||
sasiedzi[0] = new GridCoord(centralny.x, centralny.y);
|
||||
sasiedzi[1] = new GridCoord(centralny.x, centralny.y + 1);
|
||||
sasiedzi[2] = new GridCoord(centralny.x + 1, centralny.y + 1);
|
||||
sasiedzi[3] = new GridCoord(centralny.x + 1, centralny.y);
|
||||
sasiedzi[4] = new GridCoord(centralny.x + 1, centralny.y - 1);
|
||||
sasiedzi[5] = new GridCoord(centralny.x, centralny.y - 1);
|
||||
sasiedzi[6] = new GridCoord(centralny.x - 1, centralny.y - 1);
|
||||
sasiedzi[7] = new GridCoord(centralny.x - 1, centralny.y);
|
||||
sasiedzi[8] = new GridCoord(centralny.x - 1, centralny.y + 1);
|
||||
return sasiedzi;
|
||||
}
|
||||
|
||||
public boolean rowne(int x, int y) {
|
||||
return this.x == x && this.y == y;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("(x= ");
|
||||
sb.append(x);
|
||||
sb.append(", y= ");
|
||||
sb.append(y);
|
||||
sb.append(')');
|
||||
// String s = "(x= " + Integer.toString(x) + ", y= " + Integer.toString(y) + ")";
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Zamienia współrzęną GridCoord.x na długość geograficzną środka małego kwadratu
|
||||
*
|
||||
* @param idX współrzęna x GridCoord
|
||||
* @return długość geograficzna
|
||||
*/
|
||||
public static float zamienIdKwadratuXNaDlugoscGeo(int idX) {
|
||||
long xms = zamienIdKwadratuXNaWspXms(idX);
|
||||
double lon = (double) xms / (double) MapConsts.DEG_MS - 180;
|
||||
return (float) lon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zamienia współrzęną GridCoord.y na szerokość geograficzną środka małego kwadratu
|
||||
*
|
||||
* @param idY współrzęna y GridCoord
|
||||
* @return szerokość geograficzna
|
||||
*/
|
||||
public static float zamienIdKwadratuYNaSzerokoscGeo(int idY) {
|
||||
long yms = zamienIdKwadratuYNaWspYms(idY);
|
||||
double lat = (double) yms / (double) MapConsts.DEG_MS - 90;
|
||||
return (float) lat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zamienia współrzęną GridCoord.x na długość geograficzną lewego dolnego rogu małego kwadratu
|
||||
*
|
||||
* @param idX współrzęna x GridCoord
|
||||
* @return długość geograficzna
|
||||
*/
|
||||
public static float zamienIdKwadratuXNaDlugoscGeoLD(int idX) {
|
||||
long xms = zamienIdKwadratuXNaWspXmsLD(idX);
|
||||
double lon = (double) xms / (double) MapConsts.DEG_MS - 180;
|
||||
return (float) lon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zamienia współrzęną GridCoord.y na szerokość geograficzną środka małego kwadratu
|
||||
*
|
||||
* @param idY współrzęna y GridCoord
|
||||
* @return szerokość geograficzna
|
||||
*/
|
||||
public static float zamienIdKwadratuYNaSzerokoscGeoLD(int idY) {
|
||||
long yms = zamienIdKwadratuYNaWspYmsLD(idY);
|
||||
double lat = (double) yms / (double) MapConsts.DEG_MS - 90;
|
||||
return (float) lat;
|
||||
}
|
||||
|
||||
public static int zamienWspUtmNaIdkwadratuX(String wspolrzedneUtm) {
|
||||
// //////////////////////////////////
|
||||
// wspolrzedne - znaki w formacie 522644N0154232E
|
||||
// wyznaczenie numeru kwadraty Au2 dla wspolrzednej X
|
||||
// np.: '153200' to 304
|
||||
|
||||
int xms = Teren.zamienWspUtmNaWspXms(wspolrzedneUtm);
|
||||
int idKwX = GridCoord.zamienWspXmsNaIdKwadratuX(xms);
|
||||
return idKwX;
|
||||
}
|
||||
|
||||
public static int zamienWspUtmNaIdkwadratuY(String wspolrzedneUtm) {
|
||||
// //////////////////////////////////
|
||||
// wspolrzedne - znaki w formacie 522644N0154232E
|
||||
// wyznaczenie numeru kwadraty Au2 dla wspolrzednej Y
|
||||
// np.: '153200' to 304
|
||||
int yms = Teren.zamienWspUtmNaWspYms(wspolrzedneUtm);
|
||||
int idKwY = GridCoord.zamienWspYmsNaIdKwadratuY(yms);
|
||||
return idKwY;
|
||||
}
|
||||
|
||||
public GridCoord(String wspolrzedne) {
|
||||
this.x = zamienWspUtmNaIdkwadratuX(wspolrzedne);
|
||||
this.y = zamienWspUtmNaIdkwadratuY(wspolrzedne);
|
||||
}
|
||||
|
||||
public static GridCoord zamienWspUtmNaIdKwadratu(String wspolrzedne) {
|
||||
// Utworzenie obiektu GridCoord ze wspolrzednych UTM
|
||||
GridCoord kwadrat = new GridCoord(wspolrzedne);
|
||||
return kwadrat;
|
||||
}
|
||||
|
||||
public static String zamienIdKwadratuNaWspUtm(GridCoord kwadrat) {
|
||||
long xms = zamienIdKwadratuXNaWspXms(kwadrat.x);
|
||||
long yms = zamienIdKwadratuYNaWspYms(kwadrat.y);
|
||||
return Teren.zamienWspXmsYmsNaWspUtm(xms, yms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zamienia wsp. X GridCoord na wsp. geo xms w milisekundach.
|
||||
* Zwracana wspolrzedna lezy w srodku kwadratu.
|
||||
*/
|
||||
public static long zamienIdKwadratuXNaWspXms(int idKwX) {
|
||||
// indeksowanie kwadratow pola walki zaczyna sie od (0, 0)
|
||||
// przesuniecie wspolrzednych do srodka kwadratu
|
||||
long xms = MapConsts.X_REF_MS + (long) ((idKwX + 0.5) * MapConsts.SS_DX_MS);
|
||||
xms %= MapConsts.ANGLE_360_MS;
|
||||
return xms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zamienia wsp. Y GridCoord na wsp. geo yms w milisekundach.
|
||||
* Zwracana wspolrzedna lezy w srodku kwadratu.
|
||||
*/
|
||||
public static long zamienIdKwadratuYNaWspYms(int idKwY) {
|
||||
// indeksowanie kwadratow pola walki zaczyna sie od (0, 0)
|
||||
// przesuniecie wspolrzednych do srodka kwadratu
|
||||
long yms = MapConsts.Y_REF_MS + (long) ((idKwY + 0.5) * MapConsts.SS_DY_MS);
|
||||
return yms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zamienia wsp. X GridCoord na wsp. geo xms w milisekundach lewego dolnego rogu malego kwadratu.
|
||||
* Zwracana wspolrzedna lezy w srodku kwadratu.
|
||||
*/
|
||||
public static long zamienIdKwadratuXNaWspXmsLD(int idKwX) {
|
||||
// indeksowanie kwadratow pola walki zaczyna sie od (0, 0)
|
||||
// przesuniecie wspolrzednych do srodka kwadratu
|
||||
long xms = MapConsts.X_REF_MS + (long) (idKwX * MapConsts.SS_DX_MS);
|
||||
xms %= MapConsts.ANGLE_360_MS;
|
||||
return xms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zamienia wsp. Y GridCoord na wsp. geo yms w milisekundach lewego dolnego rogu malego kwadratu.
|
||||
* Zwracana wspolrzedna lezy w srodku kwadratu.
|
||||
*/
|
||||
public static long zamienIdKwadratuYNaWspYmsLD(int idKwY) {
|
||||
// indeksowanie kwadratow pola walki zaczyna sie od (0, 0)
|
||||
// przesuniecie wspolrzednych do srodka kwadratu
|
||||
long yms = MapConsts.Y_REF_MS + (long) (idKwY * MapConsts.SS_DY_MS);
|
||||
return yms;
|
||||
}
|
||||
|
||||
private static final double ODWROT_SS_DX_MS = 1.0 / MapConsts.SS_DX_MS;
|
||||
private static final double ODWROT_SS_DY_MS = 1.0 / MapConsts.SS_DY_MS;
|
||||
|
||||
/**
|
||||
* Funkcja sprawdza, czy kwadraty sa takie same.
|
||||
*
|
||||
* @param id1
|
||||
* @param id2
|
||||
* @return
|
||||
*/
|
||||
public static boolean czyIdentyczne(GridCoord id1, GridCoord id2) {
|
||||
if (null == id1 || null == id2) {
|
||||
return false;
|
||||
}
|
||||
if (id1.x != id2.x || id1.y != id2.y) {
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zwraca odleglosc miedzy srodkami malych kwadratow [m].
|
||||
*
|
||||
* @param p1 współrzędna malego kwadratu pocz.
|
||||
* @param p2 współrzędna malego kwadratu konc.
|
||||
* @return Odległość między środkami małych kwadratów [m].
|
||||
*/
|
||||
public static float odleglosc(GridCoord p1, GridCoord p2) {
|
||||
// odleglosc miedzy srodkami malych kwadratow
|
||||
if (null == p1 || null == p2) {
|
||||
return -1.0f;
|
||||
}
|
||||
int xx = p1.x - p2.x;
|
||||
xx *= xx;
|
||||
int yy = p1.y - p2.y;
|
||||
yy *= yy;
|
||||
float odl = (float) Math.sqrt(xx + yy);
|
||||
odl *= MapConsts.DL_MK;
|
||||
return odl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zwraca odległość między środkami małych kwadratów [m].
|
||||
*
|
||||
* @param x1 Wsp X id malego kwadratu pocz.
|
||||
* @param y1 Wsp Y id malego kwadratu pocz.
|
||||
* @param x2 Wsp X id malego kwadratu konc.
|
||||
* @param y2 Wsp Y id malego kwadratu konc.
|
||||
* @return Odległość miedzy srodkami malych kwadratow [m].
|
||||
*/
|
||||
public static float odleglosc(int x1, int y1, int x2, int y2) {
|
||||
// odleglosc miedzy srodkami malych kwadratow
|
||||
int xx = x1 - x2;
|
||||
xx *= xx;
|
||||
int yy = y1 - y2;
|
||||
yy *= yy;
|
||||
float odl = (float) Math.sqrt(xx + yy);
|
||||
odl *= MapConsts.DL_MK;
|
||||
return odl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zwraca odległość między środkami małych kwadratów [m].
|
||||
*
|
||||
* @param dx odległość w kwadratach na osi OX.
|
||||
* @param dy odległość w kwadratach na osi OY.
|
||||
* @return Odległość miedzy srodkami malych kwadratow [m].
|
||||
*/
|
||||
public static float odleglosc(int dx, int dy) {
|
||||
float odl = (float) Math.sqrt(dx * dx + dy * dy);
|
||||
odl *= MapConsts.DL_MK;
|
||||
return odl;
|
||||
}
|
||||
|
||||
private static final float DL_MK2 = MapConsts.DL_MK * 0.0009765625f;
|
||||
/**
|
||||
* Funkcja zwraca aproksymowaną odległość między środkami małych kwadratów [m].
|
||||
*
|
||||
* @param x1 Wsp X id malego kwadratu pocz.
|
||||
* @param y1 Wsp Y id malego kwadratu pocz.
|
||||
* @param x2 Wsp X id malego kwadratu konc.
|
||||
* @param y2 Wsp Y id malego kwadratu konc.
|
||||
* @return Odległość miedzy srodkami malych kwadratow [m].
|
||||
*/
|
||||
public static float odlegloscApprox(int x1, int y1, int x2, int y2) {
|
||||
int dx = x2 - x1;
|
||||
int dy = y2 - y1;
|
||||
int min, max, approx;
|
||||
if (dx < 0) dx = -dx;
|
||||
if (dy < 0) dy = -dy;
|
||||
if (dx < dy) {
|
||||
min = dx;
|
||||
max = dy;
|
||||
} else {
|
||||
min = dy;
|
||||
max = dx;
|
||||
}
|
||||
approx = (max * 1007) + (min * 441);
|
||||
if (max < (min << 4)) {
|
||||
approx -= (max * 40);
|
||||
}
|
||||
float odl = approx * DL_MK2;
|
||||
return odl;
|
||||
}
|
||||
|
||||
public static int iloczynSkalarny(GridCoord p1, GridCoord p2) {
|
||||
int wynik;
|
||||
wynik = p1.x * p2.x + p1.y * p2.y;
|
||||
return wynik;
|
||||
}
|
||||
|
||||
// funkcja sprawdza, czy dwa obszary skierowane maja czesc wspolna
|
||||
public static boolean majaCzescWspolna(GridCoord[] rejon1, GridCoord[] rejon2) {
|
||||
if ((rejon1 == null) || (rejon2 == null)) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < rejon2.length; i++) {
|
||||
if (GeomUtils.insidePolygon(rejon1, rejon2[i].x, rejon2[i].y)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < rejon1.length; i++) {
|
||||
if (GeomUtils.insidePolygon(rejon2, rejon1[i].x, rejon1[i].y)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// wyznacza stosunek czesci wspolnej obszarow do obszaru bazowego
|
||||
public static float stosunekCzesciWspolnej(GridCoord[] rejon_bazowy, GridCoord[] rejon2) {
|
||||
if ((rejon_bazowy == null) || (rejon2 == null)) {
|
||||
return 0.0f;
|
||||
}
|
||||
boolean majaCzescWspolna = majaCzescWspolna(rejon_bazowy, rejon2);
|
||||
if (!majaCzescWspolna) {
|
||||
return 0.0f;
|
||||
}
|
||||
GridCoord[] kwadraty1 = GeomUtils.kwadratyObszaru(rejon_bazowy);
|
||||
GridCoord[] kwadraty2 = GeomUtils.kwadratyObszaru(rejon2);
|
||||
int maxWspolnych = 0;
|
||||
if (kwadraty1.length <= kwadraty2.length) {
|
||||
maxWspolnych = kwadraty1.length;
|
||||
} else {
|
||||
maxWspolnych = kwadraty2.length;
|
||||
}
|
||||
if ((kwadraty1 == null) || (kwadraty2 == null)) {
|
||||
return 0.0f;
|
||||
}
|
||||
int wspolnych = 0;
|
||||
for (int i = 0; i < kwadraty1.length; i++) {
|
||||
for (int j = 0; j < kwadraty2.length; j++) {
|
||||
if (czyIdentyczne(kwadraty1[i], kwadraty2[j])) {
|
||||
wspolnych++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ((float) wspolnych) / ((float) (maxWspolnych));
|
||||
}
|
||||
|
||||
// wyznacza wspolrzedne lewego dolnego wierzcholka oraz
|
||||
// prawego gornego wierzcholka prostokata opisanego na obszarze: rejon
|
||||
public static void minMaxIdKwadratu(GridCoord[] rejon, GridCoord min, GridCoord max) {
|
||||
if (rejon == null) {
|
||||
return;
|
||||
}
|
||||
if (min == null) {
|
||||
min = new GridCoord(rejon[0].x, rejon[0].y);
|
||||
}
|
||||
if (max == null) {
|
||||
max = new GridCoord(rejon[0].x, rejon[0].y);
|
||||
}
|
||||
for (int i = 1; i < rejon.length; i++) {
|
||||
if (min.x > rejon[i].x) {
|
||||
min.x = rejon[i].x;
|
||||
}
|
||||
if (min.y > rejon[i].y) {
|
||||
min.y = rejon[i].y;
|
||||
}
|
||||
if (max.x < rejon[i].x) {
|
||||
max.x = rejon[i].x;
|
||||
}
|
||||
if (max.y < rejon[i].y) {
|
||||
max.y = rejon[i].y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void update(double lon, double lat) {
|
||||
double xms_f = (lon + 180) * MapConsts.DEG_MS;
|
||||
long xms = (long) xms_f;
|
||||
x = zamienWspXmsNaIdKwadratuX(xms);
|
||||
|
||||
double yms_f = (lat + 90) * MapConsts.DEG_MS;
|
||||
long yms = (long) yms_f;
|
||||
y = zamienWspYmsNaIdKwadratuY(yms);
|
||||
}
|
||||
|
||||
public GridCoord() {
|
||||
x = -1;
|
||||
y = -1;
|
||||
}
|
||||
|
||||
public GridCoord(int x, int y) {
|
||||
/* try {
|
||||
if (x < 0 || y < 0)
|
||||
throw new IdKwadratuException();
|
||||
}
|
||||
catch (IdKwadratuException e) {
|
||||
System.out.print(e.opis);
|
||||
}
|
||||
*/
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public GridCoord(GridCoord oryginal) {
|
||||
this.x = oryginal.x;
|
||||
this.y = oryginal.y;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public void set(GridCoord oryginal) {
|
||||
x = oryginal.x;
|
||||
y = oryginal.y;
|
||||
}
|
||||
|
||||
public void set(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = prime + x;
|
||||
result = prime * result + y;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof GridCoord)) {
|
||||
return false;
|
||||
}
|
||||
GridCoord other = (GridCoord) obj;
|
||||
if (x != other.x) {
|
||||
return false;
|
||||
}
|
||||
if (y != other.y) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,358 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje;
|
||||
|
||||
|
||||
import pl.wat.ms4ds.common.EGeoDirection;
|
||||
|
||||
public class Kwadrat {
|
||||
|
||||
public static final Kwadrat EMPTY_SQUARE = new Kwadrat(null, 0.0f, 0.0f, 0.0f, 0.0f, 200, 0,
|
||||
new boolean[8], new boolean[8], new boolean[8]);
|
||||
|
||||
float stopienZabudowy;
|
||||
float stopienZalesienia;
|
||||
float stopienZawodnienia;
|
||||
float stopienZabagnienia;
|
||||
boolean jestDroga[];
|
||||
boolean jestRow[];
|
||||
boolean jestPrzeszkodaWodna[];
|
||||
int roznicaWzniesien;
|
||||
int wysokoscSrednia;
|
||||
|
||||
/**
|
||||
* The height above the level of the sea.
|
||||
*/
|
||||
short elevation;
|
||||
/**
|
||||
* 0 - BARE_GROUND
|
||||
* 1 - GRASS
|
||||
* 2 - SWAMP
|
||||
* 3 - WATER
|
||||
* 4 - SCRUB, BUSHES
|
||||
* 5 - BUILDINGS
|
||||
* 6 - FOREST
|
||||
*/
|
||||
short terrainType;
|
||||
/**
|
||||
* Rodzaj drogi na danym kierunku.
|
||||
* 0 - no road, 1 - small roads, 2 - minor roads, 3 - major roads
|
||||
*/
|
||||
byte[] roads;
|
||||
/**
|
||||
* Rodzaj przeszkody wodnej na danym kierunku.
|
||||
* 0 - no watercourse, 1 - drain, ditch, 2 - canal, stream, 3 - river
|
||||
*/
|
||||
byte[] waterWays;
|
||||
|
||||
|
||||
|
||||
transient RightBigSquare bs;
|
||||
|
||||
public float getStopienZabudowy() {
|
||||
return stopienZabudowy;
|
||||
}
|
||||
|
||||
public float getStopienZalesienia() {
|
||||
return stopienZalesienia;
|
||||
}
|
||||
|
||||
public float getStopienZawodnienia() {
|
||||
return stopienZawodnienia;
|
||||
}
|
||||
|
||||
public float getStopienZabagnienia() {
|
||||
return stopienZabagnienia;
|
||||
}
|
||||
|
||||
public int getRoznicaWzniesien() {
|
||||
return roznicaWzniesien;
|
||||
}
|
||||
|
||||
public int getWysokoscSrednia() {
|
||||
return wysokoscSrednia;
|
||||
}
|
||||
|
||||
public boolean[] getJestDroga() {
|
||||
return jestDroga;
|
||||
}
|
||||
|
||||
public boolean jestOdcinekDrogi() {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (jestDroga[i])
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean getJestDroga(EGeoDirection naKierunku) {
|
||||
if (naKierunku == EGeoDirection.UNDEFINED) {
|
||||
return false;
|
||||
}
|
||||
return jestDroga[naKierunku.id];
|
||||
}
|
||||
|
||||
public boolean[] getJestRow() {
|
||||
return jestRow;
|
||||
}
|
||||
|
||||
public boolean[] getJestPrzeszkodaWodna() {
|
||||
return jestPrzeszkodaWodna;
|
||||
}
|
||||
|
||||
public void setStopienZabudowy(float stopienZabudowy) {
|
||||
this.stopienZabudowy = stopienZabudowy;
|
||||
normalizujDanePokrycia();
|
||||
// try {
|
||||
// if (null != bs) {
|
||||
// bs.updateFile(false);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// }
|
||||
}
|
||||
|
||||
public void setStopienZalesienia(float stopienZalesienia) {
|
||||
this.stopienZalesienia = stopienZalesienia;
|
||||
normalizujDanePokrycia();
|
||||
// try {
|
||||
// if (null != bs) {
|
||||
// bs.updateFile(false);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// }
|
||||
}
|
||||
|
||||
public void setStopienZawodnienia(float stopienZawodnienia) {
|
||||
this.stopienZawodnienia = stopienZawodnienia;
|
||||
normalizujDanePokrycia();
|
||||
// try {
|
||||
// if (null != bs) {
|
||||
// bs.updateFile(false);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// }
|
||||
}
|
||||
|
||||
public void setStopienZabagnienia(float stopienZabagnienia) {
|
||||
this.stopienZabagnienia = stopienZabagnienia;
|
||||
normalizujDanePokrycia();
|
||||
// try {
|
||||
// if (null != bs) {
|
||||
// bs.updateFile(false);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// }
|
||||
}
|
||||
|
||||
public void normalizujDanePokrycia() {
|
||||
float suma = stopienZalesienia + stopienZawodnienia + stopienZabudowy + stopienZabagnienia;
|
||||
if (suma > 1.0f) {
|
||||
stopienZalesienia /= suma;
|
||||
stopienZawodnienia /= suma;
|
||||
stopienZabudowy /= suma;
|
||||
stopienZabagnienia = 1.0f - stopienZalesienia - stopienZawodnienia - stopienZabudowy;
|
||||
}
|
||||
}
|
||||
|
||||
public void setRoznicaWzniesien(int roznicaWzniesien) {
|
||||
this.roznicaWzniesien = roznicaWzniesien;
|
||||
// try {
|
||||
// if (null != bs) {
|
||||
// bs.updateFile(false);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// }
|
||||
}
|
||||
|
||||
public void setWysokoscSrednia(int wysokoscSrednia) {
|
||||
this.wysokoscSrednia = wysokoscSrednia;
|
||||
// try {
|
||||
// if (null != bs) {
|
||||
// bs.updateFile(false);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// }
|
||||
}
|
||||
|
||||
public void setJestDroga(boolean[] czyJestDroga) {
|
||||
this.jestDroga = czyJestDroga;
|
||||
// try {
|
||||
// if (null != bs) {
|
||||
// bs.updateFile(false);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// }
|
||||
}
|
||||
|
||||
public void setJestDroga(EGeoDirection naKierunku, boolean czyJest) {
|
||||
if (naKierunku == EGeoDirection.UNDEFINED) {
|
||||
return;
|
||||
}
|
||||
this.jestDroga[naKierunku.id] = czyJest;
|
||||
// try {
|
||||
// if (null != bs) {
|
||||
// bs.updateFile(false);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// }
|
||||
}
|
||||
|
||||
public void setJestPrzeszkodaWodna(EGeoDirection naKierunku, boolean czyJest) {
|
||||
if (naKierunku == EGeoDirection.UNDEFINED) {
|
||||
return;
|
||||
}
|
||||
this.jestPrzeszkodaWodna[naKierunku.id] = czyJest;
|
||||
// try {
|
||||
// if (null != bs) {
|
||||
// bs.updateFile(false);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// }
|
||||
}
|
||||
|
||||
public void setJestRow(EGeoDirection naKierunku, boolean czyJest) {
|
||||
if (naKierunku == EGeoDirection.UNDEFINED) {
|
||||
return;
|
||||
}
|
||||
this.jestRow[naKierunku.id] = czyJest;
|
||||
// try {
|
||||
// if (null != bs) {
|
||||
// bs.updateFile(false);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// }
|
||||
}
|
||||
|
||||
public void setJestRow(boolean[] czyJestRow) {
|
||||
this.jestRow = czyJestRow;
|
||||
// try {
|
||||
// if (null != bs) {
|
||||
// bs.updateFile(false);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// }
|
||||
}
|
||||
|
||||
public void setJestPrzeszkodaWodna(boolean[] czyJestPrzeszkodaWodna) {
|
||||
this.jestPrzeszkodaWodna = czyJestPrzeszkodaWodna;
|
||||
// try {
|
||||
// if (null != bs) {
|
||||
// bs.updateFile(false);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// }
|
||||
}
|
||||
|
||||
public float getStopienPofaldowania() {
|
||||
// TODO: dodac do normatywow w klasie Teren (parametr kalibracyjny)
|
||||
float stopienPofaldowania = 0.0f;
|
||||
if (this.roznicaWzniesien >= 50)
|
||||
stopienPofaldowania = 1.0f;
|
||||
else if (this.roznicaWzniesien >= 10)
|
||||
stopienPofaldowania = 0.6f;
|
||||
else if (this.roznicaWzniesien >= 5)
|
||||
stopienPofaldowania = 0.4f;
|
||||
else if (this.roznicaWzniesien >= 3)
|
||||
stopienPofaldowania = 0.2f;
|
||||
return stopienPofaldowania;
|
||||
}
|
||||
|
||||
public Kwadrat() {
|
||||
jestDroga = new boolean[8];
|
||||
jestPrzeszkodaWodna = new boolean[8];
|
||||
jestRow = new boolean[8];
|
||||
}
|
||||
|
||||
public Kwadrat(RightBigSquare _bs, float _stopienZabudowy, float _stopienZalesienia, float _stopienZabagnienia, float _stopienZawodnienia,
|
||||
int _wysokoscSrednia, int _roznicaWzniesien, boolean _czyJestDroga[], boolean _czyJestRow[], boolean _czyJestPrzeszkodaWodna[]){
|
||||
bs = _bs;
|
||||
stopienZabudowy = _stopienZabudowy;
|
||||
stopienZalesienia = _stopienZalesienia;
|
||||
stopienZabagnienia = _stopienZabagnienia;
|
||||
stopienZawodnienia = _stopienZawodnienia;
|
||||
wysokoscSrednia = _wysokoscSrednia;
|
||||
roznicaWzniesien = _roznicaWzniesien;
|
||||
jestDroga = new boolean[8];
|
||||
jestRow = new boolean[8];
|
||||
jestPrzeszkodaWodna = new boolean[8];
|
||||
for (int i = 0; i < _czyJestDroga.length; i++) {
|
||||
jestDroga[i]=_czyJestDroga[i];
|
||||
}
|
||||
for (int i = 0; i < jestRow.length; i++) {
|
||||
jestRow[i]=_czyJestRow[i];
|
||||
}
|
||||
for (int i = 0; i < _czyJestPrzeszkodaWodna.length; i++) {
|
||||
jestPrzeszkodaWodna[i]=_czyJestPrzeszkodaWodna[i];
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
float f = this.stopienZabudowy * 255.0f;
|
||||
int hex = (int)f;
|
||||
String s = String.format("%02X", hex);
|
||||
String linia = s;
|
||||
linia += " ";
|
||||
|
||||
f = this.stopienZalesienia * 255.0f;
|
||||
hex = (int)f;
|
||||
s = String.format("%02X", hex);
|
||||
linia += s;
|
||||
linia += " ";
|
||||
|
||||
f = this.stopienZabagnienia * 255.0f;
|
||||
hex = (int)f;
|
||||
s = String.format("%02X", hex);
|
||||
linia += s;
|
||||
linia += " ";
|
||||
|
||||
f = this.stopienZawodnienia * 255.0f;
|
||||
hex = (int)f;
|
||||
s = String.format("%02X", hex);
|
||||
linia += s;
|
||||
linia += " ";
|
||||
|
||||
s = String.format("%4d", this.wysokoscSrednia);
|
||||
linia += s;
|
||||
linia += " ";
|
||||
|
||||
s = String.format("%4d", this.roznicaWzniesien);
|
||||
linia += s;
|
||||
linia += " ";
|
||||
|
||||
int bity = 0;
|
||||
int bit_1 = 1;
|
||||
for (int i = 0; i < this.jestDroga.length; i++) {
|
||||
if (this.jestDroga[i]) // jest odcinek drogi na tym kierunku
|
||||
bity += bit_1;
|
||||
|
||||
bit_1 = bit_1 << 1;
|
||||
}
|
||||
s = String.format("%02X", bity);
|
||||
linia += s;
|
||||
linia += " ";
|
||||
|
||||
bity = 0;
|
||||
bit_1 = 1;
|
||||
for (int i = 0; i < this.jestPrzeszkodaWodna.length; i++) {
|
||||
if (this.jestPrzeszkodaWodna[i]) // jest przeszkod na tym kierunku
|
||||
bity += bit_1;
|
||||
|
||||
bit_1 = bit_1 << 1;
|
||||
}
|
||||
s = String.format("%02X", bity);
|
||||
linia += s;
|
||||
linia += " ";
|
||||
|
||||
bity = 0;
|
||||
bit_1 = 1;
|
||||
for (int i = 0; i < this.jestRow.length; i++) {
|
||||
if (this.jestRow[i]) // jest row na tym kierunku
|
||||
bity += bit_1;
|
||||
|
||||
bit_1 = bit_1 << 1;
|
||||
}
|
||||
s = String.format("%02X", bity);
|
||||
linia += s;
|
||||
return linia;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class LukDrogowy {
|
||||
|
||||
private WezelDrogowy[] wezly = new WezelDrogowy[2];
|
||||
int id = -1;
|
||||
int dlugosc = 0;
|
||||
int szerokosc = 0;
|
||||
int rodzajNawierzchni = 0;
|
||||
boolean jestMostem = false;
|
||||
|
||||
LukDrogowy() {}
|
||||
|
||||
LukDrogowy(String opis) {
|
||||
if (null == opis || opis.length() == 0){
|
||||
SiecDrogowa.logger.debug("Pusty ciag opis w konstruktorze Luku Drogowego.");
|
||||
return;
|
||||
}
|
||||
StringTokenizer st = new StringTokenizer(opis, " \t");
|
||||
String[] tokenTable = new String[st.countTokens()];
|
||||
for (int i = 0; st.hasMoreTokens(); i++) {
|
||||
tokenTable[i] = st.nextToken();
|
||||
}
|
||||
if (tokenTable.length == 6) {
|
||||
try {
|
||||
int id = Integer.parseInt(tokenTable[0]);
|
||||
WezelDrogowy wezel = SiecDrogowa.instancja.wezly.get(id);
|
||||
if (null == wezel)
|
||||
SiecDrogowa.logger.warn("Brak wierzcholka (1) poczatkowego luku. [" + opis + "].");
|
||||
this.getWezly()[0] = wezel;
|
||||
wezel.luki.add(this);
|
||||
} catch (NumberFormatException e) {
|
||||
SiecDrogowa.logger.warn("Bledne dane w pliku z lukami [Wezel 1].");
|
||||
}
|
||||
try {
|
||||
int id = Integer.parseInt(tokenTable[1]);
|
||||
WezelDrogowy wezel = SiecDrogowa.instancja.wezly.get(id);
|
||||
if (null == wezel)
|
||||
SiecDrogowa.logger.warn("Brak wierzcholka (2) koncowego luku. [" + opis + "].");
|
||||
this.getWezly()[1] = wezel;
|
||||
wezel.luki.add(this);
|
||||
} catch (NumberFormatException e) {
|
||||
SiecDrogowa.logger.warn("Bledne dane w pliku z lukami [Wezel 2].");
|
||||
}
|
||||
if (this.wezly[0].id == this.wezly[1].id) {
|
||||
SiecDrogowa.logger.warn("Bledne dane w pliku z lukami [wezly sa identyczne].");
|
||||
}
|
||||
if (GridCoord.czyIdentyczne(this.wezly[0].idKw, this.wezly[1].idKw)) {
|
||||
SiecDrogowa.logger.warn("Bledne dane w pliku z lukami [wezly sa identyczne].");
|
||||
}
|
||||
try {
|
||||
this.dlugosc = Integer.parseInt(tokenTable[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
SiecDrogowa.logger.warn("Bledne dane w pliku z lukami [Dlugosc].");
|
||||
}
|
||||
try {
|
||||
this.szerokosc = Integer.parseInt(tokenTable[3]);
|
||||
} catch (NumberFormatException e) {
|
||||
SiecDrogowa.logger.warn("Bledne dane w pliku z lukami [Szerokosc].");
|
||||
}
|
||||
try {
|
||||
this.rodzajNawierzchni = Integer.parseInt(tokenTable[4]);
|
||||
} catch (NumberFormatException e) {
|
||||
SiecDrogowa.logger.warn("Bledne dane w pliku z lukami [RodzajNawierzchni].");
|
||||
}
|
||||
try {
|
||||
int b = Integer.parseInt(tokenTable[5]);
|
||||
this.jestMostem = (b != 0);
|
||||
} catch (NumberFormatException e) {
|
||||
SiecDrogowa.logger.warn("Bledne dane w pliku z lukami [CzyJestMost].");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getDlugosc() {
|
||||
return dlugosc;
|
||||
}
|
||||
|
||||
public void setDlugosc(int dlugosc) {
|
||||
this.dlugosc = dlugosc;
|
||||
}
|
||||
|
||||
public int getSzerokosc() {
|
||||
return szerokosc;
|
||||
}
|
||||
|
||||
public void setSzerokosc(int szerokosc) {
|
||||
this.szerokosc = szerokosc;
|
||||
}
|
||||
|
||||
public int getRodzajNawierzchni() {
|
||||
return rodzajNawierzchni;
|
||||
}
|
||||
|
||||
public void setRodzajNawierzchni(int rodzajNawierzchni) {
|
||||
this.rodzajNawierzchni = rodzajNawierzchni;
|
||||
}
|
||||
|
||||
public boolean isJestMostem() {
|
||||
return jestMostem;
|
||||
}
|
||||
|
||||
public void setJestMostem(boolean jestMostem) {
|
||||
this.jestMostem = jestMostem;
|
||||
}
|
||||
|
||||
public WezelDrogowy[] getWezly() {
|
||||
return wezly;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,242 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
public final class MapConsts {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MapConsts.class);
|
||||
|
||||
/**
|
||||
* Umowny uklad odniesienia dla lokalizacji geograficznej: <p>
|
||||
* Długość geograficzna (wsp. X) przyjmuje wartości: [0, 360) odpowiadające [-180, 180]<p>
|
||||
* Szerokość geograficzna (wsp. Y) przyjmuje wartości: [0, 180] odpowadające [-90, 90]
|
||||
*/
|
||||
public static final int X_REF;
|
||||
/**
|
||||
* Umowny uklad odniesienia dla lokalizacji geograficznej: <p>
|
||||
* Długość geograficzna (wsp. X) przyjmuje wartości: [0, 360) odpowiadające [-180, 180]<p>
|
||||
* Szerokość geograficzna (wsp. Y) przyjmuje wartości: [0, 180] odpowadające [-90, 90]
|
||||
*/
|
||||
public static final int Y_REF;
|
||||
public static final int DX_REF;
|
||||
public static final int DY_REF;
|
||||
|
||||
public static final String KWADRATY_DIR;
|
||||
public static final String DROGI_DIR;
|
||||
|
||||
/**
|
||||
* Nazwa pliku z konfiguracja mechanizmu odpowiedzialnego za transfer. Plik
|
||||
* musi znajdowac sie w katalogu glownym aplikacji, ewentualnie musi tu byc
|
||||
* podana sciezka bezwzgledna do niego.
|
||||
*/
|
||||
private static final String PLIK_Z_USTAWIENIAMI = "teren.properties";
|
||||
|
||||
/**
|
||||
* Dlugosc boku duzego kwadratu na osi OX w liczbie malych kwadratow.
|
||||
*/
|
||||
public static final int SS_PER_BS_X;
|
||||
/**
|
||||
* Dlugosc boku duzego kwadratu na osi OY w liczbie malych kwadratow.
|
||||
*/
|
||||
public static final int SS_PER_BS_Y;
|
||||
/**
|
||||
* Dlugosc boku malego kwadratu w metrach.
|
||||
*/
|
||||
public static final int DL_MK;
|
||||
/**
|
||||
* Powierzchnia malego kwadratu w metrach.
|
||||
*/
|
||||
public static final int POW_MK;
|
||||
/**
|
||||
* Szerokość małego kwadratu w stopniach.
|
||||
*/
|
||||
public static final double DELTA_X;
|
||||
/**
|
||||
* Wysokość małego kwadratu w stopniach.
|
||||
*/
|
||||
public static final double DELTA_Y;
|
||||
/**
|
||||
* Liczba duzych kwadratow na stopien geograficzny po osi OX (dlugosc geograficzna).
|
||||
*/
|
||||
public static final int BS_PER_DEG_X = 4;
|
||||
/**
|
||||
* Liczba duzych kwadratow na stopien geograficzny po osi OY (szerokosc geograficzna).
|
||||
*/
|
||||
public static final int BS_PER_DEG_Y = 6;
|
||||
/**
|
||||
* Szerokość duzych kwadratow w stopniach geograficznych po osi OX (dlugosc geograficzna).
|
||||
*/
|
||||
public static final double BS_DX;
|
||||
/**
|
||||
* Wysokość duzych kwadratow w stopniach geograficznych po osi OY (szerokosc geograficzna).
|
||||
*/
|
||||
public static final double BS_DY;
|
||||
|
||||
static Properties ustawienia;
|
||||
|
||||
/**
|
||||
* Odczytanie ustawien z pliku konfiguracyjnego.
|
||||
*/
|
||||
static {
|
||||
String propertiesFileName = System.getProperty("user.dir") + "\\" + PLIK_Z_USTAWIENIAMI;
|
||||
|
||||
ustawienia = new Properties();
|
||||
try {
|
||||
LOGGER.debug("Odczyt ustawien z pliku " + propertiesFileName + ".");
|
||||
ustawienia.load(new FileInputStream(propertiesFileName));
|
||||
LOGGER.debug("Ustawienia wczytane.");
|
||||
} catch (FileNotFoundException e) {
|
||||
LOGGER.error(e.getLocalizedMessage());
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(e.getLocalizedMessage());
|
||||
}
|
||||
// logger.debug("Ustawienia wczytane.");
|
||||
// przesuniecie o 180 stop.
|
||||
// poludnik zerowy ma wartosc 180, zatem wspolrzedne zachodnie (ujemne) zawierają sie w <0, 180)
|
||||
// wspolrzedne wschodnie (nieujemne) zawieraja sie w przedziale <180, 360)
|
||||
X_REF = Integer.parseInt(ustawienia.getProperty("x_ref")) + 180;
|
||||
// przesuniecie o 90 stop.
|
||||
// rownik ma wartosc 90, zatem wspolrzedne poludniowe (ujemne) zawierają sie w <0, 90)
|
||||
// wspolrzedne polnocne (nieujemne) zawieraja sie w przedziale <90, 180>
|
||||
Y_REF = Integer.parseInt(ustawienia.getProperty("y_ref")) + 90;
|
||||
DX_REF = Integer.parseInt(ustawienia.getProperty("dx_ref"));
|
||||
DY_REF = Integer.parseInt(ustawienia.getProperty("dy_ref"));
|
||||
String val = ustawienia.getProperty("dl_mk");
|
||||
switch (val) {
|
||||
case "20":
|
||||
DL_MK = 20;
|
||||
break;
|
||||
case "25":
|
||||
DL_MK = 25;
|
||||
break;
|
||||
case "50":
|
||||
DL_MK = 50;
|
||||
break;
|
||||
case "100":
|
||||
DL_MK = 100;
|
||||
break;
|
||||
default:
|
||||
DL_MK = 200;
|
||||
break;
|
||||
}
|
||||
POW_MK = DL_MK * DL_MK;
|
||||
DROGI_DIR = ustawienia.getProperty("drogi_dir");
|
||||
if (DL_MK == 20) {
|
||||
SS_PER_BS_X = 83 * 10;
|
||||
SS_PER_BS_Y = 93 * 10;
|
||||
DELTA_X = 1.0 / (double) (BS_PER_DEG_X * SS_PER_BS_X);
|
||||
DELTA_Y = 1.0 / (double) (BS_PER_DEG_Y * SS_PER_BS_Y);
|
||||
KWADRATY_DIR = ustawienia.getProperty("kwadraty_dir") + "20m/";
|
||||
} else if (DL_MK == 25) {
|
||||
SS_PER_BS_X = 83 * 8;
|
||||
SS_PER_BS_Y = 93 * 8;
|
||||
DELTA_X = 1.0 / (double) (BS_PER_DEG_X * SS_PER_BS_X);
|
||||
DELTA_Y = 1.0 / (double) (BS_PER_DEG_Y * SS_PER_BS_Y);
|
||||
KWADRATY_DIR = ustawienia.getProperty("kwadraty_dir") + "25m/";
|
||||
} else if (DL_MK == 50) {
|
||||
SS_PER_BS_X = 83 * 4;
|
||||
SS_PER_BS_Y = 93 * 4;
|
||||
DELTA_X = 1.0 / (double) (BS_PER_DEG_X * SS_PER_BS_X);
|
||||
DELTA_Y = 1.0 / (double) (BS_PER_DEG_Y * SS_PER_BS_Y);
|
||||
KWADRATY_DIR = ustawienia.getProperty("kwadraty_dir") + "50m/";
|
||||
} else if (DL_MK == 100) {
|
||||
SS_PER_BS_X = 83 * 2;
|
||||
SS_PER_BS_Y = 93 * 2;
|
||||
DELTA_X = 1.0 / (double) (BS_PER_DEG_X * SS_PER_BS_X);
|
||||
DELTA_Y = 1.0 / (double) (BS_PER_DEG_Y * SS_PER_BS_Y);
|
||||
KWADRATY_DIR = ustawienia.getProperty("kwadraty_dir") + "100m/";
|
||||
} else {
|
||||
// domyslnie dlugosc kwadratu 200m
|
||||
SS_PER_BS_X = 83;
|
||||
SS_PER_BS_Y = 93;
|
||||
DELTA_X = 1.0 / (double) (BS_PER_DEG_X * SS_PER_BS_X);
|
||||
DELTA_Y = 1.0 / (double) (BS_PER_DEG_Y * SS_PER_BS_Y);
|
||||
KWADRATY_DIR = ustawienia.getProperty("kwadraty_dir") + "200m/";
|
||||
}
|
||||
BS_DX = 1.0 / (double) BS_PER_DEG_X;
|
||||
BS_DY = 1.0 / (double) BS_PER_DEG_Y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Liczba milisekund na stopien.
|
||||
*/
|
||||
public static final int DEG_MS = 3600000;
|
||||
/**
|
||||
* Liczba milisekund na 360 stopni.
|
||||
*/
|
||||
public static final long ANGLE_360_MS = 3600000 * 360;
|
||||
/**
|
||||
* Wielkosc cache'u pola walki (liczba duzych kwadratow trzymanych w RAM).
|
||||
*/
|
||||
public static final int MAX_BIG_SQUARES_IN_MEMORY = 500;
|
||||
/**
|
||||
* Wspolrzedna referencyjna X (dlugosc geograficzna) lewego dolnego rogu mapy w stopniach geograficznych.
|
||||
* @return
|
||||
*/
|
||||
public static int getX_REF() {
|
||||
return X_REF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wspolrzedna referencyjna Y (szerokosc geograficzna) lewego dolnego rogu mapy w stopniach geograficznych.
|
||||
* @return
|
||||
*/
|
||||
public static int getY_REF() {
|
||||
return Y_REF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Szerokosc referencyjna prostokata pola walki w stopniach na osi OX (dlugosc geograficzna).
|
||||
* @return
|
||||
*/
|
||||
public static int getDX_REF() {
|
||||
return DX_REF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wysokosc referencyjna prostokata pola walki w stopniach na osi OY (szerokosc geograficzna).
|
||||
* @return
|
||||
*/
|
||||
public static int getDY_REF() {
|
||||
return DY_REF;
|
||||
}
|
||||
|
||||
public static String getKwadratyDir() {
|
||||
return KWADRATY_DIR;
|
||||
}
|
||||
|
||||
public static String getDrogiDir() {
|
||||
return DROGI_DIR;
|
||||
}
|
||||
/**
|
||||
* Dlugosci bokow malego kwadratu w milisekundach geograficznych po osi OX (dlugosc geograficzna).
|
||||
*/
|
||||
public static final double SS_DX_MS = DELTA_X * DEG_MS;
|
||||
/**
|
||||
* Dlugosci bokow malego kwadratu w milisekundach geograficznych po osi OY (szerokosc geograficzna).
|
||||
*/
|
||||
public static final double SS_DY_MS = DELTA_Y * DEG_MS;
|
||||
// wspolrzedne dolnego lewego rogu mapy w ms
|
||||
// wspolrzedne geograficzne w milisekundach zawieraja sie w zakresie:
|
||||
// 0 <= x < 360 dlugosc geograficzna
|
||||
// 0 <= y <= 180 szerokosc geograficzna
|
||||
public static final int X_REF_MS = X_REF * DEG_MS;
|
||||
public static final int Y_REF_MS = Y_REF * DEG_MS;
|
||||
public static final int DX_REF_MS = DEG_MS * DX_REF; // szerokosc pola walki w stopniach
|
||||
public static final int DY_REF_MS = DEG_MS * DY_REF; // wysokosc polwa walki w stopniach
|
||||
|
||||
public static final int BS_DX_MS = (int) (BS_DX * DEG_MS);
|
||||
public static final int BS_DY_MS = (int) (BS_DY * DEG_MS);
|
||||
|
||||
/**
|
||||
* Liczba malych kwadratow przypadajaca na bok arkusza mapy drogowej.
|
||||
*/
|
||||
public static final int SS_PER_SHEET = 20;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,640 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.io.*;
|
||||
|
||||
public class RightBigSquare extends BigSquare implements Serializable {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(RightBigSquare.class);
|
||||
|
||||
private Kwadrat kwadraty[][];
|
||||
|
||||
Kwadrat getKwadrat(int ssX, int ssY) {
|
||||
return kwadraty[ssX][ssY];
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zapisująca do pliku duży kwadrat.<p>
|
||||
* Zapis następuje w trybie wskazywanym przez atrybut: RightBigSquare.binary.
|
||||
*
|
||||
* @param wymuszony flag informujacy o trybie zapisu pliku
|
||||
* @param fName nazwa pliku
|
||||
* @throws IOException generowany wyjątek
|
||||
*/
|
||||
void updateFile(boolean wymuszony, String fName) throws IOException {
|
||||
if (wymuszony) {
|
||||
if (this.liczbaZmian == 0) {
|
||||
// nie bylo modyfikacji od ostatniego zapisu
|
||||
return;
|
||||
}
|
||||
this.liczbaZmian = -1;
|
||||
}
|
||||
this.liczbaZmian++;
|
||||
this.liczbaZmian %= LICZBA_ZMIAN_DO_ZAPISU;
|
||||
if (this.liczbaZmian > 0) {
|
||||
return;
|
||||
}
|
||||
if (fName != null) {
|
||||
fileName = fName;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(100);
|
||||
sb.append(MapConsts.KWADRATY_DIR);
|
||||
sb.append(fileName);
|
||||
sb.append(".bin");
|
||||
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(sb.toString()));
|
||||
for (int x = 0; x < MapConsts.SS_PER_BS_X; x++) {
|
||||
for (int y = 0; y < MapConsts.SS_PER_BS_Y; y++) {
|
||||
float f = kwadraty[x][y].stopienZalesienia * 100.0f;
|
||||
int hex = (int) f;
|
||||
hex = (hex > 100) ? 100 : hex;
|
||||
hex = (hex < 0) ? 0 : hex;
|
||||
out.writeByte(hex);
|
||||
f = kwadraty[x][y].stopienZawodnienia * 100.0f;
|
||||
hex = (int) f;
|
||||
hex = (hex > 100) ? 100 : hex;
|
||||
hex = (hex < 0) ? 0 : hex;
|
||||
out.writeByte(hex);
|
||||
f = kwadraty[x][y].stopienZabudowy * 100.0f;
|
||||
hex = (int) f;
|
||||
hex = (hex > 100) ? 100 : hex;
|
||||
hex = (hex < 0) ? 0 : hex;
|
||||
out.writeByte(hex);
|
||||
f = kwadraty[x][y].stopienZabagnienia * 100.0f;
|
||||
hex = (int) f;
|
||||
hex = (hex > 100) ? 100 : hex;
|
||||
hex = (hex < 0) ? 0 : hex;
|
||||
out.writeByte(hex);
|
||||
out.writeInt(kwadraty[x][y].wysokoscSrednia);
|
||||
out.writeInt(kwadraty[x][y].roznicaWzniesien);
|
||||
|
||||
hex = 0;
|
||||
int bit_1 = 1;
|
||||
for (int i = 0; i < kwadraty[x][y].jestDroga.length; i++) {
|
||||
// jest odcinek drogi na tym kierunku
|
||||
if (kwadraty[x][y].jestDroga[i]) {
|
||||
hex |= bit_1;
|
||||
}
|
||||
bit_1 <<= 1;
|
||||
}
|
||||
out.writeByte(hex);
|
||||
|
||||
hex = 0;
|
||||
bit_1 = 1;
|
||||
for (int i = 0; i < kwadraty[x][y].jestPrzeszkodaWodna.length; i++) {
|
||||
// jest odcinek przeszkody wodnej na tym kierunku
|
||||
if (kwadraty[x][y].jestPrzeszkodaWodna[i]) {
|
||||
hex |= bit_1;
|
||||
}
|
||||
bit_1 <<= 1;
|
||||
}
|
||||
out.writeByte(hex);
|
||||
|
||||
hex = 0;
|
||||
bit_1 = 1;
|
||||
for (int i = 0; i < kwadraty[x][y].jestRow.length; i++) {
|
||||
// jest odcinek rowu na tym kierunku
|
||||
if (kwadraty[x][y].jestRow[i]) {
|
||||
hex |= bit_1;
|
||||
}
|
||||
bit_1 <<= 1;
|
||||
}
|
||||
out.writeByte(hex);
|
||||
}
|
||||
}
|
||||
out.close();
|
||||
logger.debug("Zapisano plik mapy: " + sb.toString());
|
||||
}
|
||||
|
||||
static final int NORTH = 0;
|
||||
static final int NORTH_EAST = 1;
|
||||
static final int EAST = 2;
|
||||
static final int SOUTH_EAST = 3;
|
||||
static final int SOUTH = 4;
|
||||
static final int SOUTH_WEST = 5;
|
||||
static final int WEST = 6;
|
||||
static final int NORTH_WEST = 7;
|
||||
static final byte NORTH_CODE = 1;
|
||||
static final byte NORTH_EAST_CODE = 2;
|
||||
static final byte EAST_CODE = 4;
|
||||
static final byte SOUTH_EAST_CODE = 8;
|
||||
static final byte SOUTH_CODE = 16;
|
||||
static final byte SOUTH_WEST_CODE = 32;
|
||||
static final byte WEST_CODE = 64;
|
||||
static final byte NORTH_WEST_CODE = -128;
|
||||
|
||||
|
||||
/**
|
||||
* Funkcja generuje nowy plik z danymi na podstawie danych z pliku referencyjnego (kwadraty o rozm. 200m).
|
||||
* <p>Nowy plik moze byc z danymi w innej skali (kwadraty o rozmiarach: 100m lub 50m) i/lub innym formacie (binarny, tekstowy).
|
||||
*
|
||||
* @param dir katalog docelowy dla nowego pliku
|
||||
* @param dlmk rozmiar kwadratow generownych danych
|
||||
* @throws IOException generowany wyjątek
|
||||
*/
|
||||
public void saveNewFileWithNewScale(String dir, int dlmk) throws IOException {
|
||||
if (MapConsts.DL_MK != 100) {
|
||||
// operacja tylko dla danych terenowych o kwadratach 200m
|
||||
return;
|
||||
}
|
||||
int m = 1;
|
||||
String s = "";
|
||||
if (dlmk == 100) {
|
||||
m = 1;
|
||||
s = "100m/";
|
||||
} else if (dlmk == 50) {
|
||||
m = 2;
|
||||
s = "50m/";
|
||||
} else if (dlmk == 25) {
|
||||
m = 4;
|
||||
s = "25m/";
|
||||
} else if (dlmk == 20) {
|
||||
m = 5;
|
||||
s = "20m/";
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(100);
|
||||
sb.append(dir);
|
||||
sb.append(s);
|
||||
// Utworzenie katalogów, gdyby nie istniały.
|
||||
File directory = new File(sb.toString());
|
||||
directory.mkdirs();
|
||||
sb.append(fileName);
|
||||
sb.append(".bin");
|
||||
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(sb.toString()));
|
||||
|
||||
SmallSquare[][][][] ss_all = new SmallSquare[MapConsts.SS_PER_BS_X][MapConsts.SS_PER_BS_Y][][];
|
||||
for (int x = 0; x < MapConsts.SS_PER_BS_X; x++) {
|
||||
for (int y = 0; y < MapConsts.SS_PER_BS_Y; y++) {
|
||||
SmallSquare[][] ss = new SmallSquare[m][m];
|
||||
for (int i = 0; i < m; i++) {
|
||||
for (int j = 0; j < m; j++) {
|
||||
ss[i][j] = new SmallSquare();
|
||||
}
|
||||
}
|
||||
ss_all[x][y] = ss;
|
||||
// jest odcinek drogi na tym kierunku
|
||||
if (kwadraty[x][y].jestDroga[NORTH]) {
|
||||
ss[2][2].majorRoads |= NORTH_CODE;
|
||||
ss[2][3].majorRoads |= NORTH_CODE | SOUTH_CODE;
|
||||
ss[2][4].majorRoads |= NORTH_CODE | SOUTH_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestDroga[NORTH_EAST]) {
|
||||
ss[2][2].majorRoads |= NORTH_EAST_CODE;
|
||||
ss[3][3].majorRoads |= NORTH_EAST_CODE | SOUTH_WEST_CODE;
|
||||
ss[4][4].majorRoads |= NORTH_EAST_CODE | SOUTH_WEST_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestDroga[EAST]) {
|
||||
ss[2][2].majorRoads |= EAST_CODE;
|
||||
ss[3][2].majorRoads |= EAST_CODE | WEST_CODE;
|
||||
ss[4][2].majorRoads |= EAST_CODE | WEST_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestDroga[SOUTH_EAST]) {
|
||||
ss[2][2].majorRoads |= SOUTH_EAST_CODE;
|
||||
ss[3][1].majorRoads |= SOUTH_EAST_CODE | NORTH_WEST_CODE;
|
||||
ss[4][0].majorRoads |= SOUTH_EAST_CODE | NORTH_WEST_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestDroga[SOUTH]) {
|
||||
ss[2][2].majorRoads |= SOUTH_CODE;
|
||||
ss[2][1].majorRoads |= SOUTH_CODE | NORTH_CODE;
|
||||
ss[2][0].majorRoads |= SOUTH_CODE | NORTH_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestDroga[SOUTH_WEST]) {
|
||||
ss[2][2].majorRoads |= SOUTH_WEST_CODE;
|
||||
ss[1][1].majorRoads |= SOUTH_WEST_CODE | NORTH_EAST_CODE;
|
||||
ss[0][0].majorRoads |= SOUTH_WEST_CODE | NORTH_EAST_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestDroga[WEST]) {
|
||||
ss[2][2].majorRoads |= WEST_CODE;
|
||||
ss[1][2].majorRoads |= WEST_CODE | EAST_CODE;
|
||||
ss[0][2].majorRoads |= WEST_CODE | EAST_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestDroga[NORTH_WEST]) {
|
||||
ss[2][2].majorRoads |= NORTH_WEST_CODE;
|
||||
ss[1][3].majorRoads |= NORTH_WEST_CODE | SOUTH_EAST_CODE;
|
||||
ss[0][4].majorRoads |= NORTH_WEST_CODE | SOUTH_EAST_CODE;
|
||||
}
|
||||
|
||||
// jest odcinek rzeki na tym kierunku
|
||||
if (kwadraty[x][y].jestPrzeszkodaWodna[NORTH]) {
|
||||
ss[2][2].rivers |= NORTH_CODE;
|
||||
ss[2][3].rivers |= NORTH_CODE | SOUTH_CODE;
|
||||
ss[2][4].rivers |= NORTH_CODE | SOUTH_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestPrzeszkodaWodna[NORTH_EAST]) {
|
||||
ss[2][2].rivers |= NORTH_EAST_CODE;
|
||||
ss[3][3].rivers |= NORTH_EAST_CODE | SOUTH_WEST_CODE;
|
||||
ss[4][4].rivers |= NORTH_EAST_CODE | SOUTH_WEST_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestPrzeszkodaWodna[EAST]) {
|
||||
ss[2][2].rivers |= EAST_CODE;
|
||||
ss[3][2].rivers |= EAST_CODE | WEST_CODE;
|
||||
ss[4][2].rivers |= EAST_CODE | WEST_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestPrzeszkodaWodna[SOUTH_EAST]) {
|
||||
ss[2][2].rivers |= SOUTH_EAST_CODE;
|
||||
ss[3][1].rivers |= SOUTH_EAST_CODE | NORTH_WEST_CODE;
|
||||
ss[4][0].rivers |= SOUTH_EAST_CODE | NORTH_WEST_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestPrzeszkodaWodna[SOUTH]) {
|
||||
ss[2][2].rivers |= SOUTH_CODE;
|
||||
ss[2][1].rivers |= SOUTH_CODE | NORTH_CODE;
|
||||
ss[2][0].rivers |= SOUTH_CODE | NORTH_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestPrzeszkodaWodna[SOUTH_WEST]) {
|
||||
ss[2][2].rivers |= SOUTH_WEST_CODE;
|
||||
ss[1][1].rivers |= SOUTH_WEST_CODE | NORTH_EAST_CODE;
|
||||
ss[0][0].rivers |= SOUTH_WEST_CODE | NORTH_EAST_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestPrzeszkodaWodna[WEST]) {
|
||||
ss[2][2].rivers |= WEST_CODE;
|
||||
ss[1][2].rivers |= WEST_CODE | EAST_CODE;
|
||||
ss[0][2].rivers |= WEST_CODE | EAST_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestPrzeszkodaWodna[NORTH_WEST]) {
|
||||
ss[2][2].rivers |= NORTH_WEST_CODE;
|
||||
ss[1][3].rivers |= NORTH_WEST_CODE | SOUTH_EAST_CODE;
|
||||
ss[0][4].rivers |= NORTH_WEST_CODE | SOUTH_EAST_CODE;
|
||||
}
|
||||
|
||||
// jest odcinek rowu na tym kierunku
|
||||
if (kwadraty[x][y].jestRow[NORTH]) {
|
||||
ss[2][2].drains |= NORTH_CODE;
|
||||
ss[2][3].drains |= NORTH_CODE | SOUTH_CODE;
|
||||
ss[2][4].drains |= NORTH_CODE | SOUTH_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestRow[NORTH_EAST]) {
|
||||
ss[2][2].drains |= NORTH_EAST_CODE;
|
||||
ss[3][3].drains |= NORTH_EAST_CODE | SOUTH_WEST_CODE;
|
||||
ss[4][4].drains |= NORTH_EAST_CODE | SOUTH_WEST_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestRow[EAST]) {
|
||||
ss[2][2].drains |= EAST_CODE;
|
||||
ss[3][2].drains |= EAST_CODE | WEST_CODE;
|
||||
ss[4][2].drains |= EAST_CODE | WEST_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestRow[SOUTH_EAST]) {
|
||||
ss[2][2].drains |= SOUTH_EAST_CODE;
|
||||
ss[3][1].drains |= SOUTH_EAST_CODE | NORTH_WEST_CODE;
|
||||
ss[4][0].drains |= SOUTH_EAST_CODE | NORTH_WEST_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestRow[SOUTH]) {
|
||||
ss[2][2].drains |= SOUTH_CODE;
|
||||
ss[2][1].drains |= SOUTH_CODE | NORTH_CODE;
|
||||
ss[2][0].drains |= SOUTH_CODE | NORTH_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestRow[SOUTH_WEST]) {
|
||||
ss[2][2].drains |= SOUTH_WEST_CODE;
|
||||
ss[1][1].drains |= SOUTH_WEST_CODE | NORTH_EAST_CODE;
|
||||
ss[0][0].drains |= SOUTH_WEST_CODE | NORTH_EAST_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestRow[WEST]) {
|
||||
ss[2][2].drains |= WEST_CODE;
|
||||
ss[1][2].drains |= WEST_CODE | EAST_CODE;
|
||||
ss[0][2].drains |= WEST_CODE | EAST_CODE;
|
||||
}
|
||||
if (kwadraty[x][y].jestRow[NORTH_WEST]) {
|
||||
ss[2][2].drains |= NORTH_WEST_CODE;
|
||||
ss[1][3].drains |= NORTH_WEST_CODE | SOUTH_EAST_CODE;
|
||||
ss[0][4].drains |= NORTH_WEST_CODE | SOUTH_EAST_CODE;
|
||||
}
|
||||
|
||||
for (int i = 0; i < m; i++) {
|
||||
for (int j = 0; j < m; j++) {
|
||||
int hex = 0;
|
||||
if (kwadraty[x][y].stopienZalesienia > 0) {
|
||||
hex = TerrainType.FOREST.ID;
|
||||
} else if (kwadraty[x][y].stopienZawodnienia > 0) {
|
||||
hex = TerrainType.WATER.ID;
|
||||
} else if (kwadraty[x][y].stopienZabudowy > 0) {
|
||||
hex = TerrainType.BUILDINGS.ID;
|
||||
} else if (kwadraty[x][y].stopienZabagnienia > 0) {
|
||||
hex = TerrainType.SWAMP.ID;
|
||||
}
|
||||
ss[i][j].terrainType = (byte) hex;
|
||||
ss[i][j].elevation = (short) kwadraty[x][y].wysokoscSrednia;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < MapConsts.SS_PER_BS_X; x++) {
|
||||
for (int i = 0; i < m; i++) {
|
||||
for (int y = 0; y < MapConsts.SS_PER_BS_Y; y++) {
|
||||
for (int j = 0; j < m; j++) {
|
||||
ss_all[x][y][i][j].save(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
out.close();
|
||||
logger.debug("Zapisano nowy plik mapy: " + sb + " dla rozmiaru MK= " + dlmk);
|
||||
}
|
||||
|
||||
void load(String FName) throws IOException {
|
||||
try {
|
||||
fileName = FName;
|
||||
StringBuilder sb = new StringBuilder(100);
|
||||
sb.append(MapConsts.KWADRATY_DIR);
|
||||
sb.append(fileName);
|
||||
sb.append(".bin");
|
||||
SmallSquare ss = new SmallSquare();
|
||||
ObjectInputStream in = new ObjectInputStream(new FileInputStream(sb.toString()));
|
||||
kwadraty = new Kwadrat[MapConsts.SS_PER_BS_X][MapConsts.SS_PER_BS_Y];
|
||||
for (int x = 0; x < MapConsts.SS_PER_BS_X; x++) {
|
||||
for (int y = 0; y < MapConsts.SS_PER_BS_Y; y++) {
|
||||
kwadraty[x][y] = new Kwadrat();
|
||||
ss.load(in);
|
||||
switch (ss.terrainType) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
break;
|
||||
case 4:
|
||||
break;
|
||||
case 2:
|
||||
kwadraty[x][y].stopienZabagnienia = 1.f;
|
||||
break;
|
||||
case 3:
|
||||
kwadraty[x][y].stopienZawodnienia = 1.f;
|
||||
break;
|
||||
case 5:
|
||||
kwadraty[x][y].stopienZabudowy = 1.f;
|
||||
break;
|
||||
case 6:
|
||||
kwadraty[x][y].stopienZalesienia = 1.f;
|
||||
break;
|
||||
}
|
||||
|
||||
kwadraty[x][y].wysokoscSrednia = ss.elevation;
|
||||
kwadraty[x][y].roznicaWzniesien = 0;
|
||||
|
||||
int bit_1 = 1;
|
||||
int hex = ss.majorRoads;
|
||||
for (int i = 0; i < kwadraty[x][y].jestDroga.length; i++) {
|
||||
// jest odcinek rowu na tym kierunku
|
||||
if ((hex & bit_1) != 0) {
|
||||
kwadraty[x][y].jestDroga[i] = true;
|
||||
}
|
||||
bit_1 <<= 1;
|
||||
}
|
||||
bit_1 = 1;
|
||||
hex = ss.rivers;
|
||||
for (int i = 0; i < kwadraty[x][y].jestPrzeszkodaWodna.length; i++) {
|
||||
// jest odcinek rowu na tym kierunku
|
||||
if ((hex & bit_1) != 0) {
|
||||
kwadraty[x][y].jestPrzeszkodaWodna[i] = true;
|
||||
}
|
||||
bit_1 <<= 1;
|
||||
}
|
||||
bit_1 = 1;
|
||||
hex = ss.drains;
|
||||
for (int i = 0; i < kwadraty[x][y].jestRow.length; i++) {
|
||||
// jest odcinek rowu na tym kierunku
|
||||
if ((hex & bit_1) != 0) {
|
||||
kwadraty[x][y].jestRow[i] = true;
|
||||
}
|
||||
bit_1 <<= 1;
|
||||
}
|
||||
kwadraty[x][y].bs = this;
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
logger.debug("Doczytano plik mapy: " + sb.toString());
|
||||
} catch (IOException e) {
|
||||
kwadraty = null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja generuje nowy plik z danymi na podstawie danych z pliku referencyjnego (kwadraty o rozm. 200m).
|
||||
* <p>Nowy plik moze byc z danymi w innej skali (kwadraty o rozmiarach: 100m lub 50m) i/lub innym formacie (binarny, tekstowy).
|
||||
*
|
||||
* @param dir katalog docelowy dla nowego pliku
|
||||
* @param dlmk rozmiar kwadratow generownych danych
|
||||
* @throws IOException generowany wyjątek
|
||||
*/
|
||||
public void saveNewFileWithNewScale_old_format(String dir, int dlmk,
|
||||
boolean zalesienie, boolean zawodnienie, boolean zabudowa, boolean zabagnienie,
|
||||
boolean wysokosc, boolean roznicaWzniesien, boolean drogi,
|
||||
boolean rzeki, boolean rowy) throws IOException {
|
||||
if (MapConsts.DL_MK != 200) {
|
||||
// operacja tylko dla danych terenowych o kwadratach 200m
|
||||
return;
|
||||
}
|
||||
int m = 1;
|
||||
String s = "";
|
||||
if (dlmk == 200) {
|
||||
m = 1;
|
||||
s = "200m/";
|
||||
} else if (dlmk == 100) {
|
||||
m = 2;
|
||||
s = "100m/";
|
||||
} else if (dlmk == 50) {
|
||||
m = 4;
|
||||
s = "50m/";
|
||||
} else if (dlmk == 25) {
|
||||
m = 8;
|
||||
s = "25m/";
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(100);
|
||||
sb.append(dir);
|
||||
sb.append(s);
|
||||
// Utworzenie katalogów, gdyby nie istniały.
|
||||
File directory = new File(sb.toString());
|
||||
directory.mkdirs();
|
||||
sb.append(fileName);
|
||||
sb.append(".bin");
|
||||
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(sb.toString()));
|
||||
for (int x = 0; x < MapConsts.SS_PER_BS_X; x++) {
|
||||
for (int y = 0; y < MapConsts.SS_PER_BS_Y; y++) {
|
||||
for (int k = 0; k < m * m; k++) {
|
||||
float f;
|
||||
int hex = 0;
|
||||
if (zalesienie) {
|
||||
f = kwadraty[x][y].stopienZalesienia * 100.0f;
|
||||
hex = (int) f;
|
||||
hex = (hex > 100) ? 100 : hex;
|
||||
hex = (hex < 0) ? 0 : hex;
|
||||
}
|
||||
out.writeByte(hex);
|
||||
hex = 0;
|
||||
if (zawodnienie) {
|
||||
f = kwadraty[x][y].stopienZawodnienia * 100.0f;
|
||||
hex = (int) f;
|
||||
hex = (hex > 100) ? 100 : hex;
|
||||
hex = (hex < 0) ? 0 : hex;
|
||||
}
|
||||
out.writeByte(hex);
|
||||
hex = 0;
|
||||
if (zabudowa) {
|
||||
f = kwadraty[x][y].stopienZabudowy * 100.0f;
|
||||
hex = (int) f;
|
||||
hex = (hex > 100) ? 100 : hex;
|
||||
hex = (hex < 0) ? 0 : hex;
|
||||
}
|
||||
out.writeByte(hex);
|
||||
hex = 0;
|
||||
if (zabagnienie) {
|
||||
f = kwadraty[x][y].stopienZabagnienia * 100.0f;
|
||||
hex = (int) f;
|
||||
hex = (hex > 100) ? 100 : hex;
|
||||
hex = (hex < 0) ? 0 : hex;
|
||||
}
|
||||
out.writeByte(hex);
|
||||
if (wysokosc) {
|
||||
out.writeInt(kwadraty[x][y].wysokoscSrednia);
|
||||
} else {
|
||||
out.writeInt(0);
|
||||
}
|
||||
if (roznicaWzniesien) {
|
||||
out.writeInt(kwadraty[x][y].roznicaWzniesien);
|
||||
} else {
|
||||
out.writeInt(0);
|
||||
}
|
||||
int bit_1;
|
||||
hex = 0;
|
||||
if (drogi) {
|
||||
bit_1 = 1;
|
||||
for (int i = 0; i < kwadraty[x][y].jestDroga.length; i++) {
|
||||
// jest odcinek drogi na tym kierunku
|
||||
if (kwadraty[x][y].jestDroga[i]) {
|
||||
hex |= bit_1;
|
||||
}
|
||||
bit_1 <<= 1;
|
||||
}
|
||||
}
|
||||
out.writeByte(hex);
|
||||
hex = 0;
|
||||
if (rzeki) {
|
||||
bit_1 = 1;
|
||||
for (int i = 0; i < kwadraty[x][y].jestPrzeszkodaWodna.length; i++) {
|
||||
// jest odcinek przeszkody wodnej na tym kierunku
|
||||
if (kwadraty[x][y].jestPrzeszkodaWodna[i]) {
|
||||
hex |= bit_1;
|
||||
}
|
||||
bit_1 <<= 1;
|
||||
}
|
||||
}
|
||||
out.writeByte(hex);
|
||||
hex = 0;
|
||||
if (rowy) {
|
||||
bit_1 = 1;
|
||||
for (int i = 0; i < kwadraty[x][y].jestRow.length; i++) {
|
||||
// jest odcinek rowu na tym kierunku
|
||||
if (kwadraty[x][y].jestRow[i]) {
|
||||
hex |= bit_1;
|
||||
}
|
||||
bit_1 <<= 1;
|
||||
}
|
||||
}
|
||||
out.writeByte(hex);
|
||||
}
|
||||
}
|
||||
}
|
||||
out.close();
|
||||
logger.debug("Zapisano nowy plik mapy: " + sb.toString() + " dla rozmiaru MK= " + dlmk);
|
||||
}
|
||||
|
||||
|
||||
public RightBigSquare() {
|
||||
}
|
||||
|
||||
// konstruktor ladujacy duzy kwadrat z pliku binarnego
|
||||
RightBigSquare(String FName) throws IOException {
|
||||
try {
|
||||
fileName = FName;
|
||||
StringBuilder sb = new StringBuilder(100);
|
||||
sb.append(MapConsts.KWADRATY_DIR);
|
||||
sb.append(fileName);
|
||||
sb.append(".bin");
|
||||
ObjectInputStream in = new ObjectInputStream(new FileInputStream(sb.toString()));
|
||||
kwadraty = new Kwadrat[MapConsts.SS_PER_BS_X][MapConsts.SS_PER_BS_Y];
|
||||
for (int x = 0; x < MapConsts.SS_PER_BS_X; x++) {
|
||||
for (int y = 0; y < MapConsts.SS_PER_BS_Y; y++) {
|
||||
kwadraty[x][y] = new Kwadrat();
|
||||
int hex = in.readByte();
|
||||
kwadraty[x][y].stopienZalesienia = (float) hex * (1.0f / 100.f);
|
||||
hex = in.readByte();
|
||||
kwadraty[x][y].stopienZawodnienia = (float) hex * (1.0f / 100.f);
|
||||
hex = in.readByte();
|
||||
kwadraty[x][y].stopienZabudowy = (float) hex * (1.0f / 100.f);
|
||||
hex = in.readByte();
|
||||
kwadraty[x][y].stopienZabagnienia = (float) hex * (1.0f / 100.f);
|
||||
kwadraty[x][y].wysokoscSrednia = in.readInt();
|
||||
kwadraty[x][y].roznicaWzniesien = in.readInt();
|
||||
int bit_1 = 1;
|
||||
hex = in.readByte();
|
||||
for (int i = 0; i < kwadraty[x][y].jestDroga.length; i++) {
|
||||
// jest odcinek rowu na tym kierunku
|
||||
if ((hex & bit_1) != 0) {
|
||||
kwadraty[x][y].jestDroga[i] = true;
|
||||
}
|
||||
bit_1 <<= 1;
|
||||
}
|
||||
bit_1 = 1;
|
||||
hex = in.readByte();
|
||||
for (int i = 0; i < kwadraty[x][y].jestPrzeszkodaWodna.length; i++) {
|
||||
// jest odcinek rowu na tym kierunku
|
||||
if ((hex & bit_1) != 0) {
|
||||
kwadraty[x][y].jestPrzeszkodaWodna[i] = true;
|
||||
}
|
||||
bit_1 <<= 1;
|
||||
}
|
||||
bit_1 = 1;
|
||||
hex = in.readByte();
|
||||
for (int i = 0; i < kwadraty[x][y].jestRow.length; i++) {
|
||||
// jest odcinek rowu na tym kierunku
|
||||
if ((hex & bit_1) != 0) {
|
||||
kwadraty[x][y].jestRow[i] = true;
|
||||
}
|
||||
bit_1 <<= 1;
|
||||
}
|
||||
kwadraty[x][y].bs = this;
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
logger.debug("Doczytano plik mapy: " + sb.toString());
|
||||
} catch (IOException e) {
|
||||
kwadraty = null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
void resetSquares(boolean zalesienie, boolean zawodnienie, boolean zabudowa, boolean zabagnienie,
|
||||
boolean wysokosc, boolean roznicaWzniesien, boolean drogi, boolean rzeki, boolean rowy) {
|
||||
for (int x = 0; x < MapConsts.SS_PER_BS_X; x++) {
|
||||
for (int y = 0; y < MapConsts.SS_PER_BS_Y; y++) {
|
||||
kwadraty[x][y].stopienZalesienia = (zalesienie) ? 0 : kwadraty[x][y].stopienZalesienia;
|
||||
kwadraty[x][y].stopienZawodnienia = (zawodnienie) ? 0 : kwadraty[x][y].stopienZawodnienia;
|
||||
kwadraty[x][y].stopienZabudowy = (zabudowa) ? 0 : kwadraty[x][y].stopienZabudowy;
|
||||
kwadraty[x][y].stopienZabagnienia = (zabagnienie) ? 0 : kwadraty[x][y].stopienZabagnienia;
|
||||
kwadraty[x][y].wysokoscSrednia = (wysokosc) ? 0 : kwadraty[x][y].wysokoscSrednia;
|
||||
kwadraty[x][y].roznicaWzniesien = (roznicaWzniesien) ? 0 : kwadraty[x][y].roznicaWzniesien;
|
||||
if (drogi) {
|
||||
for (int i = 0; i < kwadraty[x][y].jestDroga.length; i++) {
|
||||
kwadraty[x][y].jestDroga[i] = false;
|
||||
}
|
||||
}
|
||||
if (rzeki) {
|
||||
for (int i = 0; i < kwadraty[x][y].jestPrzeszkodaWodna.length; i++) {
|
||||
kwadraty[x][y].jestPrzeszkodaWodna[i] = false;
|
||||
}
|
||||
}
|
||||
if (rowy) {
|
||||
for (int i = 0; i < kwadraty[x][y].jestRow.length; i++) {
|
||||
kwadraty[x][y].jestRow[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RightBigSquare{" + this.fileName + '}';
|
||||
}
|
||||
}
|
||||
@@ -1,364 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pl.wat.ms4ds.common.EGeoDirection;
|
||||
|
||||
public class SiecDrogowa {
|
||||
|
||||
static final Logger logger = LoggerFactory.getLogger(SiecDrogowa.class);
|
||||
|
||||
ArrayList<LukDrogowy> luki;
|
||||
ArrayList<WezelDrogowy> wezly;
|
||||
static SiecDrogowa instancja;
|
||||
static String path;
|
||||
|
||||
Arkusz[][] arkusze;
|
||||
|
||||
public int liczbaZmian = 0;
|
||||
static final int LICZBA_ZMIAN = 50;
|
||||
|
||||
SiecDrogowa(String dataPath) {
|
||||
instancja = this;
|
||||
// File wd = new File(".");
|
||||
// PATH = wd.getPath();
|
||||
path = dataPath;
|
||||
this.odczytajWezly(path + "/nodes.txt");
|
||||
logger.debug("wczytano " + this.wezly.size() + " wezlow.");
|
||||
this.odczytajLuki(path + "/arcs.txt");
|
||||
logger.debug("wczytano " + this.luki.size() + " lukow.");
|
||||
stworzArkusze();
|
||||
|
||||
|
||||
// logger.debug("Liczba lukow w arkuszach:");
|
||||
// int ll = 0;
|
||||
// for (int i = 0; i < Arkusz.lx; i++) {
|
||||
// for (int j = 0; j < Arkusz.ly; j++) {
|
||||
// logger.debug(String.format("(%1$2d, %2$2d) - %3$6d", i, j, this.arkusze[i][j].luki.size()));
|
||||
// ll += this.arkusze[i][j].luki.size();
|
||||
// }
|
||||
// }
|
||||
// logger.debug("Sum. liczba lukow w arkuszach:" + ll);
|
||||
}
|
||||
|
||||
void odczytajWezly(String fname) {
|
||||
try {
|
||||
FileReader fis = new FileReader(fname);
|
||||
BufferedReader br = new BufferedReader(fis);
|
||||
if (br.ready()) {
|
||||
String line = br.readLine().trim();
|
||||
int licz = Integer.parseInt(line);
|
||||
this.wezly = new ArrayList<WezelDrogowy>(licz);// + 1000);
|
||||
while (null != (line = br.readLine())) {
|
||||
WezelDrogowy nowyWezel = new WezelDrogowy(line);
|
||||
nowyWezel.id = this.wezly.size(); //Indeksowanie od 0
|
||||
this.wezly.add(nowyWezel);
|
||||
}
|
||||
}
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
logger.warn("Brak pliku z wezlami: " + fname);
|
||||
}
|
||||
}
|
||||
|
||||
void odczytajLuki(String fname) {
|
||||
try {
|
||||
FileReader fis = new FileReader(fname);
|
||||
BufferedReader br = new BufferedReader(fis);
|
||||
if (br.ready()) {
|
||||
String line = br.readLine().trim();
|
||||
int licz = Integer.parseInt(line);
|
||||
this.luki = new ArrayList<LukDrogowy>(licz);// + 1000);
|
||||
while (null != (line = br.readLine())) {
|
||||
LukDrogowy nowyLuk = new LukDrogowy(line);
|
||||
nowyLuk.id = this.luki.size(); //Indeksowanie od 0
|
||||
this.luki.add(nowyLuk);
|
||||
}
|
||||
}
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
logger.warn("Brak pliku z lukami: " + fname);
|
||||
}
|
||||
}
|
||||
|
||||
void stworzArkusze() {
|
||||
// wyznaczenie wymiarow pola walki w malych kwadratach
|
||||
Arkusz.lx = MapConsts.getDX_REF() * MapConsts.BS_PER_DEG_X * MapConsts.SS_PER_BS_X;
|
||||
Arkusz.ly = MapConsts.getDY_REF() * MapConsts.BS_PER_DEG_Y * MapConsts.SS_PER_BS_Y;
|
||||
// wyznacznie liczby arkuszy mapy w obu wymiarach
|
||||
Arkusz.lx = Arkusz.lx / MapConsts.SS_PER_SHEET + 1;
|
||||
Arkusz.ly = Arkusz.ly / MapConsts.SS_PER_SHEET + 1;
|
||||
this.arkusze = new Arkusz[Arkusz.lx][Arkusz.ly];
|
||||
for (int i = 0; i < Arkusz.lx; i++) {
|
||||
for (int j = 0; j < Arkusz.ly; j++) {
|
||||
this.arkusze[i][j] = new Arkusz();
|
||||
}
|
||||
}
|
||||
// wspolrzedne arkusza mapy
|
||||
int xa, ya;
|
||||
for (int i = 0; i < this.wezly.size(); i++) {
|
||||
WezelDrogowy wezel = this.wezly.get(i);
|
||||
xa = wezel.idKw.x / MapConsts.SS_PER_SHEET;
|
||||
ya = wezel.idKw.y / MapConsts.SS_PER_SHEET;
|
||||
this.arkusze[xa][ya].wezly.add(wezel);
|
||||
}
|
||||
int xa2, ya2;
|
||||
for (int i = 0; i < this.luki.size(); i++) {
|
||||
LukDrogowy luk = this.luki.get(i);
|
||||
xa = luk.getWezly()[0].idKw.x / MapConsts.SS_PER_SHEET;
|
||||
ya = luk.getWezly()[0].idKw.y / MapConsts.SS_PER_SHEET;
|
||||
xa2 = luk.getWezly()[1].idKw.x / MapConsts.SS_PER_SHEET;
|
||||
ya2 = luk.getWezly()[1].idKw.y / MapConsts.SS_PER_SHEET;
|
||||
boolean b = Arkusz.mniejszeWspolrzedne(xa, ya, xa2, ya2);
|
||||
if (b) {
|
||||
this.arkusze[xa][ya].luki.add(luk);
|
||||
} else {
|
||||
this.arkusze[xa2][ya2].luki.add(luk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void utworzSiecDrogowa(){
|
||||
// if (null == instancja){
|
||||
// instancja = new SiecDrogowa(MapConsts.DROGI_DIR);
|
||||
// }
|
||||
}
|
||||
|
||||
public static LukDrogowy dodajLuk(WezelDrogowy wezel1, WezelDrogowy wezel2) {
|
||||
utworzSiecDrogowa();
|
||||
LukDrogowy nowyLuk = new LukDrogowy();
|
||||
nowyLuk.getWezly()[0] = wezel1;
|
||||
wezel1.luki.add(nowyLuk);
|
||||
nowyLuk.getWezly()[1] = wezel2;
|
||||
wezel2.luki.add(nowyLuk);
|
||||
instancja.luki.add(nowyLuk);
|
||||
nowyLuk.id = instancja.luki.size() - 1;
|
||||
return nowyLuk;
|
||||
}
|
||||
|
||||
public static WezelDrogowy dodajWezel(String wspUTM) {
|
||||
utworzSiecDrogowa();
|
||||
// TODO dodac weryfikacje poprawnosci wspolrzednych UTM
|
||||
WezelDrogowy nowyWezel = new WezelDrogowy();
|
||||
nowyWezel.setXms(Teren.zamienWspUtmNaWspXms(wspUTM.substring(0, 6)));
|
||||
nowyWezel.setYms(Teren.zamienWspUtmNaWspXms(wspUTM.substring(8, 14)));
|
||||
int x = GridCoord.zamienWspXmsNaIdKwadratuX(nowyWezel.getXms());
|
||||
int y = GridCoord.zamienWspYmsNaIdKwadratuY(nowyWezel.getYms());
|
||||
nowyWezel.idKw = new GridCoord(x, y);
|
||||
nowyWezel.luki = new ArrayList<LukDrogowy>();
|
||||
instancja.wezly.add(nowyWezel);
|
||||
nowyWezel.id = instancja.wezly.size() - 1;
|
||||
return nowyWezel;
|
||||
}
|
||||
|
||||
public static void usunLuk(LukDrogowy usuwanyLuk) {
|
||||
utworzSiecDrogowa();
|
||||
if (usuwanyLuk.id < 0 || usuwanyLuk.id >= instancja.luki.size()) {
|
||||
return;
|
||||
}
|
||||
int ostatniId = instancja.luki.size() - 1;
|
||||
LukDrogowy lukOstatni = instancja.luki.get(ostatniId);
|
||||
lukOstatni.id = usuwanyLuk.id;
|
||||
instancja.luki.set(lukOstatni.id, lukOstatni);
|
||||
instancja.luki.remove(ostatniId);
|
||||
// aktualizacja wezlow luku
|
||||
usuwanyLuk.getWezly()[0].luki.remove(usuwanyLuk);
|
||||
usuwanyLuk.getWezly()[1].luki.remove(usuwanyLuk);
|
||||
if (usuwanyLuk.getWezly()[0].luki.size() == 0) {
|
||||
usunWezel(usuwanyLuk.getWezly()[0]);
|
||||
}
|
||||
if (usuwanyLuk.getWezly()[1].luki.size() == 0) {
|
||||
usunWezel(usuwanyLuk.getWezly()[1]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void usunWezel(WezelDrogowy usuwanyWezel) {
|
||||
utworzSiecDrogowa();
|
||||
if (usuwanyWezel.id < 0 || usuwanyWezel.id >= instancja.wezly.size()) {
|
||||
return;
|
||||
}
|
||||
int ostatniId = instancja.wezly.size() - 1;
|
||||
WezelDrogowy wezelOstatni = instancja.wezly.get(ostatniId);
|
||||
wezelOstatni.id = usuwanyWezel.id;
|
||||
instancja.wezly.set(wezelOstatni.id, wezelOstatni);
|
||||
instancja.wezly.remove(ostatniId);
|
||||
}
|
||||
|
||||
public static void wpiszDrogiWKwadraty() {
|
||||
utworzSiecDrogowa();
|
||||
GridCoord[] kwadratyOdcinka;
|
||||
for (int i = 0; i < instancja.luki.size(); i++) {
|
||||
LukDrogowy luk = instancja.luki.get(i);
|
||||
GridCoord kw1 = luk.getWezly()[0].idKw;
|
||||
GridCoord kw2 = luk.getWezly()[1].idKw;
|
||||
kwadratyOdcinka = GeomUtils.kwadratyOdcinka(kw1, kw2);
|
||||
wpiszOdcinekDrogiWKwadraty(kwadratyOdcinka);
|
||||
}
|
||||
Teren.zapisBuforaMapyDoPliku();
|
||||
}
|
||||
|
||||
static void wpiszOdcinekDrogiWKwadraty(GridCoord[] kwadratyOdcinka) {
|
||||
if (null == kwadratyOdcinka) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < kwadratyOdcinka.length - 1; i++) {
|
||||
GridCoord idkw1 = kwadratyOdcinka[i];
|
||||
GridCoord idkw2 = kwadratyOdcinka[i + 1];
|
||||
EGeoDirection kier = GeomUtils.kierunekDlaSasiada(idkw1, idkw2);
|
||||
Kwadrat kw = Teren.getKwadrat(idkw1.x, idkw1.y);
|
||||
if (null != kw) {
|
||||
kw.setJestDroga(kier, true);
|
||||
}
|
||||
kw = Teren.getKwadrat(idkw2.x, idkw2.y);
|
||||
if (null != kw) {
|
||||
// wyznaczam kierunek przeciwny
|
||||
kier = kier.oppositeDirect();
|
||||
kw.setJestDroga(kier, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void aktualizujPliki(boolean wymuszony) throws IOException {
|
||||
if (wymuszony) {
|
||||
if (this.liczbaZmian == 0)
|
||||
// nie bylo modyfikacji od ostatniej zapisu
|
||||
return;
|
||||
this.liczbaZmian = -1;
|
||||
}
|
||||
this.liczbaZmian++;
|
||||
this.liczbaZmian %= LICZBA_ZMIAN;
|
||||
if (0 == this.liczbaZmian) {
|
||||
try {
|
||||
// zapisanie wezlow
|
||||
BufferedWriter bw = new BufferedWriter(new FileWriter(path + "\\nodes.txt"));
|
||||
String linia = Integer.toString(this.wezly.size());
|
||||
bw.write(linia, 0, linia.length());
|
||||
bw.newLine();
|
||||
String s;
|
||||
for (int i = 0; i < this.wezly.size(); i++) {
|
||||
WezelDrogowy wezel = this.wezly.get(i);
|
||||
s = String.format("%07d", wezel.id);
|
||||
linia = s;
|
||||
linia += " ";
|
||||
s = String.format("%010d", wezel.getXms());
|
||||
linia += s;
|
||||
linia += " ";
|
||||
s = String.format("%010d", wezel.getYms());
|
||||
linia += s;
|
||||
linia += " ";
|
||||
int most = 0;
|
||||
if (wezel.jestMostem) {
|
||||
most = 1;
|
||||
}
|
||||
s = String.format("%01d", most);
|
||||
linia += s;
|
||||
bw.write(linia, 0, linia.length());
|
||||
bw.newLine();
|
||||
}
|
||||
bw.close();
|
||||
logger.info("Zapisano plik wezlow sieci drogowej: " + path + "\\nodes.txt");
|
||||
} catch (IOException e) {
|
||||
logger.warn("Blad zapisu pliku wezlow sieci drogowej: " + path + "\\nodes.txt");
|
||||
}
|
||||
try {
|
||||
// zapisanie lukow
|
||||
BufferedWriter bw = new BufferedWriter(new FileWriter(path + "\\arcs.txt"));
|
||||
String linia = Integer.toString(this.luki.size());
|
||||
bw.write(linia, 0, linia.length());
|
||||
bw.newLine();
|
||||
String s;
|
||||
for (int i = 0; i < this.luki.size(); i++) {
|
||||
LukDrogowy luk = this.luki.get(i);
|
||||
s = String.format("%07d", luk.getWezly()[0].id);
|
||||
linia = s;
|
||||
linia += " ";
|
||||
s = String.format("%07d", luk.getWezly()[1].id);
|
||||
linia += s;
|
||||
linia += " ";
|
||||
s = String.format("%05d", luk.dlugosc);
|
||||
linia += s;
|
||||
linia += " ";
|
||||
s = String.format("%02d", luk.szerokosc);
|
||||
linia += s;
|
||||
linia += " ";
|
||||
int most = 0;
|
||||
if (luk.jestMostem) {
|
||||
most = 1;
|
||||
}
|
||||
s = String.format("%01d", most);
|
||||
linia += s;
|
||||
bw.write(linia, 0, linia.length());
|
||||
bw.newLine();
|
||||
}
|
||||
bw.close();
|
||||
logger.info("Zapisano plik lukow sieci drogowej: " + path + "\\arcs.txt");
|
||||
} catch (IOException e) {
|
||||
logger.warn("Blad zapisu pliku lukow sieci drogowej: " + path + "\\arcs.txt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// funkcja zwraca kolekcje lukow wewnatrz prostokata
|
||||
// zawartego miedzy lewym dolnym i prawym gornym punktem
|
||||
public static ArrayList<LukDrogowy> dajLukiWObszarze(String wspUtmLD, String wspUtmPG) {
|
||||
utworzSiecDrogowa();
|
||||
int xms = Teren.zamienWspUtmNaWspXms(wspUtmLD);
|
||||
int yms = Teren.zamienWspUtmNaWspYms(wspUtmLD);
|
||||
int xa_ld = GridCoord.zamienWspXmsNaIdKwadratuX(xms);
|
||||
xa_ld /= MapConsts.SS_PER_SHEET;
|
||||
int ya_ld = GridCoord.zamienWspYmsNaIdKwadratuY(yms);
|
||||
ya_ld /= MapConsts.SS_PER_SHEET;
|
||||
|
||||
xms = Teren.zamienWspUtmNaWspXms(wspUtmPG);
|
||||
yms = Teren.zamienWspUtmNaWspYms(wspUtmPG);
|
||||
int xa_pg = GridCoord.zamienWspXmsNaIdKwadratuX(xms);
|
||||
xa_pg /= MapConsts.SS_PER_SHEET;
|
||||
int ya_pg = GridCoord.zamienWspYmsNaIdKwadratuY(yms);
|
||||
ya_pg /= MapConsts.SS_PER_SHEET;
|
||||
|
||||
//if (xa_ld > xa_pg || ya_ld > ya_pg) {
|
||||
// return null;
|
||||
//}
|
||||
if (xa_ld > xa_pg){
|
||||
int tmp = xa_ld;
|
||||
xa_ld = xa_pg;
|
||||
xa_pg = tmp;
|
||||
}
|
||||
if (ya_ld > ya_pg){
|
||||
int tmp = ya_ld;
|
||||
ya_ld = ya_pg;
|
||||
ya_pg = tmp;
|
||||
}
|
||||
ArrayList<LukDrogowy> luki = new ArrayList<LukDrogowy>();
|
||||
// wspolrzedne arkusza mapy
|
||||
for (int xa = xa_ld; xa <= xa_pg; xa++) {
|
||||
for (int ya = ya_ld; ya <= ya_pg; ya++) {
|
||||
if (instancja.arkusze[xa][ya].luki != null) {
|
||||
luki.addAll(instancja.arkusze[xa][ya].luki);
|
||||
}
|
||||
}
|
||||
}
|
||||
return luki;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// GridCoord idKw = GridCoord.zamienWspUtmNaIdKwadratu("520101N0160202E");
|
||||
// String utm = GridCoord.zamienIdKwadratuNaWspUtm(idKw);
|
||||
// int xms = GridCoord.zamienIdKwadratuXNaWspXms(idKw.x);
|
||||
// int yms = GridCoord.zamienIdKwadratuYNaWspYms(idKw.y);
|
||||
// utm = Teren.zamienWspXmsYmsNaWspUtm(xms, yms);
|
||||
// float lon = GridCoord.zamienIdKwadratuXNaDlugoscGeo(idKw.x);
|
||||
// float lat = GridCoord.zamienIdKwadratuYNaSzerokoscGeo(idKw.y);
|
||||
// idKw.x = GridCoord.zamienDlugoscGeoNaIdKwadratuX(lon);
|
||||
// idKw.y = GridCoord.zamienSzerokoscGeoNaIdKwadratuY(lat);
|
||||
utworzSiecDrogowa();
|
||||
SiecDrogowa.wpiszDrogiWKwadraty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
public class SmallSquare {
|
||||
|
||||
|
||||
/**
|
||||
* The height above the level of the sea.
|
||||
*/
|
||||
short elevation;
|
||||
/**
|
||||
* 0 - BARE_GROUND
|
||||
* 1 - GRASS
|
||||
* 2 - SWAMP
|
||||
* 3 - WATER
|
||||
* 4 - SCRUB, BUSHES
|
||||
* 5 - BUILDINGS
|
||||
* 6 - FOREST
|
||||
*/
|
||||
byte terrainType;
|
||||
/**
|
||||
* Rodzaj drogi na danym kierunku.
|
||||
* 0 - no road, 1 - small roads, 2 - minor roads, 3 - major roads
|
||||
*/
|
||||
// byte[] roads;
|
||||
byte smallRoads;
|
||||
byte minorRoads;
|
||||
byte majorRoads;
|
||||
|
||||
/**
|
||||
* Rodzaj przeszkody wodnej na danym kierunku.
|
||||
* 0 - no watercourse, 1 - drain, ditch, 2 - canal, stream, 3 - river
|
||||
*/
|
||||
// byte[] waterWays;
|
||||
byte drains;
|
||||
byte streams;
|
||||
byte rivers;
|
||||
|
||||
|
||||
public void reset() {
|
||||
elevation = 0;
|
||||
terrainType = 0;
|
||||
smallRoads = 0;
|
||||
minorRoads = 0;
|
||||
majorRoads = 0;
|
||||
drains = 0;
|
||||
streams = 0;
|
||||
rivers = 0;
|
||||
}
|
||||
|
||||
public void save(ObjectOutputStream out) throws IOException {
|
||||
out.writeShort(elevation);
|
||||
out.writeByte(terrainType);
|
||||
out.writeByte(smallRoads);
|
||||
out.writeByte(minorRoads);
|
||||
out.writeByte(majorRoads);
|
||||
out.writeByte(drains);
|
||||
out.writeByte(streams);
|
||||
out.writeByte(rivers);
|
||||
}
|
||||
|
||||
public void load(ObjectInputStream in) throws IOException {
|
||||
elevation = in.readShort();
|
||||
terrainType = in.readByte();
|
||||
smallRoads = in.readByte();
|
||||
minorRoads = in.readByte();
|
||||
majorRoads = in.readByte();
|
||||
drains = in.readByte();
|
||||
streams = in.readByte();
|
||||
rivers = in.readByte();
|
||||
}
|
||||
|
||||
public SmallSquare(short elevation, byte terrainType) {
|
||||
this.elevation = elevation;
|
||||
this.terrainType = terrainType;
|
||||
}
|
||||
|
||||
public SmallSquare() {
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,38 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje;
|
||||
|
||||
public enum TerrainType {
|
||||
BARE_GROUND(0),
|
||||
GRASS(1),
|
||||
SWAMP(2),
|
||||
WATER(3),
|
||||
SCRUB_BUSHES(4),
|
||||
BUILDINGS(5),
|
||||
FOREST(6);
|
||||
|
||||
static {
|
||||
BARE_GROUND.height = 0;
|
||||
BARE_GROUND.passability = true;
|
||||
|
||||
}
|
||||
|
||||
public int getHeight(byte terrainType) {
|
||||
return height;
|
||||
}
|
||||
|
||||
public final int ID;
|
||||
private int height;
|
||||
/**
|
||||
* Zdolność przekraczania
|
||||
*/
|
||||
private boolean passability;
|
||||
|
||||
TerrainType(int id) {
|
||||
this.ID = id;
|
||||
}
|
||||
|
||||
TerrainType(int id, int height, boolean passability) {
|
||||
this.ID = id;
|
||||
this.height = height;
|
||||
this.passability = passability;
|
||||
}
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje;
|
||||
|
||||
import pl.wat.ms4ds.common.EGeoDirection;
|
||||
import pl.wat.ms4ds.common.ERodzajPodwozia;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class TerrainUtils {
|
||||
|
||||
// ========================================================================
|
||||
|
||||
public static float widocznoscOptyczna(float wysokoscObserwatora, float wysokoscCelu,
|
||||
int x1, int y1, int x2, int y2) {
|
||||
if ((x1 == x2) && (y1 == y2)) {
|
||||
return 1.0f;
|
||||
}
|
||||
Kwadrat kwDo = Teren.getKwadrat(x1, y1);
|
||||
Kwadrat kwOd = Teren.getKwadrat(x2, y2);
|
||||
if (kwDo == Kwadrat.EMPTY_SQUARE || kwOd == Kwadrat.EMPTY_SQUARE) {
|
||||
return 0.0f;
|
||||
}
|
||||
// roznica wysokosci miedzy skrajnymi kwadratami
|
||||
float roznicaWysokosci = kwDo.wysokoscSrednia + wysokoscCelu - kwOd.wysokoscSrednia - wysokoscObserwatora;
|
||||
float wysBezwzgObserwatora;
|
||||
if (roznicaWysokosci < 0) {
|
||||
// sprawdzanie kwOd -> kwDo
|
||||
int swap = x1;
|
||||
x1 = x2;
|
||||
x2 = swap;
|
||||
swap = y1;
|
||||
y1 = y2;
|
||||
y2 = swap;
|
||||
roznicaWysokosci = -roznicaWysokosci;
|
||||
wysBezwzgObserwatora = kwDo.wysokoscSrednia + wysokoscCelu;
|
||||
} else {
|
||||
wysBezwzgObserwatora = kwOd.wysokoscSrednia + wysokoscObserwatora;
|
||||
}
|
||||
GridCoord[] kwadratyNaOdcinku = Bresenham.generateSegment(x1, y1, x2, y2);
|
||||
float dlugoscOdcinka = GridCoord.odleglosc(x1, y1, x2, y2);
|
||||
float tangAlfa0 = roznicaWysokosci / dlugoscOdcinka;
|
||||
|
||||
float dh_max = 0;
|
||||
for (int i = 1; i < kwadratyNaOdcinku.length - 1; i++) {
|
||||
// badanie wewnetrznych kwadratow nalezacych do odcinka,
|
||||
// czy nie sa powyzej linii widocznosci dla kwadratow skrajnych
|
||||
float wysokoscPrzeszkody = 0.0f;
|
||||
Kwadrat kwAkt = Teren.getKwadrat(kwadratyNaOdcinku[i].x, kwadratyNaOdcinku[i].y);
|
||||
if (kwAkt.stopienZalesienia > 0.5f) {
|
||||
wysokoscPrzeszkody = 10.0f;
|
||||
}
|
||||
if (kwAkt.stopienZabudowy > 0.5f) {
|
||||
wysokoscPrzeszkody = 10.0f;
|
||||
}
|
||||
// wyznaczenie roznicy wysokosci kwadratu badanego i docelowego
|
||||
// uwzgledniajac wysokosc obserwatora oraz wysokosc przeszkody
|
||||
float roznWysAkt = kwAkt.wysokoscSrednia + wysokoscPrzeszkody - wysBezwzgObserwatora;
|
||||
if (dh_max >= roznWysAkt) {
|
||||
continue;
|
||||
}
|
||||
|
||||
float odleg = GridCoord.odleglosc(kwadratyNaOdcinku[i].x, kwadratyNaOdcinku[i].y, x1, y1);
|
||||
// float tangAlfa = roznWysAkt / odleg;
|
||||
// if (tangAlfa0 < tangAlfa) {
|
||||
if (tangAlfa0 * odleg < roznWysAkt) {
|
||||
// wysokosc aktualnie badanego kwadratu jest powyzej/ponizej
|
||||
// linii poprowadzonej z kwadratu startowego do docelowego (z uwzglednieniem wysokosci obserwatora i celu)
|
||||
// odpowiednio dla katow dodatnich/ujemnych
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
dh_max = roznWysAkt;
|
||||
}
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
public static float widocznoscOptyczna(int x, int y) {
|
||||
Kwadrat kw = Teren.getKwadrat(x, y);
|
||||
if (kw.stopienZabudowy > 0.25f || kw.stopienZalesienia > 0.25f) {
|
||||
return 0.3f;
|
||||
}
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
public static float widocznoscOptyczna2(float wysokoscObserwatora, float wysokoscCelu,
|
||||
int x1, int y1, int x2, int y2) {
|
||||
if ((x1 == x2) && (y1 == y2)) {
|
||||
return 1.0f;
|
||||
}
|
||||
Kwadrat kwDo = Teren.getKwadrat(x1, y1);
|
||||
Kwadrat kwOd = Teren.getKwadrat(x2, y2);
|
||||
if (kwDo == Kwadrat.EMPTY_SQUARE || kwOd == Kwadrat.EMPTY_SQUARE) {
|
||||
return 0.0f;
|
||||
}
|
||||
// roznica wysokosci miedzy skrajnymi kwadratami
|
||||
float roznicaWysokosci = kwDo.wysokoscSrednia + wysokoscCelu - kwOd.wysokoscSrednia - wysokoscObserwatora;
|
||||
GridCoord[] kwadratyNaOdcinku = GeomUtils.kwadratyOdcinka(x1, y1, x2, y2);
|
||||
float dlugoscOdcinka = GridCoord.odleglosc(x1, y1, x2, y2);
|
||||
float tangAlfa0 = roznicaWysokosci / dlugoscOdcinka;
|
||||
for (int i = 1; i < kwadratyNaOdcinku.length - 1; i++) {
|
||||
// badanie wewnetrznych kwadratow nalezacych do odcinka,
|
||||
// czy nie sa powyzej linii widocznosci dla kwadratow skrajnych
|
||||
float wysokoscPrzeszkody = 0.0f;
|
||||
Kwadrat kwAkt = Teren.getKwadrat(kwadratyNaOdcinku[i].x, kwadratyNaOdcinku[i].y);
|
||||
if (kwAkt.stopienZalesienia > 0.5f) {
|
||||
wysokoscPrzeszkody = 10.0f;
|
||||
}
|
||||
if (kwAkt.stopienZabudowy > 0.5f) {
|
||||
wysokoscPrzeszkody = 10.0f;
|
||||
}
|
||||
// wyznaczenie roznicy wysokosci kwadratu badanego i docelowego
|
||||
// uwzgledniajac wysokosc obserwatora oraz wysokosc przeszkody
|
||||
float roznWysAkt = kwAkt.wysokoscSrednia + wysokoscPrzeszkody - kwOd.wysokoscSrednia - wysokoscObserwatora;
|
||||
float odleg = GridCoord.odleglosc(kwadratyNaOdcinku[i].x, kwadratyNaOdcinku[i].y, x1, y1);
|
||||
float tangAlfa = roznWysAkt / odleg;
|
||||
if (tangAlfa0 < tangAlfa) {
|
||||
// wysokosc aktualnie badanego kwadratu jest powyzej/ponizej
|
||||
// linii poprowadzonej z kwadratu startowego do docelowego (z uwzglednieniem wysokosci obserwatora i celu)
|
||||
// odpowiednio dla katow dodatnich/ujemnych
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
if (kwDo.stopienZabudowy > 0.25f || kwDo.stopienZalesienia > 0.25f) {
|
||||
return 0.3f;
|
||||
}
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
public static float sredStopienWidoczOptycznej(float wysokoscObserwatora, float wysokoscCelu,
|
||||
GridCoord kwadratOd, int dl1, GridCoord kwadratDo, int dl2) {
|
||||
float stop = 0.0f;
|
||||
for (int x1 = kwadratOd.x; x1 < kwadratOd.x + dl1; x1++)
|
||||
for (int y1 = kwadratOd.y; y1 < kwadratOd.y + dl1; y1++)
|
||||
for (int x2 = kwadratDo.x; x2 < kwadratDo.x + dl2; x2++)
|
||||
for (int y2 = kwadratDo.y; y2 < kwadratDo.y + dl2; y2++)
|
||||
stop += widocznoscOptyczna(wysokoscObserwatora, wysokoscCelu, x1, y1, x2, y2);
|
||||
|
||||
stop /= (dl1 * dl1 * dl2 * dl2);
|
||||
return stop;
|
||||
}
|
||||
|
||||
public static float sredStopienWidoczOptycznej2(float wysokoscObserwatora, float wysokoscCelu,
|
||||
GridCoord kwadratOd, int dl1, GridCoord kwadratDo, int dl2) {
|
||||
float stop = 0.0f;
|
||||
for (int x1 = kwadratOd.x; x1 < kwadratOd.x + dl1; x1++)
|
||||
for (int y1 = kwadratOd.y; y1 < kwadratOd.y + dl1; y1++)
|
||||
for (int x2 = kwadratDo.x; x2 < kwadratDo.x + dl2; x2++)
|
||||
for (int y2 = kwadratDo.y; y2 < kwadratDo.y + dl2; y2++)
|
||||
stop += widocznoscOptyczna2(wysokoscObserwatora, wysokoscCelu, x1, y1, x2, y2);
|
||||
|
||||
stop /= (dl1 * dl1 * dl2 * dl2);
|
||||
return stop;
|
||||
}
|
||||
|
||||
public static float stopienPrzejezdnosciAktualOdcinkaDrogi(ArrayList<GridCoord> droga, int pozycja,
|
||||
EGeoDirection zkierunku, ERodzajPodwozia podwozie) {
|
||||
if ((droga == null) || (droga.size() == 0) || (pozycja < 0) || (pozycja >= droga.size() - 1)) {
|
||||
return 0.0f;
|
||||
}
|
||||
GridCoord idKw1 = droga.get(pozycja);
|
||||
GridCoord idKw2 = droga.get(pozycja + 1);
|
||||
return (float) Teren.getStopienPrzejezdnosci(idKw1.x, idKw1.y, idKw2.x, idKw2.y, zkierunku, podwozie);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class WezelDrogowy {
|
||||
int id = -1;
|
||||
private int xms = 0;
|
||||
private int yms = 0;
|
||||
boolean jestMostem = false;
|
||||
GridCoord idKw;
|
||||
ArrayList<LukDrogowy> luki = new ArrayList<LukDrogowy>();
|
||||
|
||||
WezelDrogowy() {
|
||||
}
|
||||
|
||||
WezelDrogowy(String opis) {
|
||||
if (null == opis || opis.length() == 0){
|
||||
SiecDrogowa.logger.debug("Pusty ciag opis w konstruktorze Wezla Drogowego.");
|
||||
return;
|
||||
}
|
||||
StringTokenizer st = new StringTokenizer(opis, " \t");
|
||||
String[] tokenTable = new String[st.countTokens()];
|
||||
for (int i = 0; st.hasMoreTokens(); i++) {
|
||||
tokenTable[i] = st.nextToken();
|
||||
}
|
||||
if (tokenTable.length == 3) {
|
||||
try {
|
||||
this.xms = Integer.parseInt(tokenTable[0]);
|
||||
//TODO KONSULTACJA WYWALAMY/ ODKOMENTOWUJEMY
|
||||
// //Zabezpieczenie przed zaokraglaniem na krawedziach mapy
|
||||
// if (this.xms < MapConsts.X_REF_MS)
|
||||
// this.xms = MapConsts.X_REF_MS;
|
||||
// if (this.xms > MapConsts.X_REF_MS + MapConsts.DX_REF_MS)
|
||||
// this.xms = MapConsts.X_REF_MS + MapConsts.DX_REF_MS;
|
||||
} catch (NumberFormatException e) {
|
||||
SiecDrogowa.logger.warn("Bledne dane w pliku z wezlami [Wezel: " + this.id + " X].");
|
||||
}
|
||||
try {
|
||||
this.yms = Integer.parseInt(tokenTable[1]);
|
||||
// //Zabezpieczenie przed zaokraglaniem na krawedziach mapy
|
||||
// if (this.yms < MapConsts.Y_REF_MS)
|
||||
// this.yms = MapConsts.Y_REF_MS;
|
||||
// if (this.yms > MapConsts.Y_REF_MS + MapConsts.DY_REF_MS)
|
||||
// this.yms = MapConsts.Y_REF_MS + MapConsts.DY_REF_MS;
|
||||
} catch (NumberFormatException e) {
|
||||
SiecDrogowa.logger.warn("Bledne dane w pliku z wezlami [Wezel: " + this.id + " Y].");
|
||||
}
|
||||
try {
|
||||
this.jestMostem = Integer.parseInt(tokenTable[2]) != 0 ? true : false;
|
||||
} catch (NumberFormatException e) {
|
||||
SiecDrogowa.logger.warn("Bledne dane w pliku z wezlami [Wezel: " + this.id + " czyJestMost].");
|
||||
}
|
||||
int x = GridCoord.zamienWspXmsNaIdKwadratuX(getXms());
|
||||
int y = GridCoord.zamienWspYmsNaIdKwadratuY(getYms());
|
||||
this.idKw = new GridCoord(x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
SiecDrogowa.logger.warn("Bledne ilosc tokenow w linii [" + opis + "].");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isJestMostem() {
|
||||
return jestMostem;
|
||||
}
|
||||
|
||||
public void setJestMostem(boolean jestMostem) {
|
||||
this.jestMostem = jestMostem;
|
||||
}
|
||||
|
||||
public GridCoord getIdKw() {
|
||||
return idKw;
|
||||
}
|
||||
|
||||
public void setIdKw(GridCoord idKw) {
|
||||
this.idKw = new GridCoord(idKw);
|
||||
}
|
||||
|
||||
public void setXms(int xms) {
|
||||
this.xms = xms;
|
||||
}
|
||||
|
||||
public int getXms() {
|
||||
return xms;
|
||||
}
|
||||
|
||||
public void setYms(int yms) {
|
||||
this.yms = yms;
|
||||
}
|
||||
|
||||
public int getYms() {
|
||||
return yms;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,485 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
|
||||
import pl.wat.ms4ds.terenfunkcje.GeoCoord;
|
||||
import pl.wat.ms4ds.terenfunkcje.GridCoord;
|
||||
import pl.wat.ms4ds.terenfunkcje.Kwadrat;
|
||||
import pl.wat.ms4ds.terenfunkcje.Teren;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* Odczyt danych wysokościowych z numerycznego modelu terenu (NMT_100).
|
||||
* <p>
|
||||
* Kod źródłowy funkcji do transformacji współrzędnych elipsoidalnych na płaskie odwzorowań kartograficznych UTM, 1992, 2000
|
||||
*/
|
||||
public class CoordUtils {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CoordUtils.class);
|
||||
|
||||
static String dataDir = "d:/Workspace2/dane_wysok/";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
HashMap<GridCoord, DaneWysok> daneWysokHashMap = new HashMap<GridCoord, DaneWysok>();
|
||||
if (args.length > 0) {
|
||||
dataDir = args[0];
|
||||
}
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
String nmt_fn = args[i];
|
||||
daneWysokHashMap.clear();
|
||||
readData(nmt_fn, daneWysokHashMap);
|
||||
for (DaneWysok daneWysok : daneWysokHashMap.values()) {
|
||||
Kwadrat kw = Teren.getKwadrat(daneWysok.idKw.x, daneWysok.idKw.y);
|
||||
kw.setWysokoscSrednia((int) (daneWysok.suma / daneWysok.licz + 0.5));
|
||||
}
|
||||
logger.debug("Poczatek zapisu danych dla regionu " + nmt_fn + " >> " + i + "/" + (args.length - 1));
|
||||
Teren.zapisBuforaMapyDoPliku();
|
||||
logger.debug("Koniec zapisu danych dla regionu " + nmt_fn + " >> " + i + "/" + (args.length - 1));
|
||||
Teren.reset();
|
||||
}
|
||||
logger.debug("Start: poprawy danych wysokosciowych");
|
||||
Teren.poprawDaneWysokosciowe();
|
||||
logger.debug("Koniec: poprawy danych wysokosciowych");
|
||||
|
||||
|
||||
// GeoCoord latLon = new GeoCoord();
|
||||
// PUWGCoord puwgCoord = new PUWGCoord();
|
||||
// puwgCoord.easting = 542800.0;
|
||||
// puwgCoord.northing = 732200.0;
|
||||
// puwgCoord.proj = 1;
|
||||
//
|
||||
// convertPuwgToLatLon(puwgCoord, latLon);
|
||||
// logger.debug("latLon= (" + latLon.lat + ", " + latLon.lon + ")");
|
||||
// puwgCoord.easting = 718500.0;
|
||||
// puwgCoord.northing = 663500.0;
|
||||
// convertPuwgToLatLon(puwgCoord, latLon);
|
||||
// logger.debug("latLon= (" + latLon.lat + ", " + latLon.lon + ")");
|
||||
|
||||
}
|
||||
|
||||
private static void readData(String fileName, HashMap<GridCoord, DaneWysok> daneWysokHashMap) throws IOException {
|
||||
try {
|
||||
StringBuilder sb = new StringBuilder(100);
|
||||
sb.append(dataDir);
|
||||
sb.append(fileName);
|
||||
sb.append(".txt");
|
||||
FileReader fis = new FileReader(sb.toString());
|
||||
// PUWG 1992
|
||||
PUWGCoord puwgCoord = new PUWGCoord();
|
||||
GeoCoord latLon = new GeoCoord();
|
||||
double wysokosc = 0.0;
|
||||
StringTokenizer st = null;
|
||||
String line = null;
|
||||
BufferedReader br = new BufferedReader(fis);
|
||||
if (br.ready()) {
|
||||
line = br.readLine();
|
||||
int m = 1;
|
||||
while (line != null) {
|
||||
st = new StringTokenizer(line, " ");
|
||||
if (st.countTokens() != 3) {
|
||||
continue;
|
||||
}
|
||||
String[] tokTable = new String[st.countTokens()];
|
||||
for (int i = 0; st.hasMoreTokens(); i++) {
|
||||
tokTable[i] = st.nextToken();
|
||||
}
|
||||
try {
|
||||
puwgCoord.easting = Double.parseDouble(tokTable[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
logger.warn("Bledne dane w pliku: " + fileName);
|
||||
}
|
||||
try {
|
||||
puwgCoord.northing = Double.parseDouble(tokTable[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
logger.warn("Bledne dane w pliku: " + fileName);
|
||||
}
|
||||
try {
|
||||
wysokosc = Double.parseDouble(tokTable[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
logger.warn("Bledne dane w pliku: " + fileName);
|
||||
}
|
||||
convertPuwgToLatLon(puwgCoord, latLon);
|
||||
GridCoord idKw = new GridCoord(latLon.lon, latLon.lat);
|
||||
DaneWysok daneWysok = daneWysokHashMap.get(idKw);
|
||||
if (daneWysok == null) {
|
||||
daneWysok = new DaneWysok(idKw, wysokosc, 1);
|
||||
daneWysokHashMap.put(idKw, daneWysok);
|
||||
} else {
|
||||
daneWysok.suma += wysokosc;
|
||||
daneWysok.licz++;
|
||||
}
|
||||
line = br.readLine();
|
||||
if (m++ % 100000 == 0) {
|
||||
System.out.print('-');
|
||||
}
|
||||
}
|
||||
}
|
||||
br.close();
|
||||
System.out.println();
|
||||
logger.debug("Koniec odczytu pliku: " + fileName);
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private static final double fe = 500000.0;
|
||||
|
||||
//Deklaracja tablicy stref rownoleżnikowych
|
||||
private static final char[] cArray = {'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R',
|
||||
'S', 'T', 'U', 'V', 'W', 'X'};
|
||||
// private static final String LITERALS = "CDEFGHJKLMNPQRSTUVWX";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//Funkcje pomocnicze
|
||||
|
||||
/// /////////////////////////////////////////////////////////////////////////////
|
||||
//------------------------------------------------------------------------------
|
||||
static double calculateESquared(double a, double b) {
|
||||
a *= a;
|
||||
b *= b;
|
||||
return (a - b) / a;
|
||||
// return ((a * a) - (b * b)) / (a * a);
|
||||
}
|
||||
|
||||
static double calculateE2Squared(double a, double b) {
|
||||
a *= a;
|
||||
b *= b;
|
||||
return (a - b) / b;
|
||||
// return ((a * a) - (b * b)) / (b * b);
|
||||
}
|
||||
|
||||
static double denom(double es, double sphi) {
|
||||
double sinSphi = Math.sin(sphi);
|
||||
return Math.sqrt(1.0 - es * (sinSphi * sinSphi));
|
||||
}
|
||||
|
||||
static double sphsr(double a, double es, double sphi) {
|
||||
double dn = denom(es, sphi);
|
||||
return a * (1.0 - es) / (dn * dn * dn);
|
||||
}
|
||||
|
||||
static double sphsn(double a, double es, double sphi) {
|
||||
double sinSphi = Math.sin(sphi);
|
||||
return a / Math.sqrt(1.0 - es * (sinSphi * sinSphi));
|
||||
}
|
||||
|
||||
static double sphtmd(double ap, double bp, double cp, double dp, double ep, double sphi) {
|
||||
return (ap * sphi) - (bp * Math.sin(2.0 * sphi)) + (cp * Math.sin(4.0 * sphi))
|
||||
- (dp * Math.sin(6.0 * sphi)) + (ep * Math.sin(8.0 * sphi));
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Funkcja służy do konwersji współrzednych elipsoidalnych B, L (lat/lon) WGS84 na płaskie X-northing, Y-easting odwzorowania kartograficznego UTM
|
||||
//=======================================================================
|
||||
// Argumenty wejściowe i wyjściowe:
|
||||
// --------------------------------
|
||||
// int& utmXZone: nr strefy UTM wg. podziału południkowego (zwracane numery od 1 do 60, każda strefa ma sześć stopni)
|
||||
// char& utmYZone: nr strefy wg. podziału równoleżnikowego (zwracane wartości: CDEFGHJKLMNPQRSTUVWX)
|
||||
// double& easting: współrzędna Y UTM, w metrach po konwersji [metry]
|
||||
// double& northing: współrzędna X UTM, w metrach po konwersji [metry]
|
||||
// double lat, double lon: współrzędne lat/lon do konwersji [stopnie]
|
||||
//=======================================================================
|
||||
|
||||
/**
|
||||
*
|
||||
* @param lat współrzędna lat (szerokość geograficzna) do konwersji [stopnie] (układ WGS84)
|
||||
* @param lon współrzędna lon (długość geograficzna) do konwersji [stopnie] (układ WGS84)
|
||||
* @param utmCoord współrzędne UTM
|
||||
*/
|
||||
public static void convertLatLonToUtm(double lat, double lon, UTMCoord utmCoord) {
|
||||
// Współczynnik zniekształcenia skali w południku osiowym
|
||||
double tmd;
|
||||
double nfn;
|
||||
if (lon <= 0.0) {
|
||||
utmCoord.xZone = 30 + (int) (lon / 6.0);
|
||||
} else {
|
||||
utmCoord.xZone = 31 + (int) (lon / 6.0);
|
||||
}
|
||||
if (lat < 84.0 && lat >= 72.0) {
|
||||
// Specjalne zatrzymanie: strefa X ma 12 stopni od północy do południa, nie 8
|
||||
utmCoord.yZone = cArray[19];
|
||||
} else {
|
||||
utmCoord.yZone = cArray[(int) ((lat + 80.0) / 8.0)];
|
||||
}
|
||||
if (lat >= 84.0 || lat < -80.0) {
|
||||
// Błędna wartość szerokości geograficznej (zwracany znak gwiazdki)
|
||||
utmCoord.yZone = '*';
|
||||
}
|
||||
double latRad = lat * DEG_2_RAD;
|
||||
double lonRad = lon * DEG_2_RAD;
|
||||
double olam = (utmCoord.xZone * 6 - 183) * DEG_2_RAD;
|
||||
double dlam = lonRad - olam;
|
||||
double s = Math.sin(latRad);
|
||||
double c = Math.cos(latRad);
|
||||
double t = s / c;
|
||||
double eta = e2Squared * (c * c);
|
||||
double sn = sphsn(a, eSquared, latRad);
|
||||
tmd = sphtmd(ap, bp, cp, dp, ep, latRad);
|
||||
double t1, t2, t3, t4, t5, t6, t7, t8, t9;
|
||||
t1 = tmd * ok;
|
||||
t2 = sn * s * c * ok / 2.0;
|
||||
t3 = sn * s * (c * c * c) * ok * (5.0 - (t * t) + 9.0 * eta + 4.0 * (eta * eta)) / 24.0;
|
||||
t4 = sn * s * (c * c * c * c * c) * ok * (61.0 - 58.0 * (t * t) + (t * t * t * t) + 270.0 * eta - 330.0 * (t * t) * eta + 445.0 * (eta * eta) + 324.0 * (eta * eta * eta) - 680.0 * (t * t) * (eta * eta) + 88.0 * (eta * eta * eta * eta) - 600.0 * (t * t) * (eta * eta * eta) - 192.0 * (t * t) * (eta * eta * eta * eta)) / 720.0;
|
||||
t5 = sn * s * (c * c * c * c * c * c * c) * ok * (1385.0 - 3111.0 * (t * t) + 543.0 * (t * t * t * t) - (t * t * t * t * t * t)) / 40320.0;
|
||||
if (latRad < 0.0) nfn = 10000000.0;
|
||||
else nfn = 0;
|
||||
utmCoord.northing = nfn + t1 + (dlam * dlam) * t2 + (dlam * dlam * dlam * dlam) * t3 + (dlam * dlam * dlam * dlam * dlam * dlam) * t4 + (dlam * dlam * dlam * dlam * dlam * dlam * dlam * dlam) * t5;
|
||||
t6 = sn * c * ok;
|
||||
t7 = sn * (c * c * c) * ok * (1.0 - (t * t) + eta) / 6.0;
|
||||
t8 = sn * (c * c * c * c * c) * ok * (5.0 - 18.0 * (t * t) + (t * t * t * t) + 14.0 * eta - 58.0 * (t * t) * eta + 13.0 * (eta * eta) + 4.0 * (eta * eta * eta) - 64.0 * (t * t) * (eta * eta) - 24.0 * (t * t) * (eta * eta * eta)) / 120.0;
|
||||
t9 = sn * (c * c * c * c * c * c * c) * ok * (61.0 - 479.0 * (t * t) + 179.0 * (t * t * t * t) - (t * t * t * t * t * t)) / 5040.0;
|
||||
utmCoord.easting = fe + dlam * t6 + (dlam * dlam * dlam) * t7 + (dlam * dlam * dlam * dlam * dlam) * t8 + (dlam * dlam * dlam * dlam * dlam * dlam * dlam) * t9;
|
||||
if (utmCoord.northing >= 9999999.0) utmCoord.northing = 9999999.0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Funkcja służy do konwersji współrzednych elipsoidalnych WGS84 B, L (lat/lon) na płaskie X-northing, Y-easting odwzorowania kartograficznego 1992 i 2000
|
||||
//=======================================================================
|
||||
// --------------------------------
|
||||
// int& utmXZone: nr strefy UTM wg. podziału południkowego (zwracane numery od 1 do 60, każda strefa ma sześć stopni)
|
||||
// char& utmYZone: nr strefy wg. podziału równoleżnikowego (zwracane wartości: CDEFGHJKLMNPQRSTUVWX)
|
||||
// double& easting: współrzędna Y UTM, w metrach po konwersji [metry]
|
||||
// double& northing: współrzędna X UTM, w metrach po konwersji [metry]
|
||||
// double lat, double lon: współrzędne lat/lon do konwersji [stopnie]
|
||||
// int proj: odwzorowanie kartograficzne (proj = 1 odpowiada odwzorowaniu 1992, natomiast każda inna odwzorowaniu 2000)
|
||||
//=======================================================================
|
||||
public static void convertLatLonToPUWG(PUWGCoord puwgCoord, double lat, double lon) {
|
||||
// Współczynnik zniekształcenia skli mapy w południku osiowym dla odwzorowania kartograficznego 2000
|
||||
//Współczynnik zniekształcenia skli mapy w południku osiowym dla odwzorowania kartograficznego 1992
|
||||
double ok_new = (puwgCoord.proj != 1) ? 0.999923 : 0.9993;
|
||||
double olam = 0.0;
|
||||
double tmd;
|
||||
double nfn;
|
||||
double strf = 0.0;
|
||||
if (lon < 13.5 || lon > 25.5) {
|
||||
//Błędna wartość długości geograficznej (zwracana wartość 99999999999999)
|
||||
puwgCoord.easting = 999999999999999.0;
|
||||
puwgCoord.northing = 999999999999999.0;
|
||||
return;
|
||||
} else {
|
||||
if (puwgCoord.proj == 1) {
|
||||
olam = 19.0 * DEG_2_RAD;
|
||||
strf = 0.0;
|
||||
nfn = -5300000.0;
|
||||
} else {
|
||||
nfn = 0;
|
||||
if (lon >= 13.5 && lon < 16.5) {
|
||||
olam = 15.0 * DEG_2_RAD;
|
||||
strf = 5000000.0;
|
||||
}
|
||||
|
||||
if (lon >= 16.5 && lon < 19.5) {
|
||||
olam = 18.0 * DEG_2_RAD;
|
||||
strf = 6000000.0;
|
||||
}
|
||||
|
||||
if (lon >= 19.5 && lon < 22.5) {
|
||||
olam = 21.0 * DEG_2_RAD;
|
||||
strf = 7000000.0;
|
||||
}
|
||||
|
||||
if (lon >= 22.5 && lon < 25.5) {
|
||||
olam = 24.0 * DEG_2_RAD;
|
||||
strf = 8000000.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
double latRad = lat * DEG_2_RAD;
|
||||
double lonRad = lon * DEG_2_RAD;
|
||||
double dlam = lonRad - olam;
|
||||
double s = Math.sin(latRad);
|
||||
double c = Math.cos(latRad);
|
||||
double t = s / c;
|
||||
double eta = e2Squared * (c * c);
|
||||
double sn = sphsn(a, eSquared, latRad);
|
||||
tmd = sphtmd(ap, bp, cp, dp, ep, latRad);
|
||||
double t1, t2, t3, t4, t5, t6, t7, t8, t9;
|
||||
t1 = tmd * ok_new;
|
||||
t2 = sn * s * c * ok_new / 2.0;
|
||||
t3 = sn * s * (c * c * c) * ok_new * (5.0 - (t * t) + 9.0 * eta + 4.0 * (eta * eta)) / 24.0;
|
||||
t4 = sn * s * (c * c * c * c * c) * ok_new * (61.0 - 58.0 * (t * t) + (t * t * t * t) + 270.0 * eta - 330.0 * (t * t) * eta + 445.0 * (eta * eta) + 324.0 * (eta * eta * eta) - 680.0 * (t * t) * (eta * eta) + 88.0 * (eta * eta * eta * eta) - 600.0 * (t * t) * (eta * eta * eta) - 192.0 * (t * t) * (eta * eta * eta * eta)) / 720.0;
|
||||
t5 = sn * s * (c * c * c * c * c * c * c) * ok_new * (1385.0 - 3111.0 * (t * t) + 543.0 * (t * t * t * t) - (t * t * t * t * t * t)) / 40320.0;
|
||||
puwgCoord.northing = nfn + t1 + (dlam * dlam) * t2 + (dlam * dlam * dlam * dlam) * t3 + (dlam * dlam * dlam * dlam * dlam * dlam) * t4 + (dlam * dlam * dlam * dlam * dlam * dlam * dlam * dlam) * t5;
|
||||
t6 = sn * c * ok_new;
|
||||
t7 = sn * (c * c * c) * ok_new * (1.0 - (t * t) + eta) / 6.0;
|
||||
t8 = sn * (c * c * c * c * c) * ok_new * (5.0 - 18.0 * (t * t) + (t * t * t * t) + 14.0 * eta - 58.0 * (t * t) * eta + 13.0 * (eta * eta) + 4.0 * (eta * eta * eta) - 64.0 * (t * t) * (eta * eta) - 24.0 * (t * t) * (eta * eta * eta)) / 120.0;
|
||||
t9 = sn * (c * c * c * c * c * c * c) * ok_new * (61.0 - 479.0 * (t * t) + 179.0 * (t * t * t * t) - (t * t * t * t * t * t)) / 5040.0;
|
||||
puwgCoord.easting = fe + strf + dlam * t6 + (dlam * dlam * dlam) * t7 + (dlam * dlam * dlam * dlam * dlam) * t8 + (dlam * dlam * dlam * dlam * dlam * dlam * dlam) * t9;// + 0.5;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
// Funkcja do konwersji współrzędnych płaskich X/Y UTM na elipsoidalne lat/lon (dla dowolnej elipsoidy)
|
||||
//=======================================================================
|
||||
// Wymagania:
|
||||
// -------------------------------------
|
||||
// utmXZone musi być wartością w garanicach od 1 do 60
|
||||
// utmYZone musi być jedną z liter: CDEFGHJKLMNPQRSTUVWX
|
||||
// Argumenty wejściowe i wyjściowe:
|
||||
// ------------------------------------
|
||||
// double a: długość dużej półosi, w metrach (np. dla elipsoidy WGS 84, 6378137.0)
|
||||
// double f: spłaszczenie elipsoidalne (np. dla elipsoidy WGS 84, 1 / 298.257223563)
|
||||
// int utmXZone: nr strefy UTM wg. podziału południkowego (zwracane numery od 1 do 60, każda strefa ma sześć stopni)
|
||||
// char utmYZone: nr strefy wg. podziału równoleżnikowego (zwracane wartości: CDEFGHJKLMNPQRSTUVWX)
|
||||
// double easting, double northing: współrzędna X, Y UTM do konwersji [metry]
|
||||
// double& lat, double& lon: współrzędne elipsoidalne lat/lon po konwersji [stopnie]
|
||||
//=======================================================================
|
||||
public static void convertUtmToLatLon(UTMCoord utmCoord, GeoCoord geoCoord) {
|
||||
double nfn;
|
||||
utmCoord.yZone = Character.toUpperCase(utmCoord.yZone);
|
||||
if (utmCoord.yZone <= 'M' && utmCoord.yZone >= 'C') {
|
||||
nfn = 10000000.0;
|
||||
} else {
|
||||
nfn = 0;
|
||||
}
|
||||
double tmd = (utmCoord.northing - nfn) / ok;
|
||||
double sr = sphsr(a, eSquared, 0.0);
|
||||
double ftphi = tmd / sr;
|
||||
double t10, t11, t12, t13, t14, t15, t16, t17;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
t10 = sphtmd(ap, bp, cp, dp, ep, ftphi);
|
||||
sr = sphsr(a, eSquared, ftphi);
|
||||
ftphi = ftphi + (tmd - t10) / sr;
|
||||
}
|
||||
sr = sphsr(a, eSquared, ftphi);
|
||||
double sn = sphsn(a, eSquared, ftphi);
|
||||
double s = Math.sin(ftphi);
|
||||
double c = Math.cos(ftphi);
|
||||
double t = s / c;
|
||||
double eta = e2Squared * (c * c);
|
||||
double de = utmCoord.easting - fe;
|
||||
t10 = t / (2.0 * sr * sn * (ok * ok));
|
||||
t11 = t * (5.0 + 3.0 * (t * t) + eta - 4.0 * (eta * eta) - 9.0 * (t * t) * eta) / (24.0 * sr * (sn * sn * sn) * (ok * ok * ok * ok));
|
||||
t12 = t * (61.0 + 90.0 * (t * t) + 46.0 * eta + 45.0 * (t * t * t * t) - 252.0 * (t * t) * eta - 3.0 * (eta * eta) + 100.0 * (eta * eta * eta) - 66.0 * (t * t) * (eta * eta) - 90.0 * (t * t * t * t) * eta + 88.0 * (eta * eta * eta * eta) + 225.0 * (t * t * t * t) * (eta * eta) + 84.0 * (t * t) * (eta * eta * eta) - 192.0 * (t * t) * (eta * eta * eta * eta)) / (720.0 * sr * (sn * sn * sn * sn * sn) * (ok * ok * ok * ok * ok * ok));
|
||||
t13 = t * (1385.0 + 3633 * (t * t) + 4095.0 * (t * t * t * t) + 1575.0 * (t * t * t * t * t * t)) / (40320 * sr * (sn * sn * sn * sn * sn * sn * sn) * (ok * ok * ok * ok * ok * ok * ok * ok));
|
||||
geoCoord.lat = ftphi - (de * de) * t10 + (de * de * de * de) * t11 - (de * de * de * de * de * de) * t12 + (de * de * de * de * de * de * de * de) * t13;
|
||||
t14 = 1.0 / (sn * c * ok);
|
||||
t15 = (1.0 + 2.0 * (t * t) + eta) / (6.0 * (sn * sn * sn) * c * (ok * ok * ok));
|
||||
t16 = 1.0 * (5.0 + 6.0 * eta + 28.0 * (t * t) - 3.0 * (eta * eta) + 8.0 * (t * t) * eta + 24.0 * (t * t * t * t) - 4.0 * (eta * eta * eta) + 4.0 * (t * t) * (eta * eta) + 24.0 * (t * t) * (eta * eta * eta)) / (120.0 * (sn * sn * sn * sn * sn) * c * (ok * ok * ok * ok * ok));
|
||||
t17 = 1.0 * (61.0 + 662.0 * (t * t) + 1320.0 * (t * t * t * t) + 720.0 * (t * t * t * t * t * t)) / (5040.0 * (sn * sn * sn * sn * sn * sn * sn) * c * (ok * ok * ok * ok * ok * ok * ok));
|
||||
double dlam = de * t14 - (de * de * de) * t15 + (de * de * de * de * de) * t16 - (de * de * de * de * de * de * de) * t17;
|
||||
double olam = (utmCoord.xZone * 6 - 183.0) * DEG_2_RAD;
|
||||
geoCoord.lon = olam + dlam;
|
||||
geoCoord.lon *= RAD_2_DEG;
|
||||
geoCoord.lat *= RAD_2_DEG;
|
||||
}
|
||||
|
||||
|
||||
// Współczynnik zniekształcenia skali mapy w południku osiowym dla odwzorowania kartograficznego UTM
|
||||
private static final double ok = 0.9996;
|
||||
private static final double DEG_2_RAD = Math.PI / 180.0;
|
||||
private static final double RAD_2_DEG = 180.0 / Math.PI;
|
||||
/**
|
||||
* double a: dlługość dużej półsi, w metrach dla elipsoidy WGS-84, 6378137.0
|
||||
*/
|
||||
private static final double a = 6378137.0;
|
||||
|
||||
private static final double recf = 298.257223563;
|
||||
/**
|
||||
* double f: spłaszczenie elipsoidalne dla elipsoidy WGS-84, 1 / 298.257223563
|
||||
*/
|
||||
private static final double f = 1.0 / recf;
|
||||
// private static final double b = a * (recf - 1) / recf;
|
||||
private static final double b = a * (1.0 - f);
|
||||
private static final double eSquared = calculateESquared(a, b);
|
||||
private static final double e2Squared = calculateE2Squared(a, b);
|
||||
private static final double tn = (a - b) / (a + b);
|
||||
private static final double ap = a * (1.0 - tn + 5.0 * ((tn * tn) - (tn * tn * tn)) / 4.0 + 81.0 * ((tn * tn * tn * tn) - (tn * tn * tn * tn * tn)) / 64.0);
|
||||
private static final double bp = 3.0 * a * (tn - (tn * tn) + 7.0 * ((tn * tn * tn) - (tn * tn * tn * tn)) / 8.0 + 55.0 * (tn * tn * tn * tn * tn) / 64.0) / 2.0;
|
||||
private static final double cp = 15.0 * a * ((tn * tn) - (tn * tn * tn) + 3.0 * ((tn * tn * tn * tn) - (tn * tn * tn * tn * tn)) / 4.0) / 16.0;
|
||||
private static final double dp = 35.0 * a * ((tn * tn * tn) - (tn * tn * tn * tn) + 11.0 * (tn * tn * tn * tn * tn) / 16.0) / 48.0;
|
||||
private static final double ep = 315.0 * a * ((tn * tn * tn * tn) - (tn * tn * tn * tn * tn)) / 512.0;
|
||||
|
||||
/**
|
||||
* Funkcja do konwersji współrzędnych płaskich X/Y odwzorowania kartograficznego 1992 i 2000 na elipsoidalne lat/lon elipsoide WGS84.
|
||||
* <p>
|
||||
* PUWGCoord.proj: odwzorowanie kartograficzne (proj = 1 odpowiada odwzorowaniu 1992, natomiast każda inna odwzorowaniu 2000)
|
||||
*
|
||||
* @param puwgCoord współrzędne odwzorowania kartograficznego PUWG-1992 lub PUWG-2000 do konwersji [metry]
|
||||
* @param geoCoord współrzędne geograficzne odwzorowania WGS-84 po konwersji [stopnie]
|
||||
*/
|
||||
public static void convertPuwgToLatLon(PUWGCoord puwgCoord, GeoCoord geoCoord) {
|
||||
double ok = (puwgCoord.proj != 1) ? 0.999923 : 0.9993;
|
||||
double nfn;
|
||||
double tmd;
|
||||
double ftphi;
|
||||
double eta;
|
||||
double dlam;
|
||||
double olam = 0.0;
|
||||
double strf = 0.0;
|
||||
|
||||
if (puwgCoord.proj == 1) {
|
||||
olam = 19.0 * DEG_2_RAD;
|
||||
strf = 0.0;
|
||||
nfn = -5300000.0;
|
||||
} else {
|
||||
nfn = 0;
|
||||
if (puwgCoord.easting < 6000000.0 && puwgCoord.easting > 5000000.0) {
|
||||
strf = 5000000.0;
|
||||
olam = 15.0 * DEG_2_RAD;
|
||||
}
|
||||
if (puwgCoord.easting < 7000000.0 && puwgCoord.easting > 6000000.0) {
|
||||
strf = 6000000.0;
|
||||
olam = 18.0 * DEG_2_RAD;
|
||||
}
|
||||
if (puwgCoord.easting < 8000000.0 && puwgCoord.easting > 7000000.0) {
|
||||
strf = 7000000.0;
|
||||
olam = 21.0 * DEG_2_RAD;
|
||||
}
|
||||
if (puwgCoord.easting < 9000000.0 && puwgCoord.easting > 8000000.0) {
|
||||
strf = 8000000.0;
|
||||
olam = 24.0 * DEG_2_RAD;
|
||||
}
|
||||
}
|
||||
tmd = (puwgCoord.northing - nfn) / ok;
|
||||
double sr = sphsr(a, eSquared, 0.0);
|
||||
ftphi = tmd / sr;
|
||||
double t10, t11, t12, t13, t14, t15, t16, t17;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
t10 = sphtmd(ap, bp, cp, dp, ep, ftphi);
|
||||
sr = sphsr(a, eSquared, ftphi);
|
||||
ftphi = ftphi + (tmd - t10) / sr;
|
||||
}
|
||||
sr = sphsr(a, eSquared, ftphi);
|
||||
double sn = sphsn(a, eSquared, ftphi);
|
||||
double sn_pow_2 = sn * sn;
|
||||
double sn_pow_3 = sn_pow_2 * sn;
|
||||
double sn_pow_4 = sn_pow_3 * sn;
|
||||
double sn_pow_5 = sn_pow_4 * sn;
|
||||
double sn_pow_7 = sn_pow_5 * sn_pow_2;
|
||||
double s = Math.sin(ftphi);
|
||||
double c = Math.cos(ftphi);
|
||||
double t = s / c;
|
||||
double t_pow_2 = t * t;
|
||||
double t_pow_4 = t_pow_2 * t_pow_2;
|
||||
double t_pow_6 = t_pow_4 * t_pow_2;
|
||||
eta = e2Squared * (c * c);
|
||||
double eta_pow_2 = eta * eta;
|
||||
double eta_pow_3 = eta_pow_2 * eta;
|
||||
double eta_pow_4 = eta_pow_2 * eta_pow_2;
|
||||
double de = puwgCoord.easting - fe - strf;
|
||||
double de_pow_2 = de * de;
|
||||
double de_pow_3 = de_pow_2 * de;
|
||||
double de_pow_4 = de_pow_3 * de;
|
||||
t10 = t / (2.0 * sr * sn * (ok * ok));
|
||||
t11 = t * (5.0 + 3.0 * t_pow_2 + eta - 4.0 * eta_pow_2 - 9.0 * t_pow_2 * eta) / (24.0 * sr * sn_pow_3 * (ok * ok * ok * ok));
|
||||
t12 = t * (61.0 + 90.0 * t_pow_2 + 46.0 * eta + 45.0 * t_pow_4 - 252.0 * t_pow_2 * eta - 3.0 * eta_pow_2 + 100.0 * eta_pow_3 - 66.0 * t_pow_2 * eta_pow_2 - 90.0 * t_pow_4 * eta + 88.0 * eta_pow_4 + 225.0 * t_pow_4 * eta_pow_2 + 84.0 * t_pow_2 * eta_pow_3 - 192.0 * t_pow_2 * eta_pow_4) / (720.0 * sr * sn_pow_5 * (ok * ok * ok * ok * ok * ok));
|
||||
t13 = t * (1385.0 + 3633 * t_pow_2 + 4095.0 * t_pow_4 + 1575.0 * t_pow_6) / (40320 * sr * sn_pow_7 * (ok * ok * ok * ok * ok * ok * ok * ok));
|
||||
geoCoord.lat = ftphi - de_pow_2 * t10 + de_pow_4 * t11 - de_pow_3 * de_pow_3 * t12 + de_pow_4 * de_pow_3 * t13;
|
||||
t14 = 1.0 / (sn * c * ok);
|
||||
t15 = (1.0 + 2.0 * t_pow_2 + eta) / (6.0 * sn_pow_3 * c * (ok * ok * ok));
|
||||
t16 = 1.0 * (5.0 + 6.0 * eta + 28.0 * t_pow_2 - 3.0 * eta_pow_2 + 8.0 * t_pow_2 * eta + 24.0 * t_pow_4 - 4.0 * eta_pow_3 + 4.0 * t_pow_2 * eta_pow_2 + 24.0 * t_pow_2 * eta_pow_3) / (120.0 * sn_pow_5 * c * (ok * ok * ok * ok * ok));
|
||||
t17 = 1.0 * (61.0 + 662.0 * t_pow_2 + 1320.0 * t_pow_4 + 720.0 * t_pow_6) / (5040.0 * sn_pow_7 * c * (ok * ok * ok * ok * ok * ok * ok));
|
||||
dlam = de * t14 - de_pow_3 * t15 + de_pow_3 * de_pow_2 * t16 - de_pow_3 * de_pow_4 * t17;
|
||||
geoCoord.lon = olam + dlam;
|
||||
geoCoord.lon *= RAD_2_DEG;
|
||||
geoCoord.lat *= RAD_2_DEG;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
|
||||
import pl.wat.ms4ds.terenfunkcje.GridCoord;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class DaneWysok {
|
||||
|
||||
GridCoord idKw;
|
||||
|
||||
double suma;
|
||||
|
||||
int licz;
|
||||
|
||||
public DaneWysok(GridCoord idKw, double suma, int licz) {
|
||||
this.idKw = idKw;
|
||||
this.suma = suma;
|
||||
this.licz = licz;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
|
||||
/**
|
||||
* Współrzędne punktu odwzorowania kartograficznego PUWG 1992 lub 2000.
|
||||
* <p>
|
||||
* Wartośći współrzędnych [metry].
|
||||
*
|
||||
*/
|
||||
public class PUWGCoord {
|
||||
/**
|
||||
* Współrzędna X (oś odcietych) odwzorowania kartograficznego [metry].
|
||||
*/
|
||||
public double easting;
|
||||
/**
|
||||
* Współrzędna Y (oś rzędnych) odwzorowania kartograficznego [metry].
|
||||
*/
|
||||
public double northing;
|
||||
/**
|
||||
* proj = 1 odpowiada odwzorowaniu 1992, natomiast każda inna odwzorowaniu 2000
|
||||
*/
|
||||
public int proj;
|
||||
|
||||
public PUWGCoord() {
|
||||
this.easting = 0;
|
||||
this.northing = 0;
|
||||
// PUWG 1992
|
||||
this.proj = 1;
|
||||
}
|
||||
|
||||
public PUWGCoord(double easting, double northing, int proj) {
|
||||
this.easting = easting;
|
||||
this.northing = northing;
|
||||
this.proj = proj;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
|
||||
/**
|
||||
* Współrzędna w układzie UTM. <p>
|
||||
* Przykład: 17T 630084 4833438,
|
||||
* gdzie: xZone = 17, yZone = T, easting = 630084, northing = 4833438
|
||||
* <p>
|
||||
* xZone - nr strefy UTM wg. podziału południkowego (zwracane numery od 1 do 60, każda strefa ma sześć stopni);
|
||||
* <p>
|
||||
* yZone - nr strefy wg. podziału równoleżnikowego (zwracane wartości: CDEFGHJKLMNPQRSTUVWX).
|
||||
* <p>
|
||||
* easting - odległość w kierunku wschodnim od początku układu współrzędnych w danej strefie UTM [metr].
|
||||
* <p>
|
||||
* northing - odległość w kierunku północnym od początku układu współrzędnych w danej strefie UTM [metr].
|
||||
*/
|
||||
public class UTMCoord {
|
||||
|
||||
/**
|
||||
* Nr strefy UTM wg. podziału południkowego (zwracane numery od 1 do 60, każda strefa ma sześć stopni).
|
||||
*/
|
||||
public int xZone;
|
||||
/**
|
||||
* Nr strefy wg. podziału równoleżnikowego (zwracane wartości: CDEFGHJKLMNPQRSTUVWX).
|
||||
*/
|
||||
public char yZone;
|
||||
/**
|
||||
* Odległość w kierunku wschodnim od początku układu współrzędnych w danej strefie UTM [metr].
|
||||
*/
|
||||
public double easting;
|
||||
/**
|
||||
* Odległość w kierunku północnym od początku układu współrzędnych w danej strefie UTM [metr].
|
||||
*/
|
||||
public double northing;
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.nmt;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class NMTReader {
|
||||
|
||||
|
||||
static void main(String[] args) {
|
||||
// File dir = new File(System.getProperty("user.home") + "/nmt/gugik_SkorowidzNMT2018.gml");
|
||||
|
||||
InputStream is = null;
|
||||
try {
|
||||
File file = new File("C:/Workspace/nmt/N-34-139-A-b-2-4.asc");
|
||||
is = new FileInputStream(file);
|
||||
readFromInputStream(is);
|
||||
//...
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void readFromInputStream(InputStream inputStream) throws IOException {
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
String line= br.readLine();
|
||||
String[] split = line.split(" ");
|
||||
int ncols = Integer.parseInt(split[1]);
|
||||
line= br.readLine();
|
||||
split = line.split(" ");
|
||||
int nrows = Integer.parseInt(split[1]);
|
||||
line= br.readLine();
|
||||
split = line.split(" ");
|
||||
double xll = Double.parseDouble(split[1]);
|
||||
line= br.readLine();
|
||||
split = line.split(" ");
|
||||
double yll = Double.parseDouble(split[1]);
|
||||
line= br.readLine();
|
||||
split = line.split(" ");
|
||||
double cellsize = Double.parseDouble(split[1]);
|
||||
line= br.readLine();
|
||||
split = line.split(" ");
|
||||
double nodata = Double.parseDouble(split[1]);
|
||||
while ((line = br.readLine()) != null) {
|
||||
split = line.split(" ");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.osm.shapefile;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class DbfRecord {
|
||||
|
||||
/**
|
||||
* OSM Id taken from the Id of this feature (node_id, way_id, or relation_id) in the
|
||||
* OSM database.
|
||||
* VARCHAR (10 Bytes)
|
||||
*/
|
||||
String osmId;
|
||||
|
||||
/**
|
||||
* Digit code (between 1000 and 9999) defining the feature class. The first one or
|
||||
* two digits define the layer, the last two or three digits the class inside a layer.
|
||||
*
|
||||
*/
|
||||
int code;
|
||||
|
||||
/**
|
||||
* Class name of this feature. This does not add any information that is not already
|
||||
* in the “code” field but it is better readable.
|
||||
*/
|
||||
String fclass;
|
||||
|
||||
/**
|
||||
* Name of this feature, like a street or place name. If the name in OSM contains
|
||||
* obviously wrong data such as “fixme" or “none”, it will be empty.
|
||||
*/
|
||||
String name;
|
||||
|
||||
|
||||
public DbfRecord() throws Exception {
|
||||
}
|
||||
|
||||
public void read(BufferedInputStream bis, DbfHeader header) throws Exception {
|
||||
byte[] data = new byte[header.recordSize];
|
||||
if (bis.read(data) != header.recordSize) {
|
||||
throw new Exception("Invalid dbf file");
|
||||
}
|
||||
String str = new String(data, StandardCharsets.UTF_8);
|
||||
// Na pozycji 0 jest flag byte, dane startują od pozycji 1.
|
||||
int from = 1;
|
||||
int to = 1 + header.fields[0].size;
|
||||
osmId = str.substring(from, to);
|
||||
int endPos = osmId.indexOf(' ');
|
||||
osmId = osmId.substring(0, endPos);
|
||||
from = to;
|
||||
to += header.fields[1].size;
|
||||
String codeStr = str.substring(from, to);
|
||||
code = Integer.parseInt(codeStr);
|
||||
from = to;
|
||||
to += header.fields[2].size;
|
||||
fclass = str.substring(from, to);
|
||||
endPos = fclass.indexOf(' ');
|
||||
fclass = fclass.substring(0, endPos);
|
||||
from = to;
|
||||
to += header.fields[3].size;
|
||||
name = str.substring(from, to);
|
||||
endPos = name.indexOf(' ');
|
||||
name = name.substring(0, endPos);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.osm.shapefile;
|
||||
|
||||
|
||||
public class Main {
|
||||
|
||||
static void main(String[] args) {
|
||||
try {
|
||||
// GET DIRECTORY
|
||||
String curDir = (args[0] != null) ? args[0] : System.getProperty("user.dir");
|
||||
curDir = "";
|
||||
String folder = "C:/Workspace/osm/dolnoslaskie-251217-free.shp/";
|
||||
|
||||
// LOAD SHAPE FILE (.shp, .shx, .dbf)
|
||||
// gis_osm_buildings_a_free_1
|
||||
// gis_osm_water_a_free_1
|
||||
OsmShapeFileReader shapefile = new OsmShapeFileReader(curDir + folder, "gis_osm_buildings_a_free_1");
|
||||
ShpShape shape = shapefile.nextShape();
|
||||
System.out.println("Shape type = " + shape.getShapeType());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje;
|
||||
package pl.wat.ms4ds.terrain;
|
||||
|
||||
import pl.wat.ms4ds.common.EGeoDirection;
|
||||
import pl.wat.ms4ds.common.ERodzajDzialania;
|
||||
@@ -36,10 +36,6 @@ public final class AStar {
|
||||
return node;
|
||||
}
|
||||
|
||||
static Node dajAStarNode(GridCoord gridCoord) {
|
||||
return dajAStarNode(gridCoord.x, gridCoord.y);
|
||||
}
|
||||
|
||||
ArrayList<Node> dajNiezamknietychSasiadow() {
|
||||
ArrayList<Node> wynik = new ArrayList<>();
|
||||
Node sasiad;
|
||||
@@ -85,13 +81,13 @@ public final class AStar {
|
||||
zKierunku = EGeoDirection.UNDEFINED;
|
||||
}
|
||||
|
||||
Node(GridCoord id) {
|
||||
Node(Coord.Grid id) {
|
||||
this(id.x, id.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AStarNode{" +
|
||||
return "AStar.Node{" +
|
||||
"x=" + x +
|
||||
", y=" + y +
|
||||
", koncowy=" + koncowy +
|
||||
@@ -133,16 +129,16 @@ public final class AStar {
|
||||
* @param rodzajDzialania rodzaj działania, w ramach którego określana jest droga
|
||||
* @return uporządkowana kolekcja współrzędnych kolejnych kwadratów drogi zawierająca kwadrat startowy i docelowy lub kolekcja pusta, gdy nie istnieje droga
|
||||
*/
|
||||
public static ArrayList<GridCoord> wyznaczDroge(GridCoord[] punktyProfilujace, EGeoDirection staryKierunek,
|
||||
ERodzajPodwozia podwozie, ERodzajDzialania rodzajDzialania) {
|
||||
public static ArrayList<Coord.Grid> wyznaczDroge(Coord.Grid[] punktyProfilujace, EGeoDirection staryKierunek,
|
||||
ERodzajPodwozia podwozie, ERodzajDzialania rodzajDzialania) {
|
||||
if (null == punktyProfilujace || 0 == punktyProfilujace.length) {
|
||||
return null;
|
||||
}
|
||||
Node.reset();
|
||||
ArrayList<GridCoord> wynik = new ArrayList<>();
|
||||
GridCoord start;
|
||||
GridCoord stop = punktyProfilujace[0];
|
||||
ArrayList<GridCoord> odcinek;
|
||||
ArrayList<Coord.Grid> wynik = new ArrayList<>();
|
||||
Coord.Grid start;
|
||||
Coord.Grid stop = punktyProfilujace[0];
|
||||
ArrayList<Coord.Grid> odcinek;
|
||||
for (int i = 1; i < punktyProfilujace.length; i++) {
|
||||
start = stop;
|
||||
stop = punktyProfilujace[i];
|
||||
@@ -157,7 +153,7 @@ public final class AStar {
|
||||
} else {
|
||||
odcinek = wyznaczDroge(start, stop, staryKier, false, podwozie, rodzajDzialania);
|
||||
}
|
||||
if (odcinek.size() == 0) {
|
||||
if (odcinek.isEmpty()) {
|
||||
// gdy nie istnieje droga między danymi punktami profilującymi, to zwracam kolekcję pustą
|
||||
return odcinek;
|
||||
}
|
||||
@@ -178,8 +174,8 @@ public final class AStar {
|
||||
* @param zawieraStartowy parametr wskazujący, czy wyznaczona droga ma zawierać kwadrat startowy
|
||||
* @return uporządkowana kolekcja współrzędnych kolejnych kwadratów drogi zawierająca kwadrat startowy (jeśli zawieraStartowy==true) i docelowy lub kolekcja pusta, gdy nie istnieje droga
|
||||
*/
|
||||
public static ArrayList<GridCoord> wyznaczDroge(GridCoord start, GridCoord stop, EGeoDirection staryKierunek,
|
||||
boolean zawieraStartowy, ERodzajPodwozia podwozie, ERodzajDzialania rodzajDzialania) {
|
||||
public static ArrayList<Coord.Grid> wyznaczDroge(Coord.Grid start, Coord.Grid stop, EGeoDirection staryKierunek,
|
||||
boolean zawieraStartowy, ERodzajPodwozia podwozie, ERodzajDzialania rodzajDzialania) {
|
||||
|
||||
PriorityQueue<Node> listaOtwarta = new PriorityQueue<>(100, (o1, o2) -> Double.compare(o1.kosztZHeurystyka, o2.kosztZHeurystyka));
|
||||
boolean naPrzelaj = false;
|
||||
@@ -204,13 +200,13 @@ public final class AStar {
|
||||
aktualny = Node.dajAStarNode(start.x, start.y);
|
||||
aktualny.zKierunku = staryKierunek;
|
||||
listaOtwarta.add(aktualny);
|
||||
ArrayList<GridCoord> wynik = new ArrayList<GridCoord>();
|
||||
ArrayList<Coord.Grid> wynik = new ArrayList<Coord.Grid>();
|
||||
int licznik_zabezpieczajacy = 200000;
|
||||
while (listaOtwarta.size() > 0 && licznik_zabezpieczajacy-- > 0) {
|
||||
aktualny = listaOtwarta.remove();
|
||||
if (aktualny.koncowy) {
|
||||
while (null != aktualny) {
|
||||
wynik.add(new GridCoord(aktualny.x, aktualny.y));
|
||||
wynik.add(new Coord.Grid(aktualny.x, aktualny.y));
|
||||
aktualny = aktualny.poprzednik;
|
||||
}
|
||||
if (!zawieraStartowy) {
|
||||
@@ -222,16 +218,17 @@ public final class AStar {
|
||||
}
|
||||
sasiedzi = aktualny.dajNiezamknietychSasiadow();
|
||||
for (Node sasiad : sasiedzi) {
|
||||
double stopienPrzejezdnosci = Teren.getStopienPrzejezdnosci(aktualny.x, aktualny.y, sasiad.x, sasiad.y,
|
||||
aktualny.zKierunku, podwozie);
|
||||
// double stopienPrzejezdnosci = Teren.getStopienPrzejezdnosci(aktualny.x, aktualny.y, sasiad.x, sasiad.y,
|
||||
// aktualny.zKierunku, podwozie);
|
||||
double stopienPrzejezdnosci = 1;
|
||||
if (stopienPrzejezdnosci < 0.005f) {
|
||||
continue;
|
||||
}
|
||||
if (naPrzelaj) {
|
||||
stopienPrzejezdnosci = Math.max(Teren.minStopienPrzejezdNaPrzelaj, stopienPrzejezdnosci);
|
||||
}
|
||||
double nowyKosztOdStartu = (float) aktualny.kosztOdStartu + GridCoord.odleglosc(aktualny.x, aktualny.y, sasiad.x, sasiad.y) / stopienPrzejezdnosci;
|
||||
double nowyKosztZHeurystyka = nowyKosztOdStartu + GridCoord.odleglosc(sasiad.x, sasiad.y, stop.x, stop.y);
|
||||
double nowyKosztOdStartu = aktualny.kosztOdStartu + Coord.Grid.distance(aktualny.x, aktualny.y, sasiad.x, sasiad.y) / stopienPrzejezdnosci;
|
||||
double nowyKosztZHeurystyka = nowyKosztOdStartu + Coord.Grid.distance(sasiad.x, sasiad.y, stop.x, stop.y);
|
||||
if (sasiad.kosztZHeurystyka > nowyKosztZHeurystyka) {
|
||||
//UPDATE kosztow i zmiany w kolejce
|
||||
sasiad.kosztOdStartu = nowyKosztOdStartu;
|
||||
@@ -258,12 +255,12 @@ public final class AStar {
|
||||
* @param zawieraStartowy parametr wskazujący, czy wyznaczona droga ma zawierać kwadrat startowy
|
||||
* @return uporządkowana kolekcja współrzędnych kolejnych kwadratów drogi zawierająca kwadrat startowy (jeśli zawieraStartowy==true) i docelowy lub kolekcja pusta, gdy nie istnieje droga
|
||||
*/
|
||||
public static ArrayList<GridCoord> wyznaczDrogeNew(GridCoord start, GridCoord stop, EGeoDirection staryKierunek,
|
||||
boolean zawieraStartowy, ERodzajPodwozia podwozie,
|
||||
ERodzajDzialania rodzajDzialania,
|
||||
double szerokoscPokonywRowow,
|
||||
double glebokoscBrodzenia,
|
||||
double predkoscPlywania) {
|
||||
public static ArrayList<Coord.Grid> wyznaczDrogeNew(Coord.Grid start, Coord.Grid stop, EGeoDirection staryKierunek,
|
||||
boolean zawieraStartowy, ERodzajPodwozia podwozie,
|
||||
ERodzajDzialania rodzajDzialania,
|
||||
double szerokoscPokonywRowow,
|
||||
double glebokoscBrodzenia,
|
||||
double predkoscPlywania) {
|
||||
PriorityQueue<Node> listaOtwarta = new PriorityQueue<>(100, new Comparator<Node>() {
|
||||
public int compare(Node o1, Node o2) {
|
||||
return Double.compare(o1.kosztZHeurystyka, o2.kosztZHeurystyka);
|
||||
@@ -292,13 +289,13 @@ public final class AStar {
|
||||
aktualny = Node.dajAStarNode(start.x, start.y);
|
||||
aktualny.zKierunku = staryKierunek;
|
||||
listaOtwarta.add(aktualny);
|
||||
ArrayList<GridCoord> wynik = new ArrayList<GridCoord>();
|
||||
ArrayList<Coord.Grid> wynik = new ArrayList<Coord.Grid>();
|
||||
int licznik_zabezpieczajacy = 200000;
|
||||
while (listaOtwarta.size() > 0 && licznik_zabezpieczajacy-- > 0) {
|
||||
aktualny = listaOtwarta.remove();
|
||||
if (aktualny.koncowy) {
|
||||
while (null != aktualny) {
|
||||
wynik.add(new GridCoord(aktualny.x, aktualny.y));
|
||||
wynik.add(new Coord.Grid(aktualny.x, aktualny.y));
|
||||
aktualny = aktualny.poprzednik;
|
||||
}
|
||||
if (!zawieraStartowy) {
|
||||
@@ -310,16 +307,17 @@ public final class AStar {
|
||||
}
|
||||
sasiedzi = aktualny.dajNiezamknietychSasiadow();
|
||||
for (Node sasiad : sasiedzi) {
|
||||
double stopienPrzejezdnosci = Teren.getStopienPrzejezdnosciNew(aktualny.x, aktualny.y, sasiad.x, sasiad.y,
|
||||
aktualny.zKierunku, podwozie, szerokoscPokonywRowow, glebokoscBrodzenia, predkoscPlywania);
|
||||
// double stopienPrzejezdnosci = Teren.getStopienPrzejezdnosciNew(aktualny.x, aktualny.y, sasiad.x, sasiad.y,
|
||||
// aktualny.zKierunku, podwozie, szerokoscPokonywRowow, glebokoscBrodzenia, predkoscPlywania);
|
||||
double stopienPrzejezdnosci = 1;
|
||||
if (stopienPrzejezdnosci < 0.005f) {
|
||||
continue;
|
||||
}
|
||||
if (naPrzelaj) {
|
||||
stopienPrzejezdnosci = Math.max(Teren.minStopienPrzejezdNaPrzelaj, stopienPrzejezdnosci);
|
||||
}
|
||||
double nowyKosztOdStartu = (float) aktualny.kosztOdStartu + GridCoord.odleglosc(aktualny.x, aktualny.y, sasiad.x, sasiad.y) / stopienPrzejezdnosci;
|
||||
double nowyKosztZHeurystyka = nowyKosztOdStartu + GridCoord.odleglosc(sasiad.x, sasiad.y, stop.x, stop.y);
|
||||
double nowyKosztOdStartu = aktualny.kosztOdStartu + Coord.Grid.distance(aktualny.x, aktualny.y, sasiad.x, sasiad.y) / stopienPrzejezdnosci;
|
||||
double nowyKosztZHeurystyka = nowyKosztOdStartu + Coord.Grid.distance(sasiad.x, sasiad.y, stop.x, stop.y);
|
||||
if (sasiad.kosztZHeurystyka > nowyKosztZHeurystyka) {
|
||||
//UPDATE kosztow i zmiany w kolejce
|
||||
sasiad.kosztOdStartu = nowyKosztOdStartu;
|
||||
198
src/main/java/pl/wat/ms4ds/terrain/AltitudeColorMapper.java
Normal file
198
src/main/java/pl/wat/ms4ds/terrain/AltitudeColorMapper.java
Normal file
@@ -0,0 +1,198 @@
|
||||
package pl.wat.ms4ds.terrain;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class AltitudeColorMapper {
|
||||
|
||||
// Define the color stops and corresponding normalized values (0.0 to 1.0)
|
||||
private static final float[] STOPS = {0.0f, 0.1f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0f};
|
||||
private static final Color[] COLORS2 = {
|
||||
new Color(0, 0, 64), // Dark Navy Blue
|
||||
new Color(0, 64, 204), // Medium Blue
|
||||
new Color(51, 204, 51), // Bright Green
|
||||
new Color(255, 255, 128),// Yellow
|
||||
new Color(228, 96, 0), // Orange
|
||||
new Color(96, 0, 0), // Red
|
||||
new Color(158, 110, 110),
|
||||
new Color(220, 220, 220), // Red
|
||||
Color.WHITE // White
|
||||
};
|
||||
private static final Color[] COLORS = {
|
||||
new Color(40, 0, 40),
|
||||
|
||||
// new Color(20, 0, 60),
|
||||
|
||||
new Color(0, 0, 80), // DARK BLUE
|
||||
|
||||
// new Color(0, 0, 160),
|
||||
// new Color(0, 0, 200),
|
||||
|
||||
new Color(0, 0, 255), // BLUE
|
||||
|
||||
// new Color(0, 80, 255),
|
||||
// new Color(0, 160, 255),
|
||||
// new Color(0, 200, 255),
|
||||
|
||||
new Color(0, 255, 255),
|
||||
|
||||
// new Color(0, 255, 200),
|
||||
//
|
||||
// new Color(0, 255, 160),
|
||||
|
||||
new Color(0, 255, 0), // GREEN
|
||||
|
||||
// new Color(80, 255, 0),
|
||||
|
||||
// new Color(80, 160, 20),
|
||||
|
||||
// new Color(120, 255, 0),
|
||||
|
||||
// new Color(200, 255, 0),
|
||||
|
||||
new Color(255, 255, 0), // YELLOW
|
||||
|
||||
// new Color(255, 200, 0),
|
||||
// new Color(255, 120, 0),
|
||||
// new Color(255, 60, 0),
|
||||
|
||||
new Color(255, 0, 0), // RED
|
||||
|
||||
// new Color(120, 0, 0),
|
||||
|
||||
new Color(40, 0, 0), // DARK RED
|
||||
|
||||
// new Color(80, 40, 40),
|
||||
// new Color(120, 60, 60),
|
||||
// new Color(160, 100, 100),
|
||||
// new Color(200, 140, 140),
|
||||
|
||||
// new Color(220, 180, 180),
|
||||
new Color(255, 215, 215),
|
||||
|
||||
Color.WHITE // White
|
||||
};
|
||||
|
||||
/**
|
||||
* RGB value representing the color in the default sRGB ColorModel.
|
||||
* Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue.
|
||||
* value = ((a & 0xFF) << 24) |
|
||||
* ((r & 0xFF) << 16) |
|
||||
* ((g & 0xFF) << 8) |
|
||||
* ((b & 0xFF) << 0);
|
||||
*/
|
||||
private static final int[] COLORS_RGB = new int[7];
|
||||
|
||||
// static {
|
||||
// Color c = new Color(0x37004E);
|
||||
// int v = 0x37004E;
|
||||
// int a = 0;
|
||||
// int r = 0;
|
||||
// int g = 0;
|
||||
// int b = 50;
|
||||
// int value = ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF) << 0);
|
||||
// COLORS_RGB[0] = value;
|
||||
// a = 0;
|
||||
// r = 0;
|
||||
// g = 0;
|
||||
// b = 0;
|
||||
// value = ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF) << 0);
|
||||
// COLORS_RGB[0] = value;
|
||||
// }
|
||||
|
||||
private static final Color[] gamaKolorow;
|
||||
|
||||
static {
|
||||
Color[] gamaKolorowTemp = new Color[2000];
|
||||
int i = 0;
|
||||
int r = 40;
|
||||
int g = 0;
|
||||
int b = 40;
|
||||
gamaKolorowTemp[i++] = new Color(r, g, b, 255);
|
||||
for (int j = 0; j < 40; j++) {
|
||||
// r: 40->0, g:0, b: 40->80
|
||||
r--;
|
||||
b++;
|
||||
gamaKolorowTemp[i++] = new Color(r, g, b, 255);
|
||||
}
|
||||
for (int j = 0; j < 175; j++) {
|
||||
// r: 0, g:0, b: 80->255
|
||||
b++;
|
||||
gamaKolorowTemp[i++] = new Color(r, g, b, 255);
|
||||
}
|
||||
for (int j = 0; j < 255; j++) {
|
||||
// r: 0, g:1->255, b: 255
|
||||
g++;
|
||||
gamaKolorowTemp[i++] = new Color(r, g, b, 255);
|
||||
}
|
||||
for (int j = 0; j < 255; j++) {
|
||||
// r: 0, g:255, b: 254->0
|
||||
b--;
|
||||
gamaKolorowTemp[i++] = new Color(r, g, b, 255);
|
||||
}
|
||||
for (int j = 0; j < 255; j++) {
|
||||
// r: 1->255, g:255, b: 0
|
||||
r++;
|
||||
gamaKolorowTemp[i++] = new Color(r, g, b, 255);
|
||||
}
|
||||
for (int j = 0; j < 255; j++) {
|
||||
// r: 255, g:254->0, b: 0
|
||||
g--;
|
||||
gamaKolorowTemp[i++] = new Color(r, g, b, 255);
|
||||
}
|
||||
for (int j = 0; j < 215; j++) {
|
||||
// r: 254->40, g: 0, b: 0
|
||||
r--;
|
||||
gamaKolorowTemp[i++] = new Color(r, g, b, 255);
|
||||
}
|
||||
for (int j = 0; j < 215; j++) {
|
||||
// r: 41->255, g: 0->215, b: 0->215
|
||||
r++;
|
||||
g++;
|
||||
b++;
|
||||
gamaKolorowTemp[i++] = new Color(r, g, b, 255);
|
||||
}
|
||||
gamaKolorow = Arrays.copyOf(gamaKolorowTemp, i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color corresponding to a given altitude value within a specified range.
|
||||
*
|
||||
* @param value The altitude value.
|
||||
* @param minValue The minimum possible altitude.
|
||||
* @param maxValue The maximum possible altitude.
|
||||
* @return The interpolated color.
|
||||
*/
|
||||
public static Color getColorForAltitude(double value, double minValue, double maxValue) {
|
||||
// Normalize the value to a 0.0 to 1.0 range
|
||||
double normalizedValue = (value - minValue) / (maxValue - minValue);
|
||||
|
||||
if (normalizedValue <= 0.0) return COLORS[0];
|
||||
if (normalizedValue >= 1.0) return COLORS[COLORS.length - 1];
|
||||
|
||||
// Find the correct interval in the color stops array
|
||||
int stopIndex = 0;
|
||||
while (stopIndex < STOPS.length - 1 && normalizedValue > STOPS[stopIndex + 1]) {
|
||||
stopIndex++;
|
||||
}
|
||||
|
||||
// Interpolate between the two nearest colors
|
||||
float start = STOPS[stopIndex];
|
||||
float end = STOPS[stopIndex + 1];
|
||||
float range = end - start;
|
||||
float fraction = (float) ((normalizedValue - start) / range);
|
||||
|
||||
Color c1 = COLORS[stopIndex];
|
||||
Color c2 = COLORS[stopIndex + 1];
|
||||
|
||||
int r = (int) (c1.getRed() + (c2.getRed() - c1.getRed()) * fraction);
|
||||
int g = (int) (c1.getGreen() + (c2.getGreen() - c1.getGreen()) * fraction);
|
||||
int b = (int) (c1.getBlue() + (c2.getBlue() - c1.getBlue()) * fraction);
|
||||
|
||||
return new Color(r, g, b);
|
||||
}
|
||||
|
||||
static void main() {
|
||||
Color c = gamaKolorow[0];
|
||||
}
|
||||
}
|
||||
18
src/main/java/pl/wat/ms4ds/terrain/BigSquare.java
Normal file
18
src/main/java/pl/wat/ms4ds/terrain/BigSquare.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package pl.wat.ms4ds.terrain;
|
||||
|
||||
|
||||
import javafx.scene.image.ImageView;
|
||||
|
||||
abstract class BigSquare {
|
||||
abstract Square getSquare(int x, int y);
|
||||
|
||||
protected transient String fileName;
|
||||
public int idX = 0;
|
||||
public int idY = 0;
|
||||
public transient int liczbaZmian = 0;
|
||||
// TODO zamienic na 100
|
||||
static final int LICZBA_ZMIAN_DO_ZAPISU = 100000;
|
||||
public ImageView imageView = null;
|
||||
|
||||
|
||||
}
|
||||
529
src/main/java/pl/wat/ms4ds/terrain/Coord.java
Normal file
529
src/main/java/pl/wat/ms4ds/terrain/Coord.java
Normal file
@@ -0,0 +1,529 @@
|
||||
package pl.wat.ms4ds.terrain;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Coord {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Coord.class);
|
||||
|
||||
public static class Geo {
|
||||
public double lat;
|
||||
public double lon;
|
||||
|
||||
public Geo() {
|
||||
}
|
||||
|
||||
public Geo(double lat, double lon) {
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
}
|
||||
|
||||
public Geo(Geo other) {
|
||||
lat = other.lat;
|
||||
lon = other.lon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Geo{" + "lat=" + lat + ", lon=" + lon + '}';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Współrzędne punktu odwzorowania kartograficznego PUWG 1992.
|
||||
* <p>
|
||||
* Wartości współrzędnych [metry].
|
||||
*
|
||||
*/
|
||||
public static class Puwg {
|
||||
/**
|
||||
* Współrzędna X (oś odcietych) odwzorowania kartograficznego [metry].
|
||||
*/
|
||||
public double easting;
|
||||
/**
|
||||
* Współrzędna Y (oś rzędnych) odwzorowania kartograficznego [metry].
|
||||
*/
|
||||
public double northing;
|
||||
|
||||
public Puwg() {
|
||||
this.easting = 0;
|
||||
this.northing = 0;
|
||||
}
|
||||
|
||||
public Puwg(double easting, double northing) {
|
||||
this.easting = easting;
|
||||
this.northing = northing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Puwg{" + "easting=" + easting + ", northing=" + northing + '}';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Klasa reprezentująca współrzędne/położenie w siatce kwadratów terenu.
|
||||
*
|
||||
*/
|
||||
public static class Grid {
|
||||
|
||||
/**
|
||||
* Współrzędna pozioma (oś OX) w siatce kwadratów. Indeks kolumny.
|
||||
*/
|
||||
public int x;
|
||||
/**
|
||||
* Współrzędna pionowa (oś OY) w siatce kwadratów. Indeks wiersza.
|
||||
*/
|
||||
public int y;
|
||||
|
||||
/**
|
||||
* Konstruktor klasy na bazie współrzędnych geograficznych.
|
||||
*
|
||||
* @param lon długość geograficzna
|
||||
* @param lat szerokość geograficzna
|
||||
*/
|
||||
public Grid(double lon, double lat) {
|
||||
double xms_f = (lon + 180) * MapConsts.DEG_MS;
|
||||
long xms = (long) xms_f;
|
||||
x = zamienWspXmsNaIdKwadratuX(xms);
|
||||
|
||||
double yms_f = (lat + 90) * MapConsts.DEG_MS;
|
||||
long yms = (long) yms_f;
|
||||
y = zamienWspYmsNaIdKwadratuY(yms);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Grid{" + "x=" + x + ", y=" + y + '}';
|
||||
}
|
||||
|
||||
private static final double ODWROT_SS_DX_MS = 1.0 / MapConsts.SS_DELTA_LON_MS;
|
||||
private static final double ODWROT_SS_DY_MS = 1.0 / MapConsts.SS_DELTA_LAT_MS;
|
||||
|
||||
public static double distance(Grid a, Grid b) {
|
||||
int dx = a.x - b.x;
|
||||
int dy = a.y - b.y;
|
||||
return Math.sqrt(dx * dx + dy * dy) * MapConsts.SS_SIZE;
|
||||
}
|
||||
|
||||
public static double distance(int x1, int y1, int x2, int y2) {
|
||||
int dx = x2 - x1;
|
||||
int dy = y2 - y1;
|
||||
return Math.sqrt(dx * dx + dy * dy) * MapConsts.SS_SIZE;
|
||||
}
|
||||
|
||||
private static final float DL_MK2 = MapConsts.SS_SIZE * 0.0009765625f;
|
||||
|
||||
/**
|
||||
* Funkcja zwraca aproksymowaną odległość między środkami małych kwadratów [m].
|
||||
*
|
||||
* @param x1 Wsp X id malego kwadratu pocz.
|
||||
* @param y1 Wsp Y id malego kwadratu pocz.
|
||||
* @param x2 Wsp X id malego kwadratu konc.
|
||||
* @param y2 Wsp Y id malego kwadratu konc.
|
||||
* @return Odległość miedzy srodkami malych kwadratow [m].
|
||||
*/
|
||||
public static float distanceApprox(int x1, int y1, int x2, int y2) {
|
||||
int dx = x2 - x1;
|
||||
int dy = y2 - y1;
|
||||
int min, max, approx;
|
||||
if (dx < 0) dx = -dx;
|
||||
if (dy < 0) dy = -dy;
|
||||
if (dx < dy) {
|
||||
min = dx;
|
||||
max = dy;
|
||||
} else {
|
||||
min = dy;
|
||||
max = dx;
|
||||
}
|
||||
approx = (max * 1007) + (min * 441);
|
||||
if (max < (min << 4)) {
|
||||
approx -= (max * 40);
|
||||
}
|
||||
float odl = approx * DL_MK2;
|
||||
return odl;
|
||||
}
|
||||
|
||||
public Grid() {
|
||||
x = -1;
|
||||
y = -1;
|
||||
}
|
||||
|
||||
public Grid(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public Grid(Grid orig) {
|
||||
this.x = orig.x;
|
||||
this.y = orig.y;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public void set(Grid orig) {
|
||||
x = orig.x;
|
||||
y = orig.y;
|
||||
}
|
||||
|
||||
public void set(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object o) {
|
||||
if (!(o instanceof Grid grid)) return false;
|
||||
|
||||
return x == grid.x && y == grid.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
int result = x;
|
||||
result = 31 * result + y;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Zamienia współrzęną GridCoord.x na długość geograficzną środka małego kwadratu
|
||||
*
|
||||
* @param idX współrzęna x GridCoord
|
||||
* @return długość geograficzna
|
||||
*/
|
||||
public static float convertGridXToLon(int idX) {
|
||||
long xms = zamienIdKwadratuXNaWspXms(idX);
|
||||
double lon = (double) xms / (double) MapConsts.DEG_MS - 180;
|
||||
return (float) lon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zamienia współrzęną GridCoord.y na szerokość geograficzną środka małego kwadratu
|
||||
*
|
||||
* @param idY współrzęna y GridCoord
|
||||
* @return szerokość geograficzna
|
||||
*/
|
||||
public static float covertGridYToLat(int idY) {
|
||||
long yms = zamienIdKwadratuYNaWspYms(idY);
|
||||
double lat = (double) yms / (double) MapConsts.DEG_MS - 90;
|
||||
return (float) lat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zamienia wsp. X GridCoord na wsp. geo xms w milisekundach.
|
||||
* Zwracana wspolrzedna lezy w srodku kwadratu.
|
||||
*/
|
||||
public static long zamienIdKwadratuXNaWspXms(int idKwX) {
|
||||
// indeksowanie kwadratow pola walki zaczyna sie od (0, 0)
|
||||
// przesuniecie wspolrzednych do srodka kwadratu
|
||||
long xms = MapConsts.X_REF_MS + (long) ((idKwX + 0.5) * MapConsts.SS_DELTA_LON_MS);
|
||||
xms %= MapConsts.ANGLE_360_MS;
|
||||
return xms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zamienia wsp. Y GridCoord na wsp. geo yms w milisekundach.
|
||||
* Zwracana wspolrzedna lezy w srodku kwadratu.
|
||||
*/
|
||||
public static long zamienIdKwadratuYNaWspYms(int idKwY) {
|
||||
// indeksowanie kwadratow pola walki zaczyna sie od (0, 0)
|
||||
// przesuniecie wspolrzednych do srodka kwadratu
|
||||
long yms = MapConsts.Y_REF_MS + (long) ((idKwY + 0.5) * MapConsts.SS_DELTA_LAT_MS);
|
||||
return yms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zamienia długość geograficzną na współrzędna x Coord.Grid.
|
||||
*
|
||||
* @param lon długość geograficzna
|
||||
* @return współrzędna x klasy GridCoord
|
||||
*/
|
||||
public static int convertLonToGridX(double lon) {
|
||||
double xms_f = (lon + 180) * MapConsts.DEG_MS;
|
||||
return zamienWspXmsNaIdKwadratuX((long) xms_f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zamienia szerokość geograficzną na współrzędna y Coord.Grid.
|
||||
*
|
||||
* @param lat szerokość geograficzna
|
||||
* @return współrzędna y klasy GridCoord
|
||||
*/
|
||||
public static int convertLatToGridY(double lat) {
|
||||
double yms_f = (lat + 90) * MapConsts.DEG_MS;
|
||||
return zamienWspYmsNaIdKwadratuY((long) yms_f);
|
||||
}
|
||||
|
||||
public static final double INVERT_SS_DELTA_LON = 1 / MapConsts.SS_DELTA_LON;
|
||||
public static final double INVERT_SS_DELTA_LAT = 1 / MapConsts.SS_DELTA_LAT;
|
||||
|
||||
private static final double REF_LON_OFFSET = 180 - MapConsts.REF_LON;
|
||||
private static final double REF_LAT_OFFSET = 90 - MapConsts.REF_LAT;
|
||||
|
||||
/**
|
||||
* Zamienia długość geograficzną w systemie WGS-84 na współrzędna x klasy {@link Grid}.
|
||||
*
|
||||
* @param lon długość geograficzna
|
||||
* @return współrzędna x klasy GridCoord
|
||||
*/
|
||||
public static int convertLonToGridX2(double lon) {
|
||||
double xx = (lon + REF_LON_OFFSET) * INVERT_SS_DELTA_LON;
|
||||
return (int) xx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zamienia szerokość geograficzną w systemie WGS-84 na współrzędna y klasy {@link Grid}.
|
||||
*
|
||||
* @param lat szerokość geograficzna
|
||||
* @return współrzędna y klasy GridCoord
|
||||
*/
|
||||
public static int convertLatToGridY2(double lat) {
|
||||
double yy = (lat + REF_LAT_OFFSET) * INVERT_SS_DELTA_LAT;
|
||||
return (int) yy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zamienia dlugosc geog. xms w milisekundach na IdKwadrat.x.
|
||||
*
|
||||
* @param xms długość geograficzna (lon) w milisekundach
|
||||
* @return współrzędna GridCoord.x
|
||||
*/
|
||||
public static int zamienWspXmsNaIdKwadratuX(long xms) {
|
||||
// wspolrzedne geograficzne w milisekundach zawieraja sie w zakresie:
|
||||
// 0 <= x < 360 dlugosc geograficzna
|
||||
// 0 <= y <= 180 szerokosc geograficzna
|
||||
if (xms >= MapConsts.ANGLE_360_MS) {
|
||||
// poza zakresem
|
||||
return -1;
|
||||
}
|
||||
long x = xms;
|
||||
if (x < MapConsts.X_REF_MS) {
|
||||
// // poza zakresem
|
||||
long dx = x + MapConsts.ANGLE_360_MS - MapConsts.X_REF_MS;
|
||||
if (dx > MapConsts.DX_REF_MS) {
|
||||
return -1;
|
||||
}
|
||||
x += MapConsts.ANGLE_360_MS;
|
||||
}
|
||||
// if (x > MapConsts.X_REF_MS + MapConsts.DX_REF_MS) {
|
||||
// // poza zakresem
|
||||
// return -1;
|
||||
// }
|
||||
// indeksowanie kwadratow pola walki zaczyna sie od (0, 0)
|
||||
double xx = (x - MapConsts.X_REF_MS) * INVERT_SS_DELTA_LON_MS;
|
||||
// x = (x - MapConsts.X_REF_MS) / MapConsts.SS_DX_MS;
|
||||
return (int) xx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zamienia szerokosc geog. yms w milisekundach na IdKwadrat.y.
|
||||
*
|
||||
* @param yms szerokosc geograficzna (lat) w milisekundach
|
||||
* @return współrzędna GridCoord.y
|
||||
*/
|
||||
public static int zamienWspYmsNaIdKwadratuY(long yms) {
|
||||
// wspolrzedne geograficzne w milisekundach zawieraja sie w zakresie:
|
||||
// 0 <= x < 360 dlugosc geograficzna
|
||||
// 0 <= y <= 180 szerokosc geograficzna
|
||||
if (yms < MapConsts.Y_REF_MS) {
|
||||
// poza zakresem
|
||||
return -1;
|
||||
}
|
||||
// indeksowanie kwadratow pola walki zaczyna sie od (0, 0)
|
||||
double yy = (yms - MapConsts.Y_REF_MS) * INVERT_SS_DELTA_LAT_MS;
|
||||
// long y = (yms - MapConsts.Y_REF_MS) / MapConsts.SS_DY_MS;
|
||||
return (int) yy;
|
||||
}
|
||||
|
||||
private static final double INVERT_SS_DELTA_LON_MS = 1.0 / MapConsts.SS_DELTA_LON_MS;
|
||||
private static final double INVERT_SS_DELTA_LAT_MS = 1.0 / MapConsts.SS_DELTA_LAT_MS;
|
||||
|
||||
/**
|
||||
* Funkcja służy do konwersji współrzednych elipsoidalnych WGS84 (lat/lon) na płaskie X-northing, Y-easting
|
||||
* odwzorowania kartograficznego 1992.
|
||||
*
|
||||
* @param puwgCoord współrzędne PUWG1992 (easting, northing) [metry]
|
||||
* @param lat szerokość geograficzna WSG-84 [stopnie dziesiętnie]
|
||||
* @param lon długość geograficzna WSG-84 [stopnie dziesiętnie]
|
||||
*/
|
||||
public static void convertWGS84ToPUWG1992(double lat, double lon, Coord.Puwg puwgCoord) {
|
||||
if (lon < 13.5 || lon > 25.5) {
|
||||
//Błędna wartość długości geograficznej (zwracana wartość 999999999999999)
|
||||
puwgCoord.easting = 999999999999999.0;
|
||||
puwgCoord.northing = 999999999999999.0;
|
||||
return;
|
||||
}
|
||||
double latRad = Math.toRadians(lat);
|
||||
double dlam = Math.toRadians(lon - 19.0);
|
||||
double dlam_pow_2 = dlam * dlam;
|
||||
double dlam_pow_3 = dlam_pow_2 * dlam;
|
||||
double dlam_pow_4 = dlam_pow_3 * dlam;
|
||||
double s = Math.sin(latRad);
|
||||
double c = Math.cos(latRad);
|
||||
double c_pow_2 = c * c;
|
||||
double c_pow_3 = c_pow_2 * c;
|
||||
double c_pow_4 = c_pow_3 * c;
|
||||
double t = s / c;
|
||||
double t_pow_2 = t * t;
|
||||
double t_pow_3 = t_pow_2 * t;
|
||||
double t_pow_4 = t_pow_3 * t;
|
||||
double t_pow_5 = t_pow_4 * t;
|
||||
double eta = E2_SQUARED * c_pow_2;
|
||||
double eta_pow_2 = eta * eta;
|
||||
double eta_pow_3 = eta_pow_2 * eta;
|
||||
double eta_pow_4 = eta_pow_3 * eta;
|
||||
double sn = sphsn(latRad);
|
||||
double tmd = sphtmd(latRad);
|
||||
double t1, t2, t3, t4, t5;
|
||||
t1 = tmd * OK;
|
||||
double sns = sn * s;
|
||||
t2 = sns * c * OK / 2.0;
|
||||
t3 = sns * c_pow_3 * OK * (5.0 - t_pow_2 + 9.0 * eta + 4.0 * eta_pow_2) / 24.0;
|
||||
t4 = sns * c_pow_4 * c * OK * (61.0 - 58.0 * t_pow_2 + t_pow_4 + 270.0 * eta - 330.0 * t_pow_2 * eta + 445.0 * eta_pow_2 + 324.0 * eta_pow_3 - 680.0 * t_pow_2 * eta_pow_2 + 88.0 * eta_pow_4 - 600.0 * t_pow_2 * eta_pow_3 - 192.0 * t_pow_2 * eta_pow_4) / 720.0;
|
||||
t5 = sns * c_pow_4 * c_pow_3 * OK * (1385.0 - 3111.0 * t_pow_2 + 543.0 * t_pow_4 - t_pow_5 * t) / 40320.0;
|
||||
puwgCoord.northing = -5300000.0 + t1 + dlam_pow_2 * t2 + dlam_pow_4 * t3 + dlam_pow_4 * dlam_pow_2 * t4 + dlam_pow_4 * dlam_pow_4 * t5;
|
||||
t1 = sn * c * OK;
|
||||
t2 = sn * c_pow_3 * OK * (1.0 - t_pow_2 + eta) / 6.0;
|
||||
t3 = sn * c_pow_4 * c * OK * (5.0 - 18.0 * t_pow_2 + t_pow_4 + 14.0 * eta - 58.0 * t_pow_2 * eta + 13.0 * eta_pow_2 + 4.0 * eta_pow_3 - 64.0 * t_pow_2 * eta_pow_2 - 24.0 * t_pow_2 * eta_pow_3) / 120.0;
|
||||
t4 = sn * c_pow_4 * c_pow_3 * OK * (61.0 - 479.0 * t_pow_2 + 179.0 * t_pow_4 - t_pow_5 * t) / 5040.0;
|
||||
puwgCoord.easting = 500000.0 + dlam * t1 + dlam_pow_3 * t2 + dlam_pow_4 * dlam * t3 + dlam_pow_4 * dlam_pow_3 * t4;// + 0.5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja do konwersji współrzędnych płaskich X/Y odwzorowania kartograficznego 1992 na elipsoidalne lat/lon elipsoide WGS84.
|
||||
* <p>
|
||||
* PUWGCoord.proj: odwzorowanie kartograficzne (proj = 1 odpowiada odwzorowaniu 1992, natomiast każda inna odwzorowaniu 2000)
|
||||
*
|
||||
* @param northing współrzędne na osi OY odwzorowania kartograficznego PUWG-1992 do konwersji [metry]
|
||||
* @param easting współrzędne na osi OX odwzorowania kartograficznego PUWG-1992 do konwersji [metry]
|
||||
* @param geoCoord współrzędne geograficzne odwzorowania WGS-84 po konwersji [stopnie]
|
||||
*/
|
||||
public static void convertPUWG1992ToWGS84(double northing, double easting, Coord.Geo geoCoord) {
|
||||
double tmd = (northing + 5300000.0) / OK;
|
||||
double sr = sphsr(0.0);
|
||||
double ftphi = tmd / sr;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
ftphi += (tmd - sphtmd(ftphi)) / sphsr(ftphi);
|
||||
}
|
||||
sr = sphsr(ftphi);
|
||||
double sn = sphsn(ftphi);
|
||||
double sn_pow_2 = sn * sn;
|
||||
double sn_pow_3 = sn_pow_2 * sn;
|
||||
double sn_pow_4 = sn_pow_3 * sn;
|
||||
double sn_pow_5 = sn_pow_4 * sn;
|
||||
double sn_pow_7 = sn_pow_5 * sn_pow_2;
|
||||
double s = Math.sin(ftphi);
|
||||
double c = Math.cos(ftphi);
|
||||
double t = s / c;
|
||||
double t_pow_2 = t * t;
|
||||
double t_pow_4 = t_pow_2 * t_pow_2;
|
||||
double t_pow_6 = t_pow_4 * t_pow_2;
|
||||
double eta = E2_SQUARED * (c * c);
|
||||
double eta_pow_2 = eta * eta;
|
||||
double eta_pow_3 = eta_pow_2 * eta;
|
||||
double eta_pow_4 = eta_pow_2 * eta_pow_2;
|
||||
double de = easting - 500000.0;
|
||||
double de_pow_2 = de * de;
|
||||
double de_pow_3 = de_pow_2 * de;
|
||||
double de_pow_4 = de_pow_3 * de;
|
||||
double t0, t1, t2, t3;
|
||||
t0 = t / (2.0 * sr * sn * OK_POW_2);
|
||||
t1 = t * (5.0 + 3.0 * t_pow_2 + eta - 4.0 * eta_pow_2 - 9.0 * t_pow_2 * eta) / (24.0 * sr * sn_pow_3 * OK_POW_4);
|
||||
t2 = t * (61.0 + 90.0 * t_pow_2 + 46.0 * eta + 45.0 * t_pow_4 - 252.0 * t_pow_2 * eta - 3.0 * eta_pow_2 + 100.0 * eta_pow_3 - 66.0 * t_pow_2 * eta_pow_2 - 90.0 * t_pow_4 * eta + 88.0 * eta_pow_4 + 225.0 * t_pow_4 * eta_pow_2 + 84.0 * t_pow_2 * eta_pow_3 - 192.0 * t_pow_2 * eta_pow_4) / (720.0 * sr * sn_pow_5 * OK_POW_6);
|
||||
t3 = t * (1385.0 + 3633.0 * t_pow_2 + 4095.0 * t_pow_4 + 1575.0 * t_pow_6) / (40320.0 * sr * sn_pow_7 * (OK_POW_8));
|
||||
double latrad = ftphi - de_pow_2 * t0 + de_pow_4 * t1 - de_pow_3 * de_pow_3 * t2 + de_pow_4 * de_pow_3 * t3;
|
||||
t0 = 1.0 / (sn * c * OK);
|
||||
t1 = (1.0 + 2.0 * t_pow_2 + eta) / (6.0 * sn_pow_3 * c * (OK_POW_3));
|
||||
t2 = (5.0 + 6.0 * eta + 28.0 * t_pow_2 - 3.0 * eta_pow_2 + 8.0 * t_pow_2 * eta + 24.0 * t_pow_4 - 4.0 * eta_pow_3 + 4.0 * t_pow_2 * eta_pow_2 + 24.0 * t_pow_2 * eta_pow_3) / (120.0 * sn_pow_5 * c * (OK_POW_5));
|
||||
t3 = (61.0 + 662.0 * t_pow_2 + 1320.0 * t_pow_4 + 720.0 * t_pow_6) / (5040.0 * sn_pow_7 * c * OK_POW_7);
|
||||
double dlam = de * t0 - de_pow_3 * t1 + de_pow_3 * de_pow_2 * t2 - de_pow_3 * de_pow_4 * t3;
|
||||
// 19.0 * DEG_2_RAD == 0.33161255787892263;
|
||||
// geoCoord.lon = 0.33161255787892263 + dlam;
|
||||
// geoCoord.lon *= RAD_2_DEG;
|
||||
geoCoord.lon = Math.toDegrees(dlam) + 19.0;
|
||||
geoCoord.lat = Math.toDegrees(latrad);
|
||||
}
|
||||
|
||||
/// //////////////////////////////////////////////////////////////////////////////
|
||||
// Funkcje pomocnicze i stałe
|
||||
static double calculateESquared(double a, double b) {
|
||||
a *= a;
|
||||
b *= b;
|
||||
return (a - b) / a;
|
||||
}
|
||||
|
||||
static double calculateE2Squared(double a, double b) {
|
||||
a *= a;
|
||||
b *= b;
|
||||
return (a - b) / b;
|
||||
}
|
||||
|
||||
static double denom(double sphi) {
|
||||
double sinSphi = Math.sin(sphi);
|
||||
return Math.sqrt(1.0 - E_SQUARED * (sinSphi * sinSphi));
|
||||
}
|
||||
|
||||
static double sphsr(double sphi) {
|
||||
double dn = denom(sphi);
|
||||
return A * (1.0 - E_SQUARED) / (dn * dn * dn);
|
||||
}
|
||||
|
||||
static double sphsn(double sphi) {
|
||||
double sinSphi = Math.sin(sphi);
|
||||
return A / Math.sqrt(1.0 - E_SQUARED * (sinSphi * sinSphi));
|
||||
}
|
||||
|
||||
static double sphtmd(double sphi) {
|
||||
return (AP * sphi) - (BP * Math.sin(2.0 * sphi)) + (CP * Math.sin(4.0 * sphi)) - (DP * Math.sin(6.0 * sphi)) + (EP * Math.sin(8.0 * sphi));
|
||||
}
|
||||
|
||||
/**
|
||||
* Dlługość dużej półsi, w metrach dla elipsoidy WGS-84.
|
||||
*/
|
||||
private static final double A = 6378137.0;
|
||||
|
||||
/**
|
||||
* double f: spłaszczenie elipsoidalne dla elipsoidy WGS-84, 1 / 298.257223563
|
||||
*/
|
||||
// private static final double F = 1.0 / 298.257223563;
|
||||
private static final double B = A * (1.0 - 1.0 / 298.257223563);
|
||||
private static final double E_SQUARED = calculateESquared(A, B);
|
||||
private static final double E2_SQUARED = calculateE2Squared(A, B);
|
||||
private static final double TN = (A - B) / (A + B);
|
||||
private static final double AP = A * (1.0 - TN + 5.0 * (TN * TN - TN * TN * TN) / 4.0 + 81.0 * TN * TN * TN * TN - TN * TN * TN * TN * TN / 64.0);
|
||||
private static final double BP = 3.0 * A * (TN - TN * TN + 7.0 * (TN * TN * TN - TN * TN * TN * TN) / 8.0 + 55.0 * TN * TN * TN * TN * TN / 64.0) / 2.0;
|
||||
private static final double CP = 15.0 * A * (TN * TN - TN * TN * TN + 3.0 * (TN * TN * TN * TN - TN * TN * TN * TN * TN) / 4.0) / 16.0;
|
||||
private static final double DP = 35.0 * A * (TN * TN * TN - TN * TN * TN * TN + 11.0 * TN * TN * TN * TN * TN / 16.0) / 48.0;
|
||||
private static final double EP = 315.0 * A * (TN * TN * TN * TN - TN * TN * TN * TN * TN) / 512.0;
|
||||
|
||||
/**
|
||||
* Współczynnik zniekształcenia skali mapy w południku osiowym dla odwzorowania kartograficznego PUWG-1992.
|
||||
*/
|
||||
private static final double OK = 0.9993;
|
||||
private static final double OK_POW_2 = OK * OK;
|
||||
private static final double OK_POW_3 = OK_POW_2 * OK;
|
||||
private static final double OK_POW_4 = OK_POW_3 * OK;
|
||||
private static final double OK_POW_5 = OK_POW_4 * OK;
|
||||
private static final double OK_POW_6 = OK_POW_5 * OK;
|
||||
private static final double OK_POW_7 = OK_POW_6 * OK;
|
||||
private static final double OK_POW_8 = OK_POW_7 * OK;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje;
|
||||
package pl.wat.ms4ds.terrain;
|
||||
|
||||
class EmptyBigSquare extends BigSquare {
|
||||
|
||||
@@ -7,7 +7,7 @@ class EmptyBigSquare extends BigSquare {
|
||||
private EmptyBigSquare() {
|
||||
}
|
||||
|
||||
Kwadrat getKwadrat(int ssX, int ssY) {
|
||||
return Kwadrat.EMPTY_SQUARE;
|
||||
Square getSquare(int ssX, int ssY) {
|
||||
return Square.EMPTY;
|
||||
}
|
||||
}
|
||||
1254
src/main/java/pl/wat/ms4ds/terrain/GeomUtils.java
Normal file
1254
src/main/java/pl/wat/ms4ds/terrain/GeomUtils.java
Normal file
File diff suppressed because it is too large
Load Diff
250
src/main/java/pl/wat/ms4ds/terrain/MapConsts.java
Normal file
250
src/main/java/pl/wat/ms4ds/terrain/MapConsts.java
Normal file
@@ -0,0 +1,250 @@
|
||||
package pl.wat.ms4ds.terrain;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
public final class MapConsts {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MapConsts.class);
|
||||
|
||||
/**
|
||||
* Długość geograficzna referencyjna początku umownego układu współrzędnych w postaci siatki kwadratów. <p>
|
||||
* Wartości długości geograficznej mapowane są: [-180, 180) -> [0, 360).
|
||||
*/
|
||||
public static final int REF_LON;
|
||||
/**
|
||||
* Szerokość geograficzna referencyjna początku umownego układu współrzędnych w postaci siatki kwadratów. <p>
|
||||
* Wartości szerokości geograficznej mapowane są: [-90, 90] -> [0, 180].
|
||||
*/
|
||||
public static final int REF_LAT;
|
||||
|
||||
public static final int DELTA_LON_REF;
|
||||
public static final int DELTA_LAT_REF;
|
||||
|
||||
public static final String DATA_DIR;
|
||||
|
||||
/**
|
||||
* Nazwa pliku z konfiguracja mechanizmu odpowiedzialnego za transfer. Plik
|
||||
* musi znajdowac sie w katalogu glownym aplikacji, ewentualnie musi tu byc
|
||||
* podana sciezka bezwzgledna do niego.
|
||||
*/
|
||||
private static final String PROPERTIES_FILE = "teren.properties";
|
||||
|
||||
/**
|
||||
* Dlugosc boku duzego kwadratu na osi OX w liczbie malych kwadratow.
|
||||
*/
|
||||
public static final int SS_PER_BS_X;
|
||||
/**
|
||||
* Dlugosc boku duzego kwadratu na osi OY w liczbie malych kwadratow.
|
||||
*/
|
||||
public static final int SS_PER_BS_Y;
|
||||
/**
|
||||
* Dlugosc boku malego kwadratu w metrach.
|
||||
*/
|
||||
public static final int SS_SIZE;
|
||||
/**
|
||||
* Powierzchnia malego kwadratu w metrach.
|
||||
*/
|
||||
public static final int SS_AREA;
|
||||
/**
|
||||
* Szerokość małego kwadratu w stopniach.
|
||||
*/
|
||||
public static final double SS_DELTA_LON;
|
||||
/**
|
||||
* Wysokość małego kwadratu w stopniach.
|
||||
*/
|
||||
public static final double SS_DELTA_LAT;
|
||||
/**
|
||||
* Liczba duzych kwadratow na stopien geograficzny po osi OX (dlugosc geograficzna).
|
||||
*/
|
||||
public static final int BS_PER_DEG_X = 4;
|
||||
/**
|
||||
* Liczba duzych kwadratow na stopien geograficzny po osi OY (szerokosc geograficzna).
|
||||
*/
|
||||
public static final int BS_PER_DEG_Y = 6;
|
||||
/**
|
||||
* Szerokość duzych kwadratow w stopniach geograficznych po osi OX (dlugosc geograficzna).
|
||||
*/
|
||||
public static final double BS_DELTA_LON;
|
||||
/**
|
||||
* Wysokość duzych kwadratow w stopniach geograficznych po osi OY (szerokosc geograficzna).
|
||||
*/
|
||||
public static final double BS_DELTA_LAT;
|
||||
/**
|
||||
* Szerokości geograficzne środków kwadratów.
|
||||
*/
|
||||
static final double[] SS_LATS;
|
||||
/**
|
||||
* Długości geograficzne środków kwadratów.
|
||||
*/
|
||||
static final double[] SS_LONS;
|
||||
|
||||
static Properties properties;
|
||||
|
||||
static {
|
||||
String propertiesFileName = System.getProperty("user.dir") + "\\" + PROPERTIES_FILE;
|
||||
|
||||
properties = new Properties();
|
||||
try {
|
||||
LOGGER.debug("Odczyt ustawien z pliku: {}.", propertiesFileName);
|
||||
properties.load(new FileInputStream(propertiesFileName));
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Brak pliku z ustawieniami.");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// przesuniecie o 180 stop.
|
||||
// poludnik zerowy ma wartosc 180, zatem wspolrzedne zachodnie (ujemne) zawierają sie w <0, 180)
|
||||
// wspolrzedne wschodnie (nieujemne) zawieraja sie w przedziale <180, 360)
|
||||
REF_LON = Integer.parseInt(properties.getProperty("x_ref")) + 180;
|
||||
// przesuniecie o 90 stop.
|
||||
// rownik ma wartosc 90, zatem wspolrzedne poludniowe (ujemne) zawierają sie w <0, 90)
|
||||
// wspolrzedne polnocne (nieujemne) zawieraja sie w przedziale <90, 180>
|
||||
REF_LAT = Integer.parseInt(properties.getProperty("y_ref")) + 90;
|
||||
DELTA_LON_REF = Integer.parseInt(properties.getProperty("dx_ref"));
|
||||
DELTA_LAT_REF = Integer.parseInt(properties.getProperty("dy_ref"));
|
||||
double BS_X_NUM = DELTA_LON_REF / BS_PER_DEG_X;
|
||||
double BS_Y_NUM = DELTA_LAT_REF / BS_PER_DEG_Y;
|
||||
String val = properties.getProperty("dl_mk");
|
||||
switch (val) {
|
||||
case "20":
|
||||
SS_SIZE = 20;
|
||||
break;
|
||||
case "25":
|
||||
SS_SIZE = 25;
|
||||
break;
|
||||
case "50":
|
||||
SS_SIZE = 50;
|
||||
break;
|
||||
case "100":
|
||||
SS_SIZE = 100;
|
||||
break;
|
||||
default:
|
||||
SS_SIZE = 200;
|
||||
break;
|
||||
}
|
||||
SS_AREA = SS_SIZE * SS_SIZE;
|
||||
if (SS_SIZE == 20) {
|
||||
SS_PER_BS_X = 83 * 10;
|
||||
SS_PER_BS_Y = 93 * 10;
|
||||
SS_DELTA_LON = 1.0 / (double) (BS_PER_DEG_X * SS_PER_BS_X);
|
||||
SS_DELTA_LAT = 1.0 / (double) (BS_PER_DEG_Y * SS_PER_BS_Y);
|
||||
DATA_DIR = properties.getProperty("kwadraty_dir") + "20m/";
|
||||
} else if (SS_SIZE == 25) {
|
||||
SS_PER_BS_X = 83 * 8;
|
||||
SS_PER_BS_Y = 93 * 8;
|
||||
SS_DELTA_LON = 1.0 / (double) (BS_PER_DEG_X * SS_PER_BS_X);
|
||||
SS_DELTA_LAT = 1.0 / (double) (BS_PER_DEG_Y * SS_PER_BS_Y);
|
||||
DATA_DIR = properties.getProperty("kwadraty_dir") + "25m/";
|
||||
} else if (SS_SIZE == 50) {
|
||||
SS_PER_BS_X = 83 * 4;
|
||||
SS_PER_BS_Y = 93 * 4;
|
||||
SS_DELTA_LON = 1.0 / (double) (BS_PER_DEG_X * SS_PER_BS_X);
|
||||
SS_DELTA_LAT = 1.0 / (double) (BS_PER_DEG_Y * SS_PER_BS_Y);
|
||||
DATA_DIR = properties.getProperty("kwadraty_dir") + "50m/";
|
||||
} else if (SS_SIZE == 100) {
|
||||
SS_PER_BS_X = 83 * 2;
|
||||
SS_PER_BS_Y = 93 * 2;
|
||||
SS_DELTA_LON = 1.0 / (double) (BS_PER_DEG_X * SS_PER_BS_X);
|
||||
SS_DELTA_LAT = 1.0 / (double) (BS_PER_DEG_Y * SS_PER_BS_Y);
|
||||
DATA_DIR = properties.getProperty("kwadraty_dir") + "100m/";
|
||||
} else {
|
||||
// domyslnie dlugosc kwadratu 200m
|
||||
SS_PER_BS_X = 83;
|
||||
SS_PER_BS_Y = 93;
|
||||
SS_DELTA_LON = 1.0 / (double) (BS_PER_DEG_X * SS_PER_BS_X);
|
||||
SS_DELTA_LAT = 1.0 / (double) (BS_PER_DEG_Y * SS_PER_BS_Y);
|
||||
DATA_DIR = properties.getProperty("kwadraty_dir") + "200m/";
|
||||
}
|
||||
BS_DELTA_LON = 1.0 / (double) BS_PER_DEG_X;
|
||||
BS_DELTA_LAT = 1.0 / (double) BS_PER_DEG_Y;
|
||||
SS_LONS = new double[DELTA_LON_REF * BS_PER_DEG_X * SS_PER_BS_X];
|
||||
for (int i = 0; i < SS_LONS.length; i++) {
|
||||
SS_LONS[i] = REF_LON + SS_DELTA_LON * (i + 0.5);
|
||||
}
|
||||
SS_LATS = new double[DELTA_LAT_REF * BS_PER_DEG_Y * SS_PER_BS_Y];
|
||||
for (int i = 0; i < SS_LATS.length; i++) {
|
||||
SS_LATS[i] = REF_LAT + SS_DELTA_LAT * (i + 0.5);
|
||||
}
|
||||
LOGGER.debug("Wczytane ustawienia:\n \tLON_REF={}, LAT_REF={}, DX_REF={}, DY_REF{}, SQUARE_SIZE={}, GRID_SIZE={}x{}, DATA_DIR={}", REF_LON, REF_LAT, DELTA_LON_REF, DELTA_LAT_REF, SS_SIZE, SS_LONS.length, SS_LATS.length, DATA_DIR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Liczba milisekund na stopien.
|
||||
*/
|
||||
public static final int DEG_MS = 3600000;
|
||||
/**
|
||||
* Liczba milisekund na 360 stopni.
|
||||
*/
|
||||
public static final long ANGLE_360_MS = DEG_MS * 360;
|
||||
/**
|
||||
* Wielkosc cache'u pola walki (liczba duzych kwadratow trzymanych w RAM).
|
||||
*/
|
||||
public static final int MAX_BIG_SQUARES_IN_MEMORY = 500;
|
||||
|
||||
/**
|
||||
* Wspolrzedna referencyjna X (dlugosc geograficzna) lewego dolnego rogu mapy w stopniach geograficznych.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getX_REF() {
|
||||
return REF_LON;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wspolrzedna referencyjna Y (szerokosc geograficzna) lewego dolnego rogu mapy w stopniach geograficznych.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getY_REF() {
|
||||
return REF_LAT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Szerokosc referencyjna prostokata pola walki w stopniach na osi OX (dlugosc geograficzna).
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getDX_REF() {
|
||||
return DELTA_LON_REF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wysokosc referencyjna prostokata pola walki w stopniach na osi OY (szerokosc geograficzna).
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getDY_REF() {
|
||||
return DELTA_LAT_REF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dlugosci bokow malego kwadratu w milisekundach geograficznych po osi OX (dlugosc geograficzna).
|
||||
*/
|
||||
public static final double SS_DELTA_LON_MS = SS_DELTA_LON * DEG_MS;
|
||||
/**
|
||||
* Dlugosci bokow malego kwadratu w milisekundach geograficznych po osi OY (szerokosc geograficzna).
|
||||
*/
|
||||
public static final double SS_DELTA_LAT_MS = SS_DELTA_LAT * DEG_MS;
|
||||
// wspolrzedne dolnego lewego rogu mapy w ms
|
||||
// wspolrzedne geograficzne w milisekundach zawieraja sie w zakresie:
|
||||
// 0 <= x < 360 dlugosc geograficzna
|
||||
// 0 <= y <= 180 szerokosc geograficzna
|
||||
public static final int X_REF_MS = REF_LON * DEG_MS;
|
||||
public static final int Y_REF_MS = REF_LAT * DEG_MS;
|
||||
public static final int DX_REF_MS = DEG_MS * DELTA_LON_REF; // szerokosc pola walki w stopniach
|
||||
public static final int DY_REF_MS = DEG_MS * DELTA_LAT_REF; // wysokosc polwa walki w stopniach
|
||||
|
||||
public static final int BS_DX_MS = (int) (BS_DELTA_LON * DEG_MS);
|
||||
public static final int BS_DY_MS = (int) (BS_DELTA_LAT * DEG_MS);
|
||||
|
||||
/**
|
||||
* Liczba malych kwadratow przypadajaca na bok arkusza mapy drogowej.
|
||||
*/
|
||||
public static final int SS_PER_SHEET = 20;
|
||||
|
||||
|
||||
}
|
||||
323
src/main/java/pl/wat/ms4ds/terrain/RightBigSquare.java
Normal file
323
src/main/java/pl/wat/ms4ds/terrain/RightBigSquare.java
Normal file
@@ -0,0 +1,323 @@
|
||||
package pl.wat.ms4ds.terrain;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pl.wat.ms4ds.terrain.nmt.NmtDataGenerator;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class RightBigSquare extends BigSquare {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(RightBigSquare.class);
|
||||
|
||||
private Square[][] squares;
|
||||
|
||||
Square getSquare(int ssX, int ssY) {
|
||||
return squares[ssX][ssY];
|
||||
}
|
||||
|
||||
public RightBigSquare() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zapisująca do pliku duży kwadrat.<p>
|
||||
*
|
||||
* @param newDir opcjonalna nowa lokalizacja pliku
|
||||
* @throws IOException generowany wyjątek
|
||||
*/
|
||||
void writeToFile(String newDir) throws IOException {
|
||||
String fn;
|
||||
if (newDir != null) {
|
||||
fn = newDir + fileName + ".bin";
|
||||
} else {
|
||||
fn = MapConsts.DATA_DIR + fileName + ".bin";
|
||||
}
|
||||
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(fn));
|
||||
byte[] buf = new byte[10 * 256];
|
||||
int offset = 0;
|
||||
for (int x = 0; x < squares.length; x++) {
|
||||
for (int y = 0; y < squares[0].length; y++) {
|
||||
Square square = squares[x][y];
|
||||
offset = square.writeToBuffer(buf, offset);
|
||||
if (offset >= buf.length) {
|
||||
out.write(buf);
|
||||
offset = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (offset > 0) {
|
||||
out.write(buf, 0, offset);
|
||||
}
|
||||
out.close();
|
||||
logger.debug("Zapisano plik mapy: {}", fn);
|
||||
}
|
||||
|
||||
void readFromFile(String dir) throws IOException {
|
||||
if (fileName == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String fullPath = dir + fileName + ".bin";
|
||||
BufferedInputStream in = new BufferedInputStream(new FileInputStream(fullPath), 2 * 8192);
|
||||
byte[] buffer = new byte[10 * 512];
|
||||
int offset = 0;
|
||||
int count = in.read(buffer);
|
||||
squares = new Square[MapConsts.SS_PER_BS_X][MapConsts.SS_PER_BS_Y];
|
||||
for (int x = 0; x < MapConsts.SS_PER_BS_X; x++) {
|
||||
for (int y = 0; y < MapConsts.SS_PER_BS_Y; y++) {
|
||||
Square kw = new Square(x, y);
|
||||
if (offset >= count) {
|
||||
count = in.read(buffer);
|
||||
offset = 0;
|
||||
}
|
||||
offset = kw.readFromBuffer(buffer, offset);
|
||||
squares[x][y] = kw;
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
logger.debug("Doczytano plik mapy: {}", fullPath);
|
||||
} catch (IOException e) {
|
||||
squares = null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generuje nowe, wyzerowane kwadraty w danej skali w nowym formacie.
|
||||
*
|
||||
* @param dir
|
||||
* @param dlmk
|
||||
* @throws IOException
|
||||
*/
|
||||
public void writeToFile_ElevationOnly(String dir, int dlmk) throws IOException {
|
||||
if (MapConsts.SS_SIZE != 100) {
|
||||
// operacja tylko dla danych terenowych o kwadratach 200m
|
||||
return;
|
||||
}
|
||||
final int m;
|
||||
String s = "";
|
||||
if (dlmk == 100) {
|
||||
m = 1;
|
||||
s = "100m/";
|
||||
} else if (dlmk == 50) {
|
||||
m = 2;
|
||||
s = "50m/";
|
||||
} else if (dlmk == 25) {
|
||||
m = 4;
|
||||
s = "25m/";
|
||||
} else if (dlmk == 20) {
|
||||
m = 5;
|
||||
s = "20m/";
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(100);
|
||||
sb.append(dir);
|
||||
sb.append(s);
|
||||
// Utworzenie katalogów, gdyby nie istniały.
|
||||
File directory = new File(sb.toString());
|
||||
directory.mkdirs();
|
||||
sb.append(fileName + ".bin");
|
||||
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(sb.toString()));
|
||||
byte[] buf = new byte[10 * 256];
|
||||
int offset = 0;
|
||||
for (int x = 0; x < squares.length; x++) {
|
||||
for (int i = 0; i < m; i++) {
|
||||
for (int y = 0; y < squares[0].length; y++) {
|
||||
Square square = squares[x][y];
|
||||
if (square.elevation > NmtDataGenerator.H_MAX) {
|
||||
logger.warn("Elevation: {}, fn= {}", square.elevation, fileName);
|
||||
}
|
||||
for (int j = 0; j < m; j++) {
|
||||
offset = square.writeToBuffer_ElevationOnly(buf, offset);
|
||||
if (offset >= buf.length) {
|
||||
out.write(buf);
|
||||
offset = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (offset > 0) {
|
||||
out.write(buf, 0, offset);
|
||||
}
|
||||
out.close();
|
||||
logger.debug("Zapisano plik mapy: {}", fileName);
|
||||
}
|
||||
|
||||
public void writeToFile_OldFormat(String dir) throws IOException {
|
||||
StringBuilder sb = new StringBuilder(100);
|
||||
sb.append(dir);
|
||||
// Utworzenie katalogów, gdyby nie istniały.
|
||||
File directory = new File(sb.toString());
|
||||
directory.mkdirs();
|
||||
sb.append(fileName);
|
||||
if (fileName.indexOf('.') < 0) {
|
||||
sb.append(".bin");
|
||||
}
|
||||
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(sb.toString()));
|
||||
for (int x = 0; x < squares.length; x++) {
|
||||
for (int y = 0; y < squares[0].length; y++) {
|
||||
Square square = squares[x][y];
|
||||
int hex_s = 0;
|
||||
int hex_w = 0;
|
||||
int hex_b = 0;
|
||||
int hex_f = 0;
|
||||
switch (square.terrainType) {
|
||||
// case 0, 1, 4:
|
||||
// hex = 0;
|
||||
// break;
|
||||
case SWAMP:
|
||||
hex_s = 100;
|
||||
break;
|
||||
case WATER:
|
||||
hex_w = 100;
|
||||
break;
|
||||
case BUILDINGS:
|
||||
hex_b = 100;
|
||||
break;
|
||||
case FOREST:
|
||||
hex_f = 100;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
out.writeByte(hex_f);
|
||||
out.writeByte(hex_w);
|
||||
out.writeByte(hex_b);
|
||||
out.writeByte(hex_s);
|
||||
int elevation = (int) square.elevation;
|
||||
out.writeInt(elevation);
|
||||
// Różnica wzniesień.
|
||||
out.writeInt(0);
|
||||
int bit_1;
|
||||
int hex = 0;
|
||||
bit_1 = 1;
|
||||
byte[] roads = square.roads;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
// jest odcinek drogi na tym kierunku
|
||||
if (roads[i] > 0) {
|
||||
hex |= bit_1;
|
||||
}
|
||||
bit_1 <<= 1;
|
||||
}
|
||||
out.writeByte(hex);
|
||||
hex = 0;
|
||||
bit_1 = 1;
|
||||
byte[] watercourses = square.watercourses;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
// jest odcinek przeszkody wodnej na tym kierunku
|
||||
if (watercourses[i] > 1) {
|
||||
hex |= bit_1;
|
||||
}
|
||||
bit_1 <<= 1;
|
||||
}
|
||||
out.writeByte(hex);
|
||||
hex = 0;
|
||||
bit_1 = 1;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
// jest odcinek rowu na tym kierunku
|
||||
if (watercourses[i] == 1) {
|
||||
hex |= bit_1;
|
||||
}
|
||||
bit_1 <<= 1;
|
||||
}
|
||||
out.writeByte(hex);
|
||||
}
|
||||
}
|
||||
out.close();
|
||||
logger.debug("Zapisano nowy plik mapy: {}", sb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Konstruktor ladujacy duzy kwadrat z pliku binarnego w starym formacie.
|
||||
*
|
||||
* @param dir opcjonalny katalog z danymi
|
||||
*
|
||||
*/
|
||||
void readFromFile_OldFormat(String dir) throws IOException {
|
||||
if (fileName == null) {
|
||||
return;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(100);
|
||||
if (dir == null) {
|
||||
sb.append(MapConsts.DATA_DIR);
|
||||
} else {
|
||||
sb.append(dir);
|
||||
}
|
||||
sb.append(fileName).append(".bin");
|
||||
try {
|
||||
ObjectInputStream in = new ObjectInputStream(new FileInputStream(sb.toString()));
|
||||
squares = new Square[MapConsts.SS_PER_BS_X][MapConsts.SS_PER_BS_Y];
|
||||
for (int x = 0; x < MapConsts.SS_PER_BS_X; x++) {
|
||||
for (int y = 0; y < MapConsts.SS_PER_BS_Y; y++) {
|
||||
Square kw = new Square(x, y);
|
||||
squares[x][y] = kw;
|
||||
kw.terrainType = TerrainType.NONE;
|
||||
int hex = in.readByte();
|
||||
if (hex > 30) {
|
||||
kw.terrainType = TerrainType.FOREST;
|
||||
}
|
||||
hex = in.readByte();
|
||||
if (hex > 30) {
|
||||
kw.terrainType = TerrainType.WATER;
|
||||
}
|
||||
hex = in.readByte();
|
||||
if (hex > 30) {
|
||||
kw.terrainType = TerrainType.BUILDINGS;
|
||||
}
|
||||
hex = in.readByte();
|
||||
if (hex > 30) {
|
||||
kw.terrainType = TerrainType.SWAMP;
|
||||
}
|
||||
kw.elevation = in.readInt();
|
||||
if (kw.elevation < NmtDataGenerator.H_MIN) {
|
||||
logger.warn("Elevation: {}, fn= {}", kw.elevation, fileName);
|
||||
}
|
||||
if (kw.elevation > NmtDataGenerator.H_MAX) {
|
||||
logger.warn("Elevation: {}, fn= {}", kw.elevation, fileName);
|
||||
}
|
||||
// Pomijam dane o różnicy wzniesień.
|
||||
in.readInt();
|
||||
int bit_1 = 1;
|
||||
hex = in.readByte();
|
||||
for (int i = 0; i < 8; i++) {
|
||||
// jest odcinek rowu na tym kierunku
|
||||
if ((hex & bit_1) != 0) {
|
||||
kw.roads[i] = 2;
|
||||
}
|
||||
bit_1 <<= 1;
|
||||
}
|
||||
bit_1 = 1;
|
||||
hex = in.readByte();
|
||||
for (int i = 0; i < 8; i++) {
|
||||
// jest odcinek rzeki na tym kierunku
|
||||
if ((hex & bit_1) != 0) {
|
||||
kw.watercourses[i] = 3;
|
||||
}
|
||||
bit_1 <<= 1;
|
||||
}
|
||||
bit_1 = 1;
|
||||
hex = in.readByte();
|
||||
for (int i = 0; i < 8; i++) {
|
||||
// jest odcinek rowu na tym kierunku
|
||||
if ((hex & bit_1) != 0) {
|
||||
kw.watercourses[i] = 1;
|
||||
}
|
||||
bit_1 <<= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
logger.debug("Doczytano plik mapy: {}", sb);
|
||||
} catch (IOException e) {
|
||||
squares = null;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RightBigSquare{" + fileName + '}';
|
||||
}
|
||||
}
|
||||
260
src/main/java/pl/wat/ms4ds/terrain/Square.java
Normal file
260
src/main/java/pl/wat/ms4ds/terrain/Square.java
Normal file
@@ -0,0 +1,260 @@
|
||||
package pl.wat.ms4ds.terrain;
|
||||
|
||||
/**
|
||||
*
|
||||
* A class representing the characteristics of a square of terrain within a regular grid.
|
||||
*
|
||||
*/
|
||||
public class Square {
|
||||
|
||||
/**
|
||||
* Horizontal grid coordinate.
|
||||
*/
|
||||
public final int x;
|
||||
/**
|
||||
* Vertical grid coordinate.
|
||||
*/
|
||||
public final int y;
|
||||
|
||||
/**
|
||||
* The height above the level of the sea. Unit of measure meter [m].
|
||||
*/
|
||||
public float elevation;
|
||||
|
||||
/**
|
||||
* Terrain type. <p></p>Possible values:
|
||||
* 0 - BARE_GROUND
|
||||
* 1 - GRASS
|
||||
* 2 - SWAMP
|
||||
* 3 - WATER
|
||||
* 4 - SCRUB, BUSHES
|
||||
* 5 - BUILDINGS
|
||||
* 6 - FOREST
|
||||
*/
|
||||
public TerrainType terrainType;
|
||||
|
||||
/**
|
||||
* Type of watercourse (water obstacle) in a given direction. Each index corresponds to a given direction.
|
||||
* <p></p>Possible values: 0 - no watercourse, 1 - drain, ditch, 2 - canal, stream, 3 - river
|
||||
*/
|
||||
public final byte[] watercourses;
|
||||
|
||||
/**
|
||||
* Type of road in a given direction. Each index corresponds to a given direction.
|
||||
* <p></p>Possible values: 0 - no road, 1 - small roads, 2 - minor roads, 3 - major roads
|
||||
*/
|
||||
public final byte[] roads;
|
||||
|
||||
/**
|
||||
* A type of crossing that allows overcoming terrain obstacles, e.g. rivers.
|
||||
* <p></p>Possible values: 0 - none, 1 - bridge, 2 - tunnel
|
||||
*/
|
||||
public CrossingType crossingType;
|
||||
|
||||
/**
|
||||
* Size of the square.
|
||||
*/
|
||||
public static final int SIZE = 50;
|
||||
|
||||
public enum CrossingType {
|
||||
NONE(0),
|
||||
BRIDGE(1),
|
||||
TUNNEL(2);
|
||||
|
||||
static final CrossingType[] values = values();
|
||||
|
||||
public static CrossingType valueById(int id) {
|
||||
return (0 <= id && id <= 2) ? values[id] : NONE;
|
||||
}
|
||||
|
||||
public final int id;
|
||||
|
||||
CrossingType(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obiekt reprezentujący tzw. pusty kwadrat (spoza obszaru).
|
||||
*/
|
||||
public static final Square EMPTY = new Square(-1, -1);
|
||||
|
||||
public Square() {
|
||||
this(-2, -2);
|
||||
}
|
||||
|
||||
public Square(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
roads = new byte[8];
|
||||
watercourses = new byte[8];
|
||||
}
|
||||
|
||||
public int writeToBuffer_ElevationOnly(byte[] buffer, int offset) {
|
||||
// Konwersja [m] -> [0.25m].
|
||||
int elev = (short) (elevation * 4);
|
||||
byte b1 = (byte) (elev & 0xFF);
|
||||
elev >>= 8;
|
||||
byte b0 = (byte) (elev & 0xFF);
|
||||
buffer[offset] = b0;
|
||||
buffer[offset + 1] = b1;
|
||||
buffer[offset + 2] = 0;
|
||||
buffer[offset + 3] = 0;
|
||||
buffer[offset + 4] = 0;
|
||||
buffer[offset + 5] = 0;
|
||||
buffer[offset + 6] = 0;
|
||||
buffer[offset + 7] = 0;
|
||||
buffer[offset + 8] = 0;
|
||||
buffer[offset + 9] = 0;
|
||||
return offset + 10;
|
||||
}
|
||||
|
||||
public int writeToBuffer(byte[] buffer, int offset) {
|
||||
// Konwersja [m] -> [0.25m].
|
||||
int elev = (short) (elevation * 4);
|
||||
byte bit = 1;
|
||||
byte drains = 0;
|
||||
byte streams = 0;
|
||||
byte rivers = 0;
|
||||
byte smallRoads = 0;
|
||||
byte minorRoads = 0;
|
||||
byte majorRoads = 0;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
switch (watercourses[i]) {
|
||||
case 1:
|
||||
drains |= bit;
|
||||
break;
|
||||
case 2:
|
||||
streams |= bit;
|
||||
break;
|
||||
case 3:
|
||||
rivers |= bit;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (roads[i]) {
|
||||
case 1:
|
||||
smallRoads |= bit;
|
||||
break;
|
||||
case 2:
|
||||
minorRoads |= bit;
|
||||
break;
|
||||
case 3:
|
||||
majorRoads |= bit;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
bit <<= 1;
|
||||
}
|
||||
// Konwersja short -> 2 bytes
|
||||
byte b1 = (byte) (elev & 0xFF);
|
||||
elev >>= 8;
|
||||
byte b0 = (byte) (elev & 0xFF);
|
||||
buffer[offset + 1] = b1;
|
||||
buffer[offset] = b0;
|
||||
buffer[offset + 2] = (byte) terrainType.id;
|
||||
buffer[offset + 3] = smallRoads;
|
||||
buffer[offset + 4] = minorRoads;
|
||||
buffer[offset + 5] = majorRoads;
|
||||
buffer[offset + 6] = drains;
|
||||
buffer[offset + 7] = streams;
|
||||
buffer[offset + 8] = rivers;
|
||||
// 0 - brak, 1 - most, 2 - tunel
|
||||
buffer[offset + 9] = (byte) crossingType.id;
|
||||
return offset + 10;
|
||||
}
|
||||
|
||||
public int readFromBuffer(byte[] buffer, int offset) {
|
||||
// Odczyt wartości typu short
|
||||
//
|
||||
int elev = buffer[offset] & 0xFF;
|
||||
// elev = (elev << 8) + (buffer[offset + 1] & 0xFF);
|
||||
elev = (elev << 8) | (buffer[offset + 1] & 0xFF);
|
||||
// Rzutowanie "elev" na short zachowuje znak liczby.
|
||||
short v = (short) elev;
|
||||
// Konwersja jednostek [0.25m]->[m]
|
||||
elevation = (float) (v) / 4;
|
||||
terrainType = TerrainType.valueFromId(buffer[offset + 2]);
|
||||
byte smallRoads = buffer[offset + 3];
|
||||
byte minorRoads = buffer[offset + 4];
|
||||
byte majorRoads = buffer[offset + 5];
|
||||
byte drains = buffer[offset + 6];
|
||||
byte streams = buffer[offset + 7];
|
||||
byte rivers = buffer[offset + 8];
|
||||
byte b = buffer[offset + 9];
|
||||
crossingType = CrossingType.valueById(b);
|
||||
int bit = 1;
|
||||
// 8 kierunków geograficznych (0 - NORTH, 1 - NORTH_EAST, ...)
|
||||
for (int i = 0; i < 8; i++) {
|
||||
int b1 = ((majorRoads & bit) != 0) ? 3 : 0;
|
||||
int b2 = ((minorRoads & bit) != 0) ? 2 : 0;
|
||||
int b3 = ((smallRoads & bit) != 0) ? 1 : 0;
|
||||
roads[i] = (byte) (b1 + b2 + b3);
|
||||
b1 = ((rivers & bit) != 0) ? 3 : 0;
|
||||
b2 = ((streams & bit) != 0) ? 2 : 0;
|
||||
b3 = ((drains & bit) != 0) ? 1 : 0;
|
||||
watercourses[i] = (byte) (b1 + b2 + b3);
|
||||
bit <<= 1;
|
||||
}
|
||||
return offset + 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object o) {
|
||||
if (!(o instanceof Square square)) return false;
|
||||
|
||||
return x == square.x && y == square.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 7;
|
||||
result = 31 * result + x;
|
||||
result = 31 * result + y;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder linia = new StringBuilder(100);
|
||||
linia.append("[");
|
||||
char c = switch (terrainType) {
|
||||
case NONE -> 'G';
|
||||
case GRASS -> 'g';
|
||||
case SWAMP -> 'S';
|
||||
case WATER -> 'W';
|
||||
case SCRUB_BUSHES -> 'R';
|
||||
case BUILDINGS -> 'B';
|
||||
case FOREST -> 'F';
|
||||
};
|
||||
linia.append(c);
|
||||
linia.append(' ');
|
||||
String s = String.format("%7.2f", elevation);
|
||||
linia.append(s);
|
||||
linia.append(' ');
|
||||
for (byte road : roads) {
|
||||
c = switch (road) {
|
||||
case 1 -> '1';
|
||||
case 2 -> '2';
|
||||
case 3 -> '3';
|
||||
default -> '0';
|
||||
};
|
||||
linia.append(c);
|
||||
}
|
||||
linia.append(' ');
|
||||
for (byte watercours : watercourses) {
|
||||
c = switch (watercours) {
|
||||
case 1 -> '1';
|
||||
case 2 -> '2';
|
||||
case 3 -> '3';
|
||||
default -> '0';
|
||||
};
|
||||
linia.append(c);
|
||||
}
|
||||
linia.append(']');
|
||||
return linia.toString();
|
||||
}
|
||||
|
||||
}
|
||||
471
src/main/java/pl/wat/ms4ds/terrain/Teren.java
Normal file
471
src/main/java/pl/wat/ms4ds/terrain/Teren.java
Normal file
@@ -0,0 +1,471 @@
|
||||
package pl.wat.ms4ds.terrain;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pl.wat.ms4ds.common.ERodzajPodwozia;
|
||||
import pl.wat.ms4ds.common.ERodzajTerenuPokrycie;
|
||||
import pl.wat.ms4ds.terrain.nmt.NmtDataProvider;
|
||||
|
||||
import static pl.wat.ms4ds.terrain.Square.EMPTY;
|
||||
|
||||
public class Teren {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Teren.class);
|
||||
|
||||
private static final int BIG_X_MAX = MapConsts.DELTA_LON_REF * MapConsts.BS_PER_DEG_X;
|
||||
private static final int BIG_Y_MAX = MapConsts.DELTA_LAT_REF * MapConsts.BS_PER_DEG_Y;
|
||||
|
||||
private static final BigSquare[][] bigSquares = new BigSquare[BIG_X_MAX][BIG_Y_MAX];
|
||||
|
||||
// tablica obiektów synchronizujących dostęp do dużych kwadratów przy odczycie z pliku
|
||||
private static Object bsSynch = new Object();
|
||||
|
||||
private static final float[][] STOPIEN_PRZEJEZDNOSCI;
|
||||
|
||||
private static final String LITERALS = "ABCDEF";
|
||||
|
||||
private static boolean przejezdnoscZawsze;
|
||||
static double minStopienPrzejezd;
|
||||
static double minStopienPrzejezdNaPrzelaj;
|
||||
|
||||
private static double minStopienPrzejezdNaDrodzeNachylenie;
|
||||
private static double minStopienPrzejezdNaPrzelajNachylenie;
|
||||
|
||||
private static double minKatNachylTerenuNaDrodze;
|
||||
private static double maxKatNachylTerenuNaDrodze;
|
||||
private static double minKatNachylTerenuNaPrzelaj;
|
||||
private static double maxKatNachylTerenuNaPrzelaj;
|
||||
|
||||
/**
|
||||
* Jawne wywolanie zapisu do pliku bufora zmian terenu. Zapisane zostaną aktywne/załadowane duże kwadraty.
|
||||
*/
|
||||
public static void saveToFiles(String dir) {
|
||||
for (int i = 0; i < BIG_X_MAX; i++) {
|
||||
for (int j = 0; j < BIG_Y_MAX; j++) {
|
||||
BigSquare bs = bigSquares[i][j];
|
||||
if (bs instanceof RightBigSquare rbs) {
|
||||
try {
|
||||
rbs.writeToFile(dir);
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("Błąd zapisu pliku mapy: " + rbs.fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
reset();
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
for (int i = 0; i < BIG_X_MAX; i++) {
|
||||
for (int j = 0; j < BIG_Y_MAX; j++) {
|
||||
bigSquares[i][j] = null;
|
||||
}
|
||||
}
|
||||
cache.clear();
|
||||
System.gc();
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca nazwę pliku na podstawie współrzędnych geograficznych.
|
||||
*
|
||||
* @param lat szerokość geograficzna
|
||||
* @param lon długość geograficzna
|
||||
* @return Nazwa zwracanego pliku z danymi (null - gdy niepoprawne współrzędne).
|
||||
*/
|
||||
public static String getFileName(double lat, double lon) {
|
||||
int idX = Coord.convertLonToGridX(lon);
|
||||
int idY = Coord.convertLatToGridY(lat);
|
||||
int bigX = idX / MapConsts.SS_PER_BS_X;
|
||||
int bigY = idY / MapConsts.SS_PER_BS_Y;
|
||||
return getFileName(bigX, bigY);
|
||||
}
|
||||
|
||||
private static String getFileName(int bsX, int bsY) {
|
||||
int x_stop = MapConsts.REF_LON + bsX / MapConsts.BS_PER_DEG_X - 180;
|
||||
char cLon = (x_stop < 0) ? 'W' : 'E';
|
||||
if (x_stop < 0) {
|
||||
x_stop = -x_stop;
|
||||
}
|
||||
int dx = bsX % MapConsts.BS_PER_DEG_X;
|
||||
char cx = LITERALS.charAt(dx);
|
||||
int y_stop = MapConsts.REF_LAT + bsY / MapConsts.BS_PER_DEG_Y - 90;
|
||||
char cLat = (y_stop < 0) ? 'S' : 'N';
|
||||
if (y_stop < 0) {
|
||||
y_stop = -y_stop;
|
||||
}
|
||||
int dy = bsY % MapConsts.BS_PER_DEG_Y;
|
||||
char cy = LITERALS.charAt(dy);
|
||||
// przykładowa nazwa pliku: E024B_N50F
|
||||
//
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(cLon);
|
||||
if (x_stop < 10) {
|
||||
sb.append("00");
|
||||
} else if (x_stop < 100) {
|
||||
sb.append('0');
|
||||
}
|
||||
sb.append(x_stop);
|
||||
sb.append(cx);
|
||||
sb.append('_');
|
||||
sb.append(cLat);
|
||||
if (y_stop < 10) {
|
||||
sb.append('0');
|
||||
}
|
||||
sb.append(y_stop);
|
||||
sb.append(cy);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static BigSquare loadArea_OldFormat(int bsX, int bsY) {
|
||||
String fName = getFileName(bsX, bsY);
|
||||
try {
|
||||
RightBigSquare bs = new RightBigSquare();
|
||||
bs.fileName = fName;
|
||||
bs.readFromFile_OldFormat(MapConsts.DATA_DIR);
|
||||
return bs;
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("Brak pliku mapy: {}{}{}", MapConsts.DATA_DIR, fName, ".bin");
|
||||
return EmptyBigSquare.EMPTY_BIG_SQUARE;
|
||||
}
|
||||
}
|
||||
|
||||
private static BigSquare loadArea(int bsX, int bsY) {
|
||||
String fName = getFileName(bsX, bsY);
|
||||
try {
|
||||
RightBigSquare bs = new RightBigSquare();
|
||||
bs.fileName = fName;
|
||||
bs.readFromFile(MapConsts.DATA_DIR);
|
||||
return bs;
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("Brak pliku mapy: {}{}{}", MapConsts.DATA_DIR, fName, ".bin");
|
||||
return EmptyBigSquare.EMPTY_BIG_SQUARE;
|
||||
}
|
||||
}
|
||||
|
||||
private static ReentrantLock synchr;
|
||||
|
||||
public static Square getKwadratPUWG(double northing, double easting) {
|
||||
Coord.Geo geoCoord = new Coord.Geo();
|
||||
Coord.convertPUWG1992ToWGS84(northing, easting, geoCoord);
|
||||
return getSquare(geoCoord.lat, geoCoord.lon);
|
||||
}
|
||||
|
||||
public static Square getSquare(double lat, double lon) {
|
||||
int idX = Coord.convertLonToGridX(lon);
|
||||
int idY = Coord.convertLatToGridY(lat);
|
||||
return getSquare(idX, idY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca kwadrat o podanych współrzędnych siatki (grida).
|
||||
*
|
||||
* @param x współrzędna pozioma (indeks kolumny)
|
||||
* @param y współrzędna pionowa (indeks wiersza)
|
||||
* @return obiekt reprezentujący charakterystyki fragmentu terenu
|
||||
*/
|
||||
public static Square getSquare(int x, int y) {
|
||||
if (x < 0 || y < 0) {
|
||||
return EMPTY;
|
||||
}
|
||||
// wspolrzędna x dużego kwadratu
|
||||
int bsX = x / MapConsts.SS_PER_BS_X;
|
||||
// wspolrzędna y dużego kwadratu
|
||||
int bsY = y / MapConsts.SS_PER_BS_Y;
|
||||
if (bsX >= BIG_X_MAX || bsY >= BIG_Y_MAX) {
|
||||
return EMPTY;
|
||||
}
|
||||
// wspolrzędna x małego kwadratu w ramach dużego kwadratu
|
||||
int ssX = x % MapConsts.SS_PER_BS_X;
|
||||
// wspolrzędna y małego kwadratu w ramach dużego kwadratu
|
||||
int ssY = y % MapConsts.SS_PER_BS_Y;
|
||||
synchronized (bsSynch) {
|
||||
if (bigSquares[bsX][bsY] == null) {
|
||||
makeRoom(bsX, bsY);
|
||||
bigSquares[bsX][bsY] = loadArea(bsX, bsY);
|
||||
}
|
||||
}
|
||||
return bigSquares[bsX][bsY].getSquare(ssX, ssY);
|
||||
}
|
||||
|
||||
private static Coord.Grid[] history = new Coord.Grid[MapConsts.MAX_BIG_SQUARES_IN_MEMORY];
|
||||
private static final ArrayList<Coord.Grid> cache = new ArrayList<>(MapConsts.MAX_BIG_SQUARES_IN_MEMORY);
|
||||
|
||||
private static void makeRoom(int bigX, int bigY) {
|
||||
if (cache.size() >= MapConsts.MAX_BIG_SQUARES_IN_MEMORY) {
|
||||
// Brak miejsca, zatem zwalniam/usuwam najstarszy element;
|
||||
Coord.Grid removing = cache.removeFirst();
|
||||
RightBigSquare rbs = (RightBigSquare) bigSquares[removing.x][removing.y];
|
||||
try {
|
||||
rbs.writeToFile(null);
|
||||
} catch (IOException _) {
|
||||
}
|
||||
bigSquares[removing.x][removing.y] = null;
|
||||
LOGGER.debug("Big square X= {}, Y= {}, fn= {} removed from cache", bigX, bigY, rbs.fileName);
|
||||
}
|
||||
cache.add(new Coord.Grid(bigX, bigY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tablica danych o braku rowów w kwadracie dla funkcji przejezdnosci, gdy nie uwzględniamy rowów.
|
||||
*/
|
||||
private static final boolean[] ROWY_DLA_PRZEJEZDNOSCI = new boolean[8];
|
||||
|
||||
private static final double TANG_ALFA_MAX_NA_DRODZE;
|
||||
private static final double TANG_ALFA_MIN_NA_DRODZE;
|
||||
|
||||
private static final double a1;
|
||||
private static final double b1;
|
||||
|
||||
/**
|
||||
* Funkcja opisujaca zmianę stopnia przejezdności podczas ruchu na drodze dla kątów w przedziale <22.5, 45>
|
||||
*
|
||||
* @param tangKataNachyl tangens kąta nachylenia zbocza
|
||||
* @return stopień przejezdności z punktu widzenia nachylenia terenu przy ruchu na drodze
|
||||
*/
|
||||
private static double stopienPrzejezdNaDrodzeNachylenie(double tangKataNachyl) {
|
||||
if (tangKataNachyl <= TANG_ALFA_MIN_NA_DRODZE) {
|
||||
return 1.0;
|
||||
}
|
||||
double st = tangKataNachyl * a1 + b1;
|
||||
return (st < minStopienPrzejezdNaDrodzeNachylenie) ? minStopienPrzejezdNaDrodzeNachylenie : st;
|
||||
}
|
||||
|
||||
private static final double TANG_ALFA_MAX_NA_PRZELAJ;
|
||||
private static final double TANG_ALFA_MIN_NA_PRZELAJ;
|
||||
|
||||
private static final double a2;
|
||||
private static final double b2;
|
||||
|
||||
/**
|
||||
* Funkcja opisujaca zmianę stopnia przejezdności podczas ruchu na przełaj dla kątów w przedziale <22.5, 45>
|
||||
*
|
||||
* @param tangKataNachyl tangens kąta nachylenia zbocza
|
||||
* @return stopień przejezdności z punktu widzenia nachylenia terenu przy ruchu na przełaj
|
||||
*/
|
||||
private static double stopienPrzejezdNaPrzelajNachylenie(double tangKataNachyl) {
|
||||
if (tangKataNachyl <= TANG_ALFA_MIN_NA_PRZELAJ) {
|
||||
return 1.0;
|
||||
}
|
||||
if (tangKataNachyl >= TANG_ALFA_MAX_NA_PRZELAJ || tangKataNachyl <= -TANG_ALFA_MAX_NA_PRZELAJ) {
|
||||
// brak przejezdnosci z powodu nachylenia
|
||||
return 0.0;
|
||||
}
|
||||
double st = tangKataNachyl * a2 + b2;
|
||||
return (st < minStopienPrzejezdNaPrzelajNachylenie) ? minStopienPrzejezdNaPrzelajNachylenie : st;
|
||||
}
|
||||
|
||||
private Teren() {
|
||||
}
|
||||
|
||||
static {
|
||||
for (int i = 0; i < history.length; i++) {
|
||||
history[i] = new Coord.Grid();
|
||||
}
|
||||
przejezdnoscZawsze = MapConsts.properties.getProperty("przejezdnosc_zawsze").equals("on");
|
||||
minStopienPrzejezd = Double.parseDouble(MapConsts.properties.getProperty("minimalny_stopien_przejezdnosci"));
|
||||
|
||||
minStopienPrzejezdNaPrzelaj = Double.parseDouble(MapConsts.properties.getProperty("stopien_przejezdnosci.minimalny_na_przelaj"));
|
||||
minStopienPrzejezdNaDrodzeNachylenie = Double.parseDouble(MapConsts.properties.getProperty("stopien_przejezdnosci.minimalny.na_drodze.nachylenie_terenu"));
|
||||
minStopienPrzejezdNaPrzelajNachylenie = Double.parseDouble(MapConsts.properties.getProperty("stopien_przejezdnosci.minimalny.na_przelaj.nachylenie_terenu"));
|
||||
|
||||
minKatNachylTerenuNaDrodze = Double.parseDouble(MapConsts.properties.getProperty("stopien_przejezdnosci.na_drodze.nachylenie_terenu.kat_minimalny"));
|
||||
minKatNachylTerenuNaDrodze = Math.max(0, minKatNachylTerenuNaDrodze);
|
||||
minKatNachylTerenuNaDrodze = Math.min(60, minKatNachylTerenuNaDrodze);
|
||||
minKatNachylTerenuNaDrodze *= Math.PI / 180;
|
||||
|
||||
maxKatNachylTerenuNaDrodze = Double.parseDouble(MapConsts.properties.getProperty("stopien_przejezdnosci.na_drodze.nachylenie_terenu.kat_maksymalny"));
|
||||
maxKatNachylTerenuNaDrodze = Math.max(0, maxKatNachylTerenuNaDrodze);
|
||||
maxKatNachylTerenuNaDrodze = Math.min(60, maxKatNachylTerenuNaDrodze);
|
||||
maxKatNachylTerenuNaDrodze *= Math.PI / 180;
|
||||
if (maxKatNachylTerenuNaDrodze < minKatNachylTerenuNaDrodze) {
|
||||
double temp = maxKatNachylTerenuNaDrodze;
|
||||
maxKatNachylTerenuNaDrodze = minKatNachylTerenuNaDrodze;
|
||||
minKatNachylTerenuNaDrodze = temp;
|
||||
}
|
||||
|
||||
minKatNachylTerenuNaPrzelaj = Double.parseDouble(MapConsts.properties.getProperty("stopien_przejezdnosci.na_przelaj.nachylenie_terenu.kat_minimalny"));
|
||||
minKatNachylTerenuNaPrzelaj = Math.max(0, minKatNachylTerenuNaPrzelaj);
|
||||
minKatNachylTerenuNaPrzelaj = Math.min(60, minKatNachylTerenuNaPrzelaj);
|
||||
minKatNachylTerenuNaPrzelaj *= Math.PI / 180;
|
||||
|
||||
maxKatNachylTerenuNaPrzelaj = Double.parseDouble(MapConsts.properties.getProperty("stopien_przejezdnosci.na_przelaj.nachylenie_terenu.kat_maksymalny"));
|
||||
maxKatNachylTerenuNaPrzelaj = Math.max(0, maxKatNachylTerenuNaPrzelaj);
|
||||
maxKatNachylTerenuNaPrzelaj = Math.min(60, maxKatNachylTerenuNaPrzelaj);
|
||||
maxKatNachylTerenuNaPrzelaj *= Math.PI / 180;
|
||||
if (maxKatNachylTerenuNaPrzelaj < minKatNachylTerenuNaPrzelaj) {
|
||||
double temp = maxKatNachylTerenuNaPrzelaj;
|
||||
maxKatNachylTerenuNaPrzelaj = minKatNachylTerenuNaPrzelaj;
|
||||
minKatNachylTerenuNaPrzelaj = temp;
|
||||
}
|
||||
|
||||
TANG_ALFA_MAX_NA_DRODZE = Math.tan(maxKatNachylTerenuNaDrodze);
|
||||
TANG_ALFA_MIN_NA_DRODZE = Math.tan(minKatNachylTerenuNaDrodze);
|
||||
a1 = (minStopienPrzejezdNaDrodzeNachylenie - 1) / (TANG_ALFA_MAX_NA_DRODZE - TANG_ALFA_MIN_NA_DRODZE);
|
||||
b1 = 1 - a1 * TANG_ALFA_MIN_NA_DRODZE;
|
||||
|
||||
TANG_ALFA_MAX_NA_PRZELAJ = Math.tan(maxKatNachylTerenuNaPrzelaj);
|
||||
TANG_ALFA_MIN_NA_PRZELAJ = Math.tan(minKatNachylTerenuNaPrzelaj);
|
||||
a2 = (minStopienPrzejezdNaPrzelajNachylenie - 1) / (TANG_ALFA_MAX_NA_PRZELAJ - TANG_ALFA_MIN_NA_PRZELAJ);
|
||||
b2 = 1 - a2 * TANG_ALFA_MIN_NA_PRZELAJ;
|
||||
|
||||
STOPIEN_PRZEJEZDNOSCI = new float[ERodzajPodwozia.numberOfValues()][ERodzajTerenuPokrycie.numberOfValues()];
|
||||
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.GASIENICE.id][ERodzajTerenuPokrycie.TEREN_ZABUDOWANY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_gasienicowe.teren_zabudowany"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.GASIENICE.id][ERodzajTerenuPokrycie.TEREN_ZALESIONY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_gasienicowe.teren_zalesiony"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.GASIENICE.id][ERodzajTerenuPokrycie.TEREN_ZABAGNIONY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_gasienicowe.teren_zabagniony"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.GASIENICE.id][ERodzajTerenuPokrycie.TEREN_ZAWODNIONY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_gasienicowe.teren_zawodniony"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.GASIENICE.id][ERodzajTerenuPokrycie.TEREN_CZYSTY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_gasienicowe.teren_czysty"));
|
||||
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.KOLA_GASIENICE.id][ERodzajTerenuPokrycie.TEREN_ZABUDOWANY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_kolowo_gasienicowe.teren_zabudowany"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.KOLA_GASIENICE.id][ERodzajTerenuPokrycie.TEREN_ZALESIONY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_kolowo_gasienicowe.teren_zalesiony"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.KOLA_GASIENICE.id][ERodzajTerenuPokrycie.TEREN_ZABAGNIONY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_kolowo_gasienicowe.teren_zabagniony"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.KOLA_GASIENICE.id][ERodzajTerenuPokrycie.TEREN_ZAWODNIONY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_kolowo_gasienicowe.teren_zawodniony"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.KOLA_GASIENICE.id][ERodzajTerenuPokrycie.TEREN_CZYSTY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_kolowo_gasienicowe.teren_czysty"));
|
||||
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.KOLA.id][ERodzajTerenuPokrycie.TEREN_ZABUDOWANY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_kolowe.teren_zabudowany"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.KOLA.id][ERodzajTerenuPokrycie.TEREN_ZALESIONY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_kolowe.teren_zalesiony"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.KOLA.id][ERodzajTerenuPokrycie.TEREN_ZABAGNIONY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_kolowe.teren_zabagniony"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.KOLA.id][ERodzajTerenuPokrycie.TEREN_ZAWODNIONY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_kolowe.teren_zawodniony"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.KOLA.id][ERodzajTerenuPokrycie.TEREN_CZYSTY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_kolowe.teren_czysty"));
|
||||
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.PODUSZKA_POW.id][ERodzajTerenuPokrycie.TEREN_ZABUDOWANY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_poduszka.teren_zabudowany"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.PODUSZKA_POW.id][ERodzajTerenuPokrycie.TEREN_ZALESIONY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_poduszka.teren_zalesiony"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.PODUSZKA_POW.id][ERodzajTerenuPokrycie.TEREN_ZABAGNIONY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_poduszka.teren_zabagniony"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.PODUSZKA_POW.id][ERodzajTerenuPokrycie.TEREN_ZAWODNIONY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_poduszka.teren_zawodniony"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.PODUSZKA_POW.id][ERodzajTerenuPokrycie.TEREN_CZYSTY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_poduszka.teren_czysty"));
|
||||
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.PLOZY.id][ERodzajTerenuPokrycie.TEREN_ZABUDOWANY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_plozy.teren_zabudowany"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.PLOZY.id][ERodzajTerenuPokrycie.TEREN_ZALESIONY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_plozy.teren_zalesiony"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.PLOZY.id][ERodzajTerenuPokrycie.TEREN_ZABAGNIONY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_plozy.teren_zabagniony"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.PLOZY.id][ERodzajTerenuPokrycie.TEREN_ZAWODNIONY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_plozy.teren_zawodniony"));
|
||||
STOPIEN_PRZEJEZDNOSCI[ERodzajPodwozia.PLOZY.id][ERodzajTerenuPokrycie.TEREN_CZYSTY.id] =
|
||||
Float.parseFloat(MapConsts.properties.getProperty("stopien_przejezdnosci.podwozie_plozy.teren_czysty"));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// boolean[] przeszk = new boolean[8];
|
||||
// boolean[] row = new boolean[8];
|
||||
// przeszk[2] = true;
|
||||
// przeszk[6] = true;
|
||||
|
||||
// Teren.poprawDaneWysokosciowe();
|
||||
|
||||
LOGGER.debug("start");
|
||||
// Teren.normalizujDanePokrycia();
|
||||
|
||||
String newDir = "D:/work/kwadraty_nmt/temp/100m/";
|
||||
String dir1 = "D:/work/terrain/";
|
||||
String inDir = "D:/work/kwadraty_nmt/withElevation/25m/";
|
||||
String dir2 = "C:/Workspace/_data/swdt/ms4ds/teren/kwadraty/100m/";
|
||||
|
||||
Set<String> fileNames = NmtDataProvider.listFiles(inDir);
|
||||
generateDataFromOldFormat(fileNames, newDir, 100);
|
||||
// Set<String> fileNames2 = new HashSet<>();
|
||||
// fileNames2.add(dir2 + "E014C_N53D.bin");
|
||||
// generateData(fileNames, inDir, newDir);
|
||||
|
||||
// Square kw = getKwadrat(1500, 2100);
|
||||
// System.out.println(kw);
|
||||
// kw = getKwadrat(2100, 1500);
|
||||
// System.out.println(kw);
|
||||
// String fn = "E017B_N54E";
|
||||
// RightBigSquare rbs = new RightBigSquare(dir2 + fn + ".bin", null);
|
||||
// rbs.writeToFileOldToNewFormatWithElevetion(dir1, 25);
|
||||
|
||||
// RightBigSquare rbs = new RightBigSquare();
|
||||
// rbs.fileName = "E017B_N54E";
|
||||
// rbs.readFromFile(dir1);
|
||||
// Teren.generateData(fileNames, dir1, newDir);
|
||||
|
||||
// Teren.generateDataOldToNewFormat(fileNames, dir2, dir1, 25);
|
||||
// Teren.wygenerujCzysteDane(dir, 25, false, false, false, false, true, false, false, false, false);
|
||||
// Teren.wyzerujDane();
|
||||
// Teren.zapisBuforaMapyDoPliku();
|
||||
// String dir1 = "D:/work/kwadraty_nmt/withElevation/25m/";
|
||||
// Set<String> fileNames = NMTDataProvider.listFiles(dir1);
|
||||
// for (String fileName : fileNames) {
|
||||
// File file = new File(fileName);
|
||||
// String fn = file.getName().substring(0, file.getName().lastIndexOf('.'));
|
||||
// RightBigSquare rbs = new RightBigSquare();
|
||||
// rbs.fileName = fn;
|
||||
// rbs.readFromFile(dir1);
|
||||
// }
|
||||
|
||||
// rbs.writeToFile(newDir);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generuje pliki z danymi w nowym formacie na podstawie danych w satrym formacie.
|
||||
*
|
||||
* @param outDir katalog z danymi terenowymi np. "d:/Workspace2/kwadraty/czyste-wysokosc/"
|
||||
* @param dlmk docelowy rozmiar generowanych kwadratów terenu
|
||||
*/
|
||||
public static void generateDataFromOldFormat(Set<String> fileNames, String outDir, int dlmk) throws IOException {
|
||||
for (String fileName : fileNames) {
|
||||
File file = new File(fileName);
|
||||
String fn = file.getName();
|
||||
RightBigSquare rbs = new RightBigSquare();
|
||||
rbs.fileName = fn.substring(0, fn.length() - 4);
|
||||
rbs.readFromFile_OldFormat(null);
|
||||
rbs.writeToFile_ElevationOnly(outDir, dlmk);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generuje pliki z danymi w starym formacie na podstawie danych w nowym formacie.
|
||||
*
|
||||
* @param outDir katalog z danymi terenowymi np. "d:/Workspace2/kwadraty/czyste-wysokosc/"
|
||||
*/
|
||||
public static void generateDataToOldFormat(Set<String> fileNames, String inDir, String outDir) throws IOException {
|
||||
for (String fileName : fileNames) {
|
||||
File file = new File(fileName);
|
||||
String fn = file.getName().substring(0, file.getName().lastIndexOf('.'));
|
||||
RightBigSquare rbs = new RightBigSquare();
|
||||
rbs.fileName = fn;
|
||||
rbs.readFromFile(inDir);
|
||||
rbs.writeToFile_OldFormat(outDir);
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateData(Set<String> fileNames, String inDir, String outDir) throws IOException {
|
||||
for (String fileName : fileNames) {
|
||||
File file = new File(fileName);
|
||||
String fn = file.getName().substring(0, file.getName().lastIndexOf('.'));
|
||||
RightBigSquare rbs = new RightBigSquare();
|
||||
rbs.fileName = fn;
|
||||
rbs.readFromFile(inDir);
|
||||
rbs.writeToFile(outDir);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
24
src/main/java/pl/wat/ms4ds/terrain/TerrainType.java
Normal file
24
src/main/java/pl/wat/ms4ds/terrain/TerrainType.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package pl.wat.ms4ds.terrain;
|
||||
|
||||
public enum TerrainType {
|
||||
NONE(0),
|
||||
GRASS(1),
|
||||
SWAMP(2),
|
||||
WATER(3),
|
||||
SCRUB_BUSHES(4),
|
||||
BUILDINGS(5),
|
||||
FOREST(6);
|
||||
|
||||
static final TerrainType[] values = values();
|
||||
|
||||
public static TerrainType valueFromId(int id) {
|
||||
return values[id];
|
||||
}
|
||||
|
||||
public final int id;
|
||||
|
||||
TerrainType(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
87
src/main/java/pl/wat/ms4ds/terrain/TerrainUtils.java
Normal file
87
src/main/java/pl/wat/ms4ds/terrain/TerrainUtils.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package pl.wat.ms4ds.terrain;
|
||||
|
||||
|
||||
public class TerrainUtils {
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* Wyznacza widoczność optyczną w linii prostej między zadanymi kwadratami. Widoczność jest cechą symetryczną
|
||||
* względem badanych kwadratów.
|
||||
* <p> Wersja metody z wykorzystaniem
|
||||
*
|
||||
* @param ho
|
||||
* @param ht
|
||||
* @param x1
|
||||
* @param y1
|
||||
* @param x2
|
||||
* @param y2
|
||||
* @return
|
||||
*/
|
||||
public static int lineOfSight(float ho, float ht, int x1, int y1, int x2, int y2) {
|
||||
if ((x1 == x2) && (y1 == y2)) {
|
||||
return 1;
|
||||
}
|
||||
Square start = Teren.getSquare(x1, y1);
|
||||
Square stop = Teren.getSquare(x2, y2);
|
||||
if (start == Square.EMPTY || stop == Square.EMPTY) {
|
||||
return 0;
|
||||
}
|
||||
// roznica wysokosci miedzy skrajnymi kwadratami
|
||||
float heightDiff;
|
||||
float observerTotalHeight = start.elevation + ho;
|
||||
float targetTotalHeight = stop.elevation + ht;
|
||||
if (observerTotalHeight > targetTotalHeight) {
|
||||
// zamiana ról
|
||||
int swap = x1;
|
||||
x1 = x2;
|
||||
x2 = swap;
|
||||
swap = y1;
|
||||
y1 = y2;
|
||||
y2 = swap;
|
||||
heightDiff = observerTotalHeight - targetTotalHeight;
|
||||
observerTotalHeight = targetTotalHeight;
|
||||
} else {
|
||||
heightDiff = targetTotalHeight - observerTotalHeight;
|
||||
}
|
||||
int[] seq = GeomUtils.generateSquaresOfSegment2(x1, y1, x2, y2);
|
||||
double dist = Coord.Grid.distance(x1, y1, x2, y2);
|
||||
double tangAlfa0 = heightDiff / dist;
|
||||
|
||||
float dh_max = 0;
|
||||
// Tablica współrzędnych: x0, y0, x1, y1, x2, y2, x3, y3...
|
||||
// Testowane kwadraty pośrednie między startowym a końcowym.
|
||||
for (int i = 2; i < seq.length - 2; ) {
|
||||
// badanie wewnetrznych kwadratow nalezacych do odcinka,
|
||||
// czy nie sa powyzej linii widocznosci dla kwadratow skrajnych
|
||||
int x = seq[i++];
|
||||
int y = seq[i++];
|
||||
Square curr = Teren.getSquare(x, y);
|
||||
float obstacleHeight = switch (curr.terrainType) {
|
||||
case TerrainType.SCRUB_BUSHES -> 1;
|
||||
case TerrainType.BUILDINGS -> 10;
|
||||
case TerrainType.FOREST -> 10;
|
||||
default -> 0;
|
||||
};
|
||||
// wyznaczenie roznicy wysokosci kwadratu badanego i docelowego
|
||||
// uwzgledniajac wysokosc obserwatora oraz wysokosc przeszkody
|
||||
float dh = curr.elevation + obstacleHeight - observerTotalHeight;
|
||||
if (dh_max >= dh) {
|
||||
continue;
|
||||
}
|
||||
dist = Coord.Grid.distance(x, y, x1, y1);
|
||||
// float tangAlfa = roznWysAkt / odleg;
|
||||
// if (tangAlfa0 < tangAlfa) {
|
||||
if (tangAlfa0 * dist < dh) {
|
||||
// wysokosc aktualnie badanego kwadratu jest powyzej
|
||||
// linii poprowadzonej z kwadratu startowego do docelowego (z uwzglednieniem wysokosci obserwatora i celu)
|
||||
// odpowiednio dla katow dodatnich
|
||||
|
||||
return 0;
|
||||
}
|
||||
dh_max = dh;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
71
src/main/java/pl/wat/ms4ds/terrain/nmt/NmtData.java
Normal file
71
src/main/java/pl/wat/ms4ds/terrain/nmt/NmtData.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package pl.wat.ms4ds.terrain.nmt;
|
||||
|
||||
/**
|
||||
* Klasa pomocnicza do generowania danych terenowych NMT.
|
||||
* <p>
|
||||
* Cachuje i agreguje dane dotyczące wysokości odczytane z siatki punktów
|
||||
* w ramach wyznaczonych granic kwadratu terenu (współrzędne PUWG1992).
|
||||
*/
|
||||
public class NmtData {
|
||||
|
||||
/**
|
||||
* Współrzędna X kwadratu w ramach siatki terenu.
|
||||
*/
|
||||
public int x;
|
||||
/**
|
||||
* Współrzędna X kwadratu w ramach siatki terenu.
|
||||
*/
|
||||
public int y;
|
||||
|
||||
/**
|
||||
* Suma wysokości z punktów "wpadających" do tego kwadratu.
|
||||
*/
|
||||
public double sum;
|
||||
|
||||
/**
|
||||
* Licznik punktów "wpadających" do tego kwadratu.
|
||||
*/
|
||||
public int count;
|
||||
|
||||
//
|
||||
// Granice kwadratu wyrażone za pomocą współrzędnych PUWG1992 używanych w danych NMT.
|
||||
//
|
||||
/**
|
||||
* Wpółrzędne PUWG1992 easting lewego dolnego wierzchołka.
|
||||
*/
|
||||
public double ell;
|
||||
/**
|
||||
* Wpółrzędne PUWG1992 northing lewego dolnego wierzchołka.
|
||||
*/
|
||||
public double nll;
|
||||
/**
|
||||
* Wpółrzędne PUWG1992 easting prawego górnego wierzchołka.
|
||||
*/
|
||||
public double eur;
|
||||
/**
|
||||
* Wpółrzędne PUWG1992 northing prawego górnego wierzchołka.
|
||||
*/
|
||||
public double nur;
|
||||
|
||||
|
||||
public NmtData(int x, int y, double sum, int count) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.sum = sum;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NMTData{" +
|
||||
"x=" + x +
|
||||
", y=" + y +
|
||||
", sum=" + sum +
|
||||
", count=" + count +
|
||||
", ell=" + ell +
|
||||
", nll=" + nll +
|
||||
", eur=" + eur +
|
||||
", nur=" + nur +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
500
src/main/java/pl/wat/ms4ds/terrain/nmt/NmtDataGenerator.java
Normal file
500
src/main/java/pl/wat/ms4ds/terrain/nmt/NmtDataGenerator.java
Normal file
@@ -0,0 +1,500 @@
|
||||
package pl.wat.ms4ds.terrain.nmt;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pl.wat.ms4ds.terrain.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
/**
|
||||
* Klasa odpowiedzialna za generowanie danych wysokościowych w przyjętym formacie (sieci kwadratów) na podstawie
|
||||
* pobranych danych NMT (spakowane w plikach o nazwach skorowidzów).
|
||||
*/
|
||||
public class NmtDataGenerator {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(NmtDataGenerator.class);
|
||||
|
||||
static void main(String[] args) {
|
||||
|
||||
/*
|
||||
* Generowanie danych terenowych odbywa się na podstawie plików z danymi NMT w dwóch formatach:
|
||||
* ASC (siatka/tabela wysokość) TXT (współrzędne geo, wysokość). Pliki są spakowane.
|
||||
* Pliki znajdują się w lokalizacji określonej przez "inDir" w katalogach (odpowiadających skorowidzom).
|
||||
* W katalogu "idDir" znajdują się pliki textowe z listą nazw plików w podkatalogach skorowidzowych.
|
||||
* Dane wysokościowe z plików NMT przetwarzane są współbieżnie przez executora.
|
||||
* W ramach tego etapu/wątku:
|
||||
* 1. pliki są rozpakowywane do katalogu roboczego "workDir",
|
||||
* 2. po czym następuje ich odczyt i zapamiętanie danych szczegółowych w obiektach
|
||||
* NMTData (suma wysokości, licznik, granice kwadratu terenu we współrzędnych PUWG1992),
|
||||
* 3. obiekty NMTData (odpowiadające kwadratom terenu) są cachowane w hashmapie
|
||||
* indywidualnie w ramach wątku executora.
|
||||
* 4. po zakończeniu odczytu plik jest usuwany,
|
||||
* 5. następnie dane zagregowane (średnie wysokości) są zapisywane do kwadratów terenu
|
||||
* (zapis w kwadratach jest synchronizowany).
|
||||
*
|
||||
* Wątki są synchronizowane po tym etapie w celu zrzucenia zaktualizowanych danych na dysk.
|
||||
*
|
||||
*/
|
||||
|
||||
String inDir = "D:/work/nmt/";
|
||||
String workDir = "D:/work/temp/";
|
||||
String outDir = "D:/work/kwadraty_nmt/temp/100m/";
|
||||
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add("m-33");
|
||||
list.add("m-34");
|
||||
list.add("m-35");
|
||||
list.add("n-33");
|
||||
list.add("n-34");
|
||||
ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor();
|
||||
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
String fn_list = inDir + list.get(i) + "_files.txt";
|
||||
generateNMTData(executor, fn_list, 0, 24000, inDir + list.get(i) + "/", workDir, outDir);
|
||||
}
|
||||
|
||||
System.out.println("End.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generuje dane na podstawie listy spakowanych (zip) plików z podanego katalogu.
|
||||
*
|
||||
* @param fn_list
|
||||
* @param startPos
|
||||
* @param endPos
|
||||
* @param inDir
|
||||
* @param workDir
|
||||
* @param outDir
|
||||
*/
|
||||
static void generateNMTData(ExecutorService executor, String fn_list, int startPos, int endPos, String inDir, String workDir, String outDir) {
|
||||
final int TN = 8;
|
||||
File file = new File(fn_list);
|
||||
ArrayList<String> fileNames = new ArrayList<>();
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
fileNames.add(line);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return;
|
||||
}
|
||||
int count = 0;
|
||||
int i = startPos;
|
||||
ArrayList<Future> futures = new ArrayList<>();
|
||||
while (i < endPos) {
|
||||
if (i >= fileNames.size()) {
|
||||
break;
|
||||
}
|
||||
int j;
|
||||
for (j = 0; j < TN; j++) {
|
||||
if (i >= fileNames.size()) {
|
||||
break;
|
||||
}
|
||||
// asynchroniczne wywołanie zadania
|
||||
int ii = i;
|
||||
i++;
|
||||
Future future = executor.submit(() -> {
|
||||
long start = System.currentTimeMillis();
|
||||
String fn = fileNames.get(ii);
|
||||
File f = null;
|
||||
String[] unzippedFileNames = null;
|
||||
try {
|
||||
unzippedFileNames = unzipFile(inDir + fn, workDir);
|
||||
} catch (IOException e) {
|
||||
logger.warn("IO error while processing zip file: {}", inDir + fn);
|
||||
} catch (Exception e) {
|
||||
logger.warn(e.getMessage());
|
||||
}
|
||||
HashMap<Coord.Grid, NmtData> nmtDataHashMap = new HashMap<>();
|
||||
for (String ufn : unzippedFileNames) {
|
||||
String fpath = workDir + ufn;
|
||||
try {
|
||||
f = new File(fpath);
|
||||
if (f.length() < 10) {
|
||||
logger.warn("File: {} is empty.", ufn);
|
||||
continue;
|
||||
}
|
||||
readFromFile(fpath, nmtDataHashMap);
|
||||
} catch (Exception e) {
|
||||
logger.warn("Error while reading from file: {}.", ufn);
|
||||
} finally {
|
||||
if (f != null) {
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Coord.Grid gridCoord : nmtDataHashMap.keySet()) {
|
||||
NmtData nmtData = nmtDataHashMap.get(gridCoord);
|
||||
if (nmtData.count > 0) {
|
||||
Square square = Teren.getSquare(gridCoord.x, gridCoord.y);
|
||||
if (square == Square.EMPTY) {
|
||||
continue;
|
||||
}
|
||||
synchronized (square) {
|
||||
square.elevation = (float) (nmtData.sum / nmtData.count);
|
||||
// Zaokrąglenie do ćwiartki metra (0.0, 0.25, 0.5, 0.75)
|
||||
//
|
||||
square.elevation *= 4;
|
||||
square.elevation = (int) square.elevation;
|
||||
square.elevation /= 4;
|
||||
if (H_MIN >= square.elevation || H_MAX <= square.elevation) {
|
||||
logger.trace("!!!Dane poza zakresem: h= {}", square.elevation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
nmtDataHashMap.clear();
|
||||
logger.debug("File processed: {}, duration= {}[ms], status: {}/{}", fn, System.currentTimeMillis() - start, ii, endPos - 1);
|
||||
});
|
||||
futures.add(future);
|
||||
}
|
||||
count += j;
|
||||
// Punkt synchronizacyjny.
|
||||
for (Future future : futures) {
|
||||
try {
|
||||
future.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
logger.warn("Error in thread: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
futures.clear();
|
||||
if (count % 2000 == 0) {
|
||||
Teren.saveToFiles(outDir);
|
||||
}
|
||||
}
|
||||
Teren.saveToFiles(outDir);
|
||||
logger.info("Finished processing file list: {}", fn_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generuje dane na podstawie rozpakowanych danych z podanego katalogu.
|
||||
*
|
||||
* @param inDir
|
||||
* @param workDir
|
||||
* @param outDir
|
||||
*/
|
||||
static void generateNMTData(String inDir, String workDir, String outDir) {
|
||||
Set<String> files = NmtDataProvider.listFiles(inDir);
|
||||
HashMap<Coord.Grid, NmtData> nmtDataHashMap = new HashMap<>();
|
||||
for (String fn : files) {
|
||||
String fpath = workDir + fn;
|
||||
try {
|
||||
readFromFile(fpath, nmtDataHashMap);
|
||||
File f = new File(fpath);
|
||||
f.delete();
|
||||
} catch (Exception e) {
|
||||
logger.warn("Error while reading from file: {}", fpath);
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter("D:/Work/nmt/status.txt", true))) {
|
||||
writer.write("Error while processing file: " + fn);
|
||||
} catch (IOException e1) {
|
||||
logger.error(e1.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Coord.Grid gridCoord : nmtDataHashMap.keySet()) {
|
||||
NmtData nmtData = nmtDataHashMap.get(gridCoord);
|
||||
Square square = Teren.getSquare(gridCoord.x, gridCoord.y);
|
||||
if (square == Square.EMPTY) {
|
||||
continue;
|
||||
}
|
||||
if (nmtData.count > 0) {
|
||||
square.elevation = (float) (nmtData.sum / nmtData.count);
|
||||
// Konwersja na jednostkę 0.25m i zaokrąglenie do (0.0, 0.25, 0.5, 0.75)
|
||||
square.elevation *= 4;
|
||||
square.elevation = (int) square.elevation;
|
||||
square.elevation /= 4;
|
||||
if (H_MIN >= square.elevation || H_MAX <= square.elevation) {
|
||||
logger.trace("!!!Dane poza zakresem: h= {}", square.elevation);
|
||||
}
|
||||
}
|
||||
}
|
||||
nmtDataHashMap.clear();
|
||||
Teren.saveToFiles(outDir);
|
||||
}
|
||||
|
||||
private static void saveFileList(String fn, String[] fileList) throws IOException {
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(fn));
|
||||
for (String val : fileList) {
|
||||
writer.write(val);
|
||||
writer.newLine();
|
||||
}
|
||||
writer.close();
|
||||
}
|
||||
|
||||
// usuwanie z nazwy nadmiarowych rozszerz przed rozszerzeniem
|
||||
static void renameFiles(String inDir, String outDir) {
|
||||
Set<String> fileNames = NmtDataProvider.listFiles(inDir);
|
||||
for (String fn : fileNames) {
|
||||
String nfn = fn.substring(0, fn.indexOf('.'));
|
||||
File fileToMove = new File(inDir + fn);
|
||||
boolean isMoved = fileToMove.renameTo(new File(outDir + nfn + ".zip"));
|
||||
if (!isMoved) {
|
||||
logger.warn("Failed to rename {} to {}", inDir + fn, outDir + nfn + ".zip");
|
||||
}
|
||||
System.out.println(nfn);
|
||||
}
|
||||
}
|
||||
|
||||
// dodanie 0 do liczb dla wyrównania długości
|
||||
static void renameFiles2(String inDir, String outDir) {
|
||||
Set<String> fileNames = NmtDataProvider.listFiles(inDir);
|
||||
for (String fn : fileNames) {
|
||||
if (fn.length() >= 20) {
|
||||
continue;
|
||||
}
|
||||
// M-33-70-A-d-4-3.zip
|
||||
// M-33-7-A-d-4-3.zip
|
||||
int pos1 = fn.indexOf('-', 3);
|
||||
int pos2 = fn.indexOf('-', pos1 + 1);
|
||||
String f1 = fn.substring(0, pos1 + 1);
|
||||
String f2 = fn.substring(pos2);
|
||||
String val = fn.substring(pos1 + 1, pos2);
|
||||
int v = Integer.parseInt(val);
|
||||
String val_0;
|
||||
if (v < 10) {
|
||||
val_0 = "00" + val;
|
||||
} else if (v < 100) {
|
||||
val_0 = "0" + val;
|
||||
} else {
|
||||
val_0 = val;
|
||||
}
|
||||
String nfn = f1 + val_0 + f2;
|
||||
File fileToMove = new File(inDir + fn);
|
||||
boolean isMoved = fileToMove.renameTo(new File(outDir + nfn));
|
||||
if (!isMoved) {
|
||||
logger.warn("Failed to rename {} to {}", inDir + fn, outDir + nfn);
|
||||
}
|
||||
System.out.println(nfn);
|
||||
}
|
||||
}
|
||||
|
||||
private static void readFromFile(String fn, HashMap<Coord.Grid, NmtData> nmtDataHashMap) throws IOException {
|
||||
File file = new File(fn);
|
||||
InputStream inputStream = new FileInputStream(file);
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
String line = br.readLine();
|
||||
// Dzieli na podstringi biorąc jako znak podziału spację i jej wielokrotność
|
||||
// nawias kwadratowy zawiera znaki podziału
|
||||
String[] split = line.split("[ ]+");
|
||||
// Identyfikacja formatu na podstawie liczby danych w pierwszej linii.
|
||||
if (split.length == 2) {
|
||||
// ASC GRID format
|
||||
readASC(br, line, nmtDataHashMap);
|
||||
} else {
|
||||
// split.length ==3
|
||||
// XYZ format
|
||||
readXYZ(br, line, nmtDataHashMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final int H_MIN = -70;
|
||||
public static final int H_MAX = 2660;
|
||||
|
||||
private static void readASC(BufferedReader br, String firstLine, HashMap<Coord.Grid, NmtData> nmtDataHashMap) throws IOException {
|
||||
String line = firstLine;
|
||||
// Dzieli na podstringi biorąc jako znak podziału spację i jej wielokrotność
|
||||
// nawias kwadratowy zawiera znaki podziału
|
||||
String[] split = line.split("[ ]+");
|
||||
int ncols = Integer.parseInt(split[1]);
|
||||
line = br.readLine();
|
||||
split = line.split("[ ]+");
|
||||
int nrows = Integer.parseInt(split[1]);
|
||||
line = br.readLine();
|
||||
split = line.split("[ ]+");
|
||||
double xll_puwg = Double.parseDouble(split[1]);
|
||||
line = br.readLine();
|
||||
split = line.split("[ ]+");
|
||||
double yll_puwg = Double.parseDouble(split[1]);
|
||||
line = br.readLine();
|
||||
split = line.split("[ ]+");
|
||||
double cellsize = Double.parseDouble(split[1]);
|
||||
line = br.readLine();
|
||||
split = line.split("[ ]+");
|
||||
double nodata = Double.parseDouble(split[1]);
|
||||
double[][] data = new double[nrows][ncols];
|
||||
String s;
|
||||
for (int i = nrows - 1; i >= 0; i--) {
|
||||
line = br.readLine();
|
||||
// start od 0 (brak spacji na początku) lub 1 (wiersz zaczyna się od spacji)
|
||||
int start = (line.charAt(0) == ' ') ? 1 : 0;
|
||||
int end;
|
||||
for (int j = 0; j < ncols - 1; j++) {
|
||||
end = line.indexOf(' ', start);
|
||||
while (end - start == 0 && start < line.length() - 1) {
|
||||
start = end + 1;
|
||||
end = line.indexOf(' ', start);
|
||||
}
|
||||
s = line.substring(start, end);
|
||||
start = end + 1;
|
||||
data[i][j] = Double.parseDouble(s);
|
||||
}
|
||||
end = line.indexOf(' ', start);
|
||||
while (end - start == 0 && start < line.length() - 1) {
|
||||
start = end + 1;
|
||||
end = line.indexOf(' ', start);
|
||||
}
|
||||
s = line.substring(start);
|
||||
data[i][ncols - 1] = Double.parseDouble(s);
|
||||
}
|
||||
NmtData nmtData = new NmtData(-1, -1, 0, 0);
|
||||
Coord.Geo geoCoord = new Coord.Geo();
|
||||
Coord.Puwg puwgCoord = new Coord.Puwg();
|
||||
double h;
|
||||
int x;
|
||||
int y;
|
||||
double y_puwg = yll_puwg;
|
||||
for (int i = 0; i < nrows; i++) {
|
||||
double x_puwg = xll_puwg;
|
||||
for (int j = 0; j < ncols; j++) {
|
||||
h = data[i][j];
|
||||
if (h == nodata) {
|
||||
// Przejdź do następnej kolumny danych.
|
||||
x_puwg += cellsize;
|
||||
continue;
|
||||
}
|
||||
if (nmtData.ell > x_puwg || nmtData.eur < x_puwg || nmtData.nll > y_puwg || nmtData.nur < y_puwg) {
|
||||
// Punkt poza granicą bieżącego kwadratu.
|
||||
Coord.convertPUWG1992ToWGS84(y_puwg, x_puwg, geoCoord);
|
||||
x = Coord.convertLonToGridX(geoCoord.lon);
|
||||
y = Coord.convertLatToGridY(geoCoord.lat);
|
||||
final int x1 = x;
|
||||
final int y1 = y;
|
||||
nmtData = nmtDataHashMap.computeIfAbsent(new Coord.Grid(x, y), k -> new NmtData(x1, y1, 0, 0));
|
||||
if (nmtData.nur == 0) {
|
||||
// Kwadrat jeszcze nie był odczytany (czysty).
|
||||
// Współrzędne geo środka kwadratu.
|
||||
geoCoord.lon = Coord.convertGridXToLon(x);
|
||||
geoCoord.lat = Coord.covertGridYToLat(y);
|
||||
// Wyznacz współrzędne PUWG lewego dolnego rogu kwadratu.
|
||||
Coord.convertWGS84ToPUWG1992(geoCoord.lat - MapConsts.SS_DELTA_LAT / 2, geoCoord.lon - MapConsts.SS_DELTA_LON / 2, puwgCoord);
|
||||
nmtData.ell = (int) puwgCoord.easting;
|
||||
nmtData.nll = (int) puwgCoord.northing;
|
||||
// Wyznacz współrzędne PUWG prawego górnego rogu kwadratu.
|
||||
Coord.convertWGS84ToPUWG1992(geoCoord.lat + MapConsts.SS_DELTA_LAT / 2, geoCoord.lon + MapConsts.SS_DELTA_LON / 2, puwgCoord);
|
||||
nmtData.eur = (int) puwgCoord.easting;
|
||||
nmtData.nur = (int) puwgCoord.northing;
|
||||
}
|
||||
}
|
||||
nmtData.sum += h;
|
||||
nmtData.count++;
|
||||
// Przejdź do następnej kolumny.
|
||||
x_puwg += cellsize;
|
||||
}
|
||||
// Przejdź do następnego wiersza.
|
||||
y_puwg += cellsize;
|
||||
}
|
||||
}
|
||||
|
||||
private static void readXYZ(BufferedReader br, String firstLine, HashMap<Coord.Grid, NmtData> nmtDataHashMap) throws IOException {
|
||||
Coord.Puwg puwgCoord = new Coord.Puwg();
|
||||
Coord.Geo geo = new Coord.Geo();
|
||||
String line = firstLine;
|
||||
if (line.charAt(0) == 'S' || line.charAt(0) == 'E') {
|
||||
line = br.readLine();
|
||||
}
|
||||
char c = ' ';
|
||||
if (line.indexOf('\t', 1) != -1) {
|
||||
c = '\t';
|
||||
}
|
||||
double x_puwg;
|
||||
double y_puwg;
|
||||
double h;
|
||||
int x;
|
||||
int y;
|
||||
NmtData nmtData = new NmtData(-1, -1, 0, 0);
|
||||
int start;
|
||||
int end;
|
||||
int row = 0;
|
||||
while (line != null) {
|
||||
if (line.length() < 5 || line.charAt(0) == 'S' || line.charAt(0) == 'E') {
|
||||
line = br.readLine();
|
||||
row++;
|
||||
continue;
|
||||
}
|
||||
// start od 0, gdyż nie ma spacji na początku
|
||||
start = 0;
|
||||
end = line.indexOf(c, start);
|
||||
while (end - start == 0 && start < line.length() - 1) {
|
||||
start = end + 1;
|
||||
end = line.indexOf(c, start);
|
||||
}
|
||||
String s = line.substring(start, end);
|
||||
x_puwg = Double.parseDouble(s);
|
||||
start = end + 1;
|
||||
end = line.indexOf(c, start);
|
||||
while (end - start == 0 && start < line.length() - 1) {
|
||||
start = end + 1;
|
||||
end = line.indexOf(c, start);
|
||||
}
|
||||
s = line.substring(start, end);
|
||||
y_puwg = Double.parseDouble(s);
|
||||
start = end + 1;
|
||||
s = line.substring(start);
|
||||
h = Double.parseDouble(s);
|
||||
if (nmtData.ell > x_puwg || nmtData.eur < x_puwg || nmtData.nll > y_puwg || nmtData.nur < y_puwg) {
|
||||
// Punkt poza granicą bieżącego kwadratu.
|
||||
Coord.convertPUWG1992ToWGS84(y_puwg, x_puwg, geo);
|
||||
x = Coord.convertLonToGridX(geo.lon);
|
||||
y = Coord.convertLatToGridY(geo.lat);
|
||||
final int x1 = x;
|
||||
final int y1 = y;
|
||||
nmtData = nmtDataHashMap.computeIfAbsent(new Coord.Grid(x1, y1), k -> new NmtData(x1, y1, 0, 0));
|
||||
if (nmtData.nur == 0) {
|
||||
// Kwadrat jeszcze nie był odczytany (czysty).
|
||||
// Współrzędne geo środka kwadratu.
|
||||
geo.lon = Coord.convertGridXToLon(x);
|
||||
geo.lat = Coord.covertGridYToLat(y);
|
||||
// Wyznacz współrzędne PUWG lewego dolnego rogu kwadratu.
|
||||
Coord.convertWGS84ToPUWG1992(geo.lat - MapConsts.SS_DELTA_LAT / 2, geo.lon - MapConsts.SS_DELTA_LON / 2, puwgCoord);
|
||||
nmtData.ell = (int) puwgCoord.easting;
|
||||
nmtData.nll = (int) puwgCoord.northing;
|
||||
// Wyznacz współrzędne PUWG prawego górnego rogu kwadratu.
|
||||
Coord.convertWGS84ToPUWG1992(geo.lat + MapConsts.SS_DELTA_LAT / 2, geo.lon + MapConsts.SS_DELTA_LON / 2, puwgCoord);
|
||||
nmtData.eur = (int) puwgCoord.easting;
|
||||
nmtData.nur = (int) puwgCoord.northing;
|
||||
}
|
||||
}
|
||||
nmtData.sum += h;
|
||||
nmtData.count++;
|
||||
line = br.readLine();
|
||||
row++;
|
||||
}
|
||||
}
|
||||
|
||||
public static String[] unzipFile(String zipFileName, String destDir) throws IOException {
|
||||
byte[] buffer = new byte[1024];
|
||||
String[] unzipFileNames = new String[10];
|
||||
int i = 0;
|
||||
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFileName))) {
|
||||
ZipEntry zipEntry = zis.getNextEntry();
|
||||
while (zipEntry != null) {
|
||||
unzipFileNames[i] = zipEntry.getName();
|
||||
File newFile = new File(destDir + unzipFileNames[i]);
|
||||
// File newFile = new File(destDir + File.separator + unzipFileName);
|
||||
int len;
|
||||
// write file content
|
||||
FileOutputStream fos = new FileOutputStream(newFile);
|
||||
while ((len = zis.read(buffer)) > 0) {
|
||||
fos.write(buffer, 0, len);
|
||||
}
|
||||
fos.close();
|
||||
zipEntry = zis.getNextEntry();
|
||||
i++;
|
||||
}
|
||||
zis.closeEntry();
|
||||
}
|
||||
if (i > 0) {
|
||||
unzipFileNames = Arrays.copyOf(unzipFileNames, i);
|
||||
} else {
|
||||
unzipFileNames = new String[0];
|
||||
}
|
||||
return unzipFileNames;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,44 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.nmt;
|
||||
package pl.wat.ms4ds.terrain.nmt;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamConstants;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
public class NMTDataProvider {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NMTDataProvider.class);
|
||||
/**
|
||||
* Klasa odpowiedzialna za pozyskanie danych wysokościowych (NMT) ze stron geoportal.
|
||||
*/
|
||||
public class NmtDataProvider {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NmtDataProvider.class);
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
String dir = "C:/Workspace/nmt/gugik_1m/unzip/";
|
||||
Set<String> files = listFiles(dir);
|
||||
for (String file : files) {
|
||||
String fn = file.substring(0, file.indexOf('.'));
|
||||
zipFile(dir + fn);
|
||||
File f = new File(dir + file);
|
||||
f.delete();
|
||||
}
|
||||
// File dir = new File(System.getProperty("user.home") + "/nmt/gugik_SkorowidzNMT2018.gml");
|
||||
// HashMap<String, String> map = new HashMap<>();
|
||||
// String fn0 = "D:/nmt/gugik_SkorowidzNMT20";
|
||||
// for (int i = 18; i < 26; i++) {
|
||||
// readFileLinksFromGUGiKxml(fn0 + i + ".gml", map);
|
||||
// readFileLinksFromGugikXml(fn0 + i + ".gml", map);
|
||||
// }
|
||||
// saveLinks("D:/nmt/gugik_links.txt", map);
|
||||
|
||||
@@ -38,32 +46,16 @@ public class NMTDataProvider {
|
||||
//
|
||||
// String dir = "C:/Workspace/nmt/gugik_1m/";
|
||||
// String links_fn = "C:/Workspace/nmt/gugik_links.txt";
|
||||
String dir = args[0];
|
||||
String links_fn = args[1];
|
||||
// String dir = args[0];
|
||||
// String links_fn = args[1];
|
||||
// int start = Integer.parseInt(args[2]);
|
||||
// int end = Integer.parseInt(args[3]);
|
||||
|
||||
Set<String> files = listFiles("C:/Workspace/nmt/gugik_1m/");
|
||||
// Set<String> files = listFiles("C:/Workspace/nmt/gugik_1m/");
|
||||
|
||||
|
||||
// downloadFileSet(links_fn, start, end, dir);
|
||||
|
||||
// ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor();
|
||||
// executor.execute(() -> {
|
||||
// try {
|
||||
// downloadFileSet(links_fn, 290, 730, dir);
|
||||
// } catch (IOException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// });
|
||||
// executor.execute(() -> {
|
||||
// try {
|
||||
// downloadFileSet(links_fn, 779, 1230, dir);
|
||||
// } catch (IOException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// });
|
||||
// executor.shutdown();
|
||||
// executor.awaitTermination(25, TimeUnit.MINUTES);
|
||||
LOGGER.info("Koniec");
|
||||
}
|
||||
|
||||
@@ -133,7 +125,7 @@ public class NMTDataProvider {
|
||||
FileOutputStream fos = new FileOutputStream(sourceFile + ".zip");
|
||||
ZipOutputStream zipOut = new ZipOutputStream(fos);
|
||||
|
||||
File fileToZip = new File(sourceFile);
|
||||
File fileToZip = new File(sourceFile + ".asc");
|
||||
FileInputStream fis = new FileInputStream(fileToZip);
|
||||
ZipEntry zipEntry = new ZipEntry(fileToZip.getName());
|
||||
zipOut.putNextEntry(zipEntry);
|
||||
@@ -172,7 +164,7 @@ public class NMTDataProvider {
|
||||
|
||||
// Funkcja wykorzystana jednokrotnie w celu integracji w jednym pliku wszystkich linków
|
||||
// do zasobów rozproszonych w wielu plikach.
|
||||
private static void readFileLinksFromGUGiKxml(String fn, HashMap<String, String> map) throws Exception {
|
||||
private static void readFileLinksFromGugikXml(String fn, HashMap<String, String> map) throws Exception {
|
||||
XMLInputFactory factory = XMLInputFactory.newInstance();
|
||||
FileInputStream is = new FileInputStream(fn);
|
||||
BufferedInputStream bis = new BufferedInputStream(is);
|
||||
164
src/main/java/pl/wat/ms4ds/terrain/osm/CoordTest.java
Normal file
164
src/main/java/pl/wat/ms4ds/terrain/osm/CoordTest.java
Normal file
@@ -0,0 +1,164 @@
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pl.wat.ms4ds.terrain.Coord;
|
||||
|
||||
public class CoordTest {
|
||||
static Logger logger = LoggerFactory.getLogger(CoordTest.class);
|
||||
|
||||
static void main() {
|
||||
|
||||
byte[] INT_BYTE_ARRAY = new byte[]{
|
||||
(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE
|
||||
};
|
||||
int intValue = 0xCAFEBABE;
|
||||
int v1 = 32000;
|
||||
short value = 32033;
|
||||
byte[] bytes1 = new byte[Short.BYTES];
|
||||
int length = bytes1.length;
|
||||
for (int i = 0; i < length; i++) {
|
||||
bytes1[length - i - 1] = (byte) (value & 0xFF);
|
||||
value >>= 8;
|
||||
}
|
||||
value = 0;
|
||||
for (byte b : bytes1) {
|
||||
value = (short) ((value << 8) + (b & 0xFF));
|
||||
}
|
||||
v1 = bytes1[0] & 0xFF;
|
||||
v1 = (v1 << 8) + (bytes1[1] & 0xFF);
|
||||
value = (short) v1;
|
||||
|
||||
// try {
|
||||
// BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("./CoordTest.bin"));
|
||||
short[] val1 = {-4, -100, 32035, 32036, 32037};
|
||||
byte[] val2 = {24, 25, 26, 27, 28};
|
||||
byte[] val3 = {7, 8, 9, 10, 11};
|
||||
int pos = 0;
|
||||
byte[] buf = new byte[4 * 5];
|
||||
for (int i = 0; i < 5; i++) {
|
||||
// 4 * i - pozycja startowa i-tego recordu
|
||||
pos = 4 * i;
|
||||
short val = val1[i];
|
||||
buf[pos + 1] = (byte) (val & 0xFF);
|
||||
val >>= 8;
|
||||
buf[pos] = (byte) (val & 0xFF);
|
||||
buf[pos + 2] = val2[i];
|
||||
buf[pos + 3] = val3[i];
|
||||
}
|
||||
// out.write(buf);
|
||||
// out.flush();
|
||||
// out.close();
|
||||
|
||||
// BufferedInputStream in = new BufferedInputStream(new FileInputStream("./CoordTest.bin"), 8);
|
||||
// byte[] buf = new byte[4 * 5];
|
||||
// in.read(buf2);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
// 4 * i - pozycja startowa i-tego recordu
|
||||
pos = 4 * i;
|
||||
v1 = buf[pos] & 0xFF;
|
||||
v1 = (v1 << 8) | (buf[pos + 1] & 0xFF);
|
||||
val1[i] = (short) v1;
|
||||
val2[i] = buf[pos + 2];
|
||||
val3[i] = buf[pos + 3];
|
||||
}
|
||||
// in.close();
|
||||
|
||||
// } catch (IOException e) {
|
||||
// System.out.println(e.getMessage());
|
||||
// }
|
||||
|
||||
|
||||
short e1 = 110;
|
||||
float elevation = (float) (e1) / 4;
|
||||
e1 = 111;
|
||||
elevation = (float) (e1) / 4;
|
||||
float f1 = 101.237f;
|
||||
f1 *= 4;
|
||||
f1 = (int) f1;
|
||||
f1 /= 4;
|
||||
f1 = 101.257f;
|
||||
f1 *= 4;
|
||||
f1 = (int) f1;
|
||||
f1 /= 4;
|
||||
f1 = 101.25f;
|
||||
f1 *= 4;
|
||||
f1 = (int) f1;
|
||||
f1 /= 4;
|
||||
f1 = 101.75f;
|
||||
f1 *= 4;
|
||||
f1 = (int) f1;
|
||||
f1 /= 4;
|
||||
f1 = 101.0237f;
|
||||
f1 *= 4;
|
||||
f1 = (int) f1;
|
||||
f1 /= 4;
|
||||
f1 = 101.82f;
|
||||
f1 *= 4;
|
||||
f1 = (int) f1;
|
||||
f1 /= 4;
|
||||
String s = String.format("e = %9.4f", Math.E);
|
||||
|
||||
logger.debug(" ");
|
||||
|
||||
Coord.Puwg puwgCoord = new Coord.Puwg();
|
||||
Coord.Geo geoCoord = new Coord.Geo();
|
||||
geoCoord.lon = 19;
|
||||
geoCoord.lat = 50;
|
||||
Coord.convertWGS84ToPUWG1992(geoCoord.lat, geoCoord.lon, puwgCoord);
|
||||
logger.debug("Lat={}, Lon={} => PUWG (e,n)=({}, {})", geoCoord.lat, geoCoord.lon, puwgCoord.easting, puwgCoord.northing);
|
||||
double e = puwgCoord.easting;
|
||||
double n = puwgCoord.northing;
|
||||
geoCoord.lon = 20;
|
||||
geoCoord.lat = 51;
|
||||
Coord.convertWGS84ToPUWG1992(geoCoord.lat, geoCoord.lon, puwgCoord);
|
||||
|
||||
double dx = puwgCoord.easting - e;
|
||||
double dy = puwgCoord.northing - n;
|
||||
|
||||
|
||||
logger.debug("Lat={}, Lon={} => PUWG (e,n)=({}, {})", geoCoord.lat, geoCoord.lon, puwgCoord.easting, puwgCoord.northing);
|
||||
Coord.convertPUWG1992ToWGS84(puwgCoord.northing, puwgCoord.easting, geoCoord);
|
||||
logger.debug("PUWG (e,n)=({}, {}) => Lat={}, Lon={}", puwgCoord.easting, puwgCoord.northing, geoCoord.lat, geoCoord.lon);
|
||||
|
||||
// coord.proj = 1;
|
||||
// CoordUtils.convertWGS84ToPUWG(coord, geoCoord.lat, geoCoord.lon);
|
||||
// logger.debug("Lat={}, Lon={}, PUWG (proj={}, e={}, n={})", geoCoord.lat, geoCoord.lon, coord.proj, coord.easting, coord.northing);
|
||||
// CoordUtils.convertPuwg1992ToWgs84(coord, geoCoord);
|
||||
// logger.debug("Lat={}, Lon={}, PUWG (proj={}, e={}, n={})", geoCoord.lat, geoCoord.lon, coord.proj, coord.easting, coord.northing);
|
||||
//
|
||||
// coord.proj = 2;
|
||||
// CoordUtils.convertWGS84ToPUWG(coord, geoCoord.lat, geoCoord.lon);
|
||||
// logger.debug("Lat={}, Lon={}, PUWG (proj={}, e={}, n={})", geoCoord.lat, geoCoord.lon, coord.proj, coord.easting, coord.northing);
|
||||
// CoordUtils.convertPuwg2000ToWgs84(coord, geoCoord);
|
||||
// logger.debug("Lat={}, Lon={}, PUWG (proj={}, e={}, n={})", geoCoord.lat, geoCoord.lon, coord.proj, coord.easting, coord.northing);
|
||||
// 195828.000 673108.000
|
||||
|
||||
// puwgCoord.easting = 253974;
|
||||
// puwgCoord.northing = 476879;
|
||||
puwgCoord.easting = 500000;
|
||||
puwgCoord.northing = 500000;
|
||||
logger.debug("----------------------------------");
|
||||
Coord.convertPUWG1992ToWGS84(puwgCoord.northing, puwgCoord.easting, geoCoord);
|
||||
logger.debug("PUWG (e,n)=({}, {}) => Lat={}, Lon={}", puwgCoord.easting, puwgCoord.northing, geoCoord.lat, geoCoord.lon);
|
||||
Coord.convertWGS84ToPUWG1992(geoCoord.lat, geoCoord.lon, puwgCoord);
|
||||
logger.debug("Lat={}, Lon={} => PUWG (e,n)=({}, {})", geoCoord.lat, geoCoord.lon, puwgCoord.easting, puwgCoord.northing);
|
||||
|
||||
|
||||
puwgCoord.easting = 100000;
|
||||
puwgCoord.northing = 470642;
|
||||
Coord.convertPUWG1992ToWGS84(puwgCoord.northing, puwgCoord.easting, geoCoord);
|
||||
logger.debug("PUWG (e,n)=({}, {}) => Lat={}, Lon={}", puwgCoord.easting, puwgCoord.northing, geoCoord.lat, geoCoord.lon);
|
||||
Coord.convertWGS84ToPUWG1992(geoCoord.lat, geoCoord.lon, puwgCoord);
|
||||
logger.debug("Lat={}, Lon={} => PUWG (e,n)=({}, {})", geoCoord.lat, geoCoord.lon, puwgCoord.easting, puwgCoord.northing);
|
||||
|
||||
puwgCoord.easting = 821310;
|
||||
puwgCoord.northing = 369750;
|
||||
Coord.convertPUWG1992ToWGS84(puwgCoord.northing, puwgCoord.easting, geoCoord);
|
||||
logger.debug("PUWG (e,n)=({}, {}) => Lat={}, Lon={}", puwgCoord.easting, puwgCoord.northing, geoCoord.lat, geoCoord.lon);
|
||||
Coord.convertWGS84ToPUWG1992(geoCoord.lat, geoCoord.lon, puwgCoord);
|
||||
logger.debug("Lat={}, Lon={} => PUWG (e,n)=({}, {})", geoCoord.lat, geoCoord.lon, puwgCoord.easting, puwgCoord.northing);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
116
src/main/java/pl/wat/ms4ds/terrain/osm/CoordUtils.java
Normal file
116
src/main/java/pl/wat/ms4ds/terrain/osm/CoordUtils.java
Normal file
@@ -0,0 +1,116 @@
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
import pl.wat.ms4ds.terrain.Coord;
|
||||
import pl.wat.ms4ds.terrain.Teren;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pl.wat.ms4ds.terrain.nmt.NmtData;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* Odczyt danych wysokościowych z numerycznego modelu terenu (NMT_100).
|
||||
* <p>
|
||||
* Kod źródłowy funkcji do transformacji współrzędnych elipsoidalnych na płaskie odwzorowań kartograficznych UTM, 1992, 2000
|
||||
*/
|
||||
public class CoordUtils {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CoordUtils.class);
|
||||
|
||||
static String dataDir = "d:/Workspace2/dane_wysok/";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
|
||||
HashMap<Coord.Grid, NmtData> daneWysokHashMap = new HashMap();
|
||||
if (args.length > 0) {
|
||||
dataDir = args[0];
|
||||
}
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
String nmt_fn = args[i];
|
||||
daneWysokHashMap.clear();
|
||||
readData(nmt_fn, daneWysokHashMap);
|
||||
for (NmtData daneWysok : daneWysokHashMap.values()) {
|
||||
// Square kw = Teren.getKwadrat(daneWysok.idKw.x, daneWysok.idKw.y);
|
||||
// kw.setWysokoscSrednia((int) (daneWysok.suma / daneWysok.licz + 0.5));
|
||||
}
|
||||
logger.debug("Poczatek zapisu danych dla regionu " + nmt_fn + " >> " + i + "/" + (args.length - 1));
|
||||
Teren.saveToFiles(null);
|
||||
logger.debug("Koniec zapisu danych dla regionu " + nmt_fn + " >> " + i + "/" + (args.length - 1));
|
||||
Teren.reset();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void readData(String fileName, HashMap<Coord.Grid, NmtData> daneWysokHashMap) throws IOException {
|
||||
try {
|
||||
StringBuilder sb = new StringBuilder(100);
|
||||
sb.append(dataDir);
|
||||
sb.append(fileName);
|
||||
sb.append(".txt");
|
||||
FileReader fis = new FileReader(sb.toString());
|
||||
// PUWG 1992
|
||||
Coord.Puwg puwgCoord = new Coord.Puwg();
|
||||
Coord.Geo latLon = new Coord.Geo();
|
||||
double wysokosc = 0.0;
|
||||
StringTokenizer st = null;
|
||||
String line = null;
|
||||
BufferedReader br = new BufferedReader(fis);
|
||||
if (br.ready()) {
|
||||
line = br.readLine();
|
||||
int m = 1;
|
||||
while (line != null) {
|
||||
st = new StringTokenizer(line, " ");
|
||||
if (st.countTokens() != 3) {
|
||||
continue;
|
||||
}
|
||||
String[] tokTable = new String[st.countTokens()];
|
||||
for (int i = 0; st.hasMoreTokens(); i++) {
|
||||
tokTable[i] = st.nextToken();
|
||||
}
|
||||
try {
|
||||
puwgCoord.easting = Double.parseDouble(tokTable[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
logger.warn("Bledne dane w pliku: " + fileName);
|
||||
}
|
||||
try {
|
||||
puwgCoord.northing = Double.parseDouble(tokTable[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
logger.warn("Bledne dane w pliku: " + fileName);
|
||||
}
|
||||
try {
|
||||
wysokosc = Double.parseDouble(tokTable[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
logger.warn("Bledne dane w pliku: " + fileName);
|
||||
}
|
||||
Coord.convertPUWG1992ToWGS84(puwgCoord.northing, puwgCoord.easting, latLon);
|
||||
Coord.Grid idKw = new Coord.Grid(latLon.lon, latLon.lat);
|
||||
NmtData daneWysok = daneWysokHashMap.get(idKw);
|
||||
if (daneWysok == null) {
|
||||
daneWysok = new NmtData(idKw.x, idKw.y, wysokosc, 1);
|
||||
daneWysokHashMap.put(idKw, daneWysok);
|
||||
} else {
|
||||
daneWysok.sum += wysokosc;
|
||||
daneWysok.count++;
|
||||
}
|
||||
line = br.readLine();
|
||||
if (m++ % 100000 == 0) {
|
||||
System.out.print('-');
|
||||
}
|
||||
}
|
||||
}
|
||||
br.close();
|
||||
System.out.println();
|
||||
logger.debug("Koniec odczytu pliku: " + fileName);
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
public enum EAreaFeature {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
public enum ELinearFeature {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
public enum EOSMAmenity {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
public enum EOSMBridge {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
public enum EOSMBuilding {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
public enum EOSMHighway {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
public enum EOSMLandcover {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
public enum EOSMLanduse {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
public enum EOSMNatural {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
public enum EOSMWater {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
public enum EOSMWaterway {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
import org.nocrala.tools.gis.data.esri.shapefile.ShapeFileReader;
|
||||
import org.nocrala.tools.gis.data.esri.shapefile.ValidationPreferences;
|
||||
@@ -10,11 +10,12 @@ import org.nocrala.tools.gis.data.esri.shapefile.shape.shapes.MultiPointZShape;
|
||||
import org.nocrala.tools.gis.data.esri.shapefile.shape.shapes.PointShape;
|
||||
import org.nocrala.tools.gis.data.esri.shapefile.shape.shapes.PolygonShape;
|
||||
import org.nocrala.tools.gis.data.esri.shapefile.shape.shapes.PolylineShape;
|
||||
import pl.wat.ms4ds.terenfunkcje.GridCoord;
|
||||
import pl.wat.ms4ds.terenfunkcje.MapConsts;
|
||||
import pl.wat.ms4ds.terenfunkcje.Teren;
|
||||
import pl.wat.ms4ds.terrain.Coord;
|
||||
import pl.wat.ms4ds.terrain.MapConsts;
|
||||
import pl.wat.ms4ds.terrain.Teren;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
@@ -87,19 +88,19 @@ public class EsriFileReader {
|
||||
nodeId++;
|
||||
currNode.lon = points[j].getX() + 180;
|
||||
currNode.lat = points[j].getY() + 90;
|
||||
if (currNode.lon >= MapConsts.X_REF && currNode.lon <= MapConsts.X_REF + MapConsts.DX_REF
|
||||
&& currNode.lat >= MapConsts.Y_REF && currNode.lat <= MapConsts.Y_REF + MapConsts.DY_REF) {
|
||||
if (currNode.lon >= MapConsts.REF_LON && currNode.lon <= MapConsts.REF_LON + MapConsts.DELTA_LON_REF
|
||||
&& currNode.lat >= MapConsts.REF_LAT && currNode.lat <= MapConsts.REF_LAT + MapConsts.DELTA_LAT_REF) {
|
||||
jest_wezel_z_obszaru = true;
|
||||
}
|
||||
currNode.lon = Math.max(currNode.lon, MapConsts.X_REF);
|
||||
currNode.lon = Math.min(currNode.lon, MapConsts.X_REF + MapConsts.DX_REF);
|
||||
currNode.lon = Math.max(currNode.lon, MapConsts.REF_LON);
|
||||
currNode.lon = Math.min(currNode.lon, MapConsts.REF_LON + MapConsts.DELTA_LON_REF);
|
||||
currNode.lon -= 180;
|
||||
currNode.lat = Math.max(currNode.lat, MapConsts.Y_REF);
|
||||
currNode.lat = Math.min(currNode.lat, MapConsts.Y_REF + MapConsts.DY_REF);
|
||||
currNode.lat = Math.max(currNode.lat, MapConsts.REF_LAT);
|
||||
currNode.lat = Math.min(currNode.lat, MapConsts.REF_LAT + MapConsts.DELTA_LAT_REF);
|
||||
currNode.lat -= 90;
|
||||
|
||||
currNode.idX = GridCoord.zamienDlugoscGeoNaIdKwadratuX(currNode.lon);
|
||||
currNode.idY = GridCoord.zamienSzerokoscGeoNaIdKwadratuY(currNode.lat);
|
||||
currNode.idX = Coord.convertLonToGridX(currNode.lon);
|
||||
currNode.idY = Coord.convertLatToGridY(currNode.lat);
|
||||
if (currNode.idX > 0 || currNode.idY > 0) {
|
||||
currWay.nodes.add(currNode);
|
||||
}
|
||||
@@ -149,7 +150,7 @@ public class EsriFileReader {
|
||||
}
|
||||
}
|
||||
LOGGER.debug("Poczatek zapisu danych o pokryciu wodami");
|
||||
Teren.zapisBuforaMapyDoPliku();
|
||||
Teren.saveToFiles(null);
|
||||
// Teren.setBinarnyFormatPliku(false);
|
||||
// Teren.zapisBuforaMapyDoPliku();
|
||||
Teren.reset();
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -1,8 +1,9 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
import pl.wat.ms4ds.terenfunkcje.Kwadrat;
|
||||
import pl.wat.ms4ds.terenfunkcje.MapConsts;
|
||||
import pl.wat.ms4ds.terenfunkcje.Teren;
|
||||
import pl.wat.ms4ds.terrain.Square;
|
||||
import pl.wat.ms4ds.terrain.MapConsts;
|
||||
import pl.wat.ms4ds.terrain.Teren;
|
||||
import pl.wat.ms4ds.terrain.TerrainType;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -48,7 +49,7 @@ public class Node {
|
||||
|
||||
static final int BUILDINGS_COUNT;
|
||||
static {
|
||||
switch (MapConsts.DL_MK) {
|
||||
switch (MapConsts.SS_SIZE) {
|
||||
case 200:
|
||||
BUILDINGS_COUNT = 8;
|
||||
break;
|
||||
@@ -69,11 +70,8 @@ public class Node {
|
||||
|
||||
public void writeAreaFeatureIntoSquare(EAreaFeature type) {
|
||||
if (buildingsCount >= BUILDINGS_COUNT) {
|
||||
Kwadrat kw = Teren.getKwadrat(idX, idY);
|
||||
kw.setStopienZabudowy(1.0f);
|
||||
} else if (buildingsCount > 0) {
|
||||
Kwadrat kw = Teren.getKwadrat(idX, idY);
|
||||
kw.setStopienZabudowy(0.5f);
|
||||
Square kw = Teren.getSquare(idX, idY);
|
||||
kw.terrainType = TerrainType.BUILDINGS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
import pl.wat.ms4ds.terenfunkcje.GridCoord;
|
||||
import pl.wat.ms4ds.terenfunkcje.Teren;
|
||||
import pl.wat.ms4ds.terrain.Coord;
|
||||
import pl.wat.ms4ds.terrain.Teren;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.io.FileInputStream;
|
||||
@@ -66,7 +66,7 @@ public class OpenStreetMapReader {
|
||||
// Teren.setBinarnyFormatPliku(true);
|
||||
}
|
||||
LOGGER.debug("Poczatek zapisu danych dla regionu " + osm_fn);
|
||||
Teren.zapisBuforaMapyDoPliku();
|
||||
Teren.saveToFiles(null);
|
||||
LOGGER.debug("Koniec zapisu danych dla regionu " + osm_fn);
|
||||
}
|
||||
|
||||
@@ -238,8 +238,8 @@ public class OpenStreetMapReader {
|
||||
switch (reader.getLocalName()) {
|
||||
case "node":
|
||||
if (currNode != null) {
|
||||
currNode.idX = GridCoord.zamienDlugoscGeoNaIdKwadratuX(currNode.lon);
|
||||
currNode.idY = GridCoord.zamienSzerokoscGeoNaIdKwadratuY(currNode.lat);
|
||||
currNode.idX = Coord.convertLonToGridX(currNode.lon);
|
||||
currNode.idY = Coord.convertLatToGridY(currNode.lat);
|
||||
if ("zabudowa".equals(genGoal) && currNode.buildingsCount > 0) {
|
||||
buildingNodesMap.put(currNode.id, currNode);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -1,9 +1,10 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
import pl.wat.ms4ds.common.EGeoDirection;
|
||||
import pl.wat.ms4ds.terenfunkcje.*;
|
||||
import pl.wat.ms4ds.terrain.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@@ -147,47 +148,47 @@ public class Way {
|
||||
if (nodes.size() < 3) {
|
||||
return;
|
||||
}
|
||||
boolean toDelete[] = new boolean[nodes.size()];
|
||||
Node node_i;
|
||||
Node node_i_next;
|
||||
Node node_i_prev;
|
||||
boolean[] toDelete = new boolean[nodes.size()];
|
||||
Node curr_node;
|
||||
Node next_node;
|
||||
Node prev_node;
|
||||
boolean collinearFound = false;
|
||||
int dlMax = nodes.size();
|
||||
int lenMax = nodes.size();
|
||||
int iStart = 0;
|
||||
if (!isPolygon) {
|
||||
// łamana otwarta
|
||||
dlMax = nodes.size() - 1;
|
||||
lenMax = nodes.size() - 1;
|
||||
iStart = 1;
|
||||
}
|
||||
for (int i = iStart; i < dlMax; i++) {
|
||||
int i_plus_1 = (i + 1) % nodes.size();
|
||||
int i_minus_1 = (i + nodes.size() - 1) % nodes.size();
|
||||
node_i = nodes.get(i);
|
||||
node_i_next = nodes.get(i_plus_1);
|
||||
node_i_prev = nodes.get(i_minus_1);
|
||||
if (GeomUtils.include(node_i_prev.idX, node_i_prev.idY, node_i_next.idX, node_i_next.idY,
|
||||
node_i.idX, node_i.idY)) {
|
||||
for (int curr = iStart; curr < lenMax; curr++) {
|
||||
int next = (curr + 1) % nodes.size();
|
||||
int prev = (curr + nodes.size() - 1) % nodes.size();
|
||||
curr_node = nodes.get(curr);
|
||||
next_node = nodes.get(next);
|
||||
prev_node = nodes.get(prev);
|
||||
if (GeomUtils.include(prev_node.idX, prev_node.idY, next_node.idX, next_node.idY,
|
||||
curr_node.idX, curr_node.idY)) {
|
||||
// i-ty do usuniecia
|
||||
toDelete[i] = true;
|
||||
toDelete[curr] = true;
|
||||
collinearFound = true;
|
||||
} else if (GeomUtils.include(node_i.idX, node_i.idY, node_i_next.idX, node_i_next.idY,
|
||||
node_i_prev.idX, node_i_prev.idY)) {
|
||||
} else if (GeomUtils.include(curr_node.idX, curr_node.idY, next_node.idX, next_node.idY,
|
||||
prev_node.idX, prev_node.idY)) {
|
||||
// i-1-ty do usuniecia
|
||||
toDelete[i_minus_1] = true;
|
||||
toDelete[prev] = true;
|
||||
collinearFound = true;
|
||||
} else if (GeomUtils.include(node_i_prev.idX, node_i_prev.idY, node_i.idX, node_i.idY,
|
||||
node_i_next.idX, node_i_next.idY)) {
|
||||
} else if (GeomUtils.include(prev_node.idX, prev_node.idY, curr_node.idX, curr_node.idY,
|
||||
next_node.idX, next_node.idY)) {
|
||||
// i+1-ty do usuniecia
|
||||
toDelete[i_plus_1] = true;
|
||||
toDelete[next] = true;
|
||||
collinearFound = true;
|
||||
}
|
||||
}
|
||||
if (collinearFound) {
|
||||
ArrayList<Node> newList = new ArrayList<Node>();
|
||||
for (int i = 0; i < nodes.size(); i++) {
|
||||
node_i = nodes.get(i);
|
||||
curr_node = nodes.get(i);
|
||||
if (!toDelete[i]) {
|
||||
newList.add(node_i);
|
||||
newList.add(curr_node);
|
||||
}
|
||||
}
|
||||
// logger.trace("Liczba oryg. wezlow= {}, liczba niewspolliniowych wezlow= {}, roznica= {}", nodes.size(), newList.size(), nodes.size() - newList.size());
|
||||
@@ -202,20 +203,20 @@ public class Way {
|
||||
}
|
||||
boolean toDelete[] = new boolean[nodes.size()];
|
||||
Node node_i;
|
||||
Node node_j;
|
||||
Node node_k;
|
||||
Node node_ii;
|
||||
Node node_iii;
|
||||
boolean bylSchodek = false;
|
||||
for (int i = 0; i < nodes.size() - 2; i++) {
|
||||
node_i = nodes.get(i);
|
||||
node_j = nodes.get(i + 1);
|
||||
node_k = nodes.get(i + 2);
|
||||
int absX_i_j = Math.abs(node_j.idX - node_i.idX);
|
||||
int absY_i_j = Math.abs(node_j.idY - node_i.idY);
|
||||
int absX_j_k = Math.abs(node_k.idX - node_j.idX);
|
||||
int absY_j_k = Math.abs(node_k.idY - node_j.idY);
|
||||
if (absX_i_j + absY_i_j + absX_j_k + absY_j_k == 2) {
|
||||
node_ii = nodes.get(i + 1);
|
||||
node_iii = nodes.get(i + 2);
|
||||
int absX_i_ii = Math.abs(node_ii.idX - node_i.idX);
|
||||
int absY_i_ii = Math.abs(node_ii.idY - node_i.idY);
|
||||
int absX_ii_iii = Math.abs(node_iii.idX - node_ii.idX);
|
||||
int absY_ii_iii = Math.abs(node_iii.idY - node_ii.idY);
|
||||
if (absX_i_ii + absY_i_ii + absX_ii_iii + absY_ii_iii == 2) {
|
||||
// wezly moga tworzyc schodek
|
||||
if (absX_i_j + absX_j_k == 1) {
|
||||
if (absX_i_ii + absX_ii_iii == 1) {
|
||||
// wezly tworza schodek, zatem srodkowy wezel schodka do usuniecia
|
||||
toDelete[i + 1] = true;
|
||||
bylSchodek = true;
|
||||
@@ -243,36 +244,36 @@ public class Way {
|
||||
if (nodes.size() == 0) {
|
||||
return;
|
||||
}
|
||||
GridCoord[] punktyLamanej = new GridCoord[nodes.size()];
|
||||
Coord.Grid[] punktyLamanej = new Coord.Grid[nodes.size()];
|
||||
for (int i = 0; i < nodes.size(); i++) {
|
||||
punktyLamanej[i] = new GridCoord(nodes.get(i).idX, nodes.get(i).idY);
|
||||
punktyLamanej[i] = new Coord.Grid(nodes.get(i).idX, nodes.get(i).idY);
|
||||
}
|
||||
Kwadrat kw0;
|
||||
Kwadrat kw1;
|
||||
GridCoord id0;
|
||||
GridCoord id1;
|
||||
Square kw0;
|
||||
Square kw1;
|
||||
Coord.Grid id0;
|
||||
Coord.Grid id1;
|
||||
EGeoDirection kier;
|
||||
GridCoord[] kwadraty = GeomUtils.kwadratyLamanej2(punktyLamanej);
|
||||
Coord.Grid[] kwadraty = GeomUtils.generateSquaresOfSegments(punktyLamanej);
|
||||
// float dlug = GeomUtils.dlugoscDrogiPoKwadratch(kwadraty);
|
||||
for (int i = 0; i < kwadraty.length - 1; i++) {
|
||||
try {
|
||||
id0 = kwadraty[i];
|
||||
kw0 = Teren.getKwadrat(id0.x, id0.y);
|
||||
kw0 = Teren.getSquare(id0.x, id0.y);
|
||||
id1 = kwadraty[i + 1];
|
||||
kw1 = Teren.getKwadrat(id1.x, id1.y);
|
||||
kw1 = Teren.getSquare(id1.x, id1.y);
|
||||
kier = GeomUtils.kierunekDlaSasiada(id0, id1);
|
||||
switch (type) {
|
||||
case ROAD:
|
||||
kw0.setJestDroga(kier, true);
|
||||
kw1.setJestDroga(kier.oppositeDirect(), true);
|
||||
kw0.roads[kier.id] = 2;
|
||||
kw0.roads[kier.oppositeDirect().id] = 2;
|
||||
break;
|
||||
case WATER_WAY:
|
||||
kw0.setJestPrzeszkodaWodna(kier, true);
|
||||
kw1.setJestPrzeszkodaWodna(kier.oppositeDirect(), true);
|
||||
kw0.watercourses[kier.id] = 3;
|
||||
kw0.watercourses[kier.oppositeDirect().id] = 3;
|
||||
break;
|
||||
case DITCH:
|
||||
kw0.setJestRow(kier, true);
|
||||
kw1.setJestRow(kier.oppositeDirect(), true);
|
||||
kw0.watercourses[kier.id] = 1;
|
||||
kw0.watercourses[kier.oppositeDirect().id] = 1;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
@@ -282,25 +283,25 @@ public class Way {
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeAreaFeatureIntoSquares2(EAreaFeature type, boolean clearFeature, GridCoord[] polygon) {
|
||||
public static void writeAreaFeatureIntoSquares2(EAreaFeature type, boolean clearFeature, Coord.Grid[] polygon) {
|
||||
if (polygon.length > 20) {
|
||||
// podział wielokata na dwa mniejsze
|
||||
int m = 2;
|
||||
GridCoord pocz = polygon[0];
|
||||
Coord.Grid pocz = polygon[0];
|
||||
boolean poprawnyPodzial = false;
|
||||
while (m < polygon.length - 1 && !poprawnyPodzial) {
|
||||
// sprawdzenie, czy punkty wielokata po podziale sa po jednej stronie wektora podzialu
|
||||
poprawnyPodzial = true;
|
||||
GridCoord kon = polygon[m];
|
||||
Coord.Grid kon = polygon[m];
|
||||
for (int i = 0; i < polygon.length; i++) {
|
||||
int i_puls_1 = (i + 1) % polygon.length;
|
||||
boolean przeciecie = GeomUtils.intersection(pocz, kon, polygon[i], polygon[i_puls_1]);
|
||||
if (przeciecie) {
|
||||
// sprawdzenie, czy jakiś koniec jednego odcinka jest równy końcowi drugiego odcinka
|
||||
boolean b = pocz.rowne(polygon[i].x, polygon[i].y) ||
|
||||
pocz.rowne(polygon[i_puls_1].x, polygon[i_puls_1].y) ||
|
||||
kon.rowne(polygon[i].x, polygon[i].y) ||
|
||||
kon.rowne(polygon[i_puls_1].x, polygon[i_puls_1].y);
|
||||
boolean b = pocz.equals(polygon[i]) ||
|
||||
pocz.equals(polygon[i_puls_1]) ||
|
||||
kon.equals(polygon[i]) ||
|
||||
kon.equals(polygon[i_puls_1]);
|
||||
if (!b) {
|
||||
poprawnyPodzial = false;
|
||||
m++;
|
||||
@@ -311,13 +312,13 @@ public class Way {
|
||||
}
|
||||
if (poprawnyPodzial) {
|
||||
// punkt podziału wielokąta jest poprawny, zatem dzielę wielokąt na dwa
|
||||
GridCoord[] polygon1 = new GridCoord[m + 1];
|
||||
Coord.Grid[] polygon1 = new Coord.Grid[m + 1];
|
||||
for (int i = 0; i < polygon1.length; i++) {
|
||||
polygon1[i] = polygon[i];
|
||||
}
|
||||
writeAreaFeatureIntoSquares2(type, clearFeature, polygon1);
|
||||
|
||||
GridCoord[] polygon2 = new GridCoord[polygon.length - m + 1];
|
||||
Coord.Grid[] polygon2 = new Coord.Grid[polygon.length - m + 1];
|
||||
polygon2[0] = polygon[0];
|
||||
for (int i = m; i < polygon.length; i++) {
|
||||
polygon2[i - m + 1] = polygon[i];
|
||||
@@ -326,7 +327,7 @@ public class Way {
|
||||
} else {
|
||||
// nie udało się poprawnie podzielić wielokąta, zatem przesuwam wierzchołki, aby zmienić wierzchołek
|
||||
// startowy, który jest wierchołkiem referencyjnym podziału (drugi wierzchołek podziału jest szukany)
|
||||
GridCoord temp = polygon[0];
|
||||
Coord.Grid temp = polygon[0];
|
||||
for (int i = 0; i < polygon.length - 1; i++) {
|
||||
polygon[i] = polygon[i + 1];
|
||||
}
|
||||
@@ -341,35 +342,32 @@ public class Way {
|
||||
int maxX = polygon[0].x;
|
||||
int maxY = polygon[0].y;
|
||||
for (int i = 1; i < polygon.length; i++) {
|
||||
minX = (polygon[i].x < minX) ? polygon[i].x : minX;
|
||||
minY = (polygon[i].y < minY) ? polygon[i].y : minY;
|
||||
maxX = (polygon[i].x > maxX) ? polygon[i].x : maxX;
|
||||
maxY = (polygon[i].y > maxY) ? polygon[i].y : maxY;
|
||||
minX = Math.min(polygon[i].x, minX);
|
||||
minY = Math.min(polygon[i].y, minY);
|
||||
maxX = Math.max(polygon[i].x, maxX);
|
||||
maxY = Math.max(polygon[i].y, maxY);
|
||||
}
|
||||
GridCoord idTest = new GridCoord();
|
||||
boolean inside;
|
||||
for (int j = maxY; j >= minY; j--) {
|
||||
for (int i = minX; i <= maxX; i++) {
|
||||
idTest.x = i;
|
||||
idTest.y = j;
|
||||
Kwadrat kw = Teren.getKwadrat(idTest.x, idTest.y);
|
||||
if (kw == Kwadrat.EMPTY_SQUARE) {
|
||||
for (int y = maxY; y >= minY; y--) {
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
Square kw = Teren.getSquare(x, y);
|
||||
if (kw == Square.EMPTY) {
|
||||
continue;
|
||||
}
|
||||
inside = GeomUtils.insidePolygon(polygon, idTest);
|
||||
inside = GeomUtils.insidePolygon(polygon, x, y);
|
||||
if (inside) {
|
||||
switch (type) {
|
||||
case FOREST:
|
||||
kw.setStopienZalesienia(val);
|
||||
kw.terrainType = TerrainType.FOREST;
|
||||
break;
|
||||
case WATER:
|
||||
kw.setStopienZawodnienia(val);
|
||||
kw.terrainType = TerrainType.WATER;
|
||||
break;
|
||||
case SWAMP:
|
||||
kw.setStopienZabagnienia(val);
|
||||
kw.terrainType = TerrainType.SWAMP;
|
||||
break;
|
||||
case BUILDINGS:
|
||||
kw.setStopienZabudowy(val);
|
||||
kw.terrainType = TerrainType.BUILDINGS;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
@@ -378,33 +376,30 @@ public class Way {
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeAreaFeatureIntoSquares(EAreaFeature type, boolean clearFeature, GridCoord[] polygon,
|
||||
int minX,int maxX, int minY, int maxY) {
|
||||
public static void writeAreaFeatureIntoSquares(EAreaFeature type, boolean clearFeature, Coord.Grid[] polygon,
|
||||
int minX, int maxX, int minY, int maxY) {
|
||||
float val = (clearFeature) ? 0.0f : 1.0f;
|
||||
GridCoord idTest = new GridCoord();
|
||||
boolean inside;
|
||||
for (int i = minX; i <= maxX; i++) {
|
||||
for (int j = minY; j <= maxY; j++) {
|
||||
idTest.x = i;
|
||||
idTest.y = j;
|
||||
Kwadrat kw = Teren.getKwadrat(idTest.x, idTest.y);
|
||||
if (kw == Kwadrat.EMPTY_SQUARE) {
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
Square kw = Teren.getSquare(x, y);
|
||||
if (kw == Square.EMPTY) {
|
||||
continue;
|
||||
}
|
||||
inside = GeomUtils.insidePolygon(polygon, idTest);
|
||||
inside = GeomUtils.insidePolygon(polygon, x, y);
|
||||
if (inside) {
|
||||
switch (type) {
|
||||
case FOREST:
|
||||
kw.setStopienZalesienia(val);
|
||||
kw.terrainType = TerrainType.FOREST;
|
||||
break;
|
||||
case WATER:
|
||||
kw.setStopienZawodnienia(val);
|
||||
kw.terrainType = TerrainType.WATER;
|
||||
break;
|
||||
case SWAMP:
|
||||
kw.setStopienZabagnienia(val);
|
||||
kw.terrainType = TerrainType.SWAMP;
|
||||
break;
|
||||
case BUILDINGS:
|
||||
kw.setStopienZabudowy(val);
|
||||
kw.terrainType = TerrainType.BUILDINGS;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
@@ -417,53 +412,53 @@ public class Way {
|
||||
if (nodes.size() == 0) {
|
||||
return;
|
||||
}
|
||||
Kwadrat kw;
|
||||
Square kw;
|
||||
float val = (clearFeature) ? 0.0f : 1.0f;
|
||||
if (nodes.size() == 1) {
|
||||
kw = Teren.getKwadrat(nodes.get(0).idX, nodes.get(0).idY);
|
||||
kw = Teren.getSquare(nodes.get(0).idX, nodes.get(0).idY);
|
||||
switch (type) {
|
||||
case FOREST:
|
||||
kw.setStopienZalesienia(val);
|
||||
kw.terrainType = TerrainType.FOREST;
|
||||
break;
|
||||
case WATER:
|
||||
kw.setStopienZawodnienia(val);
|
||||
kw.terrainType = TerrainType.WATER;
|
||||
break;
|
||||
case SWAMP:
|
||||
kw.setStopienZabagnienia(val);
|
||||
kw.terrainType = TerrainType.SWAMP;
|
||||
break;
|
||||
case BUILDINGS:
|
||||
kw.setStopienZabudowy(val);
|
||||
kw.terrainType = TerrainType.BUILDINGS;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (nodes.size() == 2) {
|
||||
GridCoord[] kwadraty = GeomUtils.kwadratyOdcinka(nodes.get(0).idX, nodes.get(0).idY,
|
||||
Coord.Grid[] kwadraty = GeomUtils.generateSquaresOfSegment(nodes.get(0).idX, nodes.get(0).idY,
|
||||
nodes.get(1).idX, nodes.get(1).idY);
|
||||
for (int i = 0; i < kwadraty.length; i++) {
|
||||
kw = Teren.getKwadrat(kwadraty[i].x, kwadraty[i].y);
|
||||
kw = Teren.getSquare(kwadraty[i].x, kwadraty[i].y);
|
||||
switch (type) {
|
||||
case FOREST:
|
||||
kw.setStopienZalesienia(val);
|
||||
kw.terrainType = TerrainType.FOREST;
|
||||
break;
|
||||
case WATER:
|
||||
kw.setStopienZawodnienia(val);
|
||||
kw.terrainType = TerrainType.WATER;
|
||||
break;
|
||||
case SWAMP:
|
||||
kw.setStopienZabagnienia(val);
|
||||
kw.terrainType = TerrainType.SWAMP;
|
||||
break;
|
||||
case BUILDINGS:
|
||||
kw.setStopienZabudowy(val);
|
||||
kw.terrainType = TerrainType.BUILDINGS;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
GridCoord[] wielokat = new GridCoord[nodes.size()];
|
||||
Coord.Grid[] wielokat = new Coord.Grid[nodes.size()];
|
||||
for (int i = 0; i < nodes.size(); i++) {
|
||||
wielokat[i] = new GridCoord(nodes.get(i).idX, nodes.get(i).idY);
|
||||
wielokat[i] = new Coord.Grid(nodes.get(i).idX, nodes.get(i).idY);
|
||||
}
|
||||
writeAreaFeatureIntoSquares2(type, clearFeature, wielokat);
|
||||
}
|
||||
@@ -472,61 +467,61 @@ public class Way {
|
||||
if (nodes.size() == 0) {
|
||||
return;
|
||||
}
|
||||
Kwadrat kw;
|
||||
Square kw;
|
||||
float val = (clearFeature) ? 0.0f : 1.0f;
|
||||
if (nodes.size() == 1) {
|
||||
kw = Teren.getKwadrat(nodes.get(0).idX, nodes.get(0).idY);
|
||||
kw = Teren.getSquare(nodes.get(0).idX, nodes.get(0).idY);
|
||||
switch (type) {
|
||||
case FOREST:
|
||||
kw.setStopienZalesienia(val);
|
||||
kw.terrainType = TerrainType.FOREST;
|
||||
break;
|
||||
case WATER:
|
||||
kw.setStopienZawodnienia(val);
|
||||
kw.terrainType = TerrainType.WATER;
|
||||
break;
|
||||
case SWAMP:
|
||||
kw.setStopienZabagnienia(val);
|
||||
kw.terrainType = TerrainType.SWAMP;
|
||||
break;
|
||||
case BUILDINGS:
|
||||
kw.setStopienZabudowy(val);
|
||||
kw.terrainType = TerrainType.BUILDINGS;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (nodes.size() == 2) {
|
||||
GridCoord[] kwadraty = GeomUtils.kwadratyOdcinka(nodes.get(0).idX, nodes.get(0).idY,
|
||||
Coord.Grid[] kwadraty = GeomUtils.generateSquaresOfSegment(nodes.get(0).idX, nodes.get(0).idY,
|
||||
nodes.get(1).idX, nodes.get(1).idY);
|
||||
for (int i = 0; i < kwadraty.length; i++) {
|
||||
kw = Teren.getKwadrat(kwadraty[i].x, kwadraty[i].y);
|
||||
kw = Teren.getSquare(kwadraty[i].x, kwadraty[i].y);
|
||||
switch (type) {
|
||||
case FOREST:
|
||||
kw.setStopienZalesienia(val);
|
||||
kw.terrainType = TerrainType.FOREST;
|
||||
break;
|
||||
case WATER:
|
||||
kw.setStopienZawodnienia(val);
|
||||
kw.terrainType = TerrainType.WATER;
|
||||
break;
|
||||
case SWAMP:
|
||||
kw.setStopienZabagnienia(val);
|
||||
kw.terrainType = TerrainType.SWAMP;
|
||||
break;
|
||||
case BUILDINGS:
|
||||
kw.setStopienZabudowy(val);
|
||||
kw.terrainType = TerrainType.BUILDINGS;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
GridCoord[] wielokat = new GridCoord[nodes.size()];
|
||||
Coord.Grid[] wielokat = new Coord.Grid[nodes.size()];
|
||||
int minX = nodes.get(0).idX;
|
||||
int minY = nodes.get(0).idY;
|
||||
int maxX = nodes.get(0).idX;
|
||||
int maxY = nodes.get(0).idY;
|
||||
for (int i = 0; i < nodes.size(); i++) {
|
||||
wielokat[i] = new GridCoord(nodes.get(i).idX, nodes.get(i).idY);
|
||||
minX = (wielokat[i].x < minX) ? wielokat[i].x : minX;
|
||||
minY = (wielokat[i].y < minY) ? wielokat[i].y : minY;
|
||||
maxX = (wielokat[i].x > maxX) ? wielokat[i].x : maxX;
|
||||
maxY = (wielokat[i].y > maxY) ? wielokat[i].y : maxY;
|
||||
wielokat[i] = new Coord.Grid(nodes.get(i).idX, nodes.get(i).idY);
|
||||
minX = Math.min(wielokat[i].x, minX);
|
||||
minY = Math.min(wielokat[i].y, minY);
|
||||
maxX = Math.max(wielokat[i].x, maxX);
|
||||
maxY = Math.max(wielokat[i].y, maxY);
|
||||
}
|
||||
int ileKwTest = (maxX - minX) * (maxY - minY);
|
||||
if (ileKwTest > 100000) {
|
||||
@@ -542,37 +537,34 @@ public class Way {
|
||||
}
|
||||
return;
|
||||
}
|
||||
GridCoord idTest = new GridCoord();
|
||||
boolean nalezyDoWielokata;
|
||||
// int liczKw = 0;
|
||||
// int liczKwObszaru = 0;
|
||||
// for (int j = maxY; j >= minY; j--) {
|
||||
// for (int i = minX; i <= maxX; i++) {
|
||||
for (int i = minX; i <= maxX; i++) {
|
||||
for (int j = minY; j <= maxY; j++) {
|
||||
idTest.x = i;
|
||||
idTest.y = j;
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
// char c = ' ';
|
||||
// liczKw++;
|
||||
kw = Teren.getKwadrat(idTest.x, idTest.y);
|
||||
if (kw == Kwadrat.EMPTY_SQUARE) {
|
||||
kw = Teren.getSquare(x, y);
|
||||
if (kw == Square.EMPTY) {
|
||||
continue;
|
||||
}
|
||||
nalezyDoWielokata = GeomUtils.insidePolygon(wielokat, idTest);
|
||||
nalezyDoWielokata = GeomUtils.insidePolygon(wielokat, x, y);
|
||||
if (nalezyDoWielokata) {
|
||||
// c = 'O';
|
||||
switch (type) {
|
||||
case FOREST:
|
||||
kw.setStopienZalesienia(val);
|
||||
kw.terrainType = TerrainType.FOREST;
|
||||
break;
|
||||
case WATER:
|
||||
kw.setStopienZawodnienia(val);
|
||||
kw.terrainType = TerrainType.WATER;
|
||||
break;
|
||||
case SWAMP:
|
||||
kw.setStopienZabagnienia(val);
|
||||
kw.terrainType = TerrainType.SWAMP;
|
||||
break;
|
||||
case BUILDINGS:
|
||||
kw.setStopienZabudowy(val);
|
||||
kw.terrainType = TerrainType.BUILDINGS;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.konwersja;
|
||||
package pl.wat.ms4ds.terrain.osm;
|
||||
|
||||
import pl.wat.ms4ds.terenfunkcje.GridCoord;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pl.wat.ms4ds.terrain.Coord;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@@ -18,13 +19,13 @@ public class Worker extends Thread {
|
||||
|
||||
EAreaFeature type;
|
||||
boolean clearFeature;
|
||||
GridCoord[] polygon;
|
||||
Coord.Grid[] polygon;
|
||||
int minX;
|
||||
int maxX;
|
||||
int minY;
|
||||
int maxY;
|
||||
|
||||
public Worker(EAreaFeature type, boolean clearFeature, GridCoord[] polygon, int minX, int maxX, int minY, int maxY) {
|
||||
public Worker(EAreaFeature type, boolean clearFeature, Coord.Grid[] polygon, int minX, int maxX, int minY, int maxY) {
|
||||
super("Worker_" + nr++);
|
||||
this.type = type;
|
||||
this.clearFeature = clearFeature;
|
||||
@@ -39,14 +40,10 @@ public class Worker extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
int ileKwTest = (maxX - minX) * (maxY - minY);
|
||||
synchronized (OpenStreetMapReader.synch) {
|
||||
logger.debug(Thread.currentThread().getName() + " >>> polygon.lent= " + polygon.length + ", ileKwTest= " + Integer.toString(ileKwTest));
|
||||
}
|
||||
int ileKwTest = (maxX - minX + 1) * (maxY - minY + 1);
|
||||
logger.debug("{} >>> polygon.lent= {}, ileKwTest= {}", Thread.currentThread().getName(), polygon.length, ileKwTest);
|
||||
Way.writeAreaFeatureIntoSquares(type, clearFeature, polygon, minX, maxX, minY, maxY);
|
||||
synchronized (OpenStreetMapReader.synch) {
|
||||
logger.debug(Thread.currentThread().getName() + " <<< polygon.lent= " + polygon.length + ", ileKwTest= " + Integer.toString(ileKwTest));
|
||||
}
|
||||
logger.debug("{} <<< polygon.lent= {}, ileKwTest= {}", Thread.currentThread().getName(), polygon.length, ileKwTest);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.osm.shapefile;
|
||||
package pl.wat.ms4ds.terrain.osmshp;
|
||||
|
||||
public class DbfField {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.osm.shapefile;
|
||||
package pl.wat.ms4ds.terrain.osmshp;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
130
src/main/java/pl/wat/ms4ds/terrain/osmshp/DbfRecord.java
Normal file
130
src/main/java/pl/wat/ms4ds/terrain/osmshp/DbfRecord.java
Normal file
@@ -0,0 +1,130 @@
|
||||
package pl.wat.ms4ds.terrain.osmshp;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class DbfRecord {
|
||||
|
||||
/**
|
||||
* OSM Id taken from the Id of this feature (node_id, way_id, or relation_id) in the
|
||||
* OSM database.
|
||||
* VARCHAR (10 Bytes)
|
||||
*/
|
||||
String osmId;
|
||||
|
||||
/**
|
||||
* Digit code (between 1000 and 9999) defining the feature class. The first one or
|
||||
* two digits define the layer, the last two or three digits the class inside a layer.
|
||||
*/
|
||||
int code;
|
||||
|
||||
/**
|
||||
* Class name of this feature. This does not add any information that is not already
|
||||
* in the “code” field but it is better readable.
|
||||
*/
|
||||
String fclass;
|
||||
|
||||
/**
|
||||
* Name of this feature, like a street or place name.
|
||||
*/
|
||||
String name;
|
||||
|
||||
String roadRef;
|
||||
boolean oneway;
|
||||
int roadMaxSpeed;
|
||||
int roadLayer;
|
||||
boolean bridge;
|
||||
boolean tunnel;
|
||||
|
||||
int waterwayWidth;
|
||||
String buildingType;
|
||||
|
||||
|
||||
public DbfRecord() throws Exception {
|
||||
}
|
||||
|
||||
public void read(BufferedInputStream bis, DbfHeader header) throws Exception {
|
||||
byte[] data = new byte[header.recordSize];
|
||||
if (bis.read(data) != header.recordSize) {
|
||||
throw new Exception("Invalid dbf file");
|
||||
}
|
||||
// Zamiana znaków spoza zakresu UTF-8 (ujemnych) na spację.
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
if (data[i] < 0) {
|
||||
data[i] = 32;
|
||||
}
|
||||
}
|
||||
String str = new String(data, StandardCharsets.UTF_8);
|
||||
// Na pozycji 0 jest tzw. flag byte, dane startują od pozycji 1.
|
||||
int from = 1;
|
||||
int to = from + header.fields[0].size;
|
||||
// Pomijam czytanie osm id, gdyż nie jest wykorzystywane.
|
||||
// osmId = str.substring(from, to);
|
||||
// int endPos = osmId.indexOf(' ');
|
||||
// osmId = osmId.substring(0, endPos);
|
||||
from = to;
|
||||
to += header.fields[1].size;
|
||||
String codeStr = str.substring(from, to);
|
||||
code = Integer.parseInt(codeStr);
|
||||
from = to;
|
||||
to += header.fields[2].size;
|
||||
fclass = str.substring(from, to);
|
||||
fclass = fclass.substring(0, fclass.indexOf(' '));
|
||||
from = to;
|
||||
to += header.fields[3].size;
|
||||
name = str.substring(from, to);
|
||||
if (header.fields.length > 4) {
|
||||
String s;
|
||||
for (int i = 4; i < header.fields.length; i++) {
|
||||
from = to;
|
||||
to += header.fields[i].size;
|
||||
s = str.substring(from, to);
|
||||
if (header.fields[i].type == 'N') {
|
||||
// Wartość numeryczna (int), zatem usuwam poprzedzające spacje
|
||||
s = s.stripLeading();
|
||||
}
|
||||
switch (header.fields[i].name) {
|
||||
case "ref":
|
||||
roadRef = s;
|
||||
break;
|
||||
case "oneway":
|
||||
oneway = !s.equals("B");
|
||||
break;
|
||||
case "maxspeed":
|
||||
roadMaxSpeed = Integer.parseInt(s);
|
||||
break;
|
||||
case "layer":
|
||||
roadLayer = Integer.parseInt(s);
|
||||
break;
|
||||
case "bridge":
|
||||
bridge = s.equals("T");
|
||||
break;
|
||||
case "tunnel":
|
||||
tunnel = s.equals("T");
|
||||
break;
|
||||
case "width":
|
||||
waterwayWidth = Integer.parseInt(s);
|
||||
break;
|
||||
case "type":
|
||||
buildingType = s;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Additional attributes for roads
|
||||
//ref - VARCHAR(20) Reference number of this road ('A 5', 'L 605', ...) ref=*
|
||||
//oneway VARCHAR(1) Is this a oneway road? “F” means that only driving
|
||||
//in direction of the linestring is allowed. “T” means
|
||||
//that only the opposite direction is allowed. “B”
|
||||
//(default value) means that both directions are ok.
|
||||
//oneway=*
|
||||
//maxspeed SMALLINT Max allowed speed in km/h maxspeed=*
|
||||
//layer SMALLINT Relative layering of roads (-5, ..., 0, ..., 5) layer=*
|
||||
//bridge VARCHAR(1) Is this road on a bridge? (“T” = true, “F” = false) bridge=*
|
||||
//tunnel VARCHAR(1) Is this road in a tunnel? (“T” = true, “F” = false) tunnel=*
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.osm.shapefile;
|
||||
package pl.wat.ms4ds.terrain.osmshp;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
@@ -49,9 +49,10 @@ public class OsmShapeFileReader {
|
||||
// wetland 8221
|
||||
|
||||
/**
|
||||
* Konstruktor obiektu readera danych OSM Shp.
|
||||
*
|
||||
* <pre>
|
||||
* init the ShapeFile, and load the following files:
|
||||
* "path + filename.shx",
|
||||
* "path + filename.dbf",
|
||||
* "path + filename.shp"
|
||||
* </pre>
|
||||
@@ -63,16 +64,21 @@ public class OsmShapeFileReader {
|
||||
public OsmShapeFileReader(String path, String filename) throws Exception {
|
||||
File dir = new File(path);
|
||||
File shpFile = new File(dir, filename + ".shp");
|
||||
FileInputStream is = new FileInputStream(shpFile);
|
||||
bisShp = new BufferedInputStream(is);
|
||||
bisShp = new BufferedInputStream(new FileInputStream(shpFile));
|
||||
shpHeader = new ShpHeader(bisShp);
|
||||
File dbfFile = new File(dir, filename + ".dbf");
|
||||
bisDbf = new BufferedInputStream(new FileInputStream(dbfFile));
|
||||
dbfHeader = new DbfHeader(bisDbf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Metoda odczytuje i zwraca obiekt reprezentujący określony kształt wraz z dodatkową informacją.
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public ShpShape nextShape() throws Exception {
|
||||
boolean hasNext = false;
|
||||
boolean hasNext;
|
||||
try {
|
||||
hasNext = hasNextShape();
|
||||
} catch (IOException e) {
|
||||
@@ -82,44 +88,33 @@ public class OsmShapeFileReader {
|
||||
return null;
|
||||
}
|
||||
ShpShape shape = null;
|
||||
DbfRecord info = null;
|
||||
DbfRecord info;
|
||||
switch (shpHeader.shapeType) {
|
||||
// case Point, PointZ, PointM:
|
||||
// shape = new ShpPoint(shpHeader.shapeType);
|
||||
// shape.read(bisShp);
|
||||
// info = new DbfRecord();
|
||||
// info.read(bisDbf, dbfHeader);
|
||||
// shape.setInfo(info);
|
||||
// return shape;
|
||||
// case PolyLine, PolyLineZ, PolyLineM:
|
||||
// shape = new ShpPolyLine(shpHeader.shapeType);
|
||||
// shape.read(bisShp);
|
||||
// info = new DbfRecord();
|
||||
// info.read(bisDbf, dbfHeader);
|
||||
// shape.setInfo(info);
|
||||
// return shape;
|
||||
// case Polygon, PolygonZ, PolygonM:
|
||||
// shape = new ShpPolygon(shpHeader.shapeType);
|
||||
// shape.read(bisShp);
|
||||
// info = new DbfRecord();
|
||||
// info.read(bisDbf, dbfHeader);
|
||||
// shape.setInfo(info);
|
||||
// return shape;
|
||||
// case MultiPoint, MultiPointZ, MultiPointM:
|
||||
// shape = new ShpMultiPoint(shpHeader.shapeType);
|
||||
// shape.read(bisShp);
|
||||
// info = new DbfRecord();
|
||||
// info.read(bisDbf, dbfHeader);
|
||||
// shape.setInfo(info);
|
||||
// return shape;
|
||||
case Point, PointZ, PointM:
|
||||
shape = new ShpPoint(shpHeader.shapeType);
|
||||
break;
|
||||
case PolyLine, PolyLineZ, PolyLineM:
|
||||
shape = new ShpPolyLine(shpHeader.shapeType);
|
||||
break;
|
||||
case Polygon, PolygonZ, PolygonM:
|
||||
shape = new ShpPolygon(shpHeader.shapeType);
|
||||
break;
|
||||
case MultiPoint, MultiPointZ, MultiPointM:
|
||||
shape = new ShpMultiPoint(shpHeader.shapeType);
|
||||
break;
|
||||
default:
|
||||
return shape;
|
||||
}
|
||||
|
||||
shape.read(bisShp);
|
||||
info = new DbfRecord();
|
||||
info.read(bisDbf, dbfHeader);
|
||||
shape.setInfo(info);
|
||||
return shape;
|
||||
}
|
||||
|
||||
public boolean hasNextShape() throws IOException {
|
||||
return bisShp.available() > 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,581 @@
|
||||
package pl.wat.ms4ds.terrain.osmshp;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pl.wat.ms4ds.common.EGeoDirection;
|
||||
import pl.wat.ms4ds.terrain.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class OsmShpDataGenerator {
|
||||
private static final Logger logger = LoggerFactory.getLogger(OsmShpDataGenerator.class);
|
||||
|
||||
static void main(String[] args) {
|
||||
try {
|
||||
// GET DIRECTORY
|
||||
// "C:/Workspace/osm/warminsko-mazurskie-251217-free.shp/"
|
||||
// "dolnoslaskie"
|
||||
// "kujawsko-pomorskie"
|
||||
// "lodzkie"
|
||||
// "lubelskie"
|
||||
// "lubuskie"
|
||||
// "malopolskie"
|
||||
// "mazowieckie"
|
||||
// "opolskie"
|
||||
// "podkarpackie"
|
||||
// "podlaskie"
|
||||
// "pomorskie"
|
||||
// "slaskie"
|
||||
// "swietokrzyskie"
|
||||
// "warminsko-mazurskie"
|
||||
// "wielkopolskie"
|
||||
// "zachodniopomorskie"
|
||||
// String[] regions = new String[]{"dolnoslaskie", "kujawsko-pomorskie", "lodzkie", "lubelskie",
|
||||
// "lubuskie", "malopolskie", "mazowieckie", "opolskie",
|
||||
// "podkarpackie", "podlaskie", "pomorskie", "slaskie",
|
||||
// "swietokrzyskie", "warminsko-mazurskie", "wielkopolskie", "zachodniopomorskie"};
|
||||
|
||||
ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor();
|
||||
String ext = "-251217-free.shp/";
|
||||
String inDir = "C:/Workspace/osm/";
|
||||
String outDir = "D:/work/kwadraty_nmt/temp/100m/";
|
||||
|
||||
// final String[] areaLayers = new String[]{"landuse_a", "buildings_a", "water_a", "pois_a", "pofw_a"};
|
||||
// final String[] pointLayers = new String[]{"pois", "pofw"};
|
||||
// final String[] linearLayers = new String[]{"waterways", "roads"};
|
||||
final String[] areaLayers = new String[]{"landuse_a", "buildings_a", "water_a"};
|
||||
final String[] pointLayers = new String[]{"pois", "pofw"};
|
||||
final String[] linearLayers = new String[]{"waterways", "roads"};
|
||||
double d = 3 * MapConsts.SS_DELTA_LON;
|
||||
|
||||
// final int concurrency = 2;
|
||||
//// String layerName = "gis_osm_" + areaLayers[0] + "_free_1";
|
||||
// for (int j = 0; j < 8; j++) {
|
||||
// Future[] futures = new Future[concurrency];
|
||||
// for (int i = 0; i < concurrency; i++) {
|
||||
// final int ii = concurrency * j + i;
|
||||
// futures[i] = executor.submit(() -> {
|
||||
// for (int k = 0; k < areaLayers.length; k++) {
|
||||
// logger.info("Work started: region= {}, layer= {}", regions[ii], areaLayers[k]);
|
||||
// String ln = "gis_osm_" + areaLayers[k] + "_free_1";
|
||||
// HashSet<ArrayList<Coord.Grid[]>>[] data = generateDataFromAreaLayer(inDir + regions[ii] + ext, ln);
|
||||
// writeAreaFeatures(data);
|
||||
// int size = 0;
|
||||
// for (HashSet<ArrayList<Coord.Grid[]>> datum : data) {
|
||||
// if (datum != null) {
|
||||
// size += datum.size();
|
||||
// datum.clear();
|
||||
// }
|
||||
// }
|
||||
// logger.info("Work finished: region= {}, layer= {}, data.size= {}", regions[ii], areaLayers[k]);
|
||||
// }
|
||||
// for (int k = 0; k < pointLayers.length; k++) {
|
||||
// logger.info("Work started: region= {}, layer= {}", regions[ii], pointLayers[k]);
|
||||
// String ln = "gis_osm_" + pointLayers[k] + "_free_1";
|
||||
// HashSet<Coord.Grid> data = generateDataFromPointLayer(inDir + regions[ii] + ext, ln);
|
||||
// writeAreaFeatureIntoSquares(TerrainType.BUILDINGS, false, data);
|
||||
// int size = data.size();
|
||||
// data.clear();
|
||||
// logger.info("Work finished: region= {}, layer= {}, data.size= {}", regions[ii], pointLayers[k], size);
|
||||
// }
|
||||
// for (int k = 0; k < linearLayers.length; k++) {
|
||||
// logger.info("Work started: region= {}, layer= {}", regions[ii], linearLayers[k]);
|
||||
// String ln = "gis_osm_" + linearLayers[k] + "_free_1";
|
||||
// HashSet<ArrayList<Coord.Grid[]>>[] data = generateDataFromLinearLayer(inDir + regions[ii] + ext, ln);
|
||||
// writeLinearFeatures(data, k);
|
||||
// int size = 0;
|
||||
// for (HashSet<ArrayList<Coord.Grid[]>> datum : data) {
|
||||
// if (datum != null) {
|
||||
// size += datum.size();
|
||||
// datum.clear();
|
||||
// }
|
||||
// }
|
||||
// logger.info("Work finished: region= {}, layer= {}, data.size= {}", regions[ii], linearLayers[k], size);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// for (Future future : futures) {
|
||||
// future.get();
|
||||
// }
|
||||
// Teren.saveToFiles(outDir);
|
||||
// }
|
||||
|
||||
// String layerName = "gis_osm_" + areaLayers[0] + "_free_1";
|
||||
String[] regions = new String[]{"dolnoslaskie", "kujawsko-pomorskie", "lodzkie", "lubelskie",
|
||||
"lubuskie", "malopolskie", "opolskie", "mazowieckie", "warminsko-mazurskie",
|
||||
"podkarpackie", "podlaskie", "pomorskie", "slaskie",
|
||||
"swietokrzyskie", "wielkopolskie", "zachodniopomorskie"};
|
||||
// String[] regions = new String[]{"mazowieckie", "warminsko-mazurskie"};
|
||||
for (int i = 0; i < regions.length; i++) {
|
||||
for (int k = 0; k < areaLayers.length; k++) {
|
||||
logger.info("Work started: region= {}, layer= {}", regions[i], areaLayers[k]);
|
||||
String ln = "gis_osm_" + areaLayers[k] + "_free_1";
|
||||
HashSet<ArrayList<Coord.Grid[]>>[] data = generateDataFromAreaLayer(inDir + regions[i] + ext, ln);
|
||||
writeAreaFeatures(data);
|
||||
for (HashSet<ArrayList<Coord.Grid[]>> datum : data) {
|
||||
if (datum != null) {
|
||||
datum.clear();
|
||||
}
|
||||
}
|
||||
logger.info("Work finished: region= {}, layer= {}", regions[i], areaLayers[k]);
|
||||
}
|
||||
for (int k = 0; k < pointLayers.length; k++) {
|
||||
logger.info("Work started: region= {}, layer= {}", regions[i], pointLayers[k]);
|
||||
String ln = "gis_osm_" + pointLayers[k] + "_free_1";
|
||||
HashSet<Coord.Grid> data = generateDataFromPointLayer(inDir + regions[i] + ext, ln);
|
||||
writeAreaFeatureIntoSquares(TerrainType.BUILDINGS, false, data);
|
||||
data.clear();
|
||||
logger.info("Work finished: region= {}, layer= {}", regions[i], pointLayers[k]);
|
||||
}
|
||||
for (int k = 0; k < linearLayers.length; k++) {
|
||||
logger.info("Work started: region= {}, layer= {}", regions[i], linearLayers[k]);
|
||||
String ln = "gis_osm_" + linearLayers[k] + "_free_1";
|
||||
HashSet<ArrayList<Coord.Grid[]>>[] data = generateDataFromLinearLayer(inDir + regions[i] + ext, ln);
|
||||
writeLinearFeatures(data, k);
|
||||
for (HashSet<ArrayList<Coord.Grid[]>> datum : data) {
|
||||
if (datum != null) {
|
||||
datum.clear();
|
||||
}
|
||||
}
|
||||
logger.info("Work finished: region= {}, layer= {}", regions[i], linearLayers[k]);
|
||||
}
|
||||
Teren.saveToFiles(outDir);
|
||||
}
|
||||
|
||||
// HashSet<ArrayList<Coord.Grid[]>>[] data = generateDataFromAreaLayer(inDir + regions[0] + ext, "gis_osm_pois_a_free_1");
|
||||
// writeAreaFeatures(data);
|
||||
// String ln = "gis_osm_" + pointLayers[1] + "_free_1";
|
||||
// HashSet<Coord.Grid> data2 = generateDataFromPointLayer(inDir + regions[0] + ext, ln);
|
||||
// writeAreaFeatureIntoSquares(TerrainType.BUILDINGS, false, data2);
|
||||
|
||||
// writeLinearFeatures(data, 1);
|
||||
// Teren.saveToFiles(outDir);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zapisuje dane dotyczace określonych charakterystyk terenowych
|
||||
* (odpowiadające indeksom głównej tablicy) do kwadratów.
|
||||
* <p></p>
|
||||
* Każda cecha przetwarzana jest osobno (indeks tablicy). W ramach cechy przetwarzane są obszary.
|
||||
* Każdy obszar opisany jest listą wielokątów określających zewnętrzne granice oraz opcjonalnie dziury.
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
public static void writeAreaFeatures(HashSet<ArrayList<Coord.Grid[]>>[] data) {
|
||||
HashSet<Coord.Grid> squareSet = new HashSet<>();
|
||||
// Indeksy odpowiadają numeracji (id) wartości w TerrainType.
|
||||
for (int typeId = 1; typeId < data.length; typeId++) {
|
||||
HashSet<ArrayList<Coord.Grid[]>> set = data[typeId];
|
||||
if (set == null || set.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
TerrainType terrainType = TerrainType.valueFromId(typeId);
|
||||
for (ArrayList<Coord.Grid[]> area : set) {
|
||||
collectSquaresOfArea(area, squareSet, true);
|
||||
writeAreaFeatureIntoSquares(terrainType, false, squareSet);
|
||||
squareSet.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja gromadzi współrzędne (gridowe) kwadratów należących do obszaru opisanego wielokątami.
|
||||
* Pierwszy wielokąt opisuje zewnętrzne granice obszaru.
|
||||
* Kolejne wielokąty opisują granice obszarów wewnętrznych, będących dziurami.
|
||||
*
|
||||
* @param area
|
||||
* @param squareSet
|
||||
*/
|
||||
public static void collectSquaresOfArea(ArrayList<Coord.Grid[]> area, HashSet<Coord.Grid> squareSet, boolean onlyOuter) {
|
||||
Coord.Grid[] outerPolygon = area.getFirst();
|
||||
if (outerPolygon == null) {
|
||||
return;
|
||||
}
|
||||
int[] bounds = GeomUtils.getBounds(outerPolygon);
|
||||
int minX = bounds[0];
|
||||
int minY = bounds[1];
|
||||
int maxX = bounds[2];
|
||||
int maxY = bounds[3];
|
||||
boolean inside;
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
inside = GeomUtils.insidePolygon(outerPolygon, x, y);
|
||||
if (inside) {
|
||||
squareSet.add(new Coord.Grid(x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (onlyOuter) {
|
||||
return;
|
||||
}
|
||||
int count = squareSet.size();
|
||||
// Pozostałe wielokąty opisują obszary wewnętrzne będące tzw. dziurami.
|
||||
boolean removed;
|
||||
Coord.Grid[] innerPolygon;
|
||||
Coord.Grid test;
|
||||
for (int i = 1; i < area.size(); i++) {
|
||||
innerPolygon = area.get(i);
|
||||
bounds = GeomUtils.getBounds(innerPolygon);
|
||||
minX = bounds[0];
|
||||
minY = bounds[1];
|
||||
maxX = bounds[2];
|
||||
maxY = bounds[3];
|
||||
test = new Coord.Grid();
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
inside = GeomUtils.insidePolygon(outerPolygon, x, y);
|
||||
if (inside) {
|
||||
test.x = x;
|
||||
test.y = y;
|
||||
removed = squareSet.remove(test);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int countOfRemoved = count - squareSet.size();
|
||||
logger.trace("Num of outer= {}, num of inner= {}", count, countOfRemoved);
|
||||
|
||||
}
|
||||
|
||||
public static void writeAreaFeatureIntoSquares(TerrainType type, boolean clearFeature, HashSet<Coord.Grid> squareSet) {
|
||||
TerrainType val = (clearFeature) ? TerrainType.NONE : type;
|
||||
for (Coord.Grid coord : squareSet) {
|
||||
Square square = Teren.getSquare(coord.x, coord.y);
|
||||
if (square == Square.EMPTY) {
|
||||
continue;
|
||||
}
|
||||
synchronized (square) {
|
||||
square.terrainType = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zwraca id wartości typu wyliczeniowego {@link TerrainType} dla obiektów obszarowych.
|
||||
* <p>Wartość 0 - NONE, 1 - GRASS, 2 - SWAMP, 3 - WATER, 4 - SCRUB_BUSHES, 5 - BUILDINGS, 6 - FOREST.
|
||||
*
|
||||
* @param shpShape
|
||||
* @return
|
||||
*/
|
||||
public static int mapFclassToTerrainType(ShpShape shpShape) {
|
||||
if (shpShape.info.code == 1500) {
|
||||
return TerrainType.BUILDINGS.id;
|
||||
}
|
||||
return switch (shpShape.info.fclass) {
|
||||
// case "residential", "industrial", "commercial", "retail", "farmyard" -> TerrainType.BUILDINGS.id;
|
||||
case "police", "fire_station", "post_office", "library", "town_hall", "courthouse", "prison", "embassy",
|
||||
"theatre", "nightclub", "cinema", "nursing_home", "market_place", "university", "school",
|
||||
"kindergarten", "college", "public_building", "pharmacy", "hospital", "clinic", "doctors", "dentist",
|
||||
"veterinary", "restaurant", "fast_food", "cafe", "pub", "hotel", "motel", "bed_and_breakfast",
|
||||
"guesthouse", "hostel", "supermarket", "bakery", "mall", "department_store", "bank", "museum",
|
||||
"castle", "bookshop", "clothes", "general", "hairdresser",
|
||||
"jeweller", "optician" -> TerrainType.BUILDINGS.id;
|
||||
case "christian", "christian_anglican", "christian_catholic", "christian_evangelical",
|
||||
"christian_lutheran", "christian_methodist", "christian_orthodox", "christian_protestant",
|
||||
"christian_baptist", "christian_mormon" -> TerrainType.BUILDINGS.id;
|
||||
case "forest", "woodland", "park", "orchard" -> TerrainType.FOREST.id;
|
||||
case "grass", "meadow", "farmland", "recreation_ground", "heath" -> TerrainType.GRASS.id;
|
||||
case "scrub", "vineyard", "allotments" -> TerrainType.SCRUB_BUSHES.id;
|
||||
case "water", "reservoir", "river", "dock" -> TerrainType.WATER.id;
|
||||
case "wetland" -> TerrainType.SWAMP.id;
|
||||
default -> TerrainType.NONE.id;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generuje dane obszarowe w zakresie typu terenu {@link TerrainType}.
|
||||
* <p>
|
||||
* "gis_osm_landuse_a_free_1", "gis_osm_water_a_free_1", "gis_osm_buildings_a_free_1", "gis_osm_pois_a_free_1", "gis_osm_pofw_a_free_1"
|
||||
*
|
||||
* @param path
|
||||
*/
|
||||
static HashSet<ArrayList<Coord.Grid[]>>[] generateDataFromAreaLayer(String path, String filename) {
|
||||
HashSet<ArrayList<Coord.Grid[]>>[] result = new HashSet[TerrainType.values().length];
|
||||
result[1] = new HashSet<>();
|
||||
result[2] = new HashSet<>();
|
||||
result[3] = new HashSet<>();
|
||||
result[4] = new HashSet<>();
|
||||
result[5] = new HashSet<>();
|
||||
result[6] = new HashSet<>();
|
||||
try {
|
||||
OsmShapeFileReader osmShapeFileReader = new OsmShapeFileReader(path, filename);
|
||||
int pos = 0;
|
||||
int typeId;
|
||||
while (osmShapeFileReader.hasNextShape()) {
|
||||
ShpShape shape = osmShapeFileReader.nextShape();
|
||||
if (shape instanceof ShpPolygon shpPolygon) {
|
||||
typeId = mapFclassToTerrainType(shpPolygon);
|
||||
String fclass = shpPolygon.info.fclass;
|
||||
if (shpPolygon.info.code == 1500) {
|
||||
// Warstwa obszarowa dot. budynków nie ma zdefiniowanej fclass, zatem sprawdzam code
|
||||
// i ewentualnie zmieniam typeId.
|
||||
typeId = TerrainType.BUILDINGS.id;
|
||||
fclass = "building1500";
|
||||
}
|
||||
if (typeId == 0) {
|
||||
continue;
|
||||
}
|
||||
logger.trace("Shape pos = {}, shape type = {}, fclass= {}, numParts= {}", pos, shape.getShapeType(), fclass, shpPolygon.numberOfParts);
|
||||
ArrayList<Coord.Grid[]> polygons = generatePolylines(shpPolygon);
|
||||
result[typeId].add(polygons);
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
logger.info("End, num={}", pos);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
enum WatercourseType {
|
||||
NONE(0), DITCH_DRAIN(1), STREAM(2), RIVER(3);
|
||||
|
||||
public final int id;
|
||||
|
||||
WatercourseType(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static WatercourseType valueFromId(int id) {
|
||||
return values[id];
|
||||
}
|
||||
|
||||
static final WatercourseType[] values = WatercourseType.values();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja zwraca id wartości typu wyliczeniowego dla obiektów liniowych typu cieki wodne oraz drogi.
|
||||
* <p>Wartość 0 - brak, 1 - DITCH_DRAIN/SMALL, 2 - STREAM/MINOR, 3 - RIVER/MAJOR
|
||||
*
|
||||
* @param shpShape
|
||||
* @return typeId of linear feature: 0 - NONE, 1 - DITCH_DRAIN/SMALL, 2 - STREAM/MINOR, 3 - RIVER/MAJOR
|
||||
*/
|
||||
public static int mapFclassToLineTypeId(ShpShape shpShape) {
|
||||
return switch (shpShape.info.fclass) {
|
||||
case "river" -> WatercourseType.RIVER.id;
|
||||
case "stream", "canal" -> WatercourseType.STREAM.id;
|
||||
case "drain" -> WatercourseType.DITCH_DRAIN.id;
|
||||
case "motorway", "trunk", "primary", "secondary", "tertiary", "motorway_link", "trunk_link", "primary_link",
|
||||
"secondary_link", "tertiary_link" -> RoadType.MAJOR.id;
|
||||
case "unclassified", "residential", "living_street" -> RoadType.MINOR.id;
|
||||
case "service", "track", "track_grade1", "track_grade2", "track_grade3", "track_grade4", "track_grade5" ->
|
||||
RoadType.SMALL.id;
|
||||
default -> 0;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generuje dane liniowe w zakresie cieków/przeszkód wodnych.
|
||||
* (RIVER, STREAM, DITCH_DRAIN).
|
||||
* (MAJOR_ROADS, MINOR_ROADS, SMALL_ROADS)
|
||||
* <p>
|
||||
* "gis_osm_waterways_free_1", "gis_osm_roads_free_1"
|
||||
*
|
||||
* @param path
|
||||
*/
|
||||
static HashSet<ArrayList<Coord.Grid[]>>[] generateDataFromLinearLayer(String path, String filename) {
|
||||
HashSet<ArrayList<Coord.Grid[]>>[] result = new HashSet[]{new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>()};
|
||||
int width;
|
||||
try {
|
||||
OsmShapeFileReader osmShapeFileReader = new OsmShapeFileReader(path, filename);
|
||||
int pos = 0;
|
||||
int typeId;
|
||||
while (osmShapeFileReader.hasNextShape()) {
|
||||
ShpShape shape = osmShapeFileReader.nextShape();
|
||||
typeId = mapFclassToLineTypeId(shape);
|
||||
if (typeId == 0) {
|
||||
continue;
|
||||
}
|
||||
if (shape instanceof ShpPolyLine shpPolyLine) {
|
||||
width = shpPolyLine.info.waterwayWidth;
|
||||
logger.trace("Shape pos = {}, shape type = {}, fclass= {}, numParts= {}, width= {}", pos, shape.getShapeType(), shape.info.fclass, shpPolyLine.numberOfParts, width);
|
||||
ArrayList<Coord.Grid[]> polylines = generatePolylines(shpPolyLine);
|
||||
result[typeId].add(polylines);
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
logger.info("End, num={}", pos);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
enum RoadType {
|
||||
NONE(0), SMALL(1), MINOR(2), MAJOR(3);
|
||||
|
||||
public final int id;
|
||||
|
||||
RoadType(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static RoadType valueFromId(int id) {
|
||||
return values[id];
|
||||
}
|
||||
|
||||
static final RoadType[] values = RoadType.values();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja generalna odpowiedzialna za przekształcenie danych liniowych i zapis do kwadratów.
|
||||
*
|
||||
* @param data
|
||||
* @param featureCategory kategoria danych liniowych (0 - cieki wodne, 1 - drogi)
|
||||
*/
|
||||
public static void writeLinearFeatures(HashSet<ArrayList<Coord.Grid[]>>[] data, int featureCategory) {
|
||||
ArrayList<Coord.Grid[]> polylineList = new ArrayList<>();
|
||||
// Indeksy odpowiadają numeracji (id) wartości w typach wyliczeniowych danej charakterystyki.
|
||||
for (int typeId = 0; typeId < data.length; typeId++) {
|
||||
HashSet<ArrayList<Coord.Grid[]>> set = data[typeId];
|
||||
if (set == null || set.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
for (ArrayList<Coord.Grid[]> polylines : set) {
|
||||
collectSquaresOfPolylines(polylines, polylineList);
|
||||
writeLinearFeatureIntoSquares((byte) typeId, false, polylineList, featureCategory);
|
||||
polylineList.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja gromadzi sekwencje współrzędnych kwadratów tworzących łamane.
|
||||
*
|
||||
* @param polylines list of polylines defined by vertices
|
||||
* @param polylineList set of detailed polylines defined by squares sequances
|
||||
*/
|
||||
public static void collectSquaresOfPolylines(ArrayList<Coord.Grid[]> polylines, ArrayList<Coord.Grid[]> polylineList) {
|
||||
Coord.Grid[] squares;
|
||||
for (Coord.Grid[] polyline : polylines) {
|
||||
squares = GeomUtils.generateSquaresOfSegments(polyline);
|
||||
squares = GeomUtils.removeSteps(squares);
|
||||
polylineList.add(squares);
|
||||
}
|
||||
logger.trace("Num of polylines= {}", polylines.size());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type type of feature (depends on the feature category)
|
||||
* @param clearFeature
|
||||
* @param polylineList polylines defined by squares sequences
|
||||
* @param featureCategory feature category to write (0 - watercourses, 1 - roads)
|
||||
*/
|
||||
public static void writeLinearFeatureIntoSquares(byte type, boolean clearFeature, ArrayList<Coord.Grid[]> polylineList, int featureCategory) {
|
||||
byte val = (clearFeature) ? 0 : type;
|
||||
for (Coord.Grid[] grids : polylineList) {
|
||||
for (int i = 0; i < grids.length - 1; i++) {
|
||||
int x0 = grids[i].x;
|
||||
int y0 = grids[i].y;
|
||||
int x1 = grids[i + 1].x;
|
||||
int y1 = grids[i + 1].y;
|
||||
Square curr_square = Teren.getSquare(x0, y0);
|
||||
EGeoDirection outDirection = GeomUtils.neighborDirection(x0, y0, x1, y1);
|
||||
if (curr_square != Square.EMPTY) {
|
||||
synchronized (curr_square) {
|
||||
if (featureCategory == 0) {
|
||||
curr_square.watercourses[outDirection.id] = val;
|
||||
} else {
|
||||
curr_square.roads[outDirection.id] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
EGeoDirection inDirection = outDirection.oppositeDirect();
|
||||
Square next_square = Teren.getSquare(x1, y1);
|
||||
if (next_square != Square.EMPTY) {
|
||||
synchronized (next_square) {
|
||||
if (featureCategory == 0) {
|
||||
next_square.watercourses[inDirection.id] = val;
|
||||
} else {
|
||||
next_square.roads[inDirection.id] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generuje dane obszarowe w zakresie zabudowy {@link TerrainType}.
|
||||
* <p>
|
||||
* "gis_osm_pois_free_1", "gis_osm_pofw_free_1"
|
||||
*
|
||||
* @param path
|
||||
*/
|
||||
static HashSet<Coord.Grid> generateDataFromPointLayer(String path, String filename) {
|
||||
HashSet<Coord.Grid> result = new HashSet<>();
|
||||
try {
|
||||
OsmShapeFileReader osmShapeFileReader = new OsmShapeFileReader(path, filename);
|
||||
int pos = 0;
|
||||
int typeId;
|
||||
int x;
|
||||
int y;
|
||||
while (osmShapeFileReader.hasNextShape()) {
|
||||
ShpShape shape = osmShapeFileReader.nextShape();
|
||||
if (shape instanceof ShpPoint shpPoint) {
|
||||
typeId = mapFclassToTerrainType(shpPoint);
|
||||
if (typeId != TerrainType.BUILDINGS.id) {
|
||||
continue;
|
||||
}
|
||||
logger.trace("Shape pos = {}, shape type = {}, fclass= {}", pos, shape.getShapeType(), shape.info.fclass);
|
||||
x = Coord.convertLonToGridX(shpPoint.x);
|
||||
y = Coord.convertLatToGridY(shpPoint.y);
|
||||
Coord.Grid coord = new Coord.Grid(x, y);
|
||||
result.add(coord);
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
logger.info("End, num={}", pos);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Funkcja generuje dane geometryczne na siatce kwadratów.
|
||||
* <p> Lista łamanych (otwartych lub zamkniętych) opisujących kształt obiektu klasy {@link ShpPolyShape}.
|
||||
* <p> W przypadku obiektów obszarowych pierwszy element opisuje zewnętrzną powłokę, kolejne tzw. dziury.</p>
|
||||
* <p> W przypadku obiektów liniowych zawiera jedną łamaną.</p>
|
||||
*
|
||||
* @param shpPolyShape
|
||||
* @return
|
||||
*/
|
||||
static ArrayList<Coord.Grid[]> generatePolylines(ShpPolyShape shpPolyShape) {
|
||||
ArrayList<Coord.Grid[]> polygons = new ArrayList<>();
|
||||
int start;
|
||||
int stop;
|
||||
Coord.Grid[] polygon;
|
||||
for (int i = 0; i < shpPolyShape.numberOfParts; i++) {
|
||||
start = shpPolyShape.partsPos[i];
|
||||
int next = i + 1;
|
||||
if (next < shpPolyShape.numberOfParts) {
|
||||
stop = shpPolyShape.partsPos[next];
|
||||
} else {
|
||||
stop = shpPolyShape.numberOfPoints;
|
||||
}
|
||||
polygon = new Coord.Grid[stop - start];
|
||||
for (int j = 0; j < polygon.length; j++) {
|
||||
int x = Coord.convertLonToGridX(shpPolyShape.pointsX[start + j]);
|
||||
int y = Coord.convertLatToGridY(shpPolyShape.pointsY[start + j]);
|
||||
polygon[j] = new Coord.Grid(x, y);
|
||||
}
|
||||
// boolean b1 = GeomUtils.isClockwise(polygon);
|
||||
polygon = GeomUtils.removeAdjacentDuplicates(polygon);
|
||||
polygon = GeomUtils.removeCollinearity(polygon, true);
|
||||
// boolean b2 = GeomUtils.isClockwise(polygon);
|
||||
polygons.add(polygon);
|
||||
logger.trace("Part id = {}, numOfPoints= {}", i, polygon.length);
|
||||
}
|
||||
return polygons;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.osm.shapefile;
|
||||
package pl.wat.ms4ds.terrain.osmshp;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -67,17 +67,17 @@ public class ShpHeader {
|
||||
}
|
||||
|
||||
/**
|
||||
* get the type ShapeType the shapeFile contains.<br>
|
||||
* a shapeFile contains only one type of shape.<br>
|
||||
* Get the ShapeType the shapeFile contains.<br>
|
||||
* A shapeFile contains only one type of shape.<br>
|
||||
*
|
||||
* @return ShpShape.Type
|
||||
* @return the type of shape
|
||||
*/
|
||||
public ShpShape.Type getShapeType() {
|
||||
return shapeType;
|
||||
}
|
||||
|
||||
/**
|
||||
* data storage: [3][2] --> [x,y,z][min, max].
|
||||
* Data storage: [3][2] --> [x,y,z][min, max].
|
||||
*
|
||||
* @return boundingbox as double[][]
|
||||
*/
|
||||
@@ -86,43 +86,41 @@ public class ShpHeader {
|
||||
}
|
||||
|
||||
/**
|
||||
* get measure range.<br>
|
||||
* data storage: [2] --> [min, max]
|
||||
* Get measure range.<br>
|
||||
* [min, max]
|
||||
*
|
||||
* @return double[]
|
||||
* @return measure range as double[]
|
||||
*/
|
||||
public double[] getMeasureRange() {
|
||||
return rangeM;
|
||||
}
|
||||
|
||||
/**
|
||||
* get length in bytes of the shapeFile.
|
||||
* Get length in bytes of the shapeFile.
|
||||
*
|
||||
* @return length in bytes.
|
||||
* @return length in bytes
|
||||
*/
|
||||
public int getFileLengthBytes() {
|
||||
public int getFileLength() {
|
||||
return fileLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* get Verions on the shapeFile.
|
||||
* Get Verions on the shapeFile.
|
||||
*
|
||||
* @return should return 1000.
|
||||
* @return should return 1000
|
||||
*/
|
||||
public int getVersion() {
|
||||
return SHAPE_FILE_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* get MAGIC NUMBER of shapeFile.
|
||||
* Get MAGIC NUMBER of shapeFile.
|
||||
*
|
||||
* @return should return 9994.
|
||||
* @return should return 9994
|
||||
*/
|
||||
public int getMagicNumber() {
|
||||
return SHAPE_FILE_CODE;
|
||||
}
|
||||
|
||||
|
||||
public void print() {
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.osm.shapefile;
|
||||
package pl.wat.ms4ds.terrain.osmshp;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@@ -35,7 +35,7 @@ public class ShpMultiPoint extends ShpShape {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readRecordContent(ByteBuffer bb) {
|
||||
protected void readContent(ByteBuffer bb) {
|
||||
xMin = bb.getDouble(); // x-min
|
||||
yMin = bb.getDouble(); // y-min
|
||||
xMax = bb.getDouble(); // x-max
|
||||
@@ -49,7 +49,7 @@ public class ShpMultiPoint extends ShpShape {
|
||||
pointsY[i] = bb.getDouble(); // y - coordinate
|
||||
}
|
||||
// if SHAPE-TYPE: 18
|
||||
if (type.hasZvalues()) {
|
||||
if (type.hasZ()) {
|
||||
zMin = bb.getDouble(); // z-min
|
||||
zMax = bb.getDouble(); // z-max
|
||||
for (int i = 0; i < numberOfPoints; i++) {
|
||||
@@ -57,7 +57,7 @@ public class ShpMultiPoint extends ShpShape {
|
||||
}
|
||||
}
|
||||
// if SHAPE-TYPE: 18 | 28
|
||||
if (type.hasMvalues()) {
|
||||
if (type.hasM()) {
|
||||
mMin = bb.getDouble(); // m-min
|
||||
mMax = bb.getDouble(); // m-max
|
||||
valuesM = new double[numberOfPoints];
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.osm.shapefile;
|
||||
package pl.wat.ms4ds.terrain.osmshp;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@@ -28,15 +28,15 @@ public class ShpPoint extends ShpShape {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readRecordContent(ByteBuffer bb) {
|
||||
protected void readContent(ByteBuffer bb) {
|
||||
x = bb.getDouble(); // x - coordinate
|
||||
y = bb.getDouble(); // y - coordinate
|
||||
// if SHAPE-TYPE: 11
|
||||
if (type.hasZvalues()) {
|
||||
if (type.hasZ()) {
|
||||
z = bb.getDouble(); // z - coordinate
|
||||
}
|
||||
// if SHAPE-TYPE: 11 | 21
|
||||
if (type.hasMvalues()) {
|
||||
if (type.hasM()) {
|
||||
m = bb.getDouble(); // m - value
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.osm.shapefile;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Locale;
|
||||
package pl.wat.ms4ds.terrain.osmshp;
|
||||
|
||||
/**
|
||||
* Shape: PolyLine.<br>
|
||||
@@ -20,7 +17,7 @@ import java.util.Locale;
|
||||
* @author jrulka
|
||||
*
|
||||
*/
|
||||
public class ShpPolyLine extends ShpPollyShape {
|
||||
public class ShpPolyLine extends ShpPolyShape {
|
||||
|
||||
public ShpPolyLine(Type shape_type) {
|
||||
super(shape_type);
|
||||
@@ -1,11 +1,12 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.osm.shapefile;
|
||||
package pl.wat.ms4ds.terrain.osmshp;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* Base class for PollyLine, Pollygon
|
||||
* Base class for {@link ShpPolyLine}, {@link ShpPolygon}.
|
||||
* <p></p> Contains common attributes and methods.
|
||||
*/
|
||||
public abstract class ShpPollyShape extends ShpShape {
|
||||
public abstract class ShpPolyShape extends ShpShape {
|
||||
// SHAPE RECORD CONTENT
|
||||
double xMin;
|
||||
double yMin;
|
||||
@@ -15,20 +16,20 @@ public abstract class ShpPollyShape extends ShpShape {
|
||||
double yMax;
|
||||
double zMax;
|
||||
double mMax;
|
||||
private int numberOfParts;
|
||||
private int numberOfPoints;
|
||||
private int[] partsPos;
|
||||
int numberOfParts;
|
||||
int numberOfPoints;
|
||||
int[] partsPos;
|
||||
double[] pointsX; // [number of points][x,y,z]
|
||||
double[] pointsY;
|
||||
double[] pointsZ;
|
||||
double[] valuesM; // [number of points][m-value]
|
||||
|
||||
public ShpPollyShape(ShpShape.Type shape_type) {
|
||||
public ShpPolyShape(ShpShape.Type shape_type) {
|
||||
super(shape_type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readRecordContent(ByteBuffer bb) {
|
||||
protected void readContent(ByteBuffer bb) {
|
||||
xMin = bb.getDouble(); // x-min
|
||||
yMin = bb.getDouble(); // y-min
|
||||
xMax = bb.getDouble(); // x-max
|
||||
@@ -46,7 +47,7 @@ public abstract class ShpPollyShape extends ShpShape {
|
||||
pointsY[i] = bb.getDouble(); // y - coordinate
|
||||
}
|
||||
// if SHAPE-TYPE: 13
|
||||
if (type.hasZvalues()) {
|
||||
if (type.hasZ()) {
|
||||
zMin = bb.getDouble(); // z-min
|
||||
zMax = bb.getDouble(); // z-max
|
||||
for (int i = 0; i < numberOfPoints; i++) {
|
||||
@@ -54,7 +55,7 @@ public abstract class ShpPollyShape extends ShpShape {
|
||||
}
|
||||
}
|
||||
// if SHAPE-TYPE: 13 | 23
|
||||
if (type.hasMvalues()) {
|
||||
if (type.hasM()) {
|
||||
mMin = bb.getDouble(); // m-min
|
||||
mMax = bb.getDouble(); // m-max
|
||||
valuesM = new double[numberOfPoints];
|
||||
@@ -1,4 +1,4 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.osm.shapefile;
|
||||
package pl.wat.ms4ds.terrain.osmshp;
|
||||
|
||||
|
||||
/**
|
||||
@@ -17,7 +17,7 @@ package pl.wat.ms4ds.terenfunkcje.osm.shapefile;
|
||||
* @author jrulka
|
||||
*
|
||||
*/
|
||||
public class ShpPolygon extends ShpPollyShape {
|
||||
public class ShpPolygon extends ShpPolyShape {
|
||||
|
||||
public ShpPolygon(Type shape_type) {
|
||||
super(shape_type);
|
||||
@@ -1,11 +1,12 @@
|
||||
package pl.wat.ms4ds.terenfunkcje.osm.shapefile;
|
||||
package pl.wat.ms4ds.terrain.osmshp;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/**
|
||||
* Base class for Shapes.
|
||||
* Klasa bazowa reprezentująca kształt w formacie SHP wraz z dodatkową informacją opisową.
|
||||
* Mozliwe typy kształtów zawiera klasa enumeratora {@link Type}
|
||||
*
|
||||
* @author jrulka
|
||||
*
|
||||
@@ -35,7 +36,7 @@ public abstract class ShpShape {
|
||||
}
|
||||
ByteBuffer bb = ByteBuffer.wrap(data);
|
||||
// 1) READ RECORD HEADER
|
||||
readRecordHeader(bb);
|
||||
readHeader(bb);
|
||||
// Content length in words (16 bits)
|
||||
byte[] dataContent = new byte[contentLength * 2];
|
||||
if (bis.read(dataContent) != contentLength * 2) {
|
||||
@@ -49,7 +50,7 @@ public abstract class ShpShape {
|
||||
try {
|
||||
Type shape_type = Type.getByCode(shapeTypeCode);
|
||||
if (shape_type == type) {
|
||||
readRecordContent(bb);
|
||||
readContent(bb);
|
||||
} else if (shape_type != type) {
|
||||
throw new Exception("(Shape) shape_type = " + shape_type + ", but expected " + type);
|
||||
}
|
||||
@@ -58,20 +59,24 @@ public abstract class ShpShape {
|
||||
}
|
||||
}
|
||||
|
||||
protected void readRecordHeader(ByteBuffer bb) {
|
||||
protected void readHeader(ByteBuffer bb) {
|
||||
bb.order(ByteOrder.BIG_ENDIAN);
|
||||
recordNumber = bb.getInt();
|
||||
contentLength = bb.getInt();
|
||||
}
|
||||
|
||||
protected abstract void readRecordContent(ByteBuffer bb);
|
||||
/**
|
||||
* Reads geometric data from buffer.
|
||||
* @param bb
|
||||
*/
|
||||
protected abstract void readContent(ByteBuffer bb);
|
||||
|
||||
void setInfo(DbfRecord info) {
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the record number of the shape.
|
||||
* Gets the record number of the shape.
|
||||
*
|
||||
* @return record number
|
||||
*/
|
||||
@@ -80,17 +85,17 @@ public abstract class ShpShape {
|
||||
}
|
||||
|
||||
/**
|
||||
* get the Type of the Shape.
|
||||
* Gets the type of the shape.
|
||||
*
|
||||
* @return ShpShape.Type
|
||||
* @return {@link Type}
|
||||
*/
|
||||
public Type getShapeType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Shape Types
|
||||
//----------------------------------------------------------------------------
|
||||
/**
|
||||
* Shape types.
|
||||
*/
|
||||
public enum Type {
|
||||
/**
|
||||
* ID= 0
|
||||
@@ -151,28 +156,28 @@ public abstract class ShpShape {
|
||||
|
||||
|
||||
public final int code;
|
||||
boolean has_z_values;
|
||||
boolean has_m_values;
|
||||
boolean hasZ;
|
||||
boolean hasM;
|
||||
|
||||
Type(int code, boolean has_z_values, boolean has_m_values) {
|
||||
this.has_z_values = has_z_values;
|
||||
this.has_m_values = has_m_values;
|
||||
Type(int code, boolean hasZ, boolean hasM) {
|
||||
this.hasZ = hasZ;
|
||||
this.hasM = hasM;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public static Type getByCode(int ID) throws Exception {
|
||||
public static Type getByCode(int code) throws Exception {
|
||||
for (Type st : Type.values())
|
||||
if (st.code == ID)
|
||||
if (st.code == code)
|
||||
return st;
|
||||
throw new Exception("ShapeType: " + ID + " does not exist");
|
||||
throw new Exception("ShapeType: " + code + " does not exist");
|
||||
}
|
||||
|
||||
public boolean hasZvalues() {
|
||||
return has_z_values;
|
||||
public boolean hasZ() {
|
||||
return hasZ;
|
||||
}
|
||||
|
||||
public boolean hasMvalues() {
|
||||
return has_m_values;
|
||||
public boolean hasM() {
|
||||
return hasM;
|
||||
}
|
||||
|
||||
public boolean isTypeOfPolygon() {
|
||||
@@ -4,26 +4,18 @@ x_ref=14
|
||||
y_ref=49
|
||||
dx_ref=11
|
||||
dy_ref=7
|
||||
#kwadraty_dir=c:/Workspace/git/teren-funkcje/au2data/new_teren/Polska/kwadraty/
|
||||
kwadraty_dir=C:/Workspace/_data/swdt/ms4ds/teren/kwadraty/
|
||||
#kwadraty_dir=D:/work/terrain/
|
||||
kwadraty_dir=D:/work/kwadraty_nmt/temp/
|
||||
#kwadraty_dir=C:/Workspace/_data/swdt/ms4ds/teren/kwadraty/
|
||||
drogi_dir=au2data/new_teren/Polska/drogi/
|
||||
|
||||
#Afganistan
|
||||
#Wspolrzedne referencyjne i wielkosc obszaru
|
||||
#x_ref=60
|
||||
#y_ref=29
|
||||
#dx_ref=15
|
||||
#dy_ref=10
|
||||
#kwadraty_dir=/au2data/new_teren/Afganistan/kwadraty/
|
||||
#drogi_dir=/au2data/new_teren/Afganistan/drogi/
|
||||
|
||||
#
|
||||
#Rozdzielczosc terenu dl_mk=200 | 100 | 50 | 25 | 20
|
||||
dl_mk=100
|
||||
|
||||
#
|
||||
#W celu wymuszenia (mimo jej braku) przejezdności terenu nalezy ustawić na: on
|
||||
przejezdnosc_zawsze=off
|
||||
minimalny_stopien_przejezdnosci=0.1
|
||||
|
||||
#
|
||||
#Minimalny stopień przejezdności dla ruchu na przełaj dla kwadratów przejezdnych
|
||||
#dla algorytmów wyznaczania dróg dla działań typu: atak, obrona, rozmieszczenie, ...
|
||||
stopien_przejezdnosci.minimalny_na_przelaj=0.7
|
||||
@@ -42,32 +34,32 @@ stopien_przejezdnosci.na_drodze.nachylenie_terenu.kat_maksymalny=50
|
||||
stopien_przejezdnosci.na_przelaj.nachylenie_terenu.kat_minimalny=15
|
||||
#Maksymalny kąt nachylenia terenu wpływający na stopień przejezdności (alfa_min) dla ruchu na przełaj [stopnie]
|
||||
stopien_przejezdnosci.na_przelaj.nachylenie_terenu.kat_maksymalny=45
|
||||
|
||||
#
|
||||
#stopień przejezdności - parametr dla symulacji ruchu
|
||||
stopien_przejezdnosci.podwozie_gasienicowe.teren_zabudowany=0.8
|
||||
stopien_przejezdnosci.podwozie_gasienicowe.teren_zalesiony=0.25
|
||||
stopien_przejezdnosci.podwozie_gasienicowe.teren_zabagniony=0.2
|
||||
stopien_przejezdnosci.podwozie_gasienicowe.teren_zawodniony=0.0
|
||||
stopien_przejezdnosci.podwozie_gasienicowe.teren_czysty=1.0
|
||||
|
||||
#
|
||||
stopien_przejezdnosci.podwozie_kolowo_gasienicowe.teren_zabudowany=0.7
|
||||
stopien_przejezdnosci.podwozie_kolowo_gasienicowe.teren_zalesiony=0.15
|
||||
stopien_przejezdnosci.podwozie_kolowo_gasienicowe.teren_zabagniony=0.1
|
||||
stopien_przejezdnosci.podwozie_kolowo_gasienicowe.teren_zawodniony=0.0
|
||||
stopien_przejezdnosci.podwozie_kolowo_gasienicowe.teren_czysty=0.9
|
||||
|
||||
#
|
||||
stopien_przejezdnosci.podwozie_kolowe.teren_zabudowany=0.6
|
||||
stopien_przejezdnosci.podwozie_kolowe.teren_zalesiony=0.1
|
||||
stopien_przejezdnosci.podwozie_kolowe.teren_zabagniony=0.05
|
||||
stopien_przejezdnosci.podwozie_kolowe.teren_zawodniony=0.0
|
||||
stopien_przejezdnosci.podwozie_kolowe.teren_czysty=0.8
|
||||
|
||||
#
|
||||
stopien_przejezdnosci.podwozie_poduszka.teren_zabudowany=0.7
|
||||
stopien_przejezdnosci.podwozie_poduszka.teren_zalesiony=0.1
|
||||
stopien_przejezdnosci.podwozie_poduszka.teren_zabagniony=0.9
|
||||
stopien_przejezdnosci.podwozie_poduszka.teren_zawodniony=1.0
|
||||
stopien_przejezdnosci.podwozie_poduszka.teren_czysty=1.0
|
||||
|
||||
#
|
||||
stopien_przejezdnosci.podwozie_plozy.teren_zabudowany=0.1
|
||||
stopien_przejezdnosci.podwozie_plozy.teren_zalesiony=0.1
|
||||
stopien_przejezdnosci.podwozie_plozy.teren_zabagniony=0.1
|
||||
|
||||
Reference in New Issue
Block a user