use of org.geosdi.geoplatform.connector.geoserver.model.layers.vector.GeoserverVectorLayer in project geo-platform by geosdi.
the class GPPublisherBasicServiceImpl method publishShapeFile.
/**
* @param workspace
* @param dataStoreName
* @param charset
* @param dataSetName
* @param style
* @param shapeFile
* @param srs
* @return
* @throws IllegalArgumentException
*/
private boolean publishShapeFile(String workspace, String dataStoreName, String charset, String dataSetName, String style, File shapeFile, String srs) throws IllegalArgumentException {
boolean srsNull = !(srs != null && srs.length() != 0);
if (srsNull) {
throw new IllegalArgumentException("Unable to run: you can't force GeoServer to use an srs which is null");
}
try {
if (!this.geoserverConnectorStore.updateDataStoreWithStoreName().withWorkspace(workspace).withStore(dataStoreName).withMethod(GPGeoserverUploadMethod.FILE).withCharset(charset).withFormat(GPGeoserverDataStoreFileExtension.SHP).withFileName((dataStoreName != null) ? dataStoreName : FilenameUtils.getBaseName(shapeFile.toString())).withFile(shapeFile).getResponse()) {
logger.error("Unable to create data store for shapefile: {}\n", shapeFile.toURI());
return FALSE;
}
GPGeoserverFeatureTypeInfo gpGeoserverFeatureTypeInfo = new GPGeoserverFeatureTypeInfo();
gpGeoserverFeatureTypeInfo.setName(dataSetName);
gpGeoserverFeatureTypeInfo.setTitle(dataSetName);
gpGeoserverFeatureTypeInfo.setEnabled(TRUE);
gpGeoserverFeatureTypeInfo.setProjectionPolicy(FORCE_DECLARED);
if (!srsNull) {
gpGeoserverFeatureTypeInfo.setSrs(srs);
} else {
// this under the assumption that when the destination srs is null the nativeCRS has an EPSG one so we force them to be the same
gpGeoserverFeatureTypeInfo.setNativeCRS(null);
}
if (!this.geoserverConnectorStore.updateFeatureTypeRequest().withWorkspace(workspace).withFeatureTypeBody(gpGeoserverFeatureTypeInfo).withStore(dataStoreName).withFeatureName(dataSetName).getResponse()) {
logger.error("Unable to create a coverage store for coverage: {}\n", shapeFile.toURI());
return FALSE;
}
GeoserverVectorLayer geoserverVectorLayer = new GeoserverVectorLayer();
GPGeoserverStyle gpGeoserverStyle = new GPGeoserverStyle();
gpGeoserverStyle.setName(style.indexOf(":") != -1 ? style.split(":")[0] : style);
geoserverVectorLayer.setDefaultStyle(gpGeoserverStyle);
return this.geoserverConnectorStore.updateLayerRequest().withWorkspaceName(workspace).withLayerName(dataSetName).withLayerBody(geoserverVectorLayer).getResponse();
} catch (Exception e) {
final String error = "Error to load shape file " + e;
logger.error(error);
throw new IllegalArgumentException(error);
}
}
use of org.geosdi.geoplatform.connector.geoserver.model.layers.vector.GeoserverVectorLayer in project geo-platform by geosdi.
the class GeoserverConnectorDatastoresTest method d_updateDataStoreWithShape.
@Ignore
@Test
public void d_updateDataStoreWithShape() throws Exception {
File file = new File(of("src", "test", "resources", "admin_shp_comuni.zip").collect(joining(separator)));
assertTrue("#################FILE_EXSIST", file.exists());
logger.info("#############FILE: {}\n", file.toURI());
logger.info("##################{}\n", FilenameUtils.getBaseName(file.toURI().toString()));
if (this.geoserverConnectorStore.updateDataStoreWithStoreName().withWorkspace("sf").withStore("store_vito").withMethod(GPGeoserverUploadMethod.FILE).withCharset("UTF-8").withFormat(GPGeoserverDataStoreFileExtension.SHP).withFileName("admin_shp_comuni").withFile(file).getResponse()) {
logger.info("############ERRO TO CREATE STORE");
}
GPGeoserverFeatureTypeInfo gpGeoserverFeatureTypeInfo = new GPGeoserverFeatureTypeInfo();
gpGeoserverFeatureTypeInfo.setName("admin_shp_comuni");
gpGeoserverFeatureTypeInfo.setTitle("admin_shp_comuni");
gpGeoserverFeatureTypeInfo.setEnabled(TRUE);
gpGeoserverFeatureTypeInfo.setProjectionPolicy(FORCE_DECLARED);
String srs = "EPSG:32633";
boolean srsNull = !(srs != null && srs.length() != 0);
if (!srsNull) {
gpGeoserverFeatureTypeInfo.setSrs(srs);
} else {
// this under the assumption that when the destination srs is null the nativeCRS has an EPSG one so we force them to be the same
gpGeoserverFeatureTypeInfo.setNativeCRS(null);
}
logger.info("###############{}\n", this.geoserverConnectorStore.updateFeatureTypeRequest().withWorkspace("sf").withFeatureTypeBody(gpGeoserverFeatureTypeInfo).withStore("store_vito").withFeatureName("admin_shp_comuni").getResponse());
String defaultStyle = "polygon";
GeoserverVectorLayer geoserverRasterLayer = new GeoserverVectorLayer();
GPGeoserverStyle gpGeoserverStyle = new GPGeoserverStyle();
gpGeoserverStyle.setName(defaultStyle.indexOf(":") != -1 ? defaultStyle.split(":")[0] : defaultStyle);
geoserverRasterLayer.setDefaultStyle(gpGeoserverStyle);
logger.info("##############{}\n", this.geoserverConnectorStore.updateLayerRequest().withWorkspaceName("sf").withLayerName("admin_shp_comuni").withLayerBody(geoserverRasterLayer).getResponse());
}
Aggregations