Search in sources :

Example 1 with Formattable

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);
        }
    }
}
Also used : GeometryType(org.opengis.feature.type.GeometryType) NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) FactoryException(org.opengis.referencing.FactoryException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Integer.toBinaryString(java.lang.Integer.toBinaryString) Formattable(org.geotools.referencing.wkt.Formattable)

Aggregations

Integer.toBinaryString (java.lang.Integer.toBinaryString)1 Formattable (org.geotools.referencing.wkt.Formattable)1 GeometryType (org.opengis.feature.type.GeometryType)1 FactoryException (org.opengis.referencing.FactoryException)1 NoSuchAuthorityCodeException (org.opengis.referencing.NoSuchAuthorityCodeException)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1