Esempio n. 1
0
function toGeoJSON($resultFileURI)
{
    $doc = new DOMDocument();
    /*
     * Load error => return an empty GeoJSON
     */
    if (@$doc->load($resultFileURI) === false) {
        $geojson = array('type' => 'FeatureCollection', 'features' => array());
        return json_encode($geojson);
    }
    $entries = $doc->getElementsByTagname('entry');
    /*
     * No SearchResult => return an empty GeoJSON
     */
    if ($entries->item(0) == null) {
        /*
         * GeoJSON
         */
        $geojson = array('type' => 'FeatureCollection', 'features' => array());
        return json_encode($geojson);
    }
    /*
     * GeoJSON
     */
    $geojson = array('type' => 'FeatureCollection', 'features' => array());
    foreach ($entries as $entry) {
        /**
         * Add feature
         */
        $feature = array('type' => 'Feature', 'geometry' => pointToGeoJSONGeometry($entry->getElementsByTagname('lng')->item(0)->nodeValue, $entry->getElementsByTagname('lat')->item(0)->nodeValue), 'properties' => array('name' => $entry->getElementsByTagname('title')->item(0)->nodeValue, 'description' => $entry->getElementsByTagname('summary')->item(0)->nodeValue, 'url' => $entry->getElementsByTagname('wikipediaUrl')->item(0)->nodeValue, 'img_url' => $entry->getElementsByTagname('thumbnailImg')->item(0)->nodeValue));
        // Add feature array to feature collection array
        array_push($geojson['features'], $feature);
    }
    return json_encode($geojson);
}
Esempio n. 2
0
 *              "woeid":"2379855",
 *              "geo_is_family":0,
 *              "geo_is_friend":0,
 *              "geo_is_contact":0,
 *              "geo_is_public":1,
 *              "url_s":"http:\/\/farm6.static.flickr.com\/5150\/5637250714_88c6b1347e_m.jpg",
 *              "url_l":"http:\/\/farm6.static.flickr.com\/5150\/5637250714_88c6b1347e_b.jpg",
 *              "height_s":"188",
 *              "width_s":"240",
 *              "url_sq":"http:\/\/farm6.static.flickr.com\/5150\/5637250714_88c6b1347e_sq.jpg",
 *              "height_sq":"78",
 *              "width_sq":"100"
 *         },
 *         ...etc...
 *         ]
 *     }
 * })
 *
 */
