1

I'm trying to create a DataStore in Java with Geotools 12.3. With WFS services in geoserver works fine, but with WFS services in ArcGIS doesn't work at all.

This is the exception:

WARNING [net.refractions.xsi.element] (default task-78) Starting schema with ServiceExceptionReport element.
ERROR [stderr] (default task-78) java.lang.NullPointerException
ERROR [stderr] (default task-78)    at org.geotools.data.wfs.v1_0_0.WFS_1_0_0_DataStore.getSchema(WFS_1_0_0_DataStore.java:368)
ERROR [stderr] (default task-78)    at org.geotools.data.wfs.v1_0_0.WFSFeatureSource.getSchema(WFSFeatureSource.java:204)

This is my Java code: "Main Class"

public String getDataSelection(String url) throws IOException {

    Map mapResponse = new HashMap();
    String response = null;

    double x1 = strToDbl(this.getBboxT()[0]);
    double y1 = strToDbl(this.getBboxT()[1]);
    double x2 = strToDbl(this.getBboxT()[2]);
    double y2 = strToDbl(this.getBboxT()[3]);

    try {

        String url = "http://sigserv02.anla.gov.co:6080/arcgis/services/Alertas_tempranas_deforestacion/MapServer/WFSServer?service=WFS&VERSION=1.0.0&REQUEST=GetCapabilities";
        int layerName = 0;
        DataStore ds = configWFSDataStore(url);

        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
        FeatureSource fs = ds.getFeatureSource(layerName);
        FeatureType schema = fs.getSchema();
        CoordinateReferenceSystem worldCRS = DefaultGeographicCRS.WGS84;
        String geometryPropertyName = schema.getGeometryDescriptor().getLocalName();
        CoordinateReferenceSystem targetCRS = schema.getGeometryDescriptor().getCoordinateReferenceSystem();
        ReferencedEnvelope click = new ReferencedEnvelope(x1,x2, y1, y2, worldCRS);

        ReferencedEnvelope bbox = click.transform(targetCRS, true);
        Polygon clickPolygon = JTS.toGeometry(bbox);
        Filter filter = ff.intersects(ff.property(geometryPropertyName), ff.literal(clickPolygon));

        Query query = new Query(layerName, filter);
        query.setMaxFeatures(1500);

        FeatureReader<SimpleFeatureType, SimpleFeature> source = ds.getFeatureReader(query, Transaction.AUTO_COMMIT);

        CoordinateReferenceSystem CRSobjetivo = CRS.decode("EPSG:4326");

        if(source.hasNext()){
            .......
        }
        else{
            response = "empty";
        }
    } catch(Exception e){

        e.printStackTrace();
        ..........
    }
    return response;
}

configWFSDataStore Method:

 public static DataStore configWFSDataStore(String url) throws IOException {
    DataStore dataStore = null;

    BBConectionWFS conectionWFS = new BBConectionWFS();
    conectionWFS.setGetCapabilities(url+"service=WFS&VERSION=1.0.0&REQUEST=GetCapabilities");
    dataStore = conectionWFS.dataStoreWFS();

    return dataStore;
}

BBConectionWFS Class:

public DataStore dataStoreWFS() {
    DataStore dataStore = null;
    try {

        Map<String, String> connectionParameters;
        String getCapabilities = "http://sigserv02.anla.gov.co:6080/arcgis/services/Alertas_tempranas_deforestacion/MapServer/WFSServer?service=WFS&VERSION=1.0.0&REQUEST=GetCapabilities";

        String variableCapabilities = "WFSDataStoreFactory:GET_CAPABILITIES_URL";
        connectionParameters = new HashMap<String, String>();
        connectionParameters.put(variableCapabilities, getCapabilities);

        dataStore = (new WFSDataStoreFactory()).createDataStore(connectionParameters);

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return dataStore;
}

1 Answer 1

1

GeoTools 12 is a really old version and the WFS system has been completely rewritten since then so I would upgrade. Your code works fine with GeoTools 20 on my machine. The following gives a result of Alertas_tempranas_deforestacion:Alertas_Tempranas_Deforestacion which matches QGIS' view of it.

import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import org.geotools.data.DataStore;
import org.geotools.data.wfs.WFSDataStoreFactory;

public class EsriWFS {

  public static void main(String[] args) throws IOException {
    EsriWFS me = new EsriWFS();
    DataStore ds = me.dataStoreWFS();
    for (String n:ds.getTypeNames()) {
      System.out.println(n);
    }
  }

  public DataStore dataStoreWFS() {
    DataStore dataStore = null;
    try {

        Map<String, Serializable> connectionParameters = new HashMap<>();
        String getCapabilities = "http://sigserv02.anla.gov.co:6080/arcgis/services/Alertas_tempranas_deforestacion/MapServer/WFSServer?service=WFS&VERSION=1.0.0&REQUEST=GetCapabilities";

        String variableCapabilities = "WFSDataStoreFactory:GET_CAPABILITIES_URL";


        connectionParameters.put(variableCapabilities, getCapabilities);

        dataStore = (new WFSDataStoreFactory()).createDataStore(connectionParameters);

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return dataStore;
}
}
2
  • Update the version of the GeoTools to 19.1 but the problem persists, I post the full version of my code Jul 5, 2018 at 17:12
  • does my code work for you? just as a test?
    – Ian Turton
    Jul 5, 2018 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.