Thank you! That is super inconvenient, I guess I'l lswitch back to BRouter for the time being. Thanks a lot for the reply, I would have never thought to look there
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts MenuQuoteI just purchased a bunch of maps in Locus 3 (of which I own Pro since forever) and right after found out about Locus 4. I would really like to 'return the maps' and instead get a Gold subscription (of course I understand that a Gold sub is more expensive than what I paid for the maps/coins). Is there any way to do that ? It would suck if it turns out I wasted all that money
package com.boringville.misc.pointadder;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import de.micromata.opengis.kml.v_2_2_0.Coordinate;
import de.micromata.opengis.kml.v_2_2_0.Document;
import de.micromata.opengis.kml.v_2_2_0.Feature;
import de.micromata.opengis.kml.v_2_2_0.Kml;
import de.micromata.opengis.kml.v_2_2_0.LineString;
import de.micromata.opengis.kml.v_2_2_0.Placemark;
public class PointAdder {
@RequiredArgsConstructor
private static class Distance {
private final Coordinate first, last;
/** Basically copied from http://stackoverflow.com/questions/837872 */
public double calculate() {
double dLat = Math.toRadians(last.getLatitude() - first.getLatitude());
double dLng = Math.toRadians(last.getLongitude() - first.getLongitude());
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
+ Math.cos(Math.toRadians(first.getLatitude()))
* Math.cos(Math.toRadians(last.getLatitude())) * Math.sin(dLng / 2)
* Math.sin(dLng / 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return c;
}
}
public static void main(String[] args) {
double earthRadius = 6369628.75D;
double maxDistance = Double.parseDouble(args[0]) / earthRadius;
Kml kml = Kml.unmarshal(new File(args[1]));
Document document = (Document) kml.getFeature();
for (Feature feature : document.getFeature()) {
if (!(feature instanceof Placemark)) {
continue;
}
Placemark placemark = (Placemark) feature;
LineString ls = (LineString) placemark.getGeometry();
List<Coordinate> inCoords = ls.getCoordinates();
List<Coordinate> outCoords = new ArrayList<Coordinate>();
Coordinate lastPoint = null;
for (Coordinate coordinate : inCoords) {
if (lastPoint != null) {
double distance = new Distance(lastPoint, coordinate).calculate();
if (distance > maxDistance) {
double steps = Math.ceil(distance / maxDistance);
double stepLong = (coordinate.getLongitude() - lastPoint.getLongitude())
/ steps;
double stepLat = (coordinate.getLatitude() - lastPoint.getLatitude())
/ steps;
for (int i = 0; i < steps; i++) {
outCoords.add(new Coordinate(lastPoint.getLongitude() + stepLong * i,
lastPoint.getLatitude() + stepLat * i));
}
}
}
lastPoint = coordinate;
outCoords.add(coordinate);
}
ls.setCoordinates(outCoords);
}
try {
kml.marshal(new File(args[2]));
} catch (final FileNotFoundException e) {
e.printStackTrace();
}
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.boringville.misc</groupId>
<artifactId>pointadder</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>pointadder</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>de.micromata.jak</groupId>
<artifactId>JavaAPIforKml</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.12.4</version>
</dependency>
</dependencies>
</project>