width = $w; } function setImageHeight($h) { $this->height = $h; } function setLineThickness($t) { $this->lineThickness = $t; } function setLineColor($c) { $this->lineColor = $c; } function setTextColor($c) { $this->textColor = $c; } function setBBox($gmlIndex, $b) { $this->bbox[$gmlIndex] = explode(",", $b); } function gml() { $this->cnt_gml = -1; $this->linethickness = 1; } function addGmlList($gmlString, $separator) { $gmlArray = explode($separator, $gmlString); $this->addGml($gmlArray); } function addGml($gmlArray){ for ($i=0; $icnt_gml++; $this->gml[$this->cnt_gml] = $gmlArray[$i]; #parseBbox will calculate a bbox that delivers #some output for testing. #uncomment the following line if there is no bbox #and you want to test png output #otherwise, you have to set a bbox with setBbox #$this->parseBbox($i, $gmlArray[$i]); $this->geomColl[$this->cnt_gml] = new geomColl(); $this->parseGml($i); } } function getBBox($i) { return $this->bbox[$i]; } function getGml($i) { return $this->gml[$i]; } function getAllGeomColl(){ return $this->geomColl; } function getGeomColl($gmlIndex){ return $this->geomColl[$gmlIndex]; } function parseGml($index){ $data = str_replace("&", "&", $this->gml[$index]); $this->tagList = array_merge($this->multi, $this->pointSingle, $this->lineSingle, $this->polygonSingle); $parser = xml_parser_create(); xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0); xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1); xml_parser_set_option($parser,XML_OPTION_TARGET_ENCODING,CHARSET); xml_parse_into_struct($parser,$data,$values,$tags); $code = xml_get_error_code ($parser); if ($code) { $line = xml_get_current_line_number($parser); $mb_exception = new mb_exception(xml_error_string($code) . " in line " . $line); } xml_parser_free($parser); $item = -1; $cnt_el = 1; $geom = false; $foundGeom = false; $typeset=false; $member=false; foreach ($values as $element) { if(strtoupper($element['tag']) == strtoupper("gml:featureMember") && $element['type'] == "open"){ $member = true; } if (in_array(strtoupper($element['tag']),$this->tagList) && $element['type'] == "open" && $member==true && $geom==false && $typeset==false) { $this->geomColl[$index]->addGeometryMember($element['tag']); $typeset=true; } if(in_array(strtoupper($element['tag']),$this->pointSingle) && $element['type'] == "open" && $typeset==true){ $foundGeom = true; $geom = true; $this->geomColl[$index]->addPoint(); } if(in_array(strtoupper($element['tag']),$this->lineSingle) && $element['type'] == "open" && $typeset==true){ $foundGeom = true; $geom = true; $this->geomColl[$index]->addLine(); } if(in_array(strtoupper($element['tag']),$this->polygonSingle) && $element['type'] == "open" && $typeset==true){ $foundGeom = true; $geom = true; $this->geomColl[$index]->addPolygon(); } if(strtoupper($element['tag']) == strtoupper("gml:coordinates") && $geom == true){ $myGeom = $this->prepareCoordinates($element['value']); $coord = explode(",",$myGeom); for($i=0;$igeomColl[$index]->addCoordinates($coordinates); } } if(strtoupper($element['tag']) == strtoupper("label")){ $this->geomColl[$index]->addLabel($element['value']); } if ($foundGeom == true && $geom == false && substr($element['tag'], 0, 4) != "gml:" && isset($element['value'])) { $this->geomColl[$index]->addAttribute($element['tag'], $element['value']); } if((in_array(strtoupper($element['tag']),$this->pointSingle) || in_array(strtoupper($element['tag']),$this->lineSingle) || in_array(strtoupper($element['tag']),$this->polygonSingle)) && $element['type'] == "close"){ $geom = false; } if(strtoupper($element['tag']) == strtoupper("gml:featureMember") && $element['type'] == "close"){ $member = false; $foundGeom = false; $typeset=false; } } } // if there is no bbox given by setbbox, this funtion finds lowest and highest x- & y-coordinates // and sets the bbox according to these values // if found it very useful for testing the png output, but now it may be obsolete function parseBbox($gmlIndex, $gml){ $data = str_replace("&", "&", $gml); $parser = xml_parser_create(); xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0); xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1); xml_parse_into_struct($parser,$data,$values,$tags); $code = xml_get_error_code ($parser); if ($code) { $line = xml_get_current_line_number($parser); $mb_exception = new mb_exception(xml_error_string($code) . " in line " . $line); } xml_parser_free($parser); $boundingbox = false; $cnt_member = false; $min_x = ""; $min_y = ""; $max_x = ""; $max_y = ""; foreach ($values as $element) { if(strtoupper($element['tag']) == strtoupper("gml:featureMember") && $element['type'] == "open"){ $cnt_member=true; } if((in_array(strtoupper($element['tag']),$this->pointSingle) || in_array(strtoupper($element['tag']),$this->lineSingle) || in_array(strtoupper($element['tag']),$this->polygonSingle)) && $element['type'] == "open"){ $boundingbox=true; } if(strtoupper($element['tag']) == strtoupper("gml:coordinates") && $boundingbox == true){ $myGeom = $this->prepareCoordinates($element['value']); $coord = explode(",",$myGeom); for($i=0;$i $max_x || !$max_x) { $max_x = $coord[$i]; } if ($coord[$i+1] < $min_y || !$min_y) { $min_y = $coord[$i+1]; } if ($coord[$i+1] > $max_y || !$max_y) { $max_y = $coord[$i+1]; } } } if((in_array(strtoupper($element['tag']),$this->pointSingle) || in_array(strtoupper($element['tag']),$this->lineSingle) || in_array(strtoupper($element['tag']),$this->polygonSingle)) && $element['type'] == "close"){ $boundingbox = false; } if(strtoupper($element['tag']) == strtoupper("gml:featureMember") && $element['type'] == "close"){ $cnt_member=false; } } $this->bbox[$gmlIndex][0] = $min_x; $this->bbox[$gmlIndex][1] = $min_y; $this->bbox[$gmlIndex][2] = $max_x; $this->bbox[$gmlIndex][3] = $max_y; } function prepareCoordinates($strCoords){ $ret = preg_replace("/\s/i", ",", trim($strCoords)); return $ret; } function png ($gmlIndex, $label){ $image = imagecreate($this->width,$this->height); $transparent = ImageColorAllocate($image,255,255,255); ImageFilledRectangle($image,0,0,$this->width,$this->height,$transparent); ImageColorTransparent ($image , $transparent); $line = imagecolorallocate($image, $this->lineColor[0], $this->lineColor[1], $this->lineColor[2]); if($this->lineColor != $this->textColor){ $text = imagecolorallocate($image, $this->textColor[0], $this->textColor[1], $this->textColor[2]); } else{ $text = $line; } imagesetthickness($image, $this->lineThickness); $image = $this->geomColl[$gmlIndex]->addToPng($image, $this->bbox[$gmlIndex], $this->width, $this->height, $line, $text, $label); return $image; } function gml2JavaObj($gmlIndex) { $javaObjStr = ""; $javaObjStr .= $this->geomColl[$gmlIndex]->getJavaObjStr($this->bbox[$gmlIndex], $this->width, $this->height); return $javaObjStr; } } #so far, this class has only been tested with gmls generated by UMN map server #load gml files like this #$data[0] = implode("", file("fluesse.xml")); #$data[1] = implode("", file("staedte.xml")); #$data[2] = implode("", file("plz.xml")); #initiate gml object like this #$D = new gml(); #$D->parseGml(); #you can add gml objects by passing a string of gmls... #$separator = "___"; #$list = $data[0] . $separator . $data[1] . $separator . $data[2]; #$D->addGmlList($list, $separator); # .. or alternatively by passing an array of gmls #$D->addGml($data); #print_r($D->getBBox(0)); # you have to set a bbox for each gml # if no bbox is set, png output will not work #$D->setBBox(0, "3399409.885263,5566197.180021,3410613.307859,5573006.265254"); #you can set the parameters for graphical output like this #$D->setImageWidth(640); #$D->setImageHeight(480); #$D->setLineThickness(1); #$D->setLineColor(array(125, 40, 25)); #retrieve all geometries of all gmls like this #$data = $D->getAllGeomColl(); #this is the way to get a single feature member #$data = $D->getGeomColl(2)->getMember(3)->getGeomObj(2); #if you want the data structure of a single gml, try this #$data = $D->getGeomColl(1); #this is how the data structure looks like (view source) #print_r($data); # if your gmls have points, you can add labels # from the attributes of the gml for png output #$data = $D->getGeomColl(2); #$member = $data->getMember(0); #$keys = $member->getAllAttributeKeys(); #header("Content-type: image/png"); #imagepng($D->png(2, $keys[3])); #alternatively, you can display the png without labels #imagepng($D->png(0, "")); #imagepng($D->png(1, "")); #check the subclasses for further documentation ?>