Hi community,

I'm trying to encode some KML and I'm getting an error. I don't understand
why. This is the error:

Exception in thread "main" java.lang.NullPointerException
    at
org.geotools.xml.impl.SchemaIndexImpl.destroy(SchemaIndexImpl.java:100)
    at org.geotools.xml.Encoder.encode(Encoder.java:1026)
    at org.geotools.xml.Encoder.encode(Encoder.java:566)
    at xsdtest.main(xsdtest.java:44)


An this is my code:

import java.io.ByteArrayOutputStream;
import java.util.HashMap;
import java.util.Map;
import org.geotools.data.DataStoreFinder;
import org.geotools.data.DataStore;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.kml.KML;
import org.geotools.kml.KMLConfiguration;
import org.geotools.xml.Encoder;
import org.opengis.feature.simple.SimpleFeature;

public class xsdtest {

    public static void main(String[] args) throws Exception {

        DataStore dataStore;
        String server = "
http://www.sogis1.so.ch:8080/geoserver/ows?service=WFS&request=GetCapabilities
";
        String layer = "topp:states"; // Feature TypeName

        Map<String, Object> connectionParameters = new HashMap<String,
Object>();
        connectionParameters.put("WFSDataStoreFactory:GET_CAPABILITIES_URL",
server);
        dataStore = DataStoreFinder.getDataStore(connectionParameters);

        SimpleFeatureSource featureSource =
dataStore.getFeatureSource(layer);
        SimpleFeatureCollection featureCollection =
featureSource.getFeatures();
        SimpleFeatureIterator featuresIterator =
featureCollection.features();

        Encoder encoder = new Encoder(new KMLConfiguration());
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        while (featuresIterator.hasNext()) {
            SimpleFeature feature = featuresIterator.next();
            encoder.encode(feature, KML.Placemark, out);
            String kmlString = new String(out.toByteArray());
            System.out.println(kmlString);
        }
    }
}



What I'm doing wrong? Any ideas?
Thank you very much.

Edu.
------------------------------------------------------------------------------
Magic Quadrant for Content-Aware Data Loss Prevention
Research study explores the data loss prevention market. Includes in-depth
analysis on the changes within the DLP market, and the criteria used to
evaluate the strengths and weaknesses of these DLP solutions.
http://www.accelacomm.com/jaw/sfnl/114/51385063/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to