taxa->taxon->records->record)) { return array (0,""); } //check if there are records in the document to process: //HACK!!! I need to learn how to count with xml_simple... the count property only give you the first one, that is 1 $featureCount = 0; foreach($response->taxa->taxon->records->record as $m) $featureCount++; if ($featureCount > 0) { //common attributes: $scientificName=$response->taxa->taxon->taxonname; //create temporary table $sql.= "CREATE TABLE \"$datasetId\" (fid int8 PRIMARY KEY, scientificName varchar(400), gbifUrl varchar(400), created_when timestamp DEFAULT now()) WITHOUT OIDS;"; //change owner $sql.="\nALTER TABLE \"$datasetId\" OWNER TO postgres; \n"; //Add the geometry column to the table $sql.="SELECT AddGeometryColumn('','$datasetId','the_geom',4326,'POINT',2);\n"; //insert statement per record foreach ($response->taxa->taxon->records->record as $feature) { $foo = split("recordKey=",$feature); $fid= $foo[1]; $sql.="INSERT INTO \"$datasetId\" (fid, scientificName, gbifUrl, the_geom) VALUES ($fid, '".$scientificName."','".$feature."',GeomFromText('POINT(".$feature['long']." ".$feature['lat'].")',4326));\n"; } //create and refresh index $sql.="create index \"fi_$datasetId\" on \"$datasetId\" using GIST (\"the_geom\" GIST_GEOMETRY_OPS);\n"; $sql.="VACUUM ANALYZE \"$datasetId\";\n"; } else { $sql=""; } //echo "
";
	//echo "SQL:\n".$sql;
 	//echo "
"; //exit; //The function will return: // -number of records // -the SQL statement necessary to insert the data in PostGIS return array ($featureCount,$sql); } ?>