# create a connection to the database instance on localhost. If you # have not done anything 'clever' the username 'system' will work # with the passWord that you defined at installation $conn=oci_connect('username','password', "http://127.0.0.1/XE");
# Query our address table $sql = "SELECT name, address1, city, state, zip from address";
# oci_parse is part of the Oracle PHP library to parse the SQL statement $stmt = oci_parse($conn, $sql);
# oci_execute not surprisingly executes the statement we parsed in the previous line oci_execute($stmt);
# This loads the associative array $row with the values of each row in our # database in turn while ( $row = oci_fetch_assoc($stmt) ) { # print_r dumps a variable, including all of the keys for an associative array print_r($row); # assemble the query variable for our call to geocoder.us $address = $row["ADDRESS1"] . "," . $row["CITY"] . "," . $row["STATE"] . " " . $row["ZIP"]; # pull the name out of the associative array $name = $row["NAME"]; # the url to the free service of geocoder.us to return the data in CSV format $url = "http://rpc.geocoder.us/service/csv?address=" . (urlencode($address)); # open the url $w = fopen($url,"r"); #parse the CSV returned from the page into the array $result $result = fgetcsv($w,8000); fclose($w);
# query to update the address table with the lat/long we got from geocoder.us # granted it is poor database design to have sUCh an uncertain key as 'name' # be our primary key…I'll leave it as an exercise to the reader to implement # this code in a way that doesn't make DBA's cry. $sqlu = "update address set =$latitude, =$longitude where NAME='$name'"; echo "sqlu $sqlu/n"; # as before, parse the SQL statement $stmtu = oci_parse($conn, $sqlu); # and execute the statement oci_execute($stmtu); } ?>
無需幫手的三維地圖
所有努力都是為了向您提供包含空間數(shù)據(jù)的數(shù)據(jù)庫。現(xiàn)在,您可以清楚地了解客戶所在的位置!利用該信息,您可以完成很多事情,例如,分析市場,計劃宣傳活動、銷售路線以及送貨路線,但首當(dāng)其沖的是我們要在地圖上看到這些數(shù)據(jù)。兩年以前,在地圖上顯示數(shù)據(jù)十分困難,您必須使用昂貴且專業(yè)的工具,或使用學(xué)習(xí)起來異常困難的復(fù)雜工具。幸運的是,這一切都成為了過去。 Google Earth 是一個適用于 Windows 和 Mac 的桌面應(yīng)用程序,其用途不僅限于地圖,還提供了一個 3D 世界模型。在城鎮(zhèn)數(shù)量不斷增加的今日,它還包括了多個 3D 建筑物輪廓。您還可以使用 Google Sketch Up 將自己的 3D 模型添加到顯示中。 Google Earth 可從 http://earth.google.com 獲得。這是一個免費版本,但對于 Google Earth Plus,您每年需支付 20 美元,對于 Google Earth Pro,您每年需支付 400 美元。付費版本增加了諸如全球定位系統(tǒng) (GPS) 集成之類的功能。(單擊此處了解各個版本的不同之處。)網(wǎng)站說明非常簡單,請立即下載使用吧!剛開始,您會看到一個從太空視角拍攝的地球視圖。然后,可將視圖放大來搜索位置、探索世界,就像 Lewis 和 Clark(當(dāng)今探險軍團的成員)一樣。 活躍的 Google Earth 社區(qū)會發(fā)布一些空間信息文件。例如,單擊此處閱讀并下載有關(guān) Lewis 和 Clark 探險之旅的 Google Earth 文件:29917-lewis_and_clark_eXPedition.kmz。您會注重到,Google Earth 文件的擴展名為 KML(即 Keyhole 標記語言,Google Earth 在以前稱為 Keyhole)或 KMZ(通過 gzip 壓縮的 Keyhole 標記語言)。KMZ 文件可通過 WinZip 或 Stuffit Expander 進行解壓縮。 我喜歡我的 GUI,除非要嘗試進行腳本編寫,因此從 OSX 終端命令行,您可以輸入以下命令:gunzip -S ".kmz" 29917-lewis_and_clark_expedition.kmz 打開該文件后,您將發(fā)現(xiàn)它只不過是一個 xml 文件。好吧,或許并不是十分簡單,但易于閱讀。請深入閱讀 Google Earth KML 文檔! 例如,以下是描述 Camp Disappointment 的地標。<Placemark> <description><![CDATA[ <a > Click to read entry</a>]]></description> <name>17: Camp Disappointment</name> <LookAt> <longitude>-112.820632</longitude> <latitude>48.716670</latitude> <range>1000.000</range> <tilt>0</tilt> <heading>0</heading> </LookAt> <styleUrl>root://styles#khStyle929</styleUrl> <Point> <coordinates>-112.820632,48.716670,0</coordinates> </Point> </Placemark> 當(dāng)您調(diào)出 Lewis and Clark 文件后,您將看到 Google Earth 是如何呈現(xiàn)該 Camp Disappointment 描述的。 <name> 元素以點元素的 <coordinates> 元素中指定的 X, Y, Z 坐標形式顯示在地圖上(經(jīng)度 = X,緯度 = Y,海拔 = Z,在本例中為 0)。單擊該點時,會彈出一個描述球,其中顯示了名稱和描述元素的內(nèi)容,以及到此處去或從此點出發(fā)的選項。 請非凡注重,描述可以包含 URL。因此,假如該地標描述了您的一個客戶,那么就可以在調(diào)出中包含有關(guān)該客戶的其他屬性,然后在您的 CRM 系統(tǒng)中嵌入一個指向客戶頁面的鏈接。 <styleURL> 元素包含一個指向標記該位置的“圖釘”URL 的鏈接。在本例中,該樣式包含在本地文件系統(tǒng)上。樣式描述還可以包含在 KML 文檔內(nèi)或外部 URL 中。 最后,看一下 <LookAt> 元素。雙擊地標,您會到達 <LookAt> 元素中指定的經(jīng)度和緯度,并看到由 <heading>、<tilt> 以及 <range> 元素描述的視圖點。這答應(yīng)您在指定視圖點的地方創(chuàng)建地標。例如,以下是一個完整的 KML 文件,其內(nèi)容為“前往舊金山的 Crissy Field 觀賞金門大橋”:<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://earth.google.com/kml/2.0"> <Placemark> <name>crissy field</name> <LookAt> <longitude>-122.4592370657115</longitude> <latitude>37.8050682478946</latitude> <altitude>0</altitude> <range>1000.275193579794</range> <tilt>90</tilt> <heading>315</heading> </LookAt> <styleUrl>root://styles#default</styleUrl> <Point> <coordinates>-122.4592370657115,37.8050682478946,0</coordinates> </Point> </Placemark> </kml> 為了簡單起見,您可以除去其中一些屬性。以下是這兩個明確地點的最簡單、有用的 KML 描述: <?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://earth.google.com/kml/2.0"> <Folder> <Placemark> <name>First Place</name> <Point> <coordinates>-122.5,37.8,0</coordinates> </Point> </Placemark> <Placemark> <name>Random Place</name> <Point> <coordinates>-122.6,37.9,0</coordinates> </Point> </Placemark> </Folder> </kml> 以下是抓取地理編碼地址并生成 KML 文件的 PHP 程序:<?PHP
$conn=oci_connect('username','password', "http://127.0.0.1/XE"); $sql = "SELECT name, address1, city, state, zip, latitude, longitude from address a"; $stmt = oci_parse($conn, $sql); oci_execute($stmt);