Beispiel #1
0
 function adicionaTemaGeoRSS($servico, $dir_tmp, $locaplic, $canal)
 {
     $xml = simplexml_load_file($servico);
     $conta = 0;
     foreach ($xml->channel as $c) {
         if ($conta == $canal) {
             $canal = $c;
         }
     }
     $nos = $canal->item;
     //verifica se o canal faz referencia a elementos externos
     //se sim, usa todos os elementos do xml no lugar do canal
     foreach ($canal->items as $t) {
         foreach ($t->xpath('rdf:Seq') as $x) {
             foreach ($x->xpath('rdf:li') as $z) {
                 $nos = $xml->item;
             }
         }
     }
     $resultado = array();
     $tipog = "";
     foreach ($nos as $item) {
         $env = array();
         //define o tipo
         if ($item->xpath('geo:lat')) {
             $tipog = "geo";
         }
         if ($item->xpath('georss:point')) {
             $tipog = "georsspoint";
         }
         if ($item->xpath('georss:where')) {
             $tipog = "envelope";
         }
         if ($tipog == "envelope") {
             foreach ($item->xpath('georss:where') as $w) {
                 foreach ($w->xpath('gml:Envelope') as $e) {
                     //$lc = $e->xpath('gml:lowerCorner');
                     $lc = (string) $e->children('gml', TRUE)->lowerCorner;
                     //$uc = $e->xpath('gml:upperCorner');
                     $uc = (string) $e->children('gml', TRUE)->upperCorner;
                     $lc = explode(" ", $lc);
                     $uc = explode(" ", $uc);
                     if (is_numeric($lc[0])) {
                         $ymin = $lc[0];
                         $ymax = $uc[0];
                         $xmin = $lc[1];
                         $xmax = $uc[1];
                         if ($ymin != "") {
                             $env = array($xmin, $ymin, $xmax, $ymax);
                         }
                     }
                 }
             }
         }
         if ($tipog == "geo") {
             if ($item->xpath('geo:lon')) {
                 $x = (string) $item->children('geo', TRUE)->lon;
             } else {
                 $x = (string) $item->children('geo', TRUE)->long;
             }
             //$y = $item->xpath('geo:lat');
             $y = (string) $item->children('geo', TRUE)->lat;
             $env = array($y, $x);
         }
         if ($tipog == "georsspoint") {
             //$temp = $item->xpath('georss:point');
             $temp = (string) $item->children('georss', TRUE)->point;
             $env = explode(" ", $temp);
         }
         if (count($env) > 0) {
             $resultado[] = array(ixml($item, "title"), ixml($item, "link"), ixml($item, "description"), ixml($item, "category"), $env);
         }
     }
     //cria o shapefile com os dados
     if (count($resultado) > 0) {
         //para manipular dbf
         include_once dirname(__FILE__) . "/../pacotes/phpxbase/api_conversion.php";
         $diretorio = dirname($this->arquivo);
         $tipol = MS_SHP_POLYGON;
         if ($tipog == "georsspoint") {
             $tipol = MS_SHP_POINT;
         }
         if ($tipog == "geo") {
             $tipol = MS_SHP_POINT;
         }
         $novonomelayer = nomeRandomico(10) . "georss";
         $nomeshp = $diretorio . "/" . $novonomelayer;
         $novoshpf = ms_newShapefileObj($nomeshp, $tipol);
         $def[] = array("TITULO", "C", "254");
         $def[] = array("LINK", "C", "254");
         $def[] = array("DESC", "C", "254");
         $def[] = array("CATEGORIA", "C", "254");
         if (!function_exists(dbase_create)) {
             $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";
         $db = xbase_open($dbname, 2);
         $reg = array();
         $novoshpf = ms_newShapefileObj($nomeshp . ".shp", -2);
         //acrescenta os shapes
         foreach ($resultado as $r) {
             $pts = $r[4];
             if ($tipol == MS_SHP_POLYGON) {
                 $shp = ms_newShapeObj(MS_SHP_POLYGON);
                 $linha = ms_newLineObj();
                 $linha->addXY($pts[0], $pts[3]);
                 $linha->addXY($pts[2], $pts[3]);
                 $linha->addXY($pts[2], $pts[1]);
                 $linha->addXY($pts[0], $pts[1]);
                 $linha->addXY($pts[0], $pts[3]);
             } else {
                 $shp = ms_newShapeObj(MS_SHP_POINT);
                 $linha = ms_newLineObj();
                 $linha->addXY($pts[1], $pts[0]);
             }
             $shp->add($linha);
             $novoshpf->addShape($shp);
             $reg = array($r[0], $r[1], $r[2], $r[3]);
             xbase_add_record($db, $reg);
             $reg = array();
         }
         xbase_close($db);
         if ($tipog == "georsspoint" || $tipog == "geo") {
             $tipol = MS_LAYER_POINT;
         } else {
             $tipol = MS_LAYER_POLYGON;
         }
         $layer = criaLayer($this->mapa, $tipol, MS_DEFAULT, "GeoRSS", "SIM");
         $layer->set("data", $nomeshp . ".shp");
         $layer->set("name", basename($nomeshp));
         $layer->setmetadata("DOWNLOAD", "sim");
         $layer->setmetadata("TEMALOCAL", "SIM");
         //evita problemas no modo tile
         if ($this->v > 5) {
             $layer->setprocessing("LABEL_NO_CLIP=True");
             $layer->setprocessing("POLYLINE_NO_CLIP=True");
         }
         if ($tipol == MS_LAYER_POLYGON) {
             $classe = $layer->getclass(0);
             $estilo = $classe->getstyle(0);
             $estilo->set("symbolname", "p4");
             $estilo->set("size", 5);
             $cor = $estilo->color;
             $cor->setrgb(255, 0, 0);
             $coro = $estilo->outlinecolor;
             $coro->setrgb(255, 0, 0);
         }
         //$layer->set("transparency",50);
         $layer->setmetadata("nomeoriginal", basename($nomeshp));
         //echo $tipol;
         return "ok";
     }
     return "erro";
 }
Beispiel #2
0
dbase_close($di);
xbase_close($xi);
$di = dbase_open("test/dbase.dbf", 2);
$xi = xbase_open("test/xbase.dbf", 2);
echo "dbase<br>";
echo "index = {$di} <br>";
echo "<br>";
echo "xbase<br>";
echo "index = {$xi} <br>";
echo "header info: ";
print_r(xbase_get_header_info($xi));
dbase_close($di);
xbase_close($xi);
echo "<br><br>";
$di = dbase_open("test/xbase.dbf", 0);
$xi = xbase_open("test/dbase.dbf", 0);
echo "dbase<br>";
echo "index = {$di} <br>";
echo "column count = " . dbase_numfields($di) . " <br>";
echo "record count = " . dbase_numrecords($di) . " <br>";
echo "<table>";
for ($i = 0; $i < dbase_numrecords($di); $i++) {
    echo "<tr>";
    $r = dbase_get_record_with_names($di, $i + 1);
    foreach ($r as $c => $v) {
        echo "<td> {$c}={$v} </td>";
    }
    echo "</tr>";
}
echo "</table>";
echo "<br>";
Beispiel #3
0
function inserePoligonosUrl()
{
    global $tamanhosimbolo, $simbolo, $corsimbolo, $poligonos, $nometemapoligonos, $dir_tmp, $imgdir, $tmpfname, $locaplic;
    include_once "pacotes/phpxbase/api_conversion.php";
    if (!isset($nometemapoligonos)) {
        $nometemapoligonos = "Poligonos";
    }
    if ($nometemapoligonos == "") {
        $nometemapoligonos = "Poligonos";
    }
    //
    //cria o shape file
    //
    $tipol = MS_SHP_POLYGON;
    $nomeshp = $dir_tmp . "/" . $imgdir . "/poligonosins";
    // cria o dbf
    $def = array();
    $items = array("COORD");
    foreach ($items as $ni) {
        $def[] = array($ni, "C", "254");
    }
    if (!function_exists(dbase_create)) {
        xbase_create($nomeshp . ".dbf", $def);
    } else {
        dbase_create($nomeshp . ".dbf", $def);
    }
    $dbname = $nomeshp . ".dbf";
    $db = xbase_open($dbname, 2);
    $novoshpf = ms_newShapefileObj($nomeshp, $tipol);
    $linhas = explode(",", trim($poligonos));
    $pontosLinhas = array();
    //guarda os pontos de cada linha em arrays
    foreach ($linhas as $l) {
        $tempPTs = explode(" ", trim($l));
        $temp = array();
        foreach ($tempPTs as $p) {
            if (is_numeric($p)) {
                $temp[] = $p;
            }
        }
        $pontosLinhas[] = $temp;
    }
    foreach ($pontosLinhas as $ptsl) {
        $linhas = $ptsl;
        $shape = ms_newShapeObj($tipol);
        $linha = ms_newLineObj();
        $reg = array();
        $reg[] = "";
        for ($ci = 0; $ci < count($linhas); $ci = $ci + 2) {
            $linha->addXY($linhas[$ci], $linhas[$ci + 1]);
        }
        $shape->add($linha);
        $novoshpf->addShape($shape);
        xbase_add_record($db, $reg);
    }
    $novoshpf->free();
    xbase_close($db);
    //adiciona o layer
    $mapa = ms_newMapObj($tmpfname);
    $layer = ms_newLayerObj($mapa);
    $layer->set("name", "linhains");
    $layer->set("data", $nomeshp . ".shp");
    $layer->setmetadata("DOWNLOAD", "sim");
    $layer->setmetadata("temalocal", "sim");
    $layer->setmetadata("tema", $nometemapoligonos);
    $layer->setmetadata("classe", "sim");
    $layer->setmetadata("ATLAS", "nao");
    $layer->set("type", MS_LAYER_POLYGON);
    $layer->set("opacity", "50");
    $layer->set("status", MS_DEFAULT);
    $classe = ms_newClassObj($layer);
    $classe->set("name", " ");
    $estilo = ms_newStyleObj($classe);
    $cor = $estilo->color;
    if (!isset($corsimbolo)) {
        $corsimbolo = "255,0,0";
    }
    $corsimbolo = str_replace(" ", ",", $corsimbolo);
    $corsimbolo = explode(",", $corsimbolo);
    $cor->setRGB($corsimbolo[0], $corsimbolo[1], $corsimbolo[2]);
    $salvo = $mapa->save($tmpfname);
    erroCriacao();
}
function dbase_open($filename, $mode = 0)
{
    return xbase_open($filename, $mode);
}
Beispiel #5
0
function verificaDBF($arq)
{
    if (function_exists("dbase_open")) {
        $db = dbase_open($arq, 0);
    } else {
        include_once dirname(__FILE__) . "/../pacotes/phpxbase/api_conversion.php";
        $db = xbase_open($arq, 0);
    }
    //nas vers&otilde;es novas do PHP open retorna vazio, n&atilde;o d&aacute; pra verificar
    //if ($db) {
    if (function_exists("dbase_numrecords")) {
        $record_numbers = dbase_numrecords($db);
        dbase_close($db);
    } else {
        $record_numbers = xbase_numrecords($db);
        xbase_close($db);
    }
    if ($record_numbers > 0) {
        return true;
    } else {
        return false;
    }
    //}
    //else {return false;}
}
Beispiel #6
0
 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;
 }
Beispiel #7
0
 function insereSHP($xy, $projecao, $item = "", $valor = "")
 {
     if (!$this->layer) {
         return "erro";
     }
     if ($this->dbaseExiste == false) {
         include_once dirname(__FILE__) . "/../pacotes/phpxbase/api_conversion.php";
     }
     $xy = explode(" ", $xy);
     $data = $this->layer->data;
     $data = explode(".shp", $data);
     $data = $data[0];
     $items = pegaItens($this->layer);
     $dbname = $data . ".dbf";
     if ($this->dbaseExiste == false) {
         $db = xbase_open($dbname, 2);
     } else {
         $db = dbase_open($dbname, 2);
     }
     for ($i = 0; $i < count($xy) / 2; ++$i) {
         $reg = array();
         foreach ($items as $ni) {
             //verifica se deve acrescentar o valor para um item, caso tenha sido definido
             if ($ni == $item) {
                 $reg[] = $valor;
             } else {
                 $reg[] = "-";
             }
         }
         if ($this->dbaseExiste == false) {
             xbase_add_record($db, $reg);
         } else {
             dbase_add_record($db, $reg);
         }
     }
     if ($this->dbaseExiste == false) {
         xbase_close($db);
     } else {
         dbase_close($db);
     }
     if (@($shapefileObj = ms_newShapefileObj($data, -2))) {
         for ($i = 0; $i < count($xy); $i = $i + 2) {
             $poPoint = ms_newpointobj();
             $poPoint->setXY($xy[$i], $xy[$i + 1]);
             if ($projecao != "") {
                 //$projOutObj = ms_newprojectionobj("proj=longlat,ellps=WGS84,datum=WGS84,no_defs");
                 $pmap = pegaProjecaoDefault("proj4");
                 $projOutObj = ms_newprojectionobj($pmap);
                 $projInObj = ms_newprojectionobj("init=epsg:" . $projecao);
                 $poPoint->project($projInObj, $projOutObj);
             }
             $shapefileObj->addpoint($poPoint);
         }
         return "ok";
     } else {
         return "erro";
     }
 }
Beispiel #8
0
 $novoshpf->free();
 if (!file_exists($nomeshp)) {
     echo "<p class='paragrafo'>Erro ao criar arquivo shapefile</p>";
     paraAguarde();
 }
 $shapefileObj = ms_newShapefileObj($nomeshp, -2);
 if ($i3GEOuploaddbftipoarquivo != "dbf") {
     foreach ($csv->data as $d) {
         $poPoint = ms_newpointobj();
         $poPoint->setXY($d[$i3GEOuploaddbfnomex], $d[$i3GEOuploaddbfnomey]);
         $shapefileObj->addpoint($poPoint);
     }
 } else {
     require_once dirname(__FILE__) . "/../../pacotes/phpxbase/api_conversion.php";
     echo "<p class='paragrafo'>Lendo arquivo </p>";
     $dbf = xbase_open($dirmap . "/" . $nome . ".dbf");
     $records = xbase_numrecords($dbf);
     echo "<p class='paragrafo'>Numero de pontos: {$records}</p>";
     ob_flush();
     flush();
     sleep(1);
     $record = array();
     for ($x = 1; $x <= $records; $x++) {
         $record = xbase_get_record_with_names($dbf, $x);
         $poPoint = ms_newpointobj();
         $poPoint->setXY($record[$nomex], $record[$nomey]);
         $shapefileObj->addpoint($poPoint);
     }
 }
 $shapefileObj->free();
 $novolayer = ms_newLayerObj($mapa);