Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Chi Hoang  >  PHP Concave Hull  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example
Class: PHP Concave Hull
Find a concave shape that contains a set of points
Author: By
Last change: Example #3 not working
Date: 7 months ago
Size: 3,507 bytes
 

Contents

Class file image Download
<?php
/***************************************************************
* Copyright notice
*
* (c) 2010-2013 Chi Hoang (info@chihoang.de)
*  All rights reserved
*
***************************************************************/
require_once("concave-hull.php");

// Turn off all error reporting
error_reporting(0);

// example 1
$file fopen("star.dat""r");
$set=array();
while (!
feof($file))
{
    list(
$x,$y)=explode(" ",rtrim(fgets($file)));
    
$set[] = array(round($x),round($y));  
}
fclose($file);
$hull=new hull();
$hull->main($set,500,400);
$pic=new visualize("/tmp/",$hull);
$pic->genimage();

//example 2
$set=array();
$tree=array(162332,182299,141292,158264,141408,160400,177430,151442,155425,134430,126447,139466,160471,167447,182466,192442,187413,173,
            
403,168425,153413,179275,163292,134270,143315,177320,163311,162281,182255,141226,156235,173207,187230,204194,165189,145201,158,
            
167,190165,206145,179153,204114,221138,243112,248139,177122,17999,19682,219,90,24075,21861,22853,21134,19751,17965,15570,165,
            
85,13480,12458,15344,17334,19227,15619,11932,12817,13836,10058,11273,10092,78100,8378,6163,8044,10026,6039,4371,3454,32,
            
90,53104,6082,6699,24794,187180,221168);
for (
$i=0,$end=count($tree);$i<$end;$i+=2)
{
    
$set[]=array($tree[$i],$tree[$i+1]);    
}
$hull=new hull();
$hull->main($set,600,600);
$pic=new visualize("/tmp/",$hull);
$pic->genimage();

//example 3
$mapPadding  100;
$mapWidth    500;
$mapHeight   500;
$mapLonLeft  =1000;
$mapLatBottom=1000;
$mapLonRight =   0;
$mapLatTop   =   0;
$set=array();
$geocoord = array ("8.6544487,50.1005233",
                   
"8.7839489,50.0907496",
                   
"8.1004734,50.2002273",
                   
"8.4117234,50.0951493",
                   
"8.3508367,49.4765982",
                   
"9.1828630,48.7827027",
                   
"9.1686483,48.7686426",
                   
"9.2118466,48.7829101",
                   
"8.9670738,48.9456327");

foreach (
$geocoord as $key => $arr)
{
    list(
$lon,$lat) = explode(",",$arr);
    
$mapLonLeft min($mapLonLeft,$lon);
    
$mapLonRight max($mapLonRight,$lon);
    
$mapLatBottom min($mapLatBottom,$lat);
    
$mapLatTop max($mapLatTop,$lat);
    
$set[]=array($lon,$lat);
}

$mapLonDelta $mapLonRight-$mapLonLeft;
$mapLatDelta $mapLatTop-$mapLatBottom;

$mapLatTopY=$mapLatTop*(M_PI/180);
$worldMapWidth=(($mapWidth/$mapLonDelta)*360)/(2*M_PI);
$LatBottomSin=min(max(sin($mapLatBottom*(M_PI/180)),-0.9999),0.9999);
$mapOffsetY=$worldMapWidth/log((1+$LatBottomSin)/(1-$LatBottomSin));
$LatTopSin=min(max(sin($mapLatTop*(M_PI/180)),-0.9999),0.9999);
$mapOffsetTopY=$worldMapWidth/log((1+$LatTopSin)/(1-$LatTopSin));
$mapHeightD=$mapOffsetTopY-$mapOffsetY;
$mapRatioH=$mapHeight/$mapHeightD;
$newWidth=$mapWidth*($mapHeightD/$mapHeight);
$mapRatioW=$mapWidth/$newWidth;

foreach (
$set as $key => $arr)
{
    list(
$lon,$lat) = $arr;
    
$tx = ($lon $mapLonLeft) * ($newWidth/$mapLonDelta)*$mapRatioW;
    
$f sin($lat*M_PI/180);
    
$ty = ($mapHeightD-(($worldMapWidth/log((1+$f)/(1-$f)))-$mapOffsetY));
    
$proj[]=array($tx,$ty);
}


$hull=new hull();
$hull->main($proj,$mapWidth,$mapHeightD);
 
$pic=new visualize("/tmp/",$hull);
$pic->genimage();

?>