function crearImagenPoligono($x, $y, $zi, $mx, $my, $capa) { $factor = 366468.447793805 / $x; $img = imagecreatetruecolor($x, $y); $green = imagecolorallocatealpha($img, 52, 255, 27, 63); $fondo = imagecolorallocatealpha($img, 37, 89, 255, 28); $host = 'localhost'; $db = 'cursoGIS'; $usr = '******'; $pass = '******'; $strconn = "host={$host} port=5432 dbname={$db} user={$usr} password={$pass}"; $conn = pg_connect($strconn) or die("Error de Conexion con la base de datos"); //889283 $query1 = "SELECT gid, ndistrito, geom FROM {$capa}"; $result1 = pg_query($conn, $query1) or die("Error al ejecutar la consulta"); $pila = array(); $i = 0; $row1 = pg_fetch_all($result1); imagefilledrectangle($img, 0, 0, $x, $y, $fondo); foreach ($row1 as &$valor) { $geom = $valor["geom"]; //echo $geom; $query2 = "SELECT (st_x( (ST_DumpPoints(geom)).geom )-283585.639702539)/{$factor} as x,{$x}- ((st_y( (ST_DumpPoints(geom)).geom )-889378.554139937)/{$factor}) As y FROM ST_GeomFromText(st_astext('{$geom}')) as geom"; $result2 = pg_query($conn, $query2) or die("Error al ejecutar la consulta 2"); while ($row2 = pg_fetch_row($result2)) { $row2[0] = ajustar($row2[0], $zi, $x, $mx); $row2[1] = ajustar($row2[1], $zi, $y, $my); $pila[$i] = $row2[0]; $i++; $pila[$i] = $row2[1]; $i++; } imagefilledpolygon($img, $pila, count($pila) / 2, $green); unset($pila); $pila = array(); $i = 0; } /* $query = " SELECT gid, ndistrito, (st_x( (ST_DumpPoints(geom)).geom )-283585.639702539)/$factor as x,$x- ((st_y( (ST_DumpPoints(geom)).geom )-889378.554139937)/$factor) As y FROM $capa where ndistrito not in( '', 'NA' ,'SIN NOMBRE')"; $result = pg_query($conn, $query) or die("Error al ejecutar la consulta"); $pila = array(); $i = 0; $row = pg_fetch_row($result); $nombre = $row[1]; $nombreAnterior = $row[1]; while ($row = pg_fetch_row($result)) { $row[2] = ajustar($row[2], $zi, $x, $mx); $row[3] = ajustar($row[3], $zi, $y, $my); if ($nombreAnterior != $nombre) { imagefilledpolygon($img, $pila, count($pila) / 2, $green); $nombreAnterior = $row[1]; $i = 0; $pila = array(); } $nombre = $row[1]; $pila[$i] = $row[2]; $i++; $pila[$i] = ($row[3]); $i++; } */ return $img; }
/** * Funcion para dibujar las capas compuestas por líneas, este recibe un arreglo desde la consulta * y lo recorre, creando polígonos por cada registro. * @param type $x dimension en x * @param type $y dimension en y * @param type $zi cantidad de zoom * @param type $mx movimientos solicitados en x * @param type $my movimientos solicitados en y * @param type $capa nombre de la capa que solicita * @return type. */ function crearImagenPoligono($x, $y, $zi, $mx, $my, $capa, $conn) { $factor = 366468.447793805 / $x; $img = imagecreatetruecolor($x, $y); $green = imagecolorallocatealpha($img, 52, 255, 27, 63); $fondo = imagecolorallocatealpha($img, 37, 89, 255, 28); //889283 $query1 = "SELECT gid, ndistrito, geom FROM {$capa}"; $result1 = pg_query($conn, $query1) or die("Error al ejecutar la consulta"); $pila = array(); $i = 0; $row1 = pg_fetch_all($result1); imagefilledrectangle($img, 0, 0, $x, $y, $fondo); foreach ($row1 as &$valor) { $geom = $valor["geom"]; //echo $geom; $query2 = "SELECT (st_x( (ST_DumpPoints(geom)).geom )-283585.639702539)/{$factor} as x,{$x}- ((st_y( (ST_DumpPoints(geom)).geom )-889378.554139937)/{$factor}) As y FROM ST_GeomFromText(st_astext('{$geom}')) as geom"; $result2 = pg_query($conn, $query2) or die("Error al ejecutar la consulta 2"); while ($row2 = pg_fetch_row($result2)) { $row2[0] = ajustar($row2[0], $zi, $x, $mx); $row2[1] = ajustar($row2[1], $zi, $y, $my); $pila[$i] = $row2[0]; $i++; $pila[$i] = $row2[1]; $i++; } imagefilledpolygon($img, $pila, count($pila) / 2, $green); unset($pila); $pila = array(); $i = 0; } return $img; }