Search in sources :

Example 1 with GeoserverVectorLayer

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);
    }
}
Also used : GeoserverVectorLayer(org.geosdi.geoplatform.connector.geoserver.model.layers.vector.GeoserverVectorLayer) IGPGeoserverStyle(org.geosdi.geoplatform.connector.geoserver.model.styles.IGPGeoserverStyle) GPGeoserverStyle(org.geosdi.geoplatform.connector.geoserver.model.styles.GPGeoserverStyle) GPGeoserverFeatureTypeInfo(org.geosdi.geoplatform.connector.geoserver.model.featuretypes.GPGeoserverFeatureTypeInfo) FactoryException(org.opengis.referencing.FactoryException) DataSourceException(org.geotools.data.DataSourceException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 2 with GeoserverVectorLayer

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());
}
Also used : GeoserverVectorLayer(org.geosdi.geoplatform.connector.geoserver.model.layers.vector.GeoserverVectorLayer) GPGeoserverStyle(org.geosdi.geoplatform.connector.geoserver.model.styles.GPGeoserverStyle) GPGeoserverFeatureTypeInfo(org.geosdi.geoplatform.connector.geoserver.model.featuretypes.GPGeoserverFeatureTypeInfo) File(java.io.File) Ignore(org.junit.Ignore) GeoserverConnectorTest(org.geosdi.geoplatform.geoserver.GeoserverConnectorTest) Test(org.junit.Test)

Aggregations

GPGeoserverFeatureTypeInfo (org.geosdi.geoplatform.connector.geoserver.model.featuretypes.GPGeoserverFeatureTypeInfo)2 GeoserverVectorLayer (org.geosdi.geoplatform.connector.geoserver.model.layers.vector.GeoserverVectorLayer)2 GPGeoserverStyle (org.geosdi.geoplatform.connector.geoserver.model.styles.GPGeoserverStyle)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 IGPGeoserverStyle (org.geosdi.geoplatform.connector.geoserver.model.styles.IGPGeoserverStyle)1 GeoserverConnectorTest (org.geosdi.geoplatform.geoserver.GeoserverConnectorTest)1 DataSourceException (org.geotools.data.DataSourceException)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 FactoryException (org.opengis.referencing.FactoryException)1