function adicionaTemaIMG($arq) { if (file_exists($arq)) { $layer = criaLayer($this->mapa, MS_LAYER_RASTER, MS_DEFAULT, basename($arq), "SIM"); $layer->set("data", $arq); $layer->set("name", basename($arq)); $layer->setmetadata("DOWNLOAD", "nao"); $layer->setmetadata("TEMALOCAL", "NAO"); } return "ok"; }
function insereFeature($marca, $tipo, $xy, $texto, $position, $partials, $offsetx, $offsety, $minfeaturesize, $mindistance, $force, $shadowcolor, $shadowsizex, $shadowsizey, $outlinecolor, $cor, $sombray, $sombrax, $sombra, $fundo, $angulo, $tamanho, $fonte, $wrap, $wkt = false, $nomeTema = "") { //verifica se ja existe um layer criado anteriormente com o mesmo nome e apaga se existir if ($tipo == "limpaponto") { if ($this->layer) { $this->layer->set("status", MS_DELETE); $this->layer->set("name", "pindelete"); $tipo = "POINT"; } } if (!$this->layer) { $pinlayer = criaLayer($this->mapa, MS_LAYER_LINE, MS_DEFAULT, "Ins", $metaClasse = "SIM"); $c = $pinlayer->getclass(0); $c->set("name", ""); $e = $c->getstyle(0); $e->set("size", 1); $e->set("symbol", "ponto"); $core = $e->color; $core->setrgb(255, 0, 0); if (!isset($cor)) { $cor = "255 0 0"; } switch ($tipo) { case "GRAFICOPIZZA": if (!isset($tamanho)) { $tamanho = 5; } $e->set("size", $tamanho); $pinlayer->setmetadata("tema", "Pontos inseridos"); $pinlayer->set("type", MS_LAYER_POINT); break; case "POINT": if (!isset($marca) || $marca == "") { $marca = "marca"; } if (!isset($tamanho)) { $tamanho = 5; } $e->set("size", $tamanho); $e->set("symbolname", $marca); corE($e, $cor, "color"); $pinlayer->setmetadata("tema", "Pontos inseridos"); $pinlayer->set("type", MS_LAYER_POINT); break; case "LINE": if (!isset($marca) || $marca == "") { $marca = "linha"; } if (!isset($tamanho)) { $tamanho = 2; } $e->set("size", $tamanho); $e->set("symbol", $marca); if (isset($cor) && $cor != "") { corE($e, $cor, "color"); } if (isset($texto) && $texto != "") { $pinlayer->setmetadata("TEMA", $texto); } else { $pinlayer->setmetadata("tema", "Linhas inseridas"); } $pinlayer->set("type", MS_LAYER_LINE); break; case "POLYGON": if (!isset($marca)) { $marca = "p9"; } if (!isset($tamanho)) { $tamanho = 5; } $e->set("size", $tamanho); $e->set("symbol", $marca); $pinlayer->setmetadata("tema", "Poligonos inseridos"); $pinlayer->set("type", MS_LAYER_POLYGON); $pinlayer->set("opacity", "50"); break; case "ANNOTATION": //$c->set("status",MS_DELETE); $pinlayer->setmetadata("TEMA", $texto); $pinlayer->setmetadata("tiles", "nao"); $pinlayer->set("type", MS_LAYER_POINT); $pinlayer->set("opacity", "100"); break; } } switch ($tipo) { case "ANNOTATION": $shp = ms_newshapeobj(MS_SHAPE_POINT); break; case "POINT": $shp = ms_newshapeobj(MS_SHAPE_POINT); break; case "LINE": $shp = ms_newshapeobj(MS_SHAPE_LINE); break; case "POLYGON": $shp = ms_newshapeobj(MS_SHAPE_POLYGON); break; } if ($wkt == false) { $apt = explode(" ", $xy); $lin = ms_newlineobj(); for ($i = 0; $i < count($apt); $i = $i + 2) { $lin->addxy($apt[$i], $apt[$i + 1]); } $shp->add($lin); } else { $shp = ms_shapeObjFromWkt($xy); } if ($texto != "") { $texto = str_replace("*", "&", $texto); $texto = str_replace("|", ";", $texto); $shp->set("text", $texto); //caso nao seja do tipo annotation if ($pinlayer->numclasses == 1) { $novac = $pinlayer->getclass(0); } else { $novac = ms_newclassobj($pinlayer); } $this->adicionaLabel($novac, $wrap, $fonte, $tamanho, $angulo, $fundo, $sombra, $cor, $outlinecolor, $shadowcolor, $shadowsizex, $shadowsizey, $force, $mindistance, $minfeaturesize, $offsetx, $offsety, $partials, $position, ""); } $pinlayer->addfeature($shp); if ($nomeTema != "") { $pinlayer->setmetadata("tema", $nomeTema); } //verifica a projecao $c = $shp->getCentroid(); $c = $c->x; if ($c > -181 && $c < 181) { $pinlayer->setprojection(pegaProjecaoDefault("proj4")); } else { $pinlayer->setprojection($this->mapa->getProjection()); } return "ok"; }
function incmapageometrias($dir_tmp, $imgdir, $lista, $tipoLista = "stringArquivos") { $dir = $dir_tmp . "/" . $imgdir . "/"; $tituloTema = " geometria"; if ($tipoLista == "stringArquivos") { $lista = explode(",", $lista); $shapes = array(); $valoresoriginais = array(); foreach ($lista as $l) { $geos = $this->unserializeGeo($dir . $l); // pega todas as geometrias foreach ($geos["dados"] as $geo) { // echo $geo["wkt"]."<br>"; $shapes[] = ms_shapeObjFromWkt(str_replace("'", "", $geo["wkt"])); foreach ($geo["valores"] as $v) { $valorestemp[] = $v["item"] . "=" . $v["valor"]; } $valoresoriginais[] = implode(" ", $valorestemp); } } } if ($tipoLista == "arraywkt") { $shapes = array(); $valoresoriginais = array(); foreach ($lista as $l) { $shapes[] = ms_shapeObjFromWkt($l); } } if ($tipoLista == "marcadores") { $shapes = array(); $valoresoriginais = array(); foreach ($lista as $l) { $valoresoriginais[] = $l["nome"]; $p = explode(" ", $l["ext"]); $l = "POLYGON ((" . $p[0] . " " . $p[1] . "," . $p[0] . " " . $p[3] . "," . $p[2] . " " . $p[3] . "," . $p[2] . " " . $p[1] . "," . $p[0] . " " . $p[1] . "))"; $shapes[] = ms_shapeObjFromWkt($l); } $tituloTema = " marcadores"; } // verifica o tipo if (count($shapes) == 0) { return "erro."; } $tiposhape = $shapes[0]->type; $tiposhapefile = MS_SHP_POLYGON; if ($tiposhape == 0) { $tiposhapefile = MS_SHP_MULTIPOINT; } if ($tiposhape == 1) { $tiposhapefile = MS_SHP_ARC; } // cria o shapefile if ($this->dbaseExiste == false) { include_once dirname(__FILE__) . "/../pacotes/phpxbase/api_conversion.php"; } $diretorio = dirname($this->arquivo); $novonomelayer = nomeRandomico(); $nomeshp = $diretorio . "/" . $novonomelayer; $l = criaLayer($this->mapa, $tiposhape, MS_DEFAULT, "Ins", "SIM"); $novoshpf = ms_newShapefileObj($nomeshp, $tiposhapefile); $def[] = array("ID", "C", "250"); if ($this->dbaseExiste == false) { $db = xbase_create($nomeshp . ".dbf", $def); xbase_close($db); } else { $db = dbase_create($nomeshp . ".dbf", $def); dbase_close($db); } // acrescenta os pontos no novo shapefile $dbname = $nomeshp . ".dbf"; if ($this->dbaseExiste == false) { $db = xbase_open($dbname, 2); } else { $db = dbase_open($dbname, 2); } $conta = 0; foreach ($shapes as $s) { $reg = array(); $reg[] = $valoresoriginais[$conta]; if ($this->dbaseExiste == false) { xbase_add_record($db, $reg); } else { dbase_add_record($db, $reg); } $novoshpf->addshape($s); $conta = $conta + 1; } if ($this->dbaseExiste == false) { xbase_close($db); } else { dbase_close($db); } $l->set("opacity", 80); $l->setmetadata("tema", $novonomelayer . $tituloTema); $l->setmetadata("TEMALOCAL", "SIM"); $l->setmetadata("DOWNLOAD", "sim"); $l->set("data", $nomeshp); $l->set("name", $novonomelayer); $classe = $l->getclass(0); $estilo = $classe->getstyle(0); if ($tiposhape == 0) { $estilo->set("symbolname", "ponto"); $estilo->set("size", 6); } $cor = $estilo->color; $cor->setrgb(255, 210, 0); $cor = $estilo->outlinecolor; $cor->setrgb(255, 0, 0); $this->salva(); return $novonomelayer; }
function selecao2tema($locaplic, $dir_tmp) { if (!$this->layer) { return "erro"; } $this->layer->setfilter(""); $nomeshp = criaSHP($this->nome, $this->arquivo, $locaplic, $dir_tmp, true, "", false); $novolayer = criaLayer($this->mapa, $this->layer->type, MS_DEFAULT, "Seleção de " . pegaNome($this->layer) . " (" . $this->nome . ")", $metaClasse = "SIM"); if ($this->layer->getprojection() != "") { $novolayer->setprojection($this->layer->getprojection()); } $novolayer->set("data", $nomeshp . ".shp"); $novolayer->set("name", basename($nomeshp)); $down = "nao"; $down = $this->layer->getmetadata("download"); if ($down == "") { $down = "sim"; } $novolayer->setmetadata("DOWNLOAD", $down); $tipo = $this->layer->type; if ($this->layer->getmetadata("TABELA") != '') { $novolayer->setmetadata("TABELA", "NAO"); } $novolayer->setmetadata("TEMALOCAL", "SIM"); $novolayer->setfilter(""); return "ok"; }
function shpPT2shp($locaplic, $para) { if (!$this->layer) { return "erro"; } $this->layer->set("template", "none.htm"); $diretorio = dirname($this->arquivo); $tipol = MS_SHP_ARC; $tipos = MS_SHAPE_LINE; if ($para == "poligono") { $tipol = MS_SHP_POLYGON; $tipos = MS_SHAPE_POLYGON; } $novonomelayer = nomeRandomico(); $nomeshp = $diretorio . "/" . $novonomelayer; $items = pegaItens($this->layer); // cria o dbf $def = array(); foreach ($items as $ni) { $temp = strtoupper($ni); $def[] = array($temp, "C", "254"); } //para manipular dbf if ($this->dbaseExiste == false) { include_once dirname(__FILE__) . "/../pacotes/phpxbase/api_conversion.php"; $db = xbase_create($nomeshp . ".dbf", $def); } else { $db = dbase_create($nomeshp . ".dbf", $def); } $dbname = $nomeshp . ".dbf"; $reg = array(); $novoshpf = ms_newShapefileObj($nomeshp . ".shp", $tipol); $this->layer->open(); $prjMapa = $this->mapa->getProjection(); $prjTema = $this->layer->getProjection(); $ret = $this->mapa->extent; if ($prjTema != "" && $prjMapa != $prjTema) { $projOutObj = ms_newprojectionobj($prjTema); $projInObj = ms_newprojectionobj($prjMapa); $ret->project($projInObj, $projOutObj); } $this->layer->whichShapes($ret); $linha = ms_newLineObj(); $pponto = ""; $pontos = array(); while ($shape = $this->layer->nextShape()) { $lin = $shape->line(0); $pt = $lin->point(0); if ($pponto == "") { $pponto = $pt; } if ($prjTema != "" && $prjMapa != $prjTema) { $pt->project($projInObj, $projOutObj); } $pontos[] = $pt->x; $pontos[] = $pt->y; } $pontos = implode(" ", $pontos); $pontos = xy2wkt($pontos); if ($para == "poligono") { $shape = ms_shapeObjFromWkt($pontos["poligono"]); } else { $shape = ms_shapeObjFromWkt($pontos["linha"]); } foreach ($items as $ni) { $reg[] = "-"; } $novoshpf->addShape($shape); if ($this->dbaseExiste == false) { xbase_add_record($db, $reg); xbase_close($db); } else { dbase_add_record($db, $reg); dbase_close($db); } $this->layer->close(); //cria o novo layer $layer = criaLayer($this->mapa, MS_LAYER_LINE, MS_DEFAULT, "", $metaClasse = "SIM"); $layer->set("data", $nomeshp); $layer->setmetadata("tema", $novonomelayer . " (linear)"); $layer->setmetadata("download", "sim"); $layer->setmetadata("temalocal", "sim"); $classe = $layer->getclass(0); $estilo = $classe->getstyle(0); $estilo->set("symbolname", "linha"); if ($para == "poligono") { $layer->set("type", MS_LAYER_POLYGON); $layer->set("opacity", "50"); $layer->setmetadata("tema", $novonomelayer . " (poligonal)"); } return "ok"; }