use of org.geotools.referencing.wkt.Formattable in project GeoGig by boundlessgeo.
the class FormatCommonV2 method writePropertyType.
private static void writePropertyType(PropertyType type, DataOutput data) throws IOException {
writeName(type.getName(), data);
data.writeByte(FieldType.forBinding(type.getBinding()).getTag());
if (type instanceof GeometryType) {
GeometryType gType = (GeometryType) type;
CoordinateReferenceSystem crs = gType.getCoordinateReferenceSystem();
String srsName;
if (crs == null) {
srsName = "urn:ogc:def:crs:EPSG::0";
} else {
final boolean longitudeFirst = CRS.getAxisOrder(crs, false) == AxisOrder.EAST_NORTH;
final boolean codeOnly = true;
String crsCode = CRS.toSRS(crs, codeOnly);
if (crsCode != null) {
srsName = (longitudeFirst ? "EPSG:" : "urn:ogc:def:crs:EPSG::") + crsCode;
// able to decode it later. If not, we will use WKT instead
try {
CRS.decode(srsName, longitudeFirst);
} catch (NoSuchAuthorityCodeException e) {
srsName = null;
} catch (FactoryException e) {
srsName = null;
}
} else {
srsName = null;
}
}
if (srsName != null) {
data.writeBoolean(true);
data.writeUTF(srsName);
} else {
final String wkt;
if (crs instanceof Formattable) {
wkt = ((Formattable) crs).toWKT(Formattable.SINGLE_LINE);
} else {
wkt = crs.toWKT();
}
data.writeBoolean(false);
data.writeUTF(wkt);
}
}
}
Aggregations