All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.evrythng.thng.resource.model.store.geojson.GeoJsonHelper Maven / Gradle / Ivy

There is a newer version: 1.33
Show newest version
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