Voici la documentation : https://geoplateforme.pages.gpf-tech.ign.fr/documentation

Skip to content
Extraits de code Groupes Projets
Valider 11bd5b00 rédigé par fcerizay's avatar fcerizay
Parcourir les fichiers

client

parent 1d4ebe08
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -3,8 +3,6 @@
namespace Ign\Component\WFS ;
/**
* Client
*
......@@ -25,6 +23,14 @@ class Client {
*/
private $browser;
const FILTER_OR = "Or";
const FILTER_AND = "And";
/**
*
* @var unknown $proxy
*/
private $proxy;
/**
* Constructor
......@@ -34,6 +40,8 @@ class Client {
*/
public function __construct( $proxy = '' ){
$this->proxy = $proxy;
$client = new \Buzz\Client\Curl() ;
$client->setProxy( $proxy ) ;
$client->setTimeout( 60000 ) ;
......@@ -96,14 +104,7 @@ class Client {
*/
public function getUpdateSequence(){
$params = array(
"service" => "WFS",
"version"=>"2.0.0",
"request" => "GetCapabilities"
);
$url = $this->url_wfs.'?'.http_build_query( $params ) ;
$data = $this->browser->get( $url )->getContent() ;
$data = $this->getCapabilities();
return $this->parseUpdateSequence( $data );
......@@ -119,19 +120,24 @@ class Client {
*/
public function getFeatureFormats(){
$data = $this->getCapabilities();
return $this->parseFeatureFormats( $data );
}
private function getCapabilities(){
$params = array(
"service" => "WFS",
"version"=>"2.0.0",
"request" => "GetCapabilities"
"service" => "WFS",
"version"=>"2.0.0",
"request" => "GetCapabilities"
);
$url = $this->url_wfs.'?'.http_build_query( $params ) ;
$data = $this->browser->get( $url )->getContent() ;
$formats = $this->parseFeatureFormats( $data );
return $formats;
return $data;
}
/**
* desbribeFeatureTypes
......@@ -256,59 +262,82 @@ class Client {
$featureCollection = $this->browser->get( $url )->getContent();
return $featureCollection;
}
/**
* exportFeatures
*
*
* exporter les features dans un fichier
*
*
* @param string $path
* @param string $outputFormat
* @param array $featureFilter
*/
public function exportFeatures( $path, $outputFormat, $typeName , $featureFilter ){
$formats = $this->getFeatureFormats();
if( ! in_array ( $outputFormat , $formats)){
return false;
}
public function exportFeatures(
$path,
$outputFormat,
$typeName ,
$featureFilter
){
// $formats = $this->getFeatureFormats();
// if( ! in_array ( $outputFormat , $formats)){
// return false;
// }
$query = '<wfs:GetFeature service="WFS" outputFormat="'.$outputFormat.'" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" >';
$query .= ' <wfs:Query typeName="'.$typeName.'">';
$query .= ' <ogc:Filter>';
$query .= ' <ogc:And>';
$query = '<wfs:GetFeature service="WFS" outputFormat="'.$outputFormat.'" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" >';
$query .= ' <wfs:Query typeName="'.$typeName.'">';
$query .= ' <ogc:Filter>';
$query .= ' <ogc:And>';
foreach ($featureFilter as $key => $value ){
$query .= ' <ogc:PropertyIsEqualTo>';
$query .= ' <ogc:PropertyName>'.$key.'</ogc:PropertyName>';
$query .= ' <ogc:Literal>'.$value.'</ogc:Literal>';
$query .= ' </ogc:PropertyIsEqualTo>';
}
$query .= ' </ogc:And>';
$query .= ' </ogc:Filter>';
$query .= ' </wfs:Query>';
$query .= '</wfs:GetFeature>';
$headers = ['Expect:', 'Content-type: application/xml'];
$response = $this->browser->post(
$this->url_wfs,
$headers,
$query
);
if (!$response->isSuccessful()) {
return false;
foreach ($featureFilter as $propertyName=>$literal ){
if ( is_array( $literal ) ){
$query .= ' <ogc:Or>';
foreach ( $literal as $value ){
$query .= ' <ogc:PropertyIsEqualTo>';
$query .= ' <ogc:PropertyName>'.$propertyName.'</ogc:PropertyName>';
$query .= ' <ogc:Literal>'.$value.'</ogc:Literal>';
$query .= ' </ogc:PropertyIsEqualTo>';
}
$query .= ' </ogc:Or>';
}else{
$query .= ' <ogc:PropertyIsEqualTo>';
$query .= ' <ogc:PropertyName>'.$propertyName.'</ogc:PropertyName>';
$query .= ' <ogc:Literal>'.$literal.'</ogc:Literal>';
$query .= ' </ogc:PropertyIsEqualTo>';
}
}
$query .= ' </ogc:And>';
$query .= ' </ogc:Filter>';
$query .= ' </wfs:Query>';
$query .= '</wfs:GetFeature>';
$headers = ['Expect:', 'Content-type: application/xml'];
$response = $this->browser->post(
$this->url_wfs,
$headers,
$query
);
if ( ! $response->isSuccessful() ) {
return false;
}
$features = $response->getContent();
return $this->createFile ( $path, $features);
}
$features = $response->getContent();
return $this->createFile ( $path, $features);
}
/**
* Download Archive
*
......@@ -316,36 +345,54 @@ class Client {
* @param unknown $filename
*
*/
public function downloadArchive( $url , $path ){
echo $url.PHP_EOL;
$out = fopen($path, 'wb');
public function downloadFile( $url , $path ){
$out = fopen( $path , 'wb' );
$ch = curl_init();
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
curl_setopt($ch, CURLOPT_FILE, $out);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 1600 ); // 30 minutes
$result = curl_exec($ch);
if($result === false){
return false;
}
curl_close($ch);
return true;;
}
public function extractArchive ($archivePath , $filePath){
/**
*
* @param unknown $archivePath
* @param unknown $filePath
*/
public function extractArchive ( $archivePath , $filePath ){
$zip = new \ZipArchive;
$res = $zip->open($archivePath);
$res = $zip->open( $archivePath );
if ($res === true) {
if ( $res === true ){
$zip->extractTo($filePath);
$zip->close();
unlink ( $archivePath);
} else {
return false;
unlink ( $archivePath );
return true;
}
return false;
}
/**
*
* @param unknown $urlMetadata
*/
public function getMetadataContent($urlMetadata){
$headers = ['Expect:', 'Content-type: application/xml'];
......@@ -359,8 +406,6 @@ class Client {
}
return $response->getContent();
}
/**
......@@ -382,6 +427,7 @@ class Client {
return $updateSequenceElement->item(0)->getAttribute('updateSequence');
}
/**
* parseFeatureFormats
......@@ -477,6 +523,7 @@ class Client {
return $featureType;
}
public function setUrl($url_wfs){
$this->url_wfs = $url_wfs;
return $this;
......@@ -507,7 +554,6 @@ class Client {
}
$xmlDoc->save( $path );
return true;
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter