Last active
May 21, 2017 20:03
-
-
Save smzn/2bf7712ac74feb3b3a2b958af4a48ee6 to your computer and use it in GitHub Desktop.
import
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
public function import(){ | |
APP::import('Model','Boundary'); | |
$this->Boundary = new Boundary; | |
if($this->request->is('post')){ | |
$up_file = $this->data['Zone']['XmlFile']['tmp_name']; | |
$fileName = 'post.xml'; | |
if(is_uploaded_file($up_file)){ | |
move_uploaded_file($up_file, $fileName); | |
$xmlArray = Xml::toArray(Xml::build($fileName)); | |
foreach($xmlArray['Dataset']['ksj:SecondMedicalArea'] as $line){//2次医療圏の情報を入れる | |
$data = array( | |
'id' => $line['ksj:secondMedicalAreaCode'], | |
'population' => $line['ksj:totalPopulationOfBrr'], | |
'area' => $line['ksj:areaOfGsi'], | |
'population15' => $line['ksj:under15YearsOldPopulationOfBrr'], | |
'population1564' => $line['ksj:between15And64YearsOldPopulationOfBrr'], | |
'population65' => $line['ksj:over65YearsOldPopulationOfBrr'] | |
); | |
$this->Zone->save($data); | |
$region_id = str_pad($line['ksj:secondMedicalAreaCode'],4,'0',STR_PAD_LEFT);//2次医療圏idは4桁 | |
for($i = 0; $i < count($xmlArray['Dataset']['gml:Curve']);$i++){ | |
$id = substr($xmlArray['Dataset']['gml:Curve'][$i]['@gml:id'],2);//cvXXXX_0なので最初のcvをとる | |
$id2 = explode("_",$id);//後ろの_0をとる | |
$link = substr($line['ksj:area']['@xlink:href'],3);//#sfXXXXで3文字目から | |
if($id2[0] == $link){ | |
$latlng = explode(" ",$xmlArray['Dataset']['gml:Curve'][$i]['gml:segments']['gml:LineStringSegment']['gml:posList']); | |
for($j = 0; $j < count($latlng);$j+=7){ | |
$data = array( | |
'region_id' => $region_id, | |
'latitude' => $latlng[$j], | |
'longitude' => $latlng[$j+1] | |
); | |
$this->Boundary->create($data); | |
$this->Boundary->save(); | |
} | |
} | |
} | |
} | |
} | |
} | |
$this->redirect(array('action'=>'index')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment