use of org.hwyl.sexytopo.model.survey.Station in project sexytopo by richsmith.
the class SurveyChecker method areEqual.
public static boolean areEqual(Survey one, Survey two) {
List<Station> oneStations = one.getAllStations();
List<Station> twoStations = two.getAllStations();
if (oneStations.size() != twoStations.size()) {
return false;
}
for (Station station : one.getAllStations()) {
Station other = two.getStationByName(station.getName());
if (!areEqual(station, other)) {
return false;
}
}
Trip oneTrip = one.getTrip();
Trip twoTrip = two.getTrip();
if ((oneTrip == null) ^ (twoTrip == null)) {
return false;
}
if (oneTrip != null) {
if (!oneTrip.equalsTripData(twoTrip)) {
return false;
}
}
return true;
}
use of org.hwyl.sexytopo.model.survey.Station in project sexytopo by richsmith.
the class CompassExporter method getContent.
/**
* Export a SexyTopo Survey as a Compass .DAT file.
* @param survey
* @return
*/
public String getContent(Survey survey) {
List<GraphToListTranslator.SurveyListEntry> data = graphToListTranslator.toChronoListOfSurveyListEntries(survey);
String surveyDate = dateFormat.format(Calendar.getInstance().getTime());
StringBuilder sb = new StringBuilder(1024);
sb.append("SexyTopo Export\r\n");
sb.append(String.format("SURVEY NAME: %s\r\n", survey.getName()));
sb.append(String.format("SURVEY DATE: %s\tCOMMENT: \r\n", surveyDate));
sb.append("SURVEY TEAM:\r\n\r\n");
sb.append("DECLINATION: 0.00\tFORMAT: DMMDLRUDLADNF\tCORRECTIONS: 0.00 0.00 0.00\r\n");
sb.append("\r\n");
sb.append("FROM\tTO\tLENGTH\tBEARING\tINC\tLEFT\tUP\tDOWN\tRIGHT\tFLAGS\tCOMMENTS\r\n");
sb.append("\r\n");
for (GraphToListTranslator.SurveyListEntry entry : data) {
Leg leg = entry.getLeg();
Station from = entry.getFrom();
String to = leg.hasDestination() ? leg.getDestination().toString() : this.splayStationFrom(from);
// all Compass lengths are decimal feet!
double dist = leg.getDistance() * METERS_TO_FEET;
double azm = leg.getAzimuth();
double inc = leg.getInclination();
sb.append(String.format("%s\t%s\t%.2f\t%.2f\t%.2f\t", from, to, dist, azm, inc));
// LUDR, must be in that order
sb.append("-9.99\t-9.99\t-9.99\t-9.99\t");
if (!leg.hasDestination()) {
// exclude splay shots from cave length calculations
sb.append("#|L#");
}
// empty comments field
sb.append("\t\t\r\n");
}
// ASCII formfeed denotes end of survey
sb.append('\f');
return sb.toString();
}
use of org.hwyl.sexytopo.model.survey.Station in project sexytopo by richsmith.
the class MetadataTranslater method toJson.
public static JSONObject toJson(Survey survey) throws JSONException {
JSONObject json = new JSONObject();
String activeStationName = survey.getActiveStation().getName();
json.put(ACTIVE_STATION_TAG, activeStationName);
Map<Station, Set<SurveyConnection>> connectedSurveys = survey.getConnectedSurveys();
JSONObject jsonMap = toJson(connectedSurveys);
json.put(CONNECTIONS_TAG, jsonMap);
return json;
}
use of org.hwyl.sexytopo.model.survey.Station in project sexytopo by richsmith.
the class MetadataTranslater method toJson.
private static JSONObject toJson(Map<Station, Set<SurveyConnection>> connectedSurveys) throws JSONException {
JSONObject connectionMap = new JSONObject();
for (Station connectionPoint : connectedSurveys.keySet()) {
Set<SurveyConnection> connections = connectedSurveys.get(connectionPoint);
JSONArray setObject = new JSONArray();
for (SurveyConnection connection : connections) {
JSONArray connectionObject = toJson(connection);
setObject.put(connectionObject);
}
connectionMap.put(connectionPoint.getName(), setObject);
}
return connectionMap;
}
use of org.hwyl.sexytopo.model.survey.Station in project sexytopo by richsmith.
the class MetadataTranslater method translateAndUpdateConnections.
@SuppressWarnings("UnnecessaryContinue")
private static void translateAndUpdateConnections(Context context, Survey survey, JSONObject json, Set<String> surveyNamesNotToLoad) throws Exception {
try {
JSONObject connectionsObject = json.getJSONObject(CONNECTIONS_TAG);
Map<String, JSONArray> outerMap = Util.toMap(connectionsObject);
for (String stationName : outerMap.keySet()) {
Station station = survey.getStationByName(stationName);
JSONArray setArray = outerMap.get(stationName);
for (JSONArray connectionPair : toListOfArrays(setArray)) {
assert connectionPair.length() == 2;
String connectedSurveyName = connectionPair.get(0).toString();
String connectionPointName = connectionPair.get(1).toString();
if (surveyNamesNotToLoad.contains(connectedSurveyName)) {
// if this survey is already loaded, don't do the whole infinite loop thing
continue;
} else {
// we *really* want to avoid infinite loops :)
// this should be added on load, but just as a precaution..
surveyNamesNotToLoad.add(connectedSurveyName);
try {
Survey connectedSurvey = Loader.loadSurvey(context, connectedSurveyName, surveyNamesNotToLoad, false);
Station connectionPoint = connectedSurvey.getStationByName(connectionPointName);
if (connectionPoint == null) {
Log.e("Connection point not found: " + connectionPoint.getName());
throw new Exception("Connection point not found");
}
survey.connect(station, connectedSurvey, connectionPoint);
} catch (Exception exception) {
// the linked survey or connecting station has probably been deleted;
// not much we can do...
Log.e("Could not load connected survey " + connectedSurveyName);
continue;
}
}
}
}
} catch (JSONException exception) {
Log.e(exception.toString());
throw new Exception("Error loading connected surveys");
}
}
Aggregations