Search in sources :

Example 1 with GML

use of org.geotools.GML in project polymap4-core by Polymap4.

the class SchemaCoder method gmlEncode.

protected String gmlEncode(SimpleFeatureType schema) throws Exception {
    GML coder = new GML(GML.Version.WFS1_1);
    coder.setEncoding(ENCODING);
    OutputStream out = new ByteArrayOutputStream(4096);
    coder.setBaseURL(new URL("file:///"));
    coder.setCoordinateReferenceSystem(schema.getCoordinateReferenceSystem());
    // encoder.setNamespace( "location", locationURL.toExternalForm() );
    coder.encode(out, schema);
    return out.toString();
}
Also used : GML(org.geotools.GML) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URL(java.net.URL)

Example 2 with GML

use of org.geotools.GML in project polymap4-core by Polymap4.

the class SchemaCoder method gmlDecode.

public FeatureType gmlDecode(String input) throws Exception {
    GML coder = new GML(GML.Version.WFS1_1);
    coder.setEncoding(ENCODING);
    File f = File.createTempFile(getClass().getName(), "xsd");
    try {
        FileUtils.write(f, input, ENCODING);
        URL url = f.toURI().toURL();
        // find name
        Matcher match = COMPLEX_TYPE.matcher(input);
        if (!match.find()) {
            throw new IllegalStateException("No <xsd:complexType name=... found.");
        }
        String name = match.group(1);
        return coder.decodeSimpleFeatureType(url, new NameImpl(name));
    } finally {
        f.delete();
    }
}
Also used : NameImpl(org.geotools.feature.NameImpl) Matcher(java.util.regex.Matcher) GML(org.geotools.GML) File(java.io.File) URL(java.net.URL)

Aggregations

URL (java.net.URL)2 GML (org.geotools.GML)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 Matcher (java.util.regex.Matcher)1 NameImpl (org.geotools.feature.NameImpl)1