$photos = $json->photos->photo;
$length = count($photos);
for ($i = 0; $i < $length; $i++) {
    $row = $photos[$i];
    /*
     * Add feature
     */
    $feature = array('type' => 'Feature', 'geometry' => pointToGeoJSONGeometry($row->longitude, $row->latitude), 'properties' => array('identifier' => $row->id, 'name' => $row->title, 'owner' => $row->owner, 'thumbnail' => $row->url_s, 'quicklook' => $row->url_l, 'icon' => $row->url_sq, 'tags' => $row->tags, 'description' => $row->description->_content));
    // Add feature array to feature collection array
    array_push($geojson['features'], $feature);
}
echo json_encode($geojson);
Esempio n. 3
0
function xmlToGeoJSON($theData)
{
    $doc = new DOMDocument();
    $doc->loadXML($theData);
    /*
     * Initialiaze GeoJSON
     */
    $geojson = array('type' => 'FeatureCollection', 'totalResults' => 0, 'features' => array());
    /*
     * Number of objects returned
     */
    $disasters = $doc->getElementsByTagname('disaster');
    if ($disasters->item(0) == null) {
        return json_encode($geojson);
    }
    $count = 0;
    /*
     * Process all RegistryPackages
     */
    foreach ($disasters as $disaster) {
        // Get longitude and latitude coordinates
        $lonlat = explode(" ", $disaster->getElementsByTagname('pos')->item(0)->nodeValue);
        /*
         * Automatic correction of incorrect disasters
         * 
         * Possible values
         *  EARTHQUAKE
         *  FLOOD
         *  FIRE
         *  ICE
         *  LANDSLIDE
         *  OCEAN_STORM (CYCLONE, HURRICANE, TYPHOON)
         *  OIL_SPILL
         *  OCEAN_WAVE (TSUNAMI)
         *  VOLCANIC_ERUPTION
         *  OTHER (INDUSTRIAL_ACCIDENT, WIND_STORM, TORNADO...)
         * 
         */
        $title = $disaster->getElementsByTagname('title')->item(0)->nodeValue;
        $type = $disaster->getElementsByTagname('type')->item(0)->nodeValue;
        if ($type == "OTHER") {
            /*
             * Check for disaster type within title
             * Hypothesis is that disaster type is the first word within the title
             */
            $words = explode(' ', $title);
            foreach ($words as $word) {
                $word = strtolower(str_replace(",", "", trim($word)));
                if (in_array($word, array('flood', 'flooding', 'floods'))) {
                    $type = 'FLOOD';
                    break;
                } else {
                    if (in_array($word, array('ocean', 'tsunami', 'huricane', 'hurricane-force'))) {
                        $type = 'CYCLONE';
                        break;
                    } else {
                        if (in_array($word, array('landslide', 'landslides'))) {
                            $type = 'LANDSLIDE';
                            break;
                        } else {
                            if (in_array($word, array('earthquake'))) {
                                $type = 'EARTHQUAKE';
                                break;
                            }
                        }
                    }
                }
                /*
                                else if (in_array($first, ['snow','ice'])) {
                                    $type = '';
                                    break;
                                }
                                else if (in_array($first, ['debris'])) {
                                    $type = '';
                                    break;
                                }*/
            }
        }
        /*
         * Add feature array to feature collection array
         */
        array_push($geojson['features'], array('type' => 'Feature', 'geometry' => pointToGeoJSONGeometry(floatval($lonlat[1]), floatval($lonlat[0])), 'properties' => array('title' => $title, 'date' => $disaster->getElementsByTagname('date')->item(0)->nodeValue, 'call-id' => $disaster->getElementsByTagname('call-id')->item(0)->nodeValue, 'type' => $type, 'description' => $disaster->getElementsByTagname('description')->item(0)->nodeValue, 'link' => $disaster->getElementsByTagname('link')->item(0)->nodeValue)));
        $count++;
    }
    // Update totalResults
    $geojson["totalResults"] = $count;
    return json_encode($geojson);
}
Esempio n. 4
0
    if ($result != null) {
        $ra = $result->getElementsByTagname('ra')->item(0)->nodeValue;
        $dec = $result->getElementsByTagname('dec')->item(0)->nodeValue;
        /*
         * Only exploitable results are processed
         */
        if ($ra && $dec) {
            /*
             * Galactic to Equatorial coordinates transformation
             */
            $pos = array($ra, $dec);
            if ($r === "e") {
                /* Important : see geometry.php */
                $pos = spheric2proj($pos);
            } else {
                /* Important : see geometry.php */
                $pos = spheric2proj(eq2gal(array($ra, $dec)));
            }
            /*
             * Add feature
             */
            $feature = array('type' => 'Feature', 'geometry' => pointToGeoJSONGeometry($pos[0], $pos[1]), 'properties' => array('name' => $result->getElementsByTagname('target')->item(0)->nodeValue, 'ra' => $ra, 'dec' => $dec, 'coordsys' => $result->getElementsByTagname('coordsys')->item(0)->nodeValue, 'time' => $result->getElementsByTagname('time')->item(0)->nodeValue, 'quicklook' => 'http://alasky.u-strasbg.fr/cgi/portal/aladin/get-preview-img.py?pos=' . $ra . ',' . ($dec >= 0 ? '+' . $dec : $dec)));
            // Add feature array to feature collection array
            array_push($geojson['features'], $feature);
        }
    }
} else {
    $geojson = array('error' => array('message' => "Error : Name Resolver service is not available"));
}
/* Returns encoded geojson string */
echo json_encode($geojson);
Esempio n. 5
0
 *   "fcode":"PPL",
 *   "geonameId":3003874,
 *   "lat":43.60028402353632,
 *   "adminName1":"Midi-Pyrénées",
 *   "population":6976},
 *  {"countryName":"France",
 *   (...etc...)
 *  }]}
 */
$json = json_decode(getRemoteData($url, null, false));
$geojson = array('type' => 'FeatureCollection', 'features' => array());
/*
 * Problem reading json => return an empty GeoJSON
 */
if ($json == NULL) {
    echo json_encode($geojson);
    exit(0);
}
/*
 *
 */
foreach ($json->geonames as $row) {
    /*
     * Add feature
     */
    $feature = array('type' => 'Feature', 'geometry' => pointToGeoJSONGeometry($row->lng, $row->lat), 'properties' => array('name' => $row->name, 'countryName' => $row->countryName, 'population' => $row->population));
    // Add feature array to feature collection array
    array_push($geojson['features'], $feature);
}
/* Returns encoded geojson string */
echo json_encode($geojson);
Esempio n. 6
0
function toGeoJSON($resultFileURI)
{
    $doc = new DOMDocument();
    /*
     * Load error => return an empty GeoJSON
     */
    if (@$doc->load($resultFileURI) === false) {
        $geojson = array('type' => 'FeatureCollection', 'features' => array());
        return json_encode($geojson);
    }
    $entries = $doc->getElementsByTagname('entry');
    /*
     * No SearchResult => return an empty GeoJSON
     */
    if ($entries->item(0) == null) {
        $geojson = array('type' => 'FeatureCollection', 'features' => array());
        return json_encode($geojson);
    }
    /*
     * GeoJSON
     */
    $geojson = array('type' => 'FeatureCollection', 'features' => array());
    foreach ($entries as $entry) {
        $pos = $entry->getElementsByTagName('pos')->item(0)->nodeValue;
        if ($pos) {
            /**
             * Order of $coord = lat,lon
             */
            $coords = explode(" ", $pos);
            /**
             * Add feature
             */
            $feature = array('type' => 'Feature', 'geometry' => pointToGeoJSONGeometry($coords[1], $coords[0]), 'properties' => array('name' => $entry->getElementsByTagName('title')->item(0)->nodeValue, 'description' => $entry->getElementsByTagName('description')->item(0)->nodeValue, 'url' => $entry->getElementsByTagName('player')->item(0)->getAttribute('url'), 'thumbnail' => $entry->getElementsByTagName('thumbnail')->item(0)->getAttribute('url')));
            // Add feature array to feature collection array
            array_push($geojson['features'], $feature);
        }
    }
    return json_encode($geojson);
}