Last active
March 31, 2018 20:18
-
-
Save wilxsv/206bc282cec9b6528e6035219e807304 to your computer and use it in GitHub Desktop.
bajar peso a geojson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$servername = ""; | |
$username = ""; | |
$password = ""; | |
$dbname = ""; | |
// Crea conexion | |
$conn = new mysqli($servername, $username, $password, $dbname); | |
if ($conn->connect_error) { | |
die("Connection failed: " . $conn->connect_error); | |
} | |
lista_entidad( $conn, "tabla", "geojson"); | |
$conn->close(); | |
/* | |
Crea un archivo geojson por cada entidad que se le envie | |
*/ | |
function crea_json( $file, $tabla, $contenido){ | |
$myfile = fopen($file, "w") or die("Unable to open file!"); | |
fwrite($myfile, '{ "type": "MultiPolygon", "coordinates": [[['.$contenido.']]]}'); | |
fclose($myfile); | |
} | |
/* | |
Recorre la tabla por cada entidad | |
*/ | |
function lista_entidad( $conn, $tabla, $campo){ | |
$sql = "SELECT * FROM $tabla"; | |
$result = $conn->query($sql); | |
if ($result->num_rows > 0) { | |
while($row = $result->fetch_assoc()) { | |
crea_json( $row["id"].".json", "", $row[$campo] ); | |
} | |
} else { | |
echo "0 results"; | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "">departamentos.sql | |
for entry in *.json | |
do | |
out=$entry"_o.json" | |
echo ".bin/geojson-precision -p 7 $entry geojson/$entry" | bash | |
done | |
for entry in geojson/*.json | |
do | |
json="$(cat $entry)" | |
id="${entry##*/}" | |
id="${id%.*}" | |
echo " UPDATE tabla SET geojson_7 = '$json' WHERE id = $id; ">>departamentos.sql | |
done | |
mysql -u USER -pPASSWORD BASE < departamentos.sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment