Examples of FeatureTransformer


Examples of org.geotools.gml.producer.FeatureTransformer

    collection.add(SimpleFeatureBuilder.build(TYPE, new Object[] { wkt.read("POINT (1 2)"), "name1" }, null));
    collection.add(SimpleFeatureBuilder.build(TYPE, new Object[] { wkt.read("POINT (4 4)"), "name2" }, null));

    SimpleFeatureCollection featureCollection = new ListFeatureCollection(TYPE, collection);
 
    FeatureTransformer transform = new FeatureTransformer();
    transform.setEncoding(Charset.defaultCharset());
    transform.setIndentation(4);
    transform.setGmlPrefixing(true);
     
    // define feature information
    final SimpleFeatureType schema = featureCollection.getSchema();
    String prefix = (String) schema.getUserData().get("prefix");
    String namespace = schema.getName().getNamespaceURI();
    transform.getFeatureTypeNamespaces().declareDefaultNamespace(prefix, namespace);
    transform.addSchemaLocation(prefix, namespace);
   
    String srsName = CRS.toSRS(schema.getCoordinateReferenceSystem());
    if (srsName != null) {
        transform.setSrsName(srsName);
    }
   
    // define feature collection
    transform.setCollectionPrefix("col");
    transform.setCollectionNamespace("urn:org.geotools.xml.example.collection");
   
    // other configuration
    transform.setCollectionBounding(true); // include bbox info
   
    ByteArrayOutputStream xml = new ByteArrayOutputStream();
    transform.transform(featureCollection, xml);
    xml.close();
   
    System.out.println(xml.toString());
    // transformExample end
}
View Full Code Here

Examples of org.geotools.gml.producer.FeatureTransformer

private void transformExample2() throws Exception {
    SimpleFeatureCollection fc = null;
    OutputStream out = null;
    // transformExample2 start
    SimpleFeatureType ft = fc.getSchema();
    FeatureTransformer tx = new FeatureTransformer();
   
    // set the SRS for the entire featureCollection.
    String srsName = CRS.toSRS(ft.getCoordinateReferenceSystem(), true);
    tx.setSrsName(srsName);
   
    // set the namespace and the prefix
    String namespaceURI = ft.getName().getNamespaceURI();
    tx.getFeatureTypeNamespaces().declareNamespace(ft, "wps", namespaceURI);
   
    // also work-around, get the schema of the featureType
    Schema s = SchemaFactory.getInstance(namespaceURI);
   
    // define a schemaLocation and allow thereby validation!
    tx.addSchemaLocation(namespaceURI, s.getURI().toASCIIString());
   
    tx.transform(fc, out);
    // transformExample2 end
}
View Full Code Here

Examples of org.geotools.gml.producer.FeatureTransformer

    private void encodeLegacyGML2(OutputStream out, SimpleFeatureCollection collection)
            throws IOException {
        final SimpleFeatureType TYPE = collection.getSchema();

        FeatureTransformer transform = new FeatureTransformer();
        transform.setIndentation(4);
        transform.setGmlPrefixing(true);

        if (prefix != null && namespace != null) {
            transform.getFeatureTypeNamespaces().declareDefaultNamespace(prefix, namespace);
            transform.addSchemaLocation(prefix, namespace);
            // transform.getFeatureTypeNamespaces().declareDefaultNamespace("", namespace );
        }

        if (TYPE.getName().getNamespaceURI() != null && TYPE.getUserData().get("prefix") != null) {
            String typeNamespace = TYPE.getName().getNamespaceURI();
            String typePrefix = (String) TYPE.getUserData().get("prefix");

            transform.getFeatureTypeNamespaces().declareNamespace(TYPE, typePrefix, typeNamespace);
        } else if (prefix != null && namespace != null) {
            // ignore namespace URI in feature type
            transform.getFeatureTypeNamespaces().declareNamespace(TYPE, prefix, namespace);
        } else {
            // hopefully that works out for you then
        }

        // we probably need to do a wfs feaure collection here?
        transform.setCollectionPrefix(null);
        transform.setCollectionNamespace(null);

        // other configuration
        transform.setCollectionBounding(true);
        transform.setEncoding(encoding);

        // configure additional feature namespace lookup
        transform.getFeatureNamespaces();

        String srsName = CRS.toSRS(TYPE.getCoordinateReferenceSystem());
        if (srsName != null) {
            transform.setSrsName(srsName);
        }

        try {
            transform.transform(collection, out);
        } catch (TransformerException e) {
            throw (IOException) new IOException("Failed to encode feature collection:" + e)
                    .initCause(e);
        }
    }
View Full Code Here

Examples of org.geotools.gml.producer.FeatureTransformer

        prepare(request.getOutputFormat(), featureCollection, request);
        encode(output, featureCollection, request );
    }

    protected FeatureTransformer createTransformer() {
        return new FeatureTransformer();
    }
View Full Code Here

Examples of org.geotools.gml.producer.FeatureTransformer

        prepare(request.getOutputFormat(), featureCollection, request);
        encode(output, featureCollection, request );
    }

    protected FeatureTransformer createTransformer() {
        return new FeatureTransformer();
    }
View Full Code Here

Examples of org.geotools.gml.producer.FeatureTransformer

        OutputStream os = null;
        try {
            os = new FileOutputStream(outFile);

            // let's invoke the transformer
            FeatureTransformer ft = new FeatureTransformer();
            ft.setNumDecimals(16);
            ft.getFeatureNamespaces().declarePrefix("gs",
                    originalSchema.getName().getNamespaceURI());
            ft.transform(curCollection, os);
        } finally {
            os.close();
        }

        return outFile;
View Full Code Here

Examples of org.geotools.gml.producer.FeatureTransformer

        this.compressOutput = formatNameCompressed.equalsIgnoreCase(outputFormat);
        this.results = results;

        FeatureRequest request = results.getRequest();
        GeoServer config = request.getWFS().getGeoServer();
        transformer = new FeatureTransformer();

        FeatureTypeNamespaces ftNames = transformer.getFeatureTypeNamespaces();
        int maxFeatures = request.getMaxFeatures();
        int serverMaxFeatures = config.getMaxFeatures();
View Full Code Here

Examples of org.geotools.gml.producer.FeatureTransformer

        OutputStream os = null;
        try {
            os = new FileOutputStream(outFile);

            // let's invoke the transformer
            FeatureTransformer ft = new FeatureTransformer();
            ft.setNumDecimals(16);
            ft.setNamespaceDeclarationEnabled(false);
            ft.getFeatureNamespaces().declarePrefix("topp",
                    originalSchema.getName().getNamespaceURI());
            ft.transform(curCollection, os);
        } finally {
            os.close();
        }

        return outFile;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.