com.evrythng.thng.resource.model.store.geojson.GeoJsonHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of thng-resource-model Show documentation
Show all versions of thng-resource-model Show documentation
Models for REST resources representations.
package com.evrythng.thng.resource.model.store.geojson;
import com.evrythng.thng.resource.model.store.LocationHelper;
/**
* Helper class for GeoJson
*/
public class GeoJsonHelper {
public static Double getLatitude(final GeoJsonPoint loc) {
double[] coordinates = loc.getCoordinatesArr();
return coordinates == null ? null : loc.getCoordinatesArr()[GeoJson.LAT_IDX];
}
public static Double getLongitude(final GeoJsonPoint loc) {
double[] coordinates = loc.getCoordinatesArr();
return coordinates == null ? null : loc.getCoordinatesArr()[GeoJson.LON_IDX];
}
public static void setPosition(final GeoJsonPoint loc, final Double latitude, final Double longitude) {
if (latitude == null || longitude == null) {
if (latitude == null && longitude == null) {
loc.setCoordinates(null);
} else {
throw new IllegalArgumentException("latitude and longitude must either be both null, or both non null.");
}
} else {
double[] coordinates = loc.getCoordinatesArr();
if (coordinates == null) {
loc.setCoordinatesArr(longitude, latitude);
} else {
coordinates[GeoJson.LAT_IDX] = latitude;
coordinates[GeoJson.LON_IDX] = longitude;
}
}
}
public static GeoJsonPoint createRandomGeoJsonPoint() {
return new GeoJsonPoint(LocationHelper.randomLatitude(), LocationHelper.randomLongitude());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy