use of org.locationtech.jts.io.ParseException in project h2database by h2database.
the class ValueGeometry method get.
/**
* Get or create a geometry value for the given geometry.
*
* @param s the WKT representation of the geometry
* @param srid the srid of the object
* @return the value
*/
public static ValueGeometry get(String s, int srid) {
try {
GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), srid);
Geometry g = new WKTReader(geometryFactory).read(s);
return get(g);
} catch (ParseException ex) {
throw DbException.convert(ex);
}
}
use of org.locationtech.jts.io.ParseException in project h2database by h2database.
the class TestSpatial method geomFromText.
/**
* Convert the text to a geometry object.
*
* @param text the geometry as a Well Known Text
* @param srid the projection id
* @return Geometry object
*/
public static Geometry geomFromText(String text, int srid) throws SQLException {
WKTReader wktReader = new WKTReader();
try {
Geometry geom = wktReader.read(text);
geom.setSRID(srid);
return geom;
} catch (ParseException ex) {
throw new SQLException(ex);
}
}
use of org.locationtech.jts.io.ParseException in project arctic-sea by 52North.
the class ODataFesParser method parseGeometry.
/**
* Parse the value expression as an {@code Geometry} in WKT or EWKT format. Geographies are handled as if they would
* be geometries.
*
* @param val the geometry value
*
* @return the geometry
*
* @throws DecodingException if the geometry is invalid
*/
private static Geometry parseGeometry(ValueExpr val) throws DecodingException {
String value = val.getValue();
if (value.startsWith(GEOGRAPHY_TYPE)) {
value = value.substring(GEOGRAPHY_TYPE.length());
}
if (value.startsWith(GEOMETRY_TYPE)) {
value = value.substring(GEOMETRY_TYPE.length());
}
value = stripQuotes(value).toUpperCase();
int srid = 4326;
if (value.startsWith(SRID_PREFIX)) {
int sep = value.indexOf(';');
if (sep > SRID_PREFIX.length() && value.length() > sep) {
try {
srid = Integer.parseInt(value.substring(SRID_PREFIX.length(), sep));
} catch (NumberFormatException ex) {
throw invalidGeometry(val, ex);
}
value = value.substring(sep + 1);
} else {
throw invalidGeometry(val);
}
}
PrecisionModel precisionModel = new PrecisionModel(PrecisionModel.FLOATING);
GeometryFactory geometryFactory = new GeometryFactory(precisionModel, srid);
WKTReader wktReader = new WKTReader(geometryFactory);
try {
return wktReader.read(value);
} catch (ParseException ex) {
throw invalidGeometry(val, ex);
}
}
use of org.locationtech.jts.io.ParseException in project arctic-sea by 52North.
the class GmlDecoderv311 method parsePointType.
private Object parsePointType(PointType xbPointType) throws DecodingException {
String geomWKT = null;
int srid = -1;
if (xbPointType.getSrsName() != null) {
srid = CRSHelper.parseSrsName(xbPointType.getSrsName());
}
if (xbPointType.getPos() != null) {
DirectPositionType xbPos = xbPointType.getPos();
if (srid == -1 && xbPos.getSrsName() != null) {
srid = CRSHelper.parseSrsName(xbPos.getSrsName());
}
String directPosition = getString4Pos(xbPos);
geomWKT = JTSHelper.createWKTPointFromCoordinateString(directPosition);
} else if (xbPointType.getCoordinates() != null) {
CoordinatesType xbCoords = xbPointType.getCoordinates();
String directPosition = getString4Coordinates(xbCoords);
geomWKT = JTSHelper.createWKTPointFromCoordinateString(directPosition);
} else {
throw new DecodingException("For geometry type 'gml:Point' only elements 'gml:pos' and 'gml:coordinates' are allowed");
}
checkSrid(srid);
if (srid == -1) {
throw new DecodingException("No SrsName ist specified for geometry!");
}
try {
return JTSHelper.createGeometryFromWKT(geomWKT, srid);
} catch (ParseException ex) {
throw new DecodingException(ex);
}
}
use of org.locationtech.jts.io.ParseException in project arctic-sea by 52North.
the class GmlDecoderv311 method getGeometry4BBOX.
private Geometry getGeometry4BBOX(EnvelopeDocument xbBbox) throws DecodingException {
EnvelopeType xbEnvelope = xbBbox.getEnvelope();
// parse srid; if not set, throw exception!
int srid = CRSHelper.parseSrsName(xbEnvelope.getSrsName());
String lower = xbEnvelope.getLowerCorner().getStringValue();
String upper = xbEnvelope.getUpperCorner().getStringValue();
String geomWKT = String.format("MULTIPOINT(%s, %s)", lower, upper);
try {
return JTSHelper.createGeometryFromWKT(geomWKT, srid).getEnvelope();
} catch (ParseException ex) {
throw new DecodingException(ex);
}
}
Aggregations