我已经使用 Rest API 成功创建了一个数据存储。使用 GeoServer Web 面板创建图层时没有任何问题。但是我无法使用 Rest API 创建相同的图层。
工作空间和存储名称分别为“test”和“gis_osm_adminareas_a_07_1”。
Store 的类型为“Shapefile”并指向“.shp”文件。还有“.dbf”、“.prj”和“.shx”文件在与所述“.shp”文件相同的位置共享相同的基本名称。
ogrinfo -al -so gis_osm_adminareas_a_07_1.shp
命令正确分析并给出shapefile相关信息。
这是我使用的 URL 和帖子正文:
URL: {{host}}/geoserver/rest/workspaces/test/datastores/gis_osm_adminareas_a_07_1/featuretypes
Body:
{
"featureType":
{
"name": "gis_osm_adminareas_a_07_1",
"title": "gis_osm_adminareas_a_07_1",
"enabled": true,
"store":
{
"@class": "dataStore",
"name": "test:gis_osm_adminareas_a_07_1"
},
"attributes":
{
"attribute":
[
{
"name": "the_geom",
"minOccurs": 0,
"maxOccurs": 1,
"nillable": true,
"binding": "org.locationtech.jts.geom.MultiPolygon" // also tried "org.locationtech.jts.geom.Polygon" here
},
{
"name": "osm_id",
"minOccurs": 0,
"maxOccurs": 1,
"nillable": true,
"binding": "java.lang.String",
"length": 10
},
{
"name": "lastchange",
"minOccurs": 0,
"maxOccurs": 1,
"nillable": true,
"binding": "java.lang.String",
"length": 20
},
{
"name": "code",
"minOccurs": 0,
"maxOccurs": 1,
"nillable": true,
"binding": "java.lang.Integer",
"length": 4
},
{
"name": "fclass",
"minOccurs": 0,
"maxOccurs": 1,
"nillable": true,
"binding": "java.lang.String",
"length": 28
},
{
"name": "geomtype",
"minOccurs": 0,
"maxOccurs": 1,
"nillable": true,
"binding": "java.lang.String",
"length": 10
},
{
"name": "postalcode",
"minOccurs": 0,
"maxOccurs": 1,
"nillable": true,
"binding": "java.lang.String",
"length": 10
},
{
"name": "name",
"minOccurs": 0,
"maxOccurs": 1,
"nillable": true,
"binding": "java.lang.String",
"length": 100
}
]
}
}
}
操作失败,出现 500 内部服务器错误,响应正文中没有发送回错误信息。但是堆栈跟踪出现在日志中。这是错误日志的相关部分:
ERROR [geoserver.rest] -
java.lang.NullPointerException
at org.geoserver.catalog.impl.FeatureTypeValidator.validate(FeatureTypeValidator.java:40)
at org.geoserver.catalog.impl.CatalogImpl.validate(CatalogImpl.java:515)
at org.geoserver.security.SecureCatalogImpl.validate(SecureCatalogImpl.java:1320)
at org.geoserver.catalog.impl.AbstractFilteredCatalog.validate(AbstractFilteredCatalog.java:633)
at org.geoserver.catalog.impl.AbstractCatalogDecorator.validate(AbstractCatalogDecorator.java:274)
at org.geoserver.rest.catalog.FeatureTypeController.featureTypePost(FeatureTypeController.java:280)
我尝试了很多不同的帖子主体组合,但都没有成功。我还尝试复制使用 Web 面板创建图层时创建的“resource.json”,并将其发送到 featureType 端点,这也不起作用。
任何帮助表示赞赏。谢谢!
更新
商店是使用以下 URL 和帖子正文创建的
URL: POST {{host}}/workspaces/test/datastores
Body:
{
"dataStore":
{
"workspace": "test",
"enabled": true,
"name": "gis_osm_adminareas_a_07_1",
"nativeName": "gis_osm_adminareas_a_07_1.shp",
"connectionParameters":
{
"entry":
[
{
"@key": "filetype",
"$": "shapefile"
},
{
"@key": "create spatial index",
"$": "true"
},
{
"@key": "url",
"$": "file:///geoserver/uploads/6b82db8f-427c-4f07-9c89-e95ae6413732/gis_osm_adminareas_a_07_1.shp"
},
{
"@key": "enable spatial index",
"$": "true"
},
{
"@key": "charset",
"$": "ISO-8859-1"
},
{
"@key": "memory mapped buffer",
"$": "false"
},
{
"@key": "timezone",
"$": "GMT"
},
{
"@key": "namespace",
"$": "http://test"
},
{
"@key": "cache and reuse memory maps",
"$": "false"
},
{
"@key": "fstype",
"$": "shape"
}
]
},
"type": "Shapefile"
}
}