コード例 #1
0
ファイル: ms_criamapa.php プロジェクト: edmarmoretti/i3geo
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();
}
コード例 #2
0
ファイル: classe_mapa.php プロジェクト: edmarmoretti/i3geo
 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";
 }
コード例 #3
0
function dbase_close($dbase_identifier)
{
    return xbase_close($dbase_identifier);
}
コード例 #4
0
ファイル: test_api.php プロジェクト: abbeet/server39
echo "xbase<br>";
echo "index = {$xi} <br>";
echo "column count = " . xbase_numfields($xi) . " <br>";
echo "record count = " . xbase_numrecords($xi) . " <br>";
echo "<table>";
for ($i = 0; $i < xbase_numrecords($xi); $i++) {
    echo "<tr>";
    $r = xbase_get_record_with_names($xi, $i + 1);
    foreach ($r as $c => $v) {
        echo "<td> {$c}={$v} </td>";
    }
    echo "</tr>";
}
echo "</table>";
dbase_close($di);
xbase_close($xi);
echo "<br><br>";
$table =& new XBaseTable("test/dbase.dbf");
$table->open();
echo "name: " . $table->name . "<br />";
echo "version: " . $table->version . "<br />";
echo "foxpro: " . ($table->foxpro ? "yes" : "no") . "<br />";
echo "modifyDate: " . date("r", $table->modifyDate) . "<br />";
echo "recordCount: " . $table->recordCount . "<br />";
echo "headerLength: " . $table->headerLength . "<br />";
echo "recordByteLength: " . $table->recordByteLength . "<br />";
echo "inTransaction: " . ($table->inTransaction ? "yes" : "no") . "<br />";
echo "encrypted: " . ($table->encrypted ? "yes" : "no") . "<br />";
echo "mdxFlag: " . ord($table->mdxFlag) . "<br />";
echo "languageCode: " . ord($table->languageCode) . "<br />";
echo $table->toHTML();
コード例 #5
0
ファイル: funcoes_gerais.php プロジェクト: edmarmoretti/i3geo
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;}
}
コード例 #6
0
ファイル: classe_analise.php プロジェクト: edmarmoretti/i3geo
 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;
 }
コード例 #7
0
 /**
  * Converte um tipo de regiao em shapefile
  * @param codigo do tipo de regiao
  * @return nome do arquivo criado
  */
 function regiao2shp($codigo_tipo_regiao)
 {
     $regiao = $this->listaTipoRegiao($codigo_tipo_regiao);
     $dados = $this->obtemDadosTabelaDB($regiao["codigo_estat_conexao"], $regiao["esquemadb"], $regiao["tabela"], "sim");
     $tipol = $this->listaPropGeoRegiao($codigo_tipo_regiao);
     include_once dirname(__FILE__) . "/../../classesphp/classe_shp.php";
     $s = new SHP();
     //st_dimension returns 0 for POINT, 1 for LINESTRING, 2 for POLYGON
     //echo MS_SHP_POINT.", ".MS_SHP_ARC.", ".MS_SHP_POLYGON.", ".MS_SHP_MULTIPOINT;
     //1, 3, 5, 8
     $conv[0] = 1;
     $conv[1] = 3;
     $conv[2] = 5;
     //cria as colunas
     $cni = 0;
     foreach ($dados["colunas"] as $t) {
         $temp = strtoupper($t["field"]);
         if (strlen($temp) > 10) {
             $temp = substr($temp, 0, 8) . $cni++;
         }
         if ($t["type"] == "varchar" || $t["type"] == "char" || $t["type"] == "character varying" || $t["type"] == "character" || $t["type"] == "text") {
             $def[] = array($temp, "C", "254");
         } else {
             if ($t["lengthvar"] < 0) {
                 $t["lengthvar"] = 0;
             }
             $def[] = array($temp, "N", $t["length"], $t["lengthvar"]);
         }
     }
     $nomeshp = $this->dir_tmp . "/regiao{$codigo_tipo_regiao}" . "_" . $this->nomeRandomico();
     $dbaseExiste = false;
     if (function_exists("dbase_create")) {
         $dbaseExiste = true;
     }
     //para manipular dbf
     if ($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", $conv[$tipol["st_dimension"]]);
     $cols = $dados["colunas"];
     $nc = count($dados["colunas"]);
     foreach ($dados["linhas"] as $l) {
         $reg = array();
         for ($i = 0; $i < $nc; $i++) {
             if ($cols[$i]["type"] != "geometry" && $cols[$i]["type"] != "geography") {
                 $reg[] = $l[$i];
             } else {
                 $reg[] = 0;
                 if ($cols[$i]["field"] == $regiao["colunageo"]) {
                     $shape = ms_shapeObjFromWkt($l[$i]);
                 }
             }
         }
         $novoshpf->addShape($shape);
         if ($dbaseExiste == false) {
             xbase_add_record($db, $reg);
         } else {
             dbase_add_record($db, $reg);
         }
     }
     if ($this->dbaseExiste == false) {
         xbase_close($db);
     } else {
         dbase_close($db);
     }
     return $nomeshp;
 }
コード例 #8
0
ファイル: classe_shp.php プロジェクト: edmarmoretti/i3geo
 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";
 }
コード例 #9
0
ファイル: upload.php プロジェクト: edmarmoretti/i3geo
         }
     }
     if (!function_exists("dbase_create")) {
         xbase_create($dirmap . "/" . $nome . ".dbf", $def);
     } else {
         dbase_create($dirmap . "/" . $nome . ".dbf", $def);
     }
     $db = xbase_open($dirmap . "/" . $nome . ".dbf", 2);
     foreach ($csv->data as $d) {
         $reg = array();
         foreach ($d as $i) {
             $reg[] = $i;
         }
         xbase_add_record($db, $reg);
     }
     xbase_close($db);
 } else {
     copy($dirmap . "/" . $ArquivoDest, $dirmap . "/" . $nome . ".dbf");
 }
 echo "<p class='paragrafo'>Arquivo enviado. Criando shape file... </p>";
 ob_flush();
 flush();
 sleep(1);
 $novoshpf = ms_newShapefileObj($nomeshp, MS_SHP_POINT);
 $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") {