Skip to main content
added 16 characters in body
Source Link
Ruthe
  • 137
  • 4

optional. this is function php for change exist layer style in geoserver v2.3.0.

I solved it by folowing function notice that $params it have to put "<enabled>true</enabled>" for enable layer after chang style in geoserver.

function change_layer_style($url_layer,$style_name) {
    $params = '<layer><defaultStyle><name>'.$style_name.'</name></defaultStyle><enabled>true</enabled></layer>';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url_layer);
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($ch, CURLOPT_USERPWD,"user:password"); //geoserver.
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Receive server response ...


    $response = curl_exec($ch);

    curl_close ($ch);
    return $response;
    

}

//--> how to use.


   //--> 1. config your geoserver url.
    $your_workspace = "xxx";"workspace_name";
    $your_layer_name = = "bbb";"layer_name";

    $url_layer = "http://xxxx.co.uk:8080/geoserver/rest/layers/".$your_workspace.":".$your_layer_name;
    $style_name ="your_exist_style_name";

    //--> call above function.
    change_layer_style($url_layer,$style_name);

optional. this is function php for change exist layer style in geoserver v2.3.0.

I solved it by folowing function notice that $params it have to put "<enabled>true</enabled>" for enable layer after chang style in geoserver.

function change_layer_style($url_layer,$style_name) {
    $params = '<layer><defaultStyle><name>'.$style_name.'</name></defaultStyle><enabled>true</enabled></layer>';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url_layer);
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($ch, CURLOPT_USERPWD,"user:password"); //geoserver.
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Receive server response ...


    $response = curl_exec($ch);

    curl_close ($ch);
    return $response;
    

}

//--> how to use.


   //--> 1. config your geoserver url.
    $your_workspace = "xxx";
    $your_layer_name = = "bbb";

    $url_layer = "http://xxxx.co.uk:8080/geoserver/rest/layers/".$your_workspace.":".$your_layer_name;
    $style_name ="your_exist_style_name";

    //--> call above function.
    change_layer_style($url_layer,$style_name);

optional. this is function php for change exist layer style in geoserver v2.3.0.

I solved it by folowing function notice that $params it have to put "<enabled>true</enabled>" for enable layer after chang style in geoserver.

function change_layer_style($url_layer,$style_name) {
    $params = '<layer><defaultStyle><name>'.$style_name.'</name></defaultStyle><enabled>true</enabled></layer>';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url_layer);
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($ch, CURLOPT_USERPWD,"user:password"); //geoserver.
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Receive server response ...


    $response = curl_exec($ch);

    curl_close ($ch);
    return $response;
    

}

//--> how to use.


   //--> 1. config your geoserver url.
    $your_workspace = "workspace_name";
    $your_layer_name = "layer_name";

    $url_layer = "http://xxxx.co.uk:8080/geoserver/rest/layers/".$your_workspace.":".$your_layer_name;
    $style_name ="your_exist_style_name";

    //--> call above function.
    change_layer_style($url_layer,$style_name);
added 181 characters in body
Source Link
Ruthe
  • 137
  • 4

optional. this is function php for change exist layer style in geoserver v2.3.0.

I solved it by folowing function notice that $params it have to put "<enabled>true</enabled>" for enable layer after chang style in geoserver.

function change_layer_style($url_layer,$style_name) {
    $params = '<layer><defaultStyle><name>'.$style_name.'</name></defaultStyle><enabled>true</enabled></layer>';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url_layer);
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($ch, CURLOPT_USERPWD,"user:password"); //geoserver.
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Receive server response ...


    $response = curl_exec($ch);

    curl_close ($ch);
    return $response;
    

}

//--> how to use.


   //--> 1. config your geoserver url.
    $your_workspace = "xxx";
    $your_layer_name = = "bbb";

    $url_layer = "http://xxxx.co.uk:8080/geoserver/rest/layers/".$your_workspace.":".$your_layer_name;
    $style_name ="your_exist_style_name";

    //--> call above function.
    change_layer_style($url_layer,$style_name);

optional. this is function php for change exist layer style in geoserver v2.3.0.

