Home

KML Convertor To MySQL Script

CREATE a Db in Mysql with this statement

CREATE TABLE tablename (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
boundary VARCHAR(9000) NOT NULL,
zipcode VARCHAR(6) NOT NULL)

Then Connect this script to your DataBase!


<html>
<body>
<?php
$db_host = ''; // hostname
$db_name = ''; // databasename
$db_user = ''; // username
$user_pw = ''; // password
//THIS CAN CONVERT CENSUS DATA
$con = new PDO('mysql:host='.$db_host.'; dbname='.$db_name, $db_user, $user_pw);
$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$completeurl = "map.xml";
$xml = simplexml_load_file($completeurl);
$placemarks = $xml->Document->Folder->Placemark;
for ($i = 0; $i < count($placemarks); $i++) { $coordinates = $placemarks[$i]->ExtendedData->SchemaData->SimpleData[2][0];
$cor_d = $placemarks[$i]->Polygon->outerBoundaryIs->LinearRing->coordinates;
$cor_d = json_encode($cor_d);
$sql = "INSERT INTO tablename (zipcode, boundary) VALUES (?,?)";
$q = $con->prepare($sql);
$q->execute(array($coordinates ,$cor_d));
echo $i;
}
?>
</body>
</html>

Written by | Milo Thompson

With 5 years of complex coding and implementation experience to go along with Networking Solutions I have Created many Different Software for Many different Platforms. I am the Owner of Jimnio.com, Former Developer for Magnaflow, San Francisco Health Plan, Eburgeon, Software Master, Wendal Wilson Business and Technology Consulting, S&S Tire

Google+ linkedin

1 Comment

  1. admin

    October 4, 2016 at 5:21 AM

    Coolness

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll To Top