-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathimportfuncs.php
More file actions
executable file
·117 lines (103 loc) · 4.4 KB
/
Copy pathimportfuncs.php
File metadata and controls
executable file
·117 lines (103 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
include_once ('querymap.php');
include_once ('osmtypesstream.php');
include_once ('system.php');
function GetTimeString($sec)
{
if($sec>60.0*60.0*24.0*364.25)
return (string)(round($sec/(60.0*60.0*24.0*364.25)))."yrs";
if($sec>60.0*60.0*24.0*7.0)
return (string)(round($sec/(60.0*60.0*24.0*7.0)))."wks";
if($sec>60.0*60.0*24.0)
return (string)(round($sec/(60.0*60.0*24.0)))."dys";
if($sec>60.0*60.0)
return (string)(round($sec/(60.0*60.0)))."hrs";
if($sec>60.0)
return (string)(round($sec/60.0))."min";
return (string)(round($sec))."sec";
}
function ElementExtracted($el,$progress)
{
global $totalSize, $startTime, $count, $lastPrintOutput;
global $maxidnode, $maxidway, $maxidrelation, $maxidchangeset;
if(is_null($el)) return;
if(is_null($lastPrintOutput) or $lastPrintOutput < microtime(1) - 1.0)
{
$progressFraction = $progress/$totalSize;
$progressPercent = (round(100.0*$progressFraction,2));
$elapseTime = microtime(1) - $startTime;
if($progressFraction > 0.0)
$remaining = (1.0 - $progressFraction) * $elapseTime / ($progressFraction);
else
$remaining = null;
echo $el->GetType()." ".$el->attr['id']."\t".$progressPercent."%";
if(isset($el->attr['name'])) echo "\t".$el->attr['name'];
if(!is_null($remaining)) echo " ".GetTimeString($remaining);
echo "\n";
$lastPrintOutput = microtime(1);
}
$eltype = $el->GetType();
CallFuncByMessage(Message::MODIFY_ELEMENT,array($eltype,$el->attr['id'],$el));
//print_r($el->attr['changeset']);
$count = $count + 1;
if($eltype == "node" and $el->attr['id'] > $maxidnode) $maxidnode = $el->attr['id'];
if($eltype == "way" and $el->attr['id'] > $maxidway) $maxidway = $el->attr['id'];
if($eltype == "relation" and $el->attr['id'] > $maxidrelation) $maxidrelation = $el->attr['id'];
if(isset($el->attr['changeset']) and $el->attr['changeset'] > $maxidchangeset)
$maxidchangeset = $el->attr['changeset'];
}
function Import($filename, $nukeDatabase = 1, $getlock = 1, $originalFilename = null)
{
if($originalFilename == null)
{
$originalFilename = $filename;
}
//Create source object
$xml = new OsmTypesStream();
$xml->callback = 'ElementExtracted';
//Create destination object
if ($getlock) $lock=GetWriteDatabaseLock();
//Get extracted size
echo "Determining size of extracted data...\n";
$extractedSize = new ExtractGetSize();
$done = 0;
if(strcasecmp(substr($originalFilename,strlen($originalFilename)-4),".bz2")==0) {ExtractBz2($filename,$extractedSize);$done = 1;}
if(strcasecmp(substr($originalFilename,strlen($originalFilename)-4),".osm")==0) {ExtractOsmXml($filename,$extractedSize);$done = 1;}
if(strcasecmp(substr($originalFilename,strlen($originalFilename)-3),".gz")==0) {ExtractGz($filename,$extractedSize);$done = 1;}
if(!$done)
{
echo "Could not import file of unknown extension.\n";
exit(0);
}
global $totalSize, $startTime, $count, $lastPrintOutput;
$totalSize = $extractedSize->size;
echo "Extracted size ".$totalSize."\n";
if($nukeDatabase)
{
//Nuke the database
CallFuncByMessage(Message::PURGE_MAP,Null);
}
//Do extraction
$startTime = microtime(1);
$count = 0;
global $maxidnode, $maxidway, $maxidrelation, $maxidchangeset;
$maxidnode = Null; $maxidway = Null; $maxidrelation = Null; $maxidchangeset = Null;
$lastPrintOutput = null;
if(strcasecmp(substr($originalFilename,strlen($originalFilename)-4),".bz2")==0) {ExtractBz2($filename,$xml);}
if(strcasecmp(substr($originalFilename,strlen($originalFilename)-4),".osm")==0) {ExtractOsmXml($filename,$xml);}
if(strcasecmp(substr($originalFilename,strlen($originalFilename)-3),".gz")==0) {ExtractGz($filename,$xml);}
//Check the max ids are lower than new ids
echo "Checking max ids do not exceed new ids...\n";
echo $maxidnode." ".$maxidway." ".$maxidrelation." ".$maxidchangeset."\n";
echo ReadFileNum("nextnodeid.txt")." ".ReadFileNum("nextwayid.txt")." ".ReadFileNum("nextrelationid.txt")." ".ReadFileNum("nextchangesetid.txt")."\n";
if(!is_null($maxidnode) and $maxidnode > ReadFileNum("nextnodeid.txt"))
SetFileNum("nextnodeid.txt",$maxidnode+1);
if(!is_null($maxidway) and $maxidway > ReadFileNum("nextwayid.txt"))
SetFileNum("nextwayid.txt",$maxidway+1);
if(!is_null($maxidrelation) and $maxidrelation > ReadFileNum("nextrelationid.txt"))
SetFileNum("nextrelationid.txt",$maxidrelation+1);
if(!is_null($maxidchangeset) and $maxidchangeset > ReadFileNum("nextchangesetid.txt"))
SetFileNum("nextchangesetid.txt",$maxidchangeset+1);
echo"\n";
}
?>