use of org.geosdi.geoplatform.connector.server.request.WFSGetFeatureRequest in project geo-platform by geosdi.
the class WFSGetFeaturesRequestTest method l_percorsiNavetteTest.
@Ignore
@Test
public void l_percorsiNavetteTest() throws Exception {
String wfsURL = "http://mappe-dpc.protezionecivile.it/gssitdpc/wfs";
GPWFSConnectorStore serverConnector = WFSConnectorBuilder.newConnector().withServerUrl(new URL(wfsURL)).build();
QName percorsiNavette = new QName("PianoCampiFlegrei:CF_PercorsiNavette");
String localPart = percorsiNavette.getLocalPart();
String name = localPart.substring(localPart.indexOf(":") + 1);
WFSDescribeFeatureTypeRequest<Schema> request = serverConnector.createDescribeFeatureTypeRequest();
request.setTypeName(asList(percorsiNavette));
Schema response = request.getResponse();
logger.info("#################SCHEMA : {}\n", response);
LayerSchemaDTO layerSchema = featureReaderXSD.getFeature(response, name);
if (layerSchema == null) {
throw new IllegalStateException("The Layer Schema is null.");
}
layerSchema.setScope(wfsURL);
logger.debug("\n\t##################################LAYER_SCHEMA : {}", layerSchema);
WFSGetFeatureRequest getFeatureRequest = serverConnector.createGetFeatureRequest();
getFeatureRequest.setTypeName(new QName(layerSchema.getTypeName()));
getFeatureRequest.setSRS("EPSG:4326");
getFeatureRequest.setResultType(RESULTS.value());
getFeatureRequest.setMaxFeatures(valueOf(50));
logger.debug("@@@@@@@@@@@@@@@@@@REQUEST_AS_STRING : \n{}\n", getFeatureRequest.showRequestAsString());
InputStream is = getFeatureRequest.getResponseAsStream();
WFSGetFeatureStaxReader featureReaderStAX = new WFSGetFeatureStaxReader(layerSchema);
FeatureCollectionDTO featureCollection = featureReaderStAX.read(is);
if (!featureCollection.isFeaturesLoaded()) {
featureCollection.setErrorMessage(getFeatureRequest.getResponseAsString());
}
JAXBElement<FeatureCollectionDTO> root = new JAXBElement<>(percorsiNavette, FeatureCollectionDTO.class, featureCollection);
gpJAXBContextBuilder.marshal(root, new File(of(new File(".").getCanonicalPath(), "target", "PercorsiNavette").collect(joining(separator, "", ".xml"))));
getFeatureRequest.setOutputFormat("json");
InputStream isJson = getFeatureRequest.getResponseAsStream();
FeatureCollection featureCollectionJson = JACKSON_SUPPORT.getDefaultMapper().readValue(isJson, FeatureCollection.class);
JACKSON_SUPPORT.getDefaultMapper().writeValue(new File(of(new File(".").getCanonicalPath(), "target", "PercorsiNavette").collect(joining(separator, "", ".json"))), featureCollectionJson);
}
use of org.geosdi.geoplatform.connector.server.request.WFSGetFeatureRequest in project geo-platform by geosdi.
the class WFSGetFeaturesRequestTest method d_siteTrTest.
@Ignore(value = "Geoserver is Down")
@Test
public void d_siteTrTest() throws Exception {
String wfsURL = "http://150.145.141.241/geoserver/wfs";
QName siteTRCom = new QName("cite:tr_com");
GPWFSConnectorStore serverConnector = WFSConnectorBuilder.newConnector().withServerUrl(new URL(wfsURL)).build();
WFSDescribeFeatureTypeRequest<Schema> request = serverConnector.createDescribeFeatureTypeRequest();
request.setTypeName(asList(siteTRCom));
Schema response = request.getResponse();
String localPart = siteTRCom.getLocalPart();
String name = localPart.substring(localPart.indexOf(":") + 1);
LayerSchemaDTO layerSchema = featureReaderXSD.getFeature(response, name);
if (layerSchema == null) {
throw new IllegalStateException("The Layer Schema is null.");
}
layerSchema.setScope(wfsURL);
WFSGetFeatureRequest getFeatureRequest = serverConnector.createGetFeatureRequest();
getFeatureRequest.setTypeName(new QName(layerSchema.getTypeName()));
getFeatureRequest.setSRS("EPSG:4326");
getFeatureRequest.setResultType(RESULTS.value());
getFeatureRequest.setMaxFeatures(valueOf(50));
logger.debug("@@@@@@@@@@@@@@@@@@REQUEST_AS_STRING : \n{}\n", getFeatureRequest.showRequestAsString());
logger.debug("######################RESPONSE_AS_STRING : \n{}\n", getFeatureRequest.formatResponseAsString(2));
InputStream is = getFeatureRequest.getResponseAsStream();
WFSGetFeatureStaxReader featureReaderStAX = new WFSGetFeatureStaxReader(layerSchema);
FeatureCollectionDTO featureCollection = featureReaderStAX.read(is);
if (!featureCollection.isFeaturesLoaded()) {
featureCollection.setErrorMessage(getFeatureRequest.getResponseAsString());
}
logger.info("###################################FEATURE_COLLECTION : {}\n", featureCollection);
getFeatureRequest.setGeometryName(layerSchema.getGeometry().getName());
getFeatureRequest.setBBox(new BBox(10.329274141729897, 44.64877730606194, 10.35673996203874, 44.66831396911103));
logger.debug("@@@@@@@@@@@@@@@@@@REQUEST_FILTERED_BY_BBOX_AS_STRING : \n{}\n", getFeatureRequest.showRequestAsString());
logger.debug("######################RESPONSE_FILTERED_BY_BBOX_AS_STRING : \n{}\n", getFeatureRequest.formatResponseAsString(2));
InputStream si = getFeatureRequest.getResponseAsStream();
FeatureCollectionDTO featureCollectionByBBOX = featureReaderStAX.read(si);
if (!featureCollectionByBBOX.isFeaturesLoaded()) {
featureCollectionByBBOX.setErrorMessage(getFeatureRequest.getResponseAsString());
}
logger.info("###################################FEATURE_COLLECTION_BY_BBOX : {}\n", featureCollectionByBBOX);
}
use of org.geosdi.geoplatform.connector.server.request.WFSGetFeatureRequest in project geo-platform by geosdi.
the class WFSGetFeaturesRequestTest method b_statesTest.
// @Ignore(value = "FIX PROBLEM TO RETRIEVE ATTRIBUTES WITHOUT GEOMETRY")
@Test
public void b_statesTest() throws Exception {
String wfsURL = "http://150.145.141.92/geoserver/wfs";
GPWFSConnectorStore serverConnector = WFSConnectorBuilder.newConnector().withServerUrl(new URL(wfsURL)).build();
WFSDescribeFeatureTypeRequest<Schema> request = serverConnector.createDescribeFeatureTypeRequest();
request.setTypeName(asList(states));
Schema response = request.getResponse();
LayerSchemaDTO layerSchema = featureReaderXSD.getFeature(response, statesName);
if (layerSchema == null) {
throw new IllegalStateException("The Layer Schema is null.");
}
layerSchema.setScope(wfsURL);
logger.debug("\n\t##################################LAYER_SCHEMA : {}", layerSchema);
WFSGetFeatureRequest getFeatureRequest = serverConnector.createGetFeatureRequest();
getFeatureRequest.setTypeName(new QName(layerSchema.getTypeName()));
getFeatureRequest.setPropertyNames(asList(new String[] { "STATE_NAME", "PERSONS" }));
getFeatureRequest.setBBox(new BBox(-75.102613, 40.212597, -72.361859, 41.512517));
getFeatureRequest.setSRS("EPSG:4326");
getFeatureRequest.setResultType(RESULTS.value());
getFeatureRequest.setMaxFeatures(valueOf(50));
logger.debug("\n\t@@@@@@@@@@@@@@@@@@RESPONSE_AS_STRING : {}", getFeatureRequest.getResponseAsString());
InputStream is = getFeatureRequest.getResponseAsStream();
WFSGetFeatureStaxReader featureReaderStAX = new WFSGetFeatureStaxReader(layerSchema);
FeatureCollectionDTO featureCollection = featureReaderStAX.read(is);
if (!featureCollection.isFeaturesLoaded()) {
featureCollection.setErrorMessage(getFeatureRequest.getResponseAsString());
}
logger.debug("\n\t@@@@@@@@@@@@@@@@@@@@@@@@@@@FEATURE_COLLECTION_DTO : {}", featureCollection.getNumberOfFeatures());
}
use of org.geosdi.geoplatform.connector.server.request.WFSGetFeatureRequest in project geo-platform by geosdi.
the class WFSGetFeaturesRequestTest method c_tigerRoadsTest.
@Test
public void c_tigerRoadsTest() throws Exception {
String wfsURL = "http://150.145.141.92/geoserver/wfs";
GPWFSConnectorStore serverConnector = WFSConnectorBuilder.newConnector().withServerUrl(new URL(wfsURL)).build();
WFSDescribeFeatureTypeRequest<Schema> request = serverConnector.createDescribeFeatureTypeRequest();
request.setTypeName(asList(tigerRoads));
Schema response = request.getResponse();
LayerSchemaDTO layerSchema = featureReaderXSD.getFeature(response, tigerRoadsName);
if (layerSchema == null) {
throw new IllegalStateException("The Layer Schema is null.");
}
layerSchema.setScope(wfsURL);
logger.debug("\n\t##################################LAYER_SCHEMA : {}", layerSchema);
WFSGetFeatureRequest getFeatureRequest = serverConnector.createGetFeatureRequest();
getFeatureRequest.setTypeName(new QName(layerSchema.getTypeName()));
getFeatureRequest.setSRS("EPSG:4326");
getFeatureRequest.setResultType(RESULTS.value());
getFeatureRequest.setMaxFeatures(valueOf(50));
logger.debug("@@@@@@@@@@@@@@@@@@RESPONSE_AS_STRING : \n{}\n", getFeatureRequest.showRequestAsString());
InputStream is = getFeatureRequest.getResponseAsStream();
WFSGetFeatureStaxReader featureReaderStAX = new WFSGetFeatureStaxReader(layerSchema);
FeatureCollectionDTO featureCollection = featureReaderStAX.read(is);
if (!featureCollection.isFeaturesLoaded()) {
featureCollection.setErrorMessage(getFeatureRequest.getResponseAsString());
}
logger.debug("\n\t@@@@@@@@@@@@@@@@@@@@@@@@@@@FEATURE_COLLECTION_DTO : {}", featureCollection);
}
use of org.geosdi.geoplatform.connector.server.request.WFSGetFeatureRequest in project geo-platform by geosdi.
the class GPGetFeatureService method getFeature.
/**
* @param layerSchema
* @param maxFeatures
* @param headerParams
* @return {@link FeatureCollectionDTO}
* @throws Exception
*/
@Override
public FeatureCollectionDTO getFeature(LayerSchemaDTO layerSchema, int maxFeatures, Map<String, String> headerParams) throws Exception {
checkArgument(maxFeatures > 0, "The Parameter maxFeatures must be > 0.");
WFSGetFeatureRequest request = this.createRequest(layerSchema, headerParams);
request.setMaxFeatures(BigInteger.valueOf(maxFeatures));
return this.getFeatureCollection(request, layerSchema);
}
Aggregations