use of org.geotools.geometry.DirectPosition2D in project sldeditor by robward-scisys.
the class WKTSegmentListTest method testGetWktPointList.
/**
* Test method for {@link com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTSegmentList#getWktPointList(boolean)}.
* Test method for {@link com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTSegmentList#setWktPointList(java.util.List)}.
* Test method for {@link com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTSegmentList#addPoint(com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTPoint)}.
* Test method for {@link com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTSegmentList#getWKTString()}.
* Test method for {@link com.sldeditor.ui.detail.vendor.geoserver.marker.wkt.WKTSegmentList#getWKTString(boolean)}.
*/
@Test
public void testGetWktPointList() {
WKTSegmentList segmentList = new WKTSegmentList();
DirectPosition pos1 = new DirectPosition2D(1.0, 1.0);
segmentList.addPoint(new WKTPoint(pos1));
String actualValue = segmentList.getWKTString();
assertTrue(actualValue.compareTo("(1 1)") == 0);
List<WKTPoint> ptList = new ArrayList<WKTPoint>();
ptList.add(new WKTPoint(pos1));
DirectPosition pos2 = new DirectPosition2D(2.0, 2.0);
DirectPosition pos3 = new DirectPosition2D(3.0, 3.0);
DirectPosition pos4 = new DirectPosition2D(4.0, 4.0);
ptList.add(new WKTPoint(pos2));
ptList.add(new WKTPoint(pos3));
ptList.add(new WKTPoint(pos4));
segmentList.setWktPointList(ptList);
actualValue = segmentList.getWKTString();
assertTrue(actualValue.compareTo("(1 1, 2 2, 3 3, 4 4)") == 0);
actualValue = segmentList.getWKTString(false, false);
assertTrue(actualValue.compareTo("1 1, 2 2, 3 3, 4 4") == 0);
actualValue = segmentList.getWKTString(false, true);
assertTrue(actualValue.compareTo("1 1, 2 2, 3 3, 4 4, 1 1") == 0);
ptList.add(new WKTPoint(pos1));
segmentList.setWktPointList(ptList);
assertTrue(segmentList.getWktPointList(false).size() == ptList.size());
assertTrue((segmentList.getWktPointList(true).size() + 1) == ptList.size());
ptList.clear();
ptList.add(new WKTPoint(pos1));
assertTrue(segmentList.getWktPointList(false).size() == ptList.size());
assertTrue(segmentList.getWktPointList(true).size() == ptList.size());
segmentList.addPoint(new WKTPoint(pos2));
assertTrue(segmentList.getWktPointList(false).size() == ptList.size());
assertTrue(segmentList.getWktPointList(true).size() == ptList.size());
}
use of org.geotools.geometry.DirectPosition2D in project OpenTripPlanner by opentripplanner.
the class ElevationModule method getElevation.
/**
* Method for retrieving the elevation at a given (x, y) pair.
*
* @param x the query longitude (NAD83)
* @param y the query latitude (NAD83)
* @return elevation in meters
*/
private double getElevation(double x, double y) {
double[] values = new double[1];
try {
// We specify a CRS here because otherwise the coordinates are assumed to be in the coverage's native CRS.
// That assumption is fine when the coverage happens to be in longitude-first WGS84 but we want to support
// GeoTIFFs in various projections. Note that GeoTools defaults to strict EPSG axis ordering of (lat, long)
// for DefaultGeographicCRS.WGS84, but OTP is using (long, lat) throughout and assumes unprojected DEM
// rasters to also use (long, lat).
coverage.evaluate(new DirectPosition2D(GeometryUtils.WGS84_XY, x, y), values);
} catch (org.opengis.coverage.PointOutsideCoverageException e) {
nPointsOutsideDEM += 1;
}
nPointsEvaluated += 1;
return values[0];
}
use of org.geotools.geometry.DirectPosition2D in project structr by structr.
the class UTMToLatLonFunction method utmToLatLon.
private GraphObjectMap utmToLatLon(final String zone, final String hemisphere, final String east, final String north) {
final GraphObjectMap obj = new GraphObjectMap();
// clean zone string (remove all non-digits)
final String cleanedZone = zone.replaceAll("[\\D]+", "");
final StringBuilder epsg = new StringBuilder("EPSG:32");
switch(hemisphere) {
case "N":
epsg.append("6");
break;
case "S":
epsg.append("7");
break;
}
// append "0" to zone number of single-digit
if (cleanedZone.length() == 1) {
epsg.append("0");
}
// append zone number
epsg.append(cleanedZone);
try {
final CoordinateReferenceSystem src = CRS.decode(epsg.toString());
final CoordinateReferenceSystem dst = CRS.decode("EPSG:4326");
final MathTransform transform = CRS.findMathTransform(src, dst, true);
final DirectPosition sourcePt = new DirectPosition2D(getDoubleOrNull(east), getDoubleOrNull(north));
final DirectPosition targetPt = transform.transform(sourcePt, null);
obj.put(latitudeProperty, targetPt.getOrdinate(0));
obj.put(longitudeProperty, targetPt.getOrdinate(1));
} catch (Throwable t) {
logger.warn("", t);
}
return obj;
}
use of org.geotools.geometry.DirectPosition2D in project collect by openforis.
the class GeoToolsCoordinateOperations method toPosition.
private Position toPosition(double x, double y, String fromSrsId, String toSrsId) {
try {
DirectPosition src = new DirectPosition2D(x, y);
MathTransform transform = getOrCreateTransform(fromSrsId, toSrsId);
if (transform == null) {
if (LOG.isErrorEnabled()) {
LOG.error(String.format("Cannot find transform from %s to %s", fromSrsId, toSrsId));
}
return new DirectPosition2D(0, 0);
}
DirectPosition directPosition = transform.transform(src, null);
return directPosition;
} catch (Throwable t) {
if (LOG.isErrorEnabled()) {
LOG.error("Error converting: x=" + x + " y=" + y + " srs=" + fromSrsId, t);
}
return new DirectPosition2D(0, 0);
}
}
Aggregations