function change_layer_style($url_layer,$style_name) {
    $params = '<layer><defaultStyle><name>'.$style_name.'</name></defaultStyle><enabled>true</enabled></layer>';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url_layer);
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($ch, CURLOPT_USERPWD,"user:password"); //geoserver.
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Receive server response ...


    $response = curl_exec($ch);

    curl_close ($ch);
    return $response;
    

}

//--> how to use.


   //--> 1. config your geoserver url.
    $your_workspace = "xxx";
    $your_layer_name = = "bbb";

    $url_layer = "http://xxxx.co.uk:8080/geoserver/rest/layers/".$your_workspace.":".$your_layer_name;
    $style_name ="your_exist_style_name";

    //--> call above function.
    change_layer_style($url_layer,$style_name);

optional. this is function php for change exist layer style in geoserver v2.3.0.

I solved it by folowing function notice that $params it have to put "<enabled>true</enabled>" for enable layer after chang style in geoserver.

function change_layer_style($url_layer,$style_name) {
    $params = '<layer><defaultStyle><name>'.$style_name.'</name></defaultStyle><enabled>true</enabled></layer>';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url_layer);
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($ch, CURLOPT_USERPWD,"user:password"); //geoserver.
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Receive server response ...


    $response = curl_exec($ch);

    curl_close ($ch);
    return $response;
    

}

//--> how to use.


   //--> 1. config your geoserver url.
    $your_workspace = "xxx";
    $your_layer_name = = "bbb";

    $url_layer = "http://xxxx.co.uk:8080/geoserver/rest/layers/".$your_workspace.":".$your_layer_name;
    $style_name ="your_exist_style_name";

    //--> call above function.
    change_layer_style($url_layer,$style_name);
added 181 characters in body
Source Link
Ruthe
  • 137
  • 4

optional. this is function php for another searchchange exist layer style in geoserver v2.3.0.

function change_layer_style($url_layer,$style_name) {
    $params = '<layer><defaultStyle><name>'.$style_name.'</name></defaultStyle><enabled>true</enabled></layer>';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url_layer);
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($ch, CURLOPT_USERPWD,"user:password"); //geoserver.
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Receive server response ...


    $response = curl_exec($ch);

    curl_close ($ch);
    return $response;
    
    
}

//--> how to use.
  

   //--> 1. config your geoserver url.
    $your_workspace = "xxx";
    $your_layer_name = = "bbb";

    $url_layer = "http://xxxx.co.uk:8080/geoserver/rest/layers/your_workspace".$your_workspace.":your_layer_name";".$your_layer_name;
    //$style_name ="your_exist_style_name"; 

    //--> call above function.
    change_layer_style($url_layer,$style_name);
}

for another search.

function change_layer_style($url_layer,$style_name) {
    $params = '<layer><defaultStyle><name>'.$style_name.'</name></defaultStyle><enabled>true</enabled></layer>';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url_layer);
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($ch, CURLOPT_USERPWD,"user:password"); //geoserver.
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Receive server response ...


    $response = curl_exec($ch);

    curl_close ($ch);
    return $response;
    
    //--> how to use.
    //$url_layer = "http://xxxx.co.uk:8080/geoserver/rest/layers/your_workspace:your_layer_name";
    //$style_name ="your_exist_style_name";
    //change_layer_style($url_layer,$style_name);
}

optional. this is function php for change exist layer style in geoserver v2.3.0.

function change_layer_style($url_layer,$style_name) {
    $params = '<layer><defaultStyle><name>'.$style_name.'</name></defaultStyle><enabled>true</enabled></layer>';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url_layer);
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt($ch, CURLOPT_USERPWD,"user:password"); //geoserver.
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Receive server response ...


    $response = curl_exec($ch);

    curl_close ($ch);
    return $response;
    

}

//--> how to use.
 

   //--> 1. config your geoserver url.
    $your_workspace = "xxx";
    $your_layer_name = = "bbb";

    $url_layer = "http://xxxx.co.uk:8080/geoserver/rest/layers/".$your_workspace.":".$your_layer_name;
    $style_name ="your_exist_style_name"; 

    //--> call above function.
    change_layer_style($url_layer,$style_name);
Notice added Needs detailed answers by PolyGeo
Source Link
Ruthe
  • 137
  • 4
Loading