I've installed GeoServer and uploaded a shapefile in it and i want to export this added layer to shapefile using GeoTools library.

I've writtren some code which generates a shapefile(shp,dbf,shx,prj) that contains features without geomertic shape. in the other word it just exports attributes.

pls help me with this problem. where should i revise my code.

here is my code

try {
        String getCapabilities = "http://localhost:8060/geoserver/ows?service=wfs&version=1.0.0&request=GetCapabilities";
        Map connectionParameters = new HashMap();
        connectionParameters.put("WFSDataStoreFactory:GET_CAPABILITIES_URL", getCapabilities);
        DataStore data = DataStoreFinder.getDataStore(connectionParameters); 

        String[] typeNames = data.getTypeNames();

        for (int i = 0; i < typeNames.length; i++) {

            if (!typeNames[i].contains("navahi"))
            SimpleFeatureSource wfsFeatureSource = data.getFeatureSource(typeNames[i]);

            if (wfsFeatureSource instanceof SimpleFeatureStore) {
                SimpleFeatureType TYPE = wfsFeatureSource.getSchema();

                File newFile = new File(System.getProperty("user.dir") + typeNames[i].replace(":", "_") + ".shp");


                ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory();

                Map<String, Serializable> params = new HashMap<String, Serializable>();
                params.put("url", newFile.toURI().toURL());
                params.put("create spatial index", Boolean.TRUE);

                ShapefileDataStore shpDataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params);
                String shpTypeName = shpDataStore.getTypeNames()[0];
                SimpleFeatureSource shpFeatureSource = shpDataStore.getFeatureSource(shpTypeName);

                SimpleFeatureStore shpFeatureStore = (SimpleFeatureStore) shpFeatureSource;

                SimpleFeatureCollection wfsFeatureCollection = wfsFeatureSource.getFeatures();

                Transaction transaction = new DefaultTransaction("create");

                try {
                } catch (Exception problem) {

                } finally {


    } catch (Exception e) {
        // TODO: handle exception }
  • 1
    Do you have a question?
    – til_b
    Aug 24, 2016 at 19:00
  • yeah sure, if i had not why on earth i post this question Aug 24, 2016 at 19:09
  • 1
    And what is the question? Please edit your post to include a question.
    – til_b
    Aug 24, 2016 at 19:11
  • What happens with your code, do you get any outputs or errors?
    – nmtoken
    Aug 24, 2016 at 19:19
  • 2
    All right, much more understandable so. If you want shapefiles out from WFS, why don't you simply make GetFeature with shape-zip outputformat docs.geoserver.org/latest/en/user/services/wfs/…?
    – user30184
    Aug 24, 2016 at 21:02

2 Answers 2


The most likely reason to not see a geometry column in a Shapefile is that your column name is not the_geom. This is required by the ShapeFile standard - in an ideal world GeoTools would be smart enough to fix this for you behind the scenes, but no one has contributed that code yet!

So you will need to inspect the schema of your features from the WFS and modify the names of any columns that don't fit the ShapeFile standard, i.e. start with an digit, longer than 10 characters etc.

  • yes your point was completely right. When i was importing my layer to postgresql i didnt change the geometry column name and the default name was geom so i did it again with the_geom and then i published it in geoserver and when i'd run my code that worked fine. Aug 25, 2016 at 17:45

You can request a Shapefile via the WFS request to GeoServer.


States, WFS returns features and feature information in a number of formats. The syntax for specifying an output format is:


For ShapeFile


Just add that param to the request URL

  • thanks for answering my question although I need my application to be in full connection with geoserver and have list of all layers and their features and attributes and i need to mange all them in memory so Im not able to send a request for all of these stuffs but in some situations i could do make request Aug 25, 2016 at 14:43

Your Answer

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

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