2

I'm using Geoserver REST API to create a new PostGIS feature type in Geoserver doing a POST to an url following this pattern http://localhost:8080/geoserver/rest/workspaces/my_ws/datastores/my_ds/featuretypes.json

and passing it data like this:

{'featureType': {'name':'my_featuretype_name'}}.

The post effectively create the feature type but is returning a 500 code error which mean:

Internal server error.

According to the official doc the returned code is supposed to be 201.

Looking in Geoserver log show me the following error:

INFO [org.geoserver] - Loaded feature type 'my_featuretype_name', enabled

ERROR [geoserver.rest] - :Resource named 'my_featuretype_name' already exists in store: 'my_ds'

The table already exist in my database but is not published as a layer in Geoserver.

What I want to do is to reproduce, with the REST API, the exact same action of clicking publish for an existing table in my database in the add new layer page of the Geoserver Web admin.

Am I doing something wrong?

Thanks a lot

Etienne

  • I am having this same issue using gsconfig (a Python module to manage GeoServer via rest). It seems to have worked once, but now it doesn't - and the purpose of what I am working on is to clear and recreate layers, so that's a huge problem. Did you ever find a solution to this? – user71224 Nov 11 '16 at 22:25
0

I sent this json, and change neccessary with f-string. I think the problem is the same name of publicated layer and data source. May be it helps.

def publicate_shp(input_shp, host = "http://localhost:8080/geoserver", workspace = "raster_test"):

print ("Publicate shp")
shp_name = os.path.basename(input_shp)

json_shp_layer=({
    "featureType": {
        "name": f'''{shp_name[:-4]}''',
        "nativeName": f'''{shp_name[:-4]}''',
        "namespace": {
            "name": f'''{workspace}''',
            "href": f'''{host}/rest/namespaces/{workspace}.json'''
        },
        "title": f'''{shp_name[:-4]}''',
        "keywords": {
            "string": [
                "features"
            ]
        },
        "nativeCRS": {
            "@class": "projected",
            "$": "PROJCS[\"WGS 84 / Pseudo-Mercator\", \r\n  GEOGCS[\"WGS 84\", \r\n    DATUM[\"World Geodetic System 1984\", \r\n      SPHEROID[\"WGS 84\", 6378137.0, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]], \r\n      AUTHORITY[\"EPSG\",\"6326\"]], \r\n    PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], \r\n    UNIT[\"degree\", 0.017453292519943295], \r\n    AXIS[\"Geodetic longitude\", EAST], \r\n    AXIS[\"Geodetic latitude\", NORTH], \r\n    AUTHORITY[\"EPSG\",\"4326\"]], \r\n  PROJECTION[\"Popular Visualisation Pseudo Mercator\", AUTHORITY[\"EPSG\",\"1024\"]], \r\n  PARAMETER[\"semi_minor\", 6378137.0], \r\n  PARAMETER[\"latitude_of_origin\", 0.0], \r\n  PARAMETER[\"central_meridian\", 0.0], \r\n  PARAMETER[\"scale_factor\", 1.0], \r\n  PARAMETER[\"false_easting\", 0.0], \r\n  PARAMETER[\"false_northing\", 0.0], \r\n  UNIT[\"m\", 1.0], \r\n  AXIS[\"Easting\", EAST], \r\n  AXIS[\"Northing\", NORTH], \r\n  AUTHORITY[\"EPSG\",\"3857\"]]"
        },
        "srs": "EPSG:3857",
        "nativeBoundingBox": {
            "minx": 5009288.460919382,
            "maxx": 8349700.133080006,
            "miny": 6482677.681155918,
            "maxy": 10613937.178513382,
            "crs": {
                "@class": "projected",
                "$": "EPSG:3857"
            }
        },
        "latLonBoundingBox": {
            "minx": 44.99920387007435,
            "maxx": 75.00663247360572,
            "miny": 50.20973437863392,
            "maxy": 68.55500689494048,
            "crs": "EPSG:4326"
        },
        "projectionPolicy": "FORCE_DECLARED",
        "enabled": "true",
        "store": {
            "@class": "dataStore",
            "name": f'''{workspace}:{shp_name}''',
            "href": f'''{host}/rest/workspaces/{workspace}/datastores/{shp_name}.json'''
        },
        "maxFeatures": 0,
        "numDecimals": 0,
        "padWithZeros": "false",
        "forcedDecimal": "false",
        "overridingServiceSRS": "false",
        "skipNumberMatched": "false",
        "circularArcPresent": "false",
        "attributes": {
            "attribute": [
                {
                    "name": "the_geom",
                    "minOccurs": 0,
                    "maxOccurs": 1,
                    "nillable": "true",
                    "binding": "org.locationtech.jts.geom.MultiLineString"
                },
                {
                    "name": "ID",
                    "minOccurs": 0,
                    "maxOccurs": 1,
                    "nillable": "true",
                    "binding": "java.lang.Long",
                    "length": 10
                },
                {
                    "name": "elev",
                    "minOccurs": 0,
                    "maxOccurs": 1,
                    "nillable": "true",
                    "binding": "java.lang.Double",
                    "length": 19
                }
            ]
        }
    }
})


url = f'''{host}/rest/workspaces/{workspace}/datastores/{shp_name}/featuretypes'''

#print(json.dumps(json_shp_layer, indent = 4))


response = requests.post(url,
                             auth=credits,
                             headers = headers_main, 
                             data = json.dumps(json_shp_layer))


print ('''Publicate shp - ''' + str(response.status_code))